import type { HandlerResult, ResultProgressReporter, TextDocumentChangeEvent, WorkDoneProgressReporter } from 'vscode-languageserver'; import type LSP from 'vscode-languageserver-protocol'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import { Constructable, type FactoryRegistration, type InjectionToken, type Scope } from '../di/index.js'; import { ClassDecoratorFunction, CompatibleMethodDecorator, MethodDecoratorFunction } from '../di/types.js'; import type { PublicOnlyIfObject } from '../shared/types.js'; import { CommandId } from './types.js'; import { MaybeAsync } from './utils/index.js'; declare const lspServiceMetadataKey = "__languageServerServiceMetadata__"; declare const lspServiceConstructorMetadataKey = "__isLanguageServerService__"; export interface CommandHandlerMetadata { commandId: CommandId; methodName: string | symbol; handler: CommandMethod; options: CommandOptions; } export type InitializeHandler = (params?: LSP.InitializeParams) => Partial | void; export interface LspServiceInstanceMetadata { commandHandlers: CommandHandlerMetadata[]; initializerHandlers: InitializeHandler[]; textDocumentHandlers: TextDocumentHandlerMetadata[]; notificationHandlers: NotificationHandlerMetadata[]; shutdownHandlers: ShutdownHandler[]; connectionHandlers: ConnectionHandlerMetadata[]; disposables: LSP.Disposable[]; } export type TextDocumentEventName = 'onDidOpen' | 'onDidChangeContent' | 'onDidSave' | 'onDidClose'; export type TextDocumentEventHandler = (event: TextDocumentChangeEvent) => Promise | void; export interface TextDocumentHandlerMetadata { event: TextDocumentEventName; handler: TextDocumentEventHandler; } export type NotificationRegistrationType = LSP.ProtocolNotificationType0 | LSP.ProtocolNotificationType | LSP.NotificationType0 | LSP.NotificationType | string | undefined; export type NotificationMethod = (...args: unknown[]) => Promise | void; export interface NotificationHandlerMetadata { type: NotificationRegistrationType; handler: NotificationMethod; } interface ConnectionHandlerMap { completion: CompletionRequestHandler; codeAction: CodeActionRequestHandler; documentFormatting: DocumentFormattingRequestHandler; } type ConnectionHandlerKind = keyof ConnectionHandlerMap; export type ConnectionHandlerMetadata = { [K in ConnectionHandlerKind]: { kind: K; handler: ConnectionHandlerMap[K]; }; }[ConnectionHandlerKind]; type CompletionRequestHandler = (params: LSP.CompletionParams, token: LSP.CancellationToken, workDone: WorkDoneProgressReporter, resultProgress?: ResultProgressReporter) => Promise; type CodeActionRequestHandler = (params: LSP.CodeActionParams, token: LSP.CancellationToken, workDone: WorkDoneProgressReporter, resultProgress?: ResultProgressReporter<(LSP.Command | LSP.CodeAction)[]>) => Promise<(LSP.Command | LSP.CodeAction)[] | undefined | null>; type DocumentFormattingRequestHandler = (params: LSP.DocumentFormattingParams, token: LSP.CancellationToken, workDone: WorkDoneProgressReporter, resultProgress?: ResultProgressReporter) => Promise; type AsyncNotificationHandler0 = MaybeAsync<() => void>; type AsyncNotificationHandler

= MaybeAsync<(params: P) => void>; type AsyncGenericNotificationHandler = MaybeAsync; type AsyncStarNotificationHandler = MaybeAsync; export type ShutdownHandler = () => void | Promise; export type DecoratedLspServiceConstructor = Constructable & { [lspServiceConstructorMetadataKey]: true; }; /** * Returns if the given instance is of a class decorated as a language server service. */ export declare function isLanguageServerServiceInstance(instance: unknown): instance is { [lspServiceMetadataKey]: LspServiceInstanceMetadata; }; /** * Returns if the given class is decorated as a language server service. */ export declare function isLanguageServerServiceConstructor(target: Constructable): target is Constructable & { __isLanguageServerService__: true; }; /** * Gets the language server service metadata for the given instance. */ export declare function getLanguageServerServiceMetadata(instance: unknown): LspServiceInstanceMetadata | undefined; /** * Decorates a class as being a service that participates in the language server * lifecycle. */ export declare function lspService(): ClassDecoratorFunction; export interface CommandOptions { minArgs?: number; } export type CommandMethod = (...args: any[]) => HandlerResult; /** * Decorator to mark a method as a handler for a specific command ID. * @param commandId The command ID to handle. */ export declare function command(commandId: CommandId, options?: CommandOptions): MethodDecoratorFunction; /** * Decorator to mark a method as an initialization handler. */ export declare function initialize(): CompatibleMethodDecorator; /** * */ export declare function textDocumentEvent(event: TextDocumentEventName): CompatibleMethodDecorator; export declare function notification(type: LSP.ProtocolNotificationType0): CompatibleMethodDecorator; export declare function notification(type: LSP.ProtocolNotificationType): CompatibleMethodDecorator>; export declare function notification(type: LSP.NotificationType0): CompatibleMethodDecorator; export declare function notification

(type: LSP.NotificationType

): CompatibleMethodDecorator>; export declare function notification(type: string): CompatibleMethodDecorator; export declare function notification(): CompatibleMethodDecorator; /** * Marks a method as a handler for a specific completion request. */ export declare function completionRequest(): CompatibleMethodDecorator; /** * Marks a method as a handler for a specific code action request. */ export declare function codeActionRequest(): CompatibleMethodDecorator; /** * Marks a method as a handler for a specific document formatting request. */ export declare function documentFormattingRequest(): CompatibleMethodDecorator; /** * Marks a method as a shutdown handler. */ export declare function shutdown(): CompatibleMethodDecorator; /** * Create a stub with `cls.prototype` in its chain, so `instance.constructor` * points to `cls`. This satisfies `@lspService()` init hooks that check the * constructor for metadata flags. Plain objects from {@link provideTestValue} * fail that check. * * Only copies own enumerable properties from `overrides` via `Object.assign`. * Prototype methods on a fake class will not be copied. Use * {@link provideTestValue} for non-`@lspService()` stubs. */ export declare function createLspServiceStub(cls: abstract new (...args: any[]) => T, overrides: Partial): T; /** * Factory registration wrapper around {@link createLspServiceStub}. Use only * for `@lspService()` tokens. Use {@link provideTestValue} otherwise. */ export declare function provideLspServiceStub(token: InjectionToken & (abstract new (...args: any[]) => T), factory: () => Partial>, scope?: Scope): FactoryRegistration; export {};