diff --git a/packages/langium/src/lsp/language-server.ts b/packages/langium/src/lsp/language-server.ts index f5c45f459..f9fce937d 100644 --- a/packages/langium/src/lsp/language-server.ts +++ b/packages/langium/src/lsp/language-server.ts @@ -42,7 +42,7 @@ import { mergeSignatureHelpOptions } from './signature-help-provider.js'; export interface LanguageServer { initialize(params: InitializeParams): Promise - initialized(params: InitializedParams): Promise + initialized(params: InitializedParams): void onInitialize(callback: (params: InitializeParams) => void): Disposable onInitialized(callback: (params: InitializedParams) => void): Disposable } @@ -182,8 +182,8 @@ export class DefaultLanguageServer implements LanguageServer { return result; } - async initialized(params: InitializedParams): Promise { - await this.fireInitializedOnDefaultServices(params); + initialized(params: InitializedParams): void { + this.fireInitializedOnDefaultServices(params); this.onInitializedEmitter.fire(params); this.onInitializedEmitter.dispose(); @@ -194,7 +194,7 @@ export class DefaultLanguageServer implements LanguageServer { this.services.workspace.WorkspaceManager.initialize(params); } - protected async fireInitializedOnDefaultServices(params: InitializedParams): Promise { + protected fireInitializedOnDefaultServices(params: InitializedParams): void { const connection = this.services.lsp.Connection; const configurationParams = connection ? { ...params, @@ -202,8 +202,10 @@ export class DefaultLanguageServer implements LanguageServer { getConfiguration: params => connection.workspace.getConfiguration(params) } : params; - await this.services.workspace.ConfigurationProvider.initialized(configurationParams); - await this.services.workspace.WorkspaceManager.initialized(params); + this.services.workspace.WorkspaceManager.initialized(params) + .catch(err => console.error('Error in WorkspaceManager initialization:', err)); + this.services.workspace.ConfigurationProvider.initialized(configurationParams) + .catch(err => console.error('Error in ConfigurationProvider initialization:', err)); } } @@ -244,7 +246,7 @@ export function startLanguageServer(services: LangiumSharedServices): void { return services.lsp.LanguageServer.initialize(params); }); connection.onInitialized(params => { - return services.lsp.LanguageServer.initialized(params); + services.lsp.LanguageServer.initialized(params); }); // Make the text document manager listen on the connection for open, change and close text document events. diff --git a/packages/langium/src/services.ts b/packages/langium/src/services.ts index 5ed91b178..288fa0d2f 100644 --- a/packages/langium/src/services.ts +++ b/packages/langium/src/services.ts @@ -6,7 +6,6 @@ // Ensure that all imports are erased at runtime to avoid circular dependencies. import type { IParserErrorMessageProvider } from 'chevrotain'; -import type { InitializeParams, InitializedParams } from 'vscode-languageserver-protocol'; import type { CommentProvider } from './documentation/comment-provider.js'; import type { DocumentationProvider } from './documentation/documentation-provider.js'; import type { Grammar } from './languages/generated/ast.js'; @@ -26,7 +25,6 @@ import type { ScopeProvider } from './references/scope-provider.js'; import type { JsonSerializer } from './serializer/json-serializer.js'; import type { ServiceRegistry } from './service-registry.js'; import type { AstReflection } from './syntax-tree.js'; -import type { MaybePromise } from './utils/promise-utils.js'; import type { DocumentValidator } from './validation/document-validator.js'; import type { ValidationRegistry } from './validation/validation-registry.js'; import type { AstNodeDescriptionProvider, ReferenceDescriptionProvider } from './workspace/ast-descriptions.js'; @@ -40,15 +38,6 @@ import type { WorkspaceLock } from './workspace/workspace-lock.js'; import type { Hydrator } from './serializer/hydrator.js'; import type { WorkspaceManager } from './workspace/workspace-manager.js'; -export type { - InitializeParams, InitializedParams -}; - -export interface InitializableService { - initialize(params: InitializeParams): void - initialized(params: InitializedParams): MaybePromise -} - /** * The services generated by `langium-cli` for a specific language. These are derived from the * grammar definition and the language configuration. diff --git a/packages/langium/src/workspace/configuration.ts b/packages/langium/src/workspace/configuration.ts index 2d1ab2689..c97d083e1 100644 --- a/packages/langium/src/workspace/configuration.ts +++ b/packages/langium/src/workspace/configuration.ts @@ -4,13 +4,29 @@ * terms of the MIT License, which is available in the project root. ******************************************************************************/ -import type { ConfigurationItem, DidChangeConfigurationParams, DidChangeConfigurationRegistrationOptions } from 'vscode-languageserver-protocol'; +import type { + ConfigurationItem, DidChangeConfigurationParams, DidChangeConfigurationRegistrationOptions, InitializeParams, + InitializedParams +} from 'vscode-languageserver-protocol'; import type { ServiceRegistry } from '../service-registry.js'; -import type { InitializableService, InitializeParams, InitializedParams, LangiumSharedCoreServices } from '../services.js'; +import type { LangiumSharedCoreServices } from '../services.js'; /* eslint-disable @typescript-eslint/no-explicit-any */ -export interface ConfigurationProvider extends InitializableService { +export interface ConfigurationProvider { + + /** + * When used in a language server context, this method is called when the server receives + * the `initialize` request. + */ + initialize(params: InitializeParams): void; + + /** + * When used in a language server context, this method is called when the server receives + * the `initialized` notification. + */ + initialized(params: ConfigurationInitializedParams): Promise; + /** * Returns a configuration value stored for the given language. * diff --git a/packages/langium/src/workspace/workspace-manager.ts b/packages/langium/src/workspace/workspace-manager.ts index 730b351ba..77aff2a61 100644 --- a/packages/langium/src/workspace/workspace-manager.ts +++ b/packages/langium/src/workspace/workspace-manager.ts @@ -4,9 +4,10 @@ * terms of the MIT License, which is available in the project root. ******************************************************************************/ +import type { InitializeParams, InitializedParams } from 'vscode-languageserver-protocol'; import type { WorkspaceFolder } from 'vscode-languageserver-types'; import type { ServiceRegistry } from '../service-registry.js'; -import type { InitializableService, InitializeParams, InitializedParams, LangiumSharedCoreServices } from '../services.js'; +import type { LangiumSharedCoreServices } from '../services.js'; import { CancellationToken } from '../utils/cancellation.js'; import { interruptAndCheck } from '../utils/promise-utils.js'; import { URI, UriUtils } from '../utils/uri-utils.js'; @@ -23,11 +24,23 @@ export type { WorkspaceFolder }; * The workspace manager is responsible for finding source files in the workspace. * This service is shared between all languages of a language server. */ -export interface WorkspaceManager extends InitializableService { +export interface WorkspaceManager { /** The options used for the initial workspace build. */ initialBuildOptions: BuildOptions | undefined; + /** + * When used in a language server context, this method is called when the server receives + * the `initialize` request. + */ + initialize(params: InitializeParams): void; + + /** + * When used in a language server context, this method is called when the server receives + * the `initialized` notification. + */ + initialized(params: InitializedParams): Promise; + /** * Does the initial indexing of workspace folders. * Collects information about exported and referenced AstNodes in