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

ImprovedVersionChecking

上级 f0910528
......@@ -75,6 +75,16 @@
"default": null,
"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": {
"type": "string",
"enum": ["off", "messages", "verbose"],
......
......@@ -5,6 +5,8 @@
"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_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.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",
......
......@@ -68,9 +68,8 @@ namespace Trace {
enum MessageAction {
useLocal,
alwaysUseLocal,
useBundled,
doNotCheckAgain
neverCheckLocalVersion
}
interface MyMessageItem extends MessageItem {
......@@ -291,65 +290,69 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
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);
const doLocalVersionCheckKey: string = 'doLocalVersionCheck';
if (!this.tsdk && workspace.rootPath) {
let localModulePath = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
if (fs.existsSync(localModulePath)) {
let localVersion = this.getTypeScriptVersion(localModulePath);
let shippedVersion = this.getTypeScriptVersion(modulePath);
if (localVersion && localVersion !== shippedVersion) {
checkGlobalVersion = false;
versionCheckPromise = window.showInformationMessage<MyMessageItem>(
localize(
'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('useBundled', 'Use {0}', shippedVersion),
id: MessageAction.useBundled,
},
{
title: localize('useAlways', /*'Always use {0}'*/ 'More Information', localVersion),
id: MessageAction.alwaysUseLocal
},
{
title: localize('doNotCheckAgain', 'Don\'t Check Again'),
id: MessageAction.doNotCheckAgain,
isCloseAffordance: true
}
).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:
if (!workspace.rootPath) {
versionCheckPromise = this.informAboutTS20(modulePath);
} else {
if (!this.tsdk && tsConfig.get(checkWorkspaceVersionKey, true)) {
let localModulePath = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
if (fs.existsSync(localModulePath)) {
let localVersion = this.getTypeScriptVersion(localModulePath);
let shippedVersion = this.getTypeScriptVersion(modulePath);
if (localVersion && localVersion !== shippedVersion) {
checkGlobalVersion = false;
versionCheckPromise = window.showInformationMessage<MyMessageItem>(
localize(
'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 Workspace ({0})', localVersion),
id: MessageAction.useLocal
},
{
title: localize('useBundled', 'Use Bundled ({0})', shippedVersion),
id: MessageAction.useBundled,
},
{
title: localize('neverCheckLocalVesion', 'Never Check for Workspace Version'),
id: MessageAction.neverCheckLocalVersion,
isCloseAffordance: true
}
).then((selected) => {
if (!selected) {
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) => {
this.info(`Using tsserver from location: ${modulePath}`);
if (!fs.existsSync(modulePath)) {
......@@ -372,7 +375,12 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
VersionStatus.setInfo(label, tooltip);
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;
try {
let out = cp.execSync('tsc --version', { encoding: 'utf8' });
......@@ -405,6 +413,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
openUrl('http://go.microsoft.com/fwlink/?LinkId=826239');
break;
case 2:
tsConfig.update(checkTscVersion, false, true);
window.showInformationMessage(localize('updateTscCheck', 'Updated user setting \'typescript.check.tscVersion\' to false'));
this.globalState.update(doGlobalVersionCheckKey, false);
break;
}
......@@ -460,13 +470,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
});
}
private informAboutTS20(): void {
private informAboutTS20(modulePath: string): Thenable<string> {
const informAboutTS20: string = 'informAboutTS20';
if (!this.globalState.get(informAboutTS20, false)) {
window.showInformationMessage(
return window.showInformationMessage(
localize(
'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'),
......@@ -477,7 +487,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if (selected && selected.id === 1) {
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.
先完成此消息的编辑!
想要评论请 注册