Make sure more TS commands are disabled when tsgo is active

We need to clear the contexts when switching to tsgo
This commit is contained in:
Matt Bierner
2025-10-16 17:14:38 -07:00
parent af6adc61ce
commit d02b204cb0
4 changed files with 23 additions and 10 deletions

View File

@@ -1632,7 +1632,7 @@
},
{
"command": "typescript.goToProjectConfig",
"when": "editorLangId == typescriptreact"
"when": "editorLangId == typescriptreact && typescript.isManagedFile"
},
{
"command": "javascript.goToProjectConfig",
@@ -1682,7 +1682,7 @@
"editor/context": [
{
"command": "typescript.goToSourceDefinition",
"when": "tsSupportsSourceDefinition && (resourceLangId == typescript || resourceLangId == typescriptreact || resourceLangId == javascript || resourceLangId == javascriptreact)",
"when": "!config.typescript.experimental.useTsgo && tsSupportsSourceDefinition && (resourceLangId == typescript || resourceLangId == typescriptreact || resourceLangId == javascript || resourceLangId == javascriptreact)",
"group": "navigation@1.41"
}
],

View File

@@ -79,11 +79,14 @@ export function register(
client: ITypeScriptServiceClient,
commandManager: CommandManager
) {
function updateContext() {
vscode.commands.executeCommand('setContext', FileReferencesCommand.context, client.apiVersion.gte(FileReferencesCommand.minVersion));
function updateContext(overrideValue?: boolean) {
vscode.commands.executeCommand('setContext', FileReferencesCommand.context, overrideValue ?? client.apiVersion.gte(FileReferencesCommand.minVersion));
}
updateContext();
commandManager.register(new FileReferencesCommand(client));
return client.onTsServerStarted(() => updateContext());
return vscode.Disposable.from(
client.onTsServerStarted(() => updateContext()),
new vscode.Disposable(() => updateContext(false)),
);
}

View File

@@ -80,12 +80,15 @@ class SourceDefinitionCommand implements Command {
export function register(
client: ITypeScriptServiceClient,
commandManager: CommandManager
) {
function updateContext() {
vscode.commands.executeCommand('setContext', SourceDefinitionCommand.context, client.apiVersion.gte(SourceDefinitionCommand.minVersion));
): vscode.Disposable {
function updateContext(overrideValue?: boolean) {
vscode.commands.executeCommand('setContext', SourceDefinitionCommand.context, overrideValue ?? client.apiVersion.gte(SourceDefinitionCommand.minVersion));
}
updateContext();
commandManager.register(new SourceDefinitionCommand(client));
return client.onTsServerStarted(() => updateContext());
return vscode.Disposable.from(
client.onTsServerStarted(() => updateContext()),
new vscode.Disposable(() => updateContext(false)),
);
}

View File

@@ -18,13 +18,20 @@ export default class ManagedFileContextManager extends Disposable {
private isInManagedFileContext: boolean = false;
public constructor(activeJsTsEditorTracker: ActiveJsTsEditorTracker) {
constructor(activeJsTsEditorTracker: ActiveJsTsEditorTracker) {
super();
activeJsTsEditorTracker.onDidChangeActiveJsTsEditor(this.onDidChangeActiveTextEditor, this, this._disposables);
this.onDidChangeActiveTextEditor(activeJsTsEditorTracker.activeJsTsEditor);
}
override dispose() {
// Clear the context
this.updateContext(false);
super.dispose();
}
private onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void {
if (editor) {
this.updateContext(this.isManagedFile(editor));