Skip to content

Commit

Permalink
feat(provider): set extension name on LanguageClient-based registration
Browse files Browse the repository at this point in the history
  • Loading branch information
statiolake committed Aug 3, 2024
1 parent 8382422 commit 867603a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/language-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export namespace MessageTransports {
}

export abstract class BaseLanguageClient implements FeatureClient<Middleware, LanguageClientOptions> {
public registeredExtensionName: string

private _id: string
private _name: string
private _clientOptions: ResolvedClientOptions
Expand Down
1 change: 1 addition & 0 deletions src/language-client/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ import { DidChangeTextDocumentFeatureShape, DidCloseTextDocumentFeatureShape, Di
import { WorkspaceProviderFeature } from './workspaceSymbol'

export interface FeatureClient<M, CO = object> {
registeredExtensionName: string
clientOptions: CO
middleware: M
readonly id: string
Expand Down
6 changes: 3 additions & 3 deletions src/language-client/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
]
}
Expand Down Expand Up @@ -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]
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<void>()
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,
Expand All @@ -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)
Expand Down

0 comments on commit 867603a

Please sign in to comment.