Skip to content

Commit 9409378

Browse files
authored
Merge pull request #129 from laughedelic/feat/onCustomRequest
2 parents 3ae9809 + 0370365 commit 9409378

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lib/languageclient.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface KnownNotifications {
1717
export interface KnownRequests {
1818
"window/showMessageRequest": [lsp.ShowMessageRequestParams, lsp.MessageActionItem | null]
1919
"workspace/applyEdit": [lsp.ApplyWorkspaceEditParams, lsp.ApplyWorkspaceEditResponse]
20+
[custom: string]: [Record<string, any>, Record<string, any> | null]
2021
}
2122

2223
export type RequestCallback<T extends keyof KnownRequests> = KnownRequests[T] extends [infer U, infer V]
@@ -91,16 +92,37 @@ export class LanguageClientConnection extends EventEmitter {
9192
}
9293

9394
/**
94-
* Public: Register a callback for a custom message.
95+
* Public: Register a callback for a custom notification
9596
*
9697
* @param method A string containing the name of the message to listen for.
9798
* @param callback The function to be called when the message is received.
9899
* The payload from the message is passed to the function.
99100
*/
100-
public onCustom(method: string, callback: (obj: object) => void): void {
101+
public onCustomNotification(method: string, callback: (obj: object) => void): void {
101102
this._onNotification({ method }, callback)
102103
}
103104

105+
/**
106+
* @deprecated Use `onCustomNotification` method instead
107+
*/
108+
public onCustom(method: string, callback: (obj: object) => void): void {
109+
this.onCustomNotification(method, callback)
110+
}
111+
112+
/**
113+
* Public: Register a callback for a custom request
114+
*
115+
* @param method A string containing the name of the message to listen for.
116+
* @param callback The function to be called when the message is received.
117+
* The payload from the message is passed to the function.
118+
*/
119+
public onCustomRequest(
120+
method: string,
121+
callback: (obj: Record<string, any>) => Promise<Record<string, any> | null>
122+
): void {
123+
this._onRequest({ method }, callback)
124+
}
125+
104126
/**
105127
* Public: Send a custom request
106128
*

0 commit comments

Comments
 (0)