Skip to content

Commit

Permalink
Allows plugin to register commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed May 27, 2021
1 parent 0e1df66 commit b411c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace ts.server {
export interface PluginModule {
create(createInfo: PluginCreateInfo): LanguageService;
getExternalFiles?(proj: Project): string[];
getProtocolHandlers?(): [command: string, handler: (request: protocol.Request) => HandlerResponse][]
onConfigurationChanged?(config: any): void;
}

Expand Down Expand Up @@ -240,6 +241,15 @@ namespace ts.server {
return result.module;
}

public setupCustomProtocolHandlers (cb: (command: string, handler: (request: protocol.Request) => HandlerResponse) => void) {
this.plugins.forEach(plugin => {
const handlers = plugin.module.getProtocolHandlers?.();
handlers?.forEach(([name, handler]) => {
cb(name, handler)
})
})
}

/*@internal*/
readonly currentDirectory: string;

Expand Down
1 change: 1 addition & 0 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ namespace ts.server {
break;
case ProjectLoadingFinishEvent:
const { project: finishProject } = event.data;
finishProject.setupCustomProtocolHandlers(this.addProtocolHandler.bind(this));
this.event<protocol.ProjectLoadingFinishEventBody>({ projectName: finishProject.getProjectName() }, ProjectLoadingFinishEvent);
break;
case LargeFileReferencedEvent:
Expand Down

0 comments on commit b411c08

Please sign in to comment.