Show text in status bar when Salsa is used, check whether the tsserver supports salsa.
This commit is contained in:
parent
a038512621
commit
7f5ebcd06c
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
@ -127,6 +128,13 @@ 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;
|
||||
}
|
||||
|
||||
let useSalsa = !!process.env['CODE_TSJS'] || !!process.env['VSCODE_TSJS'];
|
||||
if (useSalsa) {
|
||||
let versionOK = this.isTypeScriptVersionOkForSalsa(modulePath);
|
||||
SalsaStatus.show("(Salsa)", modulePath, !versionOK);
|
||||
}
|
||||
|
||||
this.servicePromise = new Promise<cp.ChildProcess>((resolve, reject) => {
|
||||
try {
|
||||
let options: electron.IForkOptions = {
|
||||
|
@ -173,6 +181,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) => {
|
||||
|
|
43
extensions/typescript/src/utils/salsaStatus.ts
Normal file
43
extensions/typescript/src/utils/salsaStatus.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
'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();
|
||||
}
|
Loading…
Reference in a new issue