Skip to content

Commit

Permalink
feat(language-service): expose language service APIs for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 14, 2024
1 parent 1ced8fa commit c117e90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/language-service/lib/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,7 @@ export function createLanguageService(
return `${embeddedContentScheme}://${encodeURIComponent(embeddedContentId)}/${encodeURIComponent(documentUri)}`;
},
};

for (const servicePlugin of servicePlugins) {
context.services.push([servicePlugin, servicePlugin.create(context)]);
}

return {

const api = {
getTriggerCharacters: () => servicePlugins.map(service => service.triggerCharacters ?? []).flat(),
getAutoFormatTriggerCharacters: () => servicePlugins.map(service => service.autoFormatTriggerCharacters ?? []).flat(),
getSignatureHelpTriggerCharacters: () => servicePlugins.map(service => service.signatureHelpTriggerCharacters ?? []).flat(),
Expand Down Expand Up @@ -230,4 +224,8 @@ export function createLanguageService(
dispose: () => context.services.forEach(service => service[1].dispose?.()),
context,
};
for (const servicePlugin of servicePlugins) {
context.services.push([servicePlugin, servicePlugin.create(context, api)]);
}
return api;
}
3 changes: 2 additions & 1 deletion packages/language-service/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as vscode from 'vscode-languageserver-protocol';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import type * as ts from 'typescript';
import type { LinkedCodeMapWithDocument, SourceMapWithDocuments } from './documents';
import type { LanguageService } from './languageService';

export type * from 'vscode-languageserver-protocol';

Expand Down Expand Up @@ -89,7 +90,7 @@ export interface LanguageServicePlugin<P = any> {
signatureHelpTriggerCharacters?: string[];
signatureHelpRetriggerCharacters?: string[];
autoFormatTriggerCharacters?: string[];
create(context: ServiceContext): LanguageServicePluginInstance<P>;
create(context: ServiceContext, languageService: LanguageService): LanguageServicePluginInstance<P>;
}

export interface EmbeddedCodeFormattingOptions {
Expand Down

0 comments on commit c117e90

Please sign in to comment.