From 7e4cc2c435927e5a2845897961a2af10ee7f784d Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 11 Jun 2020 20:05:25 -0700 Subject: [PATCH] Only run specific commands on the syntax server This works better than running all commands on the syntax server by default --- .../src/tsServer/server.ts | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/extensions/typescript-language-features/src/tsServer/server.ts b/extensions/typescript-language-features/src/tsServer/server.ts index 3c37c7e69f3..7faff5b6d71 100644 --- a/extensions/typescript-language-features/src/tsServer/server.ts +++ b/extensions/typescript-language-features/src/tsServer/server.ts @@ -380,7 +380,7 @@ class RequestRouter { } -const syntaxCommands: ReadonlySet = new Set([ +const syntaxAlwaysCommands: ReadonlySet = new Set([ 'navtree', 'getOutliningSpans', 'jsxClosingTag', @@ -407,7 +407,7 @@ export class SyntaxRoutingTsServer extends Disposable implements ITypeScriptServ this.router = new RequestRouter( [ - { server: this.syntaxServer, canRun: (command) => syntaxCommands.has(command) }, + { server: this.syntaxServer, canRun: (command) => syntaxAlwaysCommands.has(command) }, { server: this.semanticServer, canRun: undefined /* gets all other commands */ } ], delegate); @@ -527,12 +527,33 @@ export class GetErrRoutingTsServer extends Disposable implements ITypeScriptServ export class ProjectLoadingRoutingSyntaxTsServer extends Disposable implements ITypeScriptServer { + /** + * Commands that should always be run on the semantic server. + */ private static readonly semanticCommands = new Set([ 'geterr', 'geterrForProject', 'projectInfo' ]); + /** + * Commands that can be run on the syntax server but would benefit from being upgraded to the semantic server. + */ + private syntaxAllowedCommands = new Set([ + 'completions', + 'completionEntryDetails', + 'completionInfo', + 'definition', + 'definitionAndBoundSpan', + 'documentHighlights', + 'implementation', + 'navto', + 'quickinfo', + 'references', + 'rename', + 'signatureHelp', + ]); + private readonly syntaxServer: ITypeScriptServer; private readonly semanticServer: ITypeScriptServer; private readonly router: RequestRouter; @@ -553,13 +574,13 @@ export class ProjectLoadingRoutingSyntaxTsServer extends Disposable implements I { server: this.syntaxServer, canRun: (command) => { - if (syntaxCommands.has(command)) { + if (syntaxAlwaysCommands.has(command)) { return true; } if (ProjectLoadingRoutingSyntaxTsServer.semanticCommands.has(command)) { return false; } - if (this._projectLoading) { + if (this.projectLoading && this.syntaxAllowedCommands.has(command)) { return true; } return false; @@ -600,6 +621,8 @@ export class ProjectLoadingRoutingSyntaxTsServer extends Disposable implements I this._register(this.semanticServer.onError(e => this._onError.fire(e))); } + private get projectLoading() { return this._projectLoading; } + private readonly _onEvent = this._register(new vscode.EventEmitter()); public readonly onEvent = this._onEvent.event;