Skip to content

Commit

Permalink
Merge pull request #34 from mscolnick/ms/33
Browse files Browse the repository at this point in the history
improvement: make LanguageServerClient more easily inheritable
  • Loading branch information
hjr265 authored Feb 11, 2025
2 parents d8c88a4 + acf6220 commit 0e3d934
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export class LanguageServerClient {
this.initializePromise = this.initialize();
}

public async initialize() {
const { capabilities } = await this.request("initialize", {
protected getInitializationOptions(): LSP.InitializeParams["initializationOptions"] {
return {
capabilities: {
textDocument: {
hover: {
Expand Down Expand Up @@ -179,7 +179,15 @@ export class LanguageServerClient {
processId: null,
rootUri: this.rootUri,
workspaceFolders: this.workspaceFolders,
}, timeout * 3);
}
}

public async initialize() {
const { capabilities } = await this.request(
"initialize",
this.getInitializationOptions(),
timeout * 3,
);
this.capabilities = capabilities;
this.notify("initialized", {});
this.ready = true;
Expand Down Expand Up @@ -216,22 +224,22 @@ export class LanguageServerClient {
if (this.autoClose) { this.close(); }
}

private request<K extends keyof LSPRequestMap>(
protected request<K extends keyof LSPRequestMap>(
method: K,
params: LSPRequestMap[K][0],
timeout: number,
): Promise<LSPRequestMap[K][1]> {
return this.client.request({ method, params }, timeout);
}

private notify<K extends keyof LSPNotifyMap>(
protected notify<K extends keyof LSPNotifyMap>(
method: K,
params: LSPNotifyMap[K],
): Promise<LSPNotifyMap[K]> {
return this.client.notify({ method, params });
}

private processNotification(notification: Notification) {
protected processNotification(notification: Notification) {
for (const plugin of this.plugins) {
plugin.processNotification(notification);
}
Expand Down

0 comments on commit 0e3d934

Please sign in to comment.