diff --git a/src/language-client/client.ts b/src/language-client/client.ts index 7f4406be71b..4f25a5bf2f5 100644 --- a/src/language-client/client.ts +++ b/src/language-client/client.ts @@ -263,6 +263,8 @@ export namespace MessageTransports { } export abstract class BaseLanguageClient implements FeatureClient { + public registeredExtensionName: string + private _id: string private _name: string private _clientOptions: ResolvedClientOptions diff --git a/src/language-client/features.ts b/src/language-client/features.ts index 97464debe01..1692847b4c3 100644 --- a/src/language-client/features.ts +++ b/src/language-client/features.ts @@ -599,6 +599,7 @@ import { DidChangeTextDocumentFeatureShape, DidCloseTextDocumentFeatureShape, Di import { WorkspaceProviderFeature } from './workspaceSymbol' export interface FeatureClient { + registeredExtensionName: string clientOptions: CO middleware: M readonly id: string diff --git a/src/language-client/formatting.ts b/src/language-client/formatting.ts index eb9d4a254d4..97482691c55 100644 --- a/src/language-client/formatting.ts +++ b/src/language-client/formatting.ts @@ -6,7 +6,7 @@ import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, On import { DocumentFormattingRequest, DocumentOnTypeFormattingRequest, DocumentRangeFormattingRequest } from '../util/protocol' -import { ensure, FeatureClient, TextDocumentLanguageFeature } from './features' +import { FeatureClient, TextDocumentLanguageFeature, ensure } from './features' import * as cv from './utils/converter' import * as UUID from './utils/uuid' @@ -121,7 +121,7 @@ export class DocumentFormattingFeature extends TextDocumentLanguageFeature< } return [ - languages.registerDocumentFormatProvider(options.documentSelector!, provider, this._client.clientOptions.formatterPriority), + languages.registerDocumentFormatProvider(options.documentSelector!, provider, this._client.clientOptions.formatterPriority, this._client.registeredExtensionName), provider ] } @@ -176,7 +176,7 @@ export class DocumentRangeFormattingFeature extends TextDocumentLanguageFeature< } } - return [languages.registerDocumentRangeFormatProvider(options.documentSelector, provider), provider] + return [languages.registerDocumentRangeFormatProvider(options.documentSelector, provider, undefined, this._client.registeredExtensionName), provider] } } diff --git a/src/languages.ts b/src/languages.ts index d37f1ec485a..eed8061a70d 100644 --- a/src/languages.ts +++ b/src/languages.ts @@ -244,13 +244,13 @@ class Languages { return this.workspaceSymbolsManager.register(provider) } - public registerDocumentFormatProvider(selector: DocumentSelector, provider: DocumentFormattingEditProvider, priority = 0): Disposable { - const extensionName = parseExtensionName(Error().stack) + public registerDocumentFormatProvider(selector: DocumentSelector, provider: DocumentFormattingEditProvider, priority = 0, extensionName?: string): Disposable { + extensionName = extensionName ?? parseExtensionName(Error().stack) return this.formatManager.register(extensionName, selector, provider, priority) } - public registerDocumentRangeFormatProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider, priority = 0): Disposable { - const extensionName = parseExtensionName(Error().stack) + public registerDocumentRangeFormatProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider, priority = 0, extensionName?: string): Disposable { + extensionName = extensionName ?? parseExtensionName(Error().stack) return this.formatRangeManager.register(extensionName, selector, provider, priority) } diff --git a/src/services.ts b/src/services.ts index e437352a266..1d8b5302903 100644 --- a/src/services.ts +++ b/src/services.ts @@ -14,6 +14,7 @@ import { toObject } from './util/object' import { CancellationToken, Disposable, Emitter, Event } from './util/protocol' import window from './window' import workspace from './workspace' +import { parseExtensionName } from './util/extensionRegistry' const logger = createLogger('services') export enum ServiceStat { @@ -277,12 +278,15 @@ class ServiceManager implements Disposable { public registerLanguageClient(client: LanguageClient): Disposable public registerLanguageClient(name: string, config: LanguageServerConfig, folder?: URI): Disposable public registerLanguageClient(name: string | LanguageClient, config?: LanguageServerConfig, folder?: URI): Disposable { + const registeredExtensionName = parseExtensionName(Error().stack) + let id = typeof name === 'string' ? `languageserver.${name}` : name.id let disposables: Disposable[] = [] let onDidServiceReady = new Emitter() let client: LanguageClient | null = typeof name === 'string' ? null : name if (this.registered.has(id)) return Disposable.create(() => {}) if (client && typeof client.dispose === 'function') disposables.push(client) + if (client) client.registeredExtensionName = registeredExtensionName let created = false let service: IServiceProvider = { id, @@ -298,6 +302,7 @@ class ServiceManager implements Disposable { let opts = getLanguageServerOptions(id, name, config, folder) if (!opts || config.enable === false) return client = new LanguageClient(id, name, opts[1], opts[0]) + client.registeredExtensionName = registeredExtensionName service.selector = opts[0].documentSelector service.client = client disposables.push(client)