Factor in workspace trust when switching versions (#117774)
This commit is contained in:
parent
f84aa806e4
commit
8fd4a68845
|
@ -9,6 +9,7 @@
|
|||
"license": "MIT",
|
||||
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
|
||||
"enableProposedApi": true,
|
||||
"requiresWorkspaceTrust": "onDemand",
|
||||
"engines": {
|
||||
"vscode": "^1.30.0"
|
||||
},
|
||||
|
|
|
@ -32,9 +32,16 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
this._currentVersion = this.versionProvider.defaultVersion;
|
||||
|
||||
if (this.useWorkspaceTsdkSetting) {
|
||||
const localVersion = this.versionProvider.localVersion;
|
||||
if (localVersion) {
|
||||
this._currentVersion = localVersion;
|
||||
if (vscode.workspace.trustState === vscode.WorkspaceTrustState.Unknown) {
|
||||
setImmediate(() => {
|
||||
vscode.workspace.requireWorkspaceTrust(false);
|
||||
});
|
||||
}
|
||||
if (this.isWorkspaceTrusted) {
|
||||
const localVersion = this.versionProvider.localVersion;
|
||||
if (localVersion) {
|
||||
this._currentVersion = localVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +51,16 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
});
|
||||
}
|
||||
|
||||
this._register(vscode.workspace.onDidChangeWorkspaceTrustState((event: vscode.WorkspaceTrustStateChangeEvent) => {
|
||||
if (this.useWorkspaceTsdkSetting) {
|
||||
if (event.currentTrustState === vscode.WorkspaceTrustState.Trusted) {
|
||||
this.updateActiveVersion(this.versionProvider.localVersion ?? this.versionProvider.defaultVersion);
|
||||
} else {
|
||||
this.updateActiveVersion(this.versionProvider.defaultVersion);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private readonly _onDidPickNewVersion = this._register(new vscode.EventEmitter<void>());
|
||||
|
@ -86,7 +103,7 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
private getBundledPickItem(): QuickPickItem {
|
||||
const bundledVersion = this.versionProvider.defaultVersion;
|
||||
return {
|
||||
label: (!this.useWorkspaceTsdkSetting
|
||||
label: (!this.useWorkspaceTsdkSetting || !this.isWorkspaceTrusted
|
||||
? '• '
|
||||
: '') + localize('useVSCodeVersionOption', "Use VS Code's Version"),
|
||||
description: bundledVersion.displayName,
|
||||
|
@ -101,16 +118,19 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
private getLocalPickItems(): QuickPickItem[] {
|
||||
return this.versionProvider.localVersions.map(version => {
|
||||
return {
|
||||
label: (this.useWorkspaceTsdkSetting && this.currentVersion.eq(version)
|
||||
label: (this.useWorkspaceTsdkSetting && this.isWorkspaceTrusted && this.currentVersion.eq(version)
|
||||
? '• '
|
||||
: '') + localize('useWorkspaceVersionOption', "Use Workspace Version"),
|
||||
description: version.displayName,
|
||||
detail: version.pathLabel,
|
||||
run: async () => {
|
||||
await this.workspaceState.update(useWorkspaceTsdkStorageKey, true);
|
||||
const tsConfig = vscode.workspace.getConfiguration('typescript');
|
||||
await tsConfig.update('tsdk', version.pathLabel, false);
|
||||
this.updateActiveVersion(version);
|
||||
const trustState = await vscode.workspace.requireWorkspaceTrust();
|
||||
if (trustState === vscode.WorkspaceTrustState.Trusted) {
|
||||
await this.workspaceState.update(useWorkspaceTsdkStorageKey, true);
|
||||
const tsConfig = vscode.workspace.getConfiguration('typescript');
|
||||
await tsConfig.update('tsdk', version.pathLabel, false);
|
||||
this.updateActiveVersion(version);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@ -149,6 +169,10 @@ export class TypeScriptVersionManager extends Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
private get isWorkspaceTrusted(): boolean {
|
||||
return vscode.workspace.trustState === vscode.WorkspaceTrustState.Trusted;
|
||||
}
|
||||
|
||||
private get useWorkspaceTsdkSetting(): boolean {
|
||||
return this.workspaceState.get<boolean>(useWorkspaceTsdkStorageKey, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue