Skip to content

Commit 543cd6e

Browse files
committed
feat: handling custom requests
- add missing `onCustomRequest` method - rename `onCustom` to `onCustomNotification`
1 parent c9fe78a commit 543cd6e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/languageclient.ts

Lines changed: 19 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]: [object, object | null]
2021
}
2122

2223
export type RequestCallback<T extends keyof KnownRequests> = KnownRequests[T] extends [infer U, infer V]
@@ -91,16 +92,32 @@ 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+
// @deprecated Use onCustomNotification method instead
106+
public onCustom(method: string, callback: (obj: object) => void): void {
107+
this.onCustomNotification(method, callback)
108+
}
109+
110+
/**
111+
* Public: Register a callback for a custom request
112+
*
113+
* @param method A string containing the name of the message to listen for.
114+
* @param callback The function to be called when the message is received.
115+
* The payload from the message is passed to the function.
116+
*/
117+
public onCustomRequest(method: string, callback: (obj: object) => Promise<object>): void {
118+
this._onRequest({ method }, callback)
119+
}
120+
104121
/**
105122
* Public: Send a custom request
106123
*

0 commit comments

Comments
 (0)