Skip to content

Commit

Permalink
wip: Config.plugins -> Config.services
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 25, 2023
1 parent 2c8a783 commit bf22f74
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
12 changes: 6 additions & 6 deletions packages/language-server/src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function startCommonLanguageServer(connection: vscode.Connection, getCtx:

configurationHost = initParams.capabilities.workspace?.configuration ? createConfigurationHost(initParams, connection) : undefined;

let lsPlugins: Config['plugins'] = {};
let services: Config['services'] = {};
for (const root of roots) {
if (root.scheme === 'file') {
let config = loadConfig(root.path, options.configFilePath) ?? {};
Expand All @@ -76,10 +76,10 @@ export function startCommonLanguageServer(connection: vscode.Connection, getCtx:
config = plugin.resolveConfig(config, undefined);
}
}
if (config.plugins) {
lsPlugins = {
...lsPlugins,
...config.plugins,
if (config.services) {
services = {
...services,
...config.services,
};
}
}
Expand All @@ -90,7 +90,7 @@ export function startCommonLanguageServer(connection: vscode.Connection, getCtx:
options,
plugins,
getSemanticTokensLegend(),
lsPlugins,
services,
);

await createLanguageServiceHost();
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/common/utils/registerFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export function setupCapabilities(
initOptions: LanguageServerInitializationOptions,
plugins: ReturnType<LanguageServerPlugin>[],
semanticTokensLegend: vscode.SemanticTokensLegend,
lsPlugins: NonNullable<Config['plugins']>,
services: NonNullable<Config['services']>,
) {

const lsPluginInstances = Object.values(lsPlugins)
const lsPluginInstances = Object.values(services)
.map(plugin => typeof plugin === 'function' ? plugin() : plugin)
.filter((plugin): plugin is NonNullable<typeof plugin> => !!plugin);
const serverMode = initOptions.serverMode ?? ServerMode.Semantic;
Expand Down
12 changes: 4 additions & 8 deletions packages/language-service/src/baseLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,10 @@ function createLanguageServicePluginContext(
getTextDocument,
};

for (const pluginId in ctx.config.plugins ?? {}) {
const plugin = ctx.config.plugins?.[pluginId];
if (plugin instanceof Function) {
const _plugin = plugin(context);
context.plugins[pluginId] = _plugin;
}
else if (plugin) {
context.plugins[pluginId] = plugin;
for (const serviceId in ctx.config.services ?? {}) {
const service = ctx.config.services?.[serviceId];
if (service) {
context.plugins[serviceId] = service(context);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export interface RuleFix {

export interface Config {
languages?: { [id: string]: LanguageModule | undefined; };
plugins?: { [id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined; };
services?: { [id: string]: LanguageServicePlugin | undefined; };
lint?: {
rules?: { [id: string]: Rule | undefined; };
severities?: { [id: string]: vscode.DiagnosticSeverity; };
Expand Down

0 comments on commit bf22f74

Please sign in to comment.