提交 03d79160 编写于 作者: D Dirk Baeumer

ImprovedVersionChecking

上级 f0910528
...@@ -75,6 +75,16 @@ ...@@ -75,6 +75,16 @@
"default": null, "default": null,
"description": "%typescript.tsdk.desc%" "description": "%typescript.tsdk.desc%"
}, },
"typescript.check.workspaceVersion" :{
"type": "boolean",
"default": true,
"description": "%typescript.check.workspaceVersion%"
},
"typescript.check.tscVersion" :{
"type": "boolean",
"default": true,
"description": "%typescript.check.tscVersion%"
},
"typescript.tsserver.trace": { "typescript.tsserver.trace": {
"type": "string", "type": "string",
"enum": ["off", "messages", "verbose"], "enum": ["off", "messages", "verbose"],
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
"typescript.useCodeSnippetsOnMethodSuggest.dec": "Complete functions with their parameter signature.", "typescript.useCodeSnippetsOnMethodSuggest.dec": "Complete functions with their parameter signature.",
"typescript.tsdk.desc": "Specifies the folder path containing the tsserver and lib*.d.ts files to use.", "typescript.tsdk.desc": "Specifies the folder path containing the tsserver and lib*.d.ts files to use.",
"typescript.tsdk_version.desc": "Specifies the version of the tsserver. Only necessary if the tsserver is not installed using npm.", "typescript.tsdk_version.desc": "Specifies the version of the tsserver. Only necessary if the tsserver is not installed using npm.",
"typescript.check.workspaceVersion": "Check if a TypeScript version is available in the workspace",
"typescript.check.tscVersion": "Check if a global install TypeScript compiler (e.g. tsc) differs from the used TypeScript language service.",
"typescript.tsserver.trace": "Enables tracing of messages send to the TS server", "typescript.tsserver.trace": "Enables tracing of messages send to the TS server",
"typescript.tsserver.experimentalAutoBuild": "Enables experimental auto build. Requires 1.9 dev or 2.x tsserver version and a restart of VS Code after changing it.", "typescript.tsserver.experimentalAutoBuild": "Enables experimental auto build. Requires 1.9 dev or 2.x tsserver version and a restart of VS Code after changing it.",
"typescript.validate.enable": "Enable / disable TypeScript validation", "typescript.validate.enable": "Enable / disable TypeScript validation",
......
...@@ -68,9 +68,8 @@ namespace Trace { ...@@ -68,9 +68,8 @@ namespace Trace {
enum MessageAction { enum MessageAction {
useLocal, useLocal,
alwaysUseLocal,
useBundled, useBundled,
doNotCheckAgain neverCheckLocalVersion
} }
interface MyMessageItem extends MessageItem { interface MyMessageItem extends MessageItem {
...@@ -291,65 +290,69 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -291,65 +290,69 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
modulePath = path.join(workspace.rootPath, this.tsdk, 'tsserver.js'); modulePath = path.join(workspace.rootPath, this.tsdk, 'tsserver.js');
} }
} }
const tsConfig = workspace.getConfiguration('typescript');
const checkWorkspaceVersionKey = 'check.workspaceVersion';
let versionCheckPromise: Thenable<string> = Promise.resolve(modulePath); let versionCheckPromise: Thenable<string> = Promise.resolve(modulePath);
const doLocalVersionCheckKey: string = 'doLocalVersionCheck';
if (!workspace.rootPath) {
if (!this.tsdk && workspace.rootPath) { versionCheckPromise = this.informAboutTS20(modulePath);
let localModulePath = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js'); } else {
if (fs.existsSync(localModulePath)) { if (!this.tsdk && tsConfig.get(checkWorkspaceVersionKey, true)) {
let localVersion = this.getTypeScriptVersion(localModulePath); let localModulePath = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
let shippedVersion = this.getTypeScriptVersion(modulePath); if (fs.existsSync(localModulePath)) {
if (localVersion && localVersion !== shippedVersion) { let localVersion = this.getTypeScriptVersion(localModulePath);
checkGlobalVersion = false; let shippedVersion = this.getTypeScriptVersion(modulePath);
versionCheckPromise = window.showInformationMessage<MyMessageItem>( if (localVersion && localVersion !== shippedVersion) {
localize( checkGlobalVersion = false;
'localTSFound', versionCheckPromise = window.showInformationMessage<MyMessageItem>(
'The workspace folder contains TypeScript version {0}. Do you want to use this version instead of the bundled version {1}?', localize(
localVersion, shippedVersion 'localTSFound',
), 'The workspace folder contains TypeScript version {0}. Do you want to use this version instead of the bundled version {1}?',
{ localVersion, shippedVersion
title: localize('use', 'Use {0}', localVersion), ),
id: MessageAction.useLocal {
}, title: localize('use', 'Use Workspace ({0})', localVersion),
{ id: MessageAction.useLocal
title: localize('useBundled', 'Use {0}', shippedVersion), },
id: MessageAction.useBundled, {
}, title: localize('useBundled', 'Use Bundled ({0})', shippedVersion),
{ id: MessageAction.useBundled,
title: localize('useAlways', /*'Always use {0}'*/ 'More Information', localVersion), },
id: MessageAction.alwaysUseLocal {
}, title: localize('neverCheckLocalVesion', 'Never Check for Workspace Version'),
{ id: MessageAction.neverCheckLocalVersion,
title: localize('doNotCheckAgain', 'Don\'t Check Again'), isCloseAffordance: true
id: MessageAction.doNotCheckAgain, }
isCloseAffordance: true ).then((selected) => {
} if (!selected) {
).then((selected) => {
if (!selected) {
return modulePath;
}
switch(selected.id) {
case MessageAction.useLocal:
showVersionStatusItem = true;
return localModulePath;
case MessageAction.alwaysUseLocal:
window.showInformationMessage(localize('continueWithVersion', 'Continuing with version {0}', shippedVersion));
openUrl('http://go.microsoft.com/fwlink/?LinkId=826239');
return modulePath;
case MessageAction.useBundled:
return modulePath;
case MessageAction.doNotCheckAgain:
this.globalState.update(doLocalVersionCheckKey, false);
return modulePath;
default:
return modulePath; return modulePath;
} }
}); switch(selected.id) {
case MessageAction.useLocal:
let pathValue = './node_modules/typescript/lib';
tsConfig.update('tsdk', pathValue, false);
window.showInformationMessage(localize('updatedtsdk', 'Updated workspace setting \'typescript.tsdk\' to {0}', pathValue));
showVersionStatusItem = true;
return localModulePath;
case MessageAction.useBundled:
tsConfig.update(checkWorkspaceVersionKey, false, false);
window.showInformationMessage(localize('updateLocalWorkspaceCheck', 'Updated workspace setting \'typescript.check.workspaceVersion\' to false'));
return modulePath;
case MessageAction.neverCheckLocalVersion:
window.showInformationMessage(localize('updateGlobalWorkspaceCheck', 'Updated user setting \'typescript.check.workspaceVersion\' to false'));
tsConfig.update(checkWorkspaceVersionKey, false, true);
return modulePath;
default:
return modulePath;
}
});
}
} else {
versionCheckPromise = this.informAboutTS20(modulePath);
} }
} else {
this.informAboutTS20();
} }
} }
versionCheckPromise.then((modulePath) => { versionCheckPromise.then((modulePath) => {
this.info(`Using tsserver from location: ${modulePath}`); this.info(`Using tsserver from location: ${modulePath}`);
if (!fs.existsSync(modulePath)) { if (!fs.existsSync(modulePath)) {
...@@ -372,7 +375,12 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -372,7 +375,12 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
VersionStatus.setInfo(label, tooltip); VersionStatus.setInfo(label, tooltip);
const doGlobalVersionCheckKey: string = 'doGlobalVersionCheck'; const doGlobalVersionCheckKey: string = 'doGlobalVersionCheck';
if (checkGlobalVersion && this.globalState.get(doGlobalVersionCheckKey, true)) { const globalStateValue = this.globalState.get(doGlobalVersionCheckKey, true);
const checkTscVersion = 'check.tscVersion';
if (!globalStateValue) {
tsConfig.update(checkTscVersion, false, true);
}
if (checkGlobalVersion && tsConfig.get(checkTscVersion)) {
let tscVersion: string = undefined; let tscVersion: string = undefined;
try { try {
let out = cp.execSync('tsc --version', { encoding: 'utf8' }); let out = cp.execSync('tsc --version', { encoding: 'utf8' });
...@@ -405,6 +413,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -405,6 +413,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
openUrl('http://go.microsoft.com/fwlink/?LinkId=826239'); openUrl('http://go.microsoft.com/fwlink/?LinkId=826239');
break; break;
case 2: case 2:
tsConfig.update(checkTscVersion, false, true);
window.showInformationMessage(localize('updateTscCheck', 'Updated user setting \'typescript.check.tscVersion\' to false'));
this.globalState.update(doGlobalVersionCheckKey, false); this.globalState.update(doGlobalVersionCheckKey, false);
break; break;
} }
...@@ -460,13 +470,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -460,13 +470,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
}); });
} }
private informAboutTS20(): void { private informAboutTS20(modulePath: string): Thenable<string> {
const informAboutTS20: string = 'informAboutTS20'; const informAboutTS20: string = 'informAboutTS20';
if (!this.globalState.get(informAboutTS20, false)) { if (!this.globalState.get(informAboutTS20, false)) {
window.showInformationMessage( return window.showInformationMessage(
localize( localize(
'tsversion20', 'tsversion20',
'VS Code version 1.6 ships with TypeScript version 2.0.x. If you have to use a previous version of typescript set the \'typescript.tsdk\' option.' 'VS Code 1.6 ships with TypeScript version 2.0.3. If you want to use a previous version of TypeScript set the \'typescript.tsdk\' option.'
), ),
{ {
title: localize('moreInformation', 'More Information'), title: localize('moreInformation', 'More Information'),
...@@ -477,7 +487,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -477,7 +487,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if (selected && selected.id === 1) { if (selected && selected.id === 1) {
openUrl('https://go.microsoft.com/fwlink/?LinkID=533483#vscode'); openUrl('https://go.microsoft.com/fwlink/?LinkID=533483#vscode');
} }
return modulePath;
}); });
} else {
return Promise.resolve(modulePath);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册