Merge branch 'salsa-status'

This commit is contained in:
Dirk Baeumer 2016-01-22 10:05:36 +01:00
commit 3b3bba341f
3 changed files with 90 additions and 2 deletions

View file

@ -9,7 +9,7 @@
* ------------------------------------------------------------------------------------------ */
'use strict';
import { languages, commands, workspace, Uri, ExtensionContext, IndentAction, Diagnostic, DiagnosticCollection, Range } from 'vscode';
import { languages, commands, workspace, window, Uri, ExtensionContext, IndentAction, Diagnostic, DiagnosticCollection, Range } from 'vscode';
import * as Proto from './protocol';
import TypeScriptServiceClient from './typescriptServiceClient';
@ -29,6 +29,8 @@ import BufferSyncSupport from './features/bufferSyncSupport';
import CompletionItemProvider from './features/completionItemProvider';
import WorkspaceSymbolProvider from './features/workspaceSymbolProvider';
import * as SalsaStatus from './utils/salsaStatus';
export function activate(context: ExtensionContext): void {
let MODE_ID_TS = 'typescript';
@ -42,6 +44,9 @@ export function activate(context: ExtensionContext): void {
context.subscriptions.push(commands.registerCommand('typescript.reloadProjects', () => {
clientHost.reloadProjects();
}));
window.onDidChangeActiveTextEditor(SalsaStatus.showHideStatus, null, context.subscriptions);
// Register the supports for both TS and TSX so that we can have separate grammars but share the mode
client.onReady().then(() => {
registerSupports(MODE_ID_TS, clientHost, client);

View file

@ -16,6 +16,7 @@ import { workspace, window, Uri, CancellationToken } from 'vscode';
import * as Proto from './protocol';
import { ITypescriptServiceClient, ITypescriptServiceClientHost } from './typescriptService';
import * as SalsaStatus from './utils/salsaStatus';
let isWin = /^win/.test(process.platform);
let isDarwin = /^darwin/.test(process.platform);
@ -111,13 +112,15 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
private startService(resendModels: boolean = false): void {
let modulePath = path.join(__dirname, '..', 'server', 'typescript', 'lib', 'tsserver.js');
let useSalsa = !!process.env['CODE_TSJS'] || !!process.env['VSCODE_TSJS'];
if (this.tsdk) {
if ((<any>path).isAbsolute(this.tsdk)) {
modulePath = path.join(this.tsdk, 'tsserver.js');
} else if (workspace.rootPath) {
modulePath = path.join(workspace.rootPath, this.tsdk, 'tsserver.js');
}
} else if (!!process.env['CODE_TSJS'] || !!process.env['VSCODE_TSJS']) {
} else if (useSalsa) {
let candidate = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
if (fs.existsSync(candidate)) {
modulePath = candidate;
@ -127,6 +130,18 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
window.showErrorMessage(`The path ${path.dirname(modulePath)} doesn't point to a valid tsserver install. TypeScript language features will be disabled.`);
return;
}
if (useSalsa) {
let versionOK = this.isTypeScriptVersionOkForSalsa(modulePath);
let tooltip = modulePath;
if (!versionOK) {
tooltip = `${tooltip} does not support Salsa!`;
} else {
tooltip = `${tooltip} does support Salsa.`;
}
SalsaStatus.show('(Salsa)', tooltip, !versionOK);
}
this.servicePromise = new Promise<cp.ChildProcess>((resolve, reject) => {
try {
let options: electron.IForkOptions = {
@ -173,6 +188,30 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
}
}
private isTypeScriptVersionOkForSalsa(serverPath: string): boolean {
let p = serverPath.split(path.sep);
if (p.length <= 2) {
return true; // assume OK, cannot check
}
let p2 = p.slice(0, -2);
let modulePath = p2.join(path.sep);
let fileName = path.join(modulePath, 'package.json');
if (!fs.existsSync(fileName)) {
return true; // assume OK, cannot check
}
let contents = fs.readFileSync(fileName).toString();
let desc = null;
try {
desc = JSON.parse(contents);
} catch(err) {
return true;
}
if (!desc.version) {
return true;
}
return desc.version.indexOf('1.8') >= 0;
}
private serviceExited(restart: boolean): void {
this.servicePromise = null;
Object.keys(this.callbacks).forEach((key) => {

View file

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import vscode = require('vscode');
let statusBarEntry: vscode.StatusBarItem;
export function showHideStatus() {
if (!statusBarEntry) {
return;
}
if (!vscode.window.activeTextEditor) {
statusBarEntry.hide();
return;
}
let doc = vscode.window.activeTextEditor.document;
if (vscode.languages.match('javascript', doc) || vscode.languages.match('javascriptreact', doc)) {
statusBarEntry.show();
return;
}
statusBarEntry.hide();
}
export function disposeStatus() {
if (statusBarEntry) {
statusBarEntry.dispose();
}
}
export function show(message: string, tooltip: string, error: boolean) {
statusBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
statusBarEntry.text = message;
statusBarEntry.tooltip = tooltip;
let color = 'yellow';
if (error) {
color = 'red';
}
statusBarEntry.color = color;
statusBarEntry.show();
}