Skip to content

Commit

Permalink
Add API so that extensions can configure TS Server plugins
Browse files Browse the repository at this point in the history
Fixes #63181

This is a replacement for the `_typescript.configurePlugin` command. Using a command, it is easy to forget to check if the js-ts extension is active before executing it. Using an actual api prevents this  and also allows better typing
  • Loading branch information
mjbvz committed Nov 19, 2018
1 parent 848010a commit 575e163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions extensions/typescript-language-features/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { PluginManager } from './utils/plugins';

interface ApiV0 {
readonly onCompletionAccepted: vscode.Event<vscode.CompletionItem & { metadata?: any }>;
class ApiV0 {
public constructor(
public readonly onCompletionAccepted: vscode.Event<vscode.CompletionItem & { metadata?: any }>,
private readonly _pluginManager: PluginManager,
) { }

configurePlugin(pluginId: string, configuration: {}): void {
this._pluginManager.setConfiguration(pluginId, configuration);
}
}

export interface Api {
getAPI(version: 0): ApiV0 | undefined;
}

export function getExtensionApi(
onCompletionAccepted: vscode.Event<vscode.CompletionItem>
onCompletionAccepted: vscode.Event<vscode.CompletionItem>,
pluginManager: PluginManager,
): Api {
return {
getAPI(version) {
if (version === 0) {
return {
onCompletionAccepted: onCompletionAccepted
} as ApiV0;
return new ApiV0(onCompletionAccepted, pluginManager);
}
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/typescript-language-features/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function activate(
}
}

return getExtensionApi(onCompletionAccepted.event);
return getExtensionApi(onCompletionAccepted.event, pluginManager);
}

function createLazyClientHost(
Expand Down

0 comments on commit 575e163

Please sign in to comment.