Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@
"onCommand:javascript.goToProjectConfig",
"onCommand:typescript.goToProjectConfig",
"onCommand:typescript.openTsServerLog",
"onTaskType:typescript",
"onCommand:typescript.tsserverRequest",
"onCommand:_typescript.configurePlugin",
"onCommand:_typescript.learnMoreAboutRefactorings",
"onCommand:typescript.fileReferences",
"onTaskType:typescript",
"onLanguage:jsonc"
],
"main": "./out/extension",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as vscode from 'vscode';
export interface Command {
readonly id: string;

execute(...args: any[]): void;
execute(...args: any[]): void | any;
}

export class CommandManager {
Expand Down
2 changes: 2 additions & 0 deletions extensions/typescript-language-features/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { OpenTsServerLogCommand } from './openTsServerLog';
import { ReloadJavaScriptProjectsCommand, ReloadTypeScriptProjectsCommand } from './reloadProject';
import { RestartTsServerCommand } from './restartTsServer';
import { SelectTypeScriptVersionCommand } from './selectTypeScriptVersion';
import { TSServerRequestCommand } from './tsserverRequests';

export function registerBaseCommands(
commandManager: CommandManager,
Expand All @@ -31,4 +32,5 @@ export function registerBaseCommands(
commandManager.register(new JavaScriptGoToProjectConfigCommand(activeJsTsEditorTracker, lazyClientHost));
commandManager.register(new ConfigurePluginCommand(pluginManager));
commandManager.register(new LearnMoreAboutRefactoringsCommand());
commandManager.register(new TSServerRequestCommand(lazyClientHost));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TypeScriptRequests } from '../typescriptService';
import TypeScriptServiceClientHost from '../typeScriptServiceClientHost';
import { nulToken } from '../utils/cancellation';
import { Lazy } from '../utils/lazy';
import { Command } from './commandManager';

export class TSServerRequestCommand implements Command {
public readonly id = 'typescript.tsserverRequest';

public constructor(
private readonly lazyClientHost: Lazy<TypeScriptServiceClientHost>
) { }

public execute(requestID: keyof TypeScriptRequests, args?: any, config?: any) {
// A cancellation token cannot be passed through the command infrastructure
const token = nulToken;

// The list can be found in the TypeScript compiler as `const enum CommandTypes`,
// to avoid extensions making calls which could affect the internal tsserver state
// these are only read-y sorts of commands
const allowList = [
// Seeing the JS/DTS output for a file
'emit-output',
// Grabbing a file's diagnostics
'semanticDiagnosticsSync',
'syntacticDiagnosticsSync',
'suggestionDiagnosticsSync',
// Introspecting code at a position
'quickinfo',
'quickinfo-full',
'completionInfo'
];

if (!allowList.includes(requestID)) { return; }
return this.lazyClientHost.value.serviceClient.execute(requestID, args, token, config);
}
}