@lspeasy/server 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/capability-guard.d.ts +2 -26
- package/dist/capability-guard.d.ts.map +1 -1
- package/dist/capability-guard.js +35 -171
- package/dist/capability-guard.js.map +1 -1
- package/dist/capability-proxy.js.map +1 -1
- package/dist/dispatcher.d.ts +46 -7
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +46 -7
- package/dist/dispatcher.js.map +1 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -1
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/progress/partial-result-sender.d.ts +30 -1
- package/dist/progress/partial-result-sender.d.ts.map +1 -1
- package/dist/progress/partial-result-sender.js +30 -1
- package/dist/progress/partial-result-sender.js.map +1 -1
- package/dist/progress.js.map +1 -1
- package/dist/server.d.ts +168 -12
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +114 -12
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +102 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -3
- package/dist/types.js.map +1 -1
- package/dist/validation.js.map +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ const transport = new StdioTransport();
|
|
|
49
49
|
await server.listen(transport);
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## What You Get
|
|
53
53
|
|
|
54
54
|
- **Type-Safe Handlers**: Fully typed request and notification handlers with IntelliSense support
|
|
55
55
|
- **Automatic Validation**: Built-in parameter validation using Zod schemas
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for server handlers
|
|
3
3
|
*
|
|
4
|
-
* Ensures handlers can only be registered for declared capabilities
|
|
4
|
+
* Ensures handlers can only be registered for declared server capabilities,
|
|
5
|
+
* and that server-to-client messages respect declared client capabilities.
|
|
5
6
|
*/
|
|
6
7
|
import type { ClientCapabilities, ServerCapabilities } from '@lspeasy/core';
|
|
7
8
|
import type { Logger } from '@lspeasy/core';
|
|
@@ -14,15 +15,7 @@ export declare class CapabilityGuard {
|
|
|
14
15
|
private readonly logger;
|
|
15
16
|
private readonly strict;
|
|
16
17
|
constructor(capabilities: Partial<ServerCapabilities>, logger: Logger, strict?: boolean);
|
|
17
|
-
/**
|
|
18
|
-
* Check if handler registration is allowed for this method
|
|
19
|
-
*
|
|
20
|
-
* @param method - LSP method name
|
|
21
|
-
* @returns true if allowed, false otherwise
|
|
22
|
-
* @throws Error if strict mode enabled and capability not declared
|
|
23
|
-
*/
|
|
24
18
|
canRegisterHandler(method: string): boolean;
|
|
25
|
-
getAllowedMethods(): string[];
|
|
26
19
|
}
|
|
27
20
|
/**
|
|
28
21
|
* Validates that server-to-client messages respect declared client capabilities
|
|
@@ -32,25 +25,8 @@ export declare class ClientCapabilityGuard {
|
|
|
32
25
|
private readonly logger;
|
|
33
26
|
private readonly strict;
|
|
34
27
|
constructor(capabilities: Partial<ClientCapabilities>, logger: Logger, strict?: boolean);
|
|
35
|
-
/**
|
|
36
|
-
* Check if a request can be sent to the client
|
|
37
|
-
*
|
|
38
|
-
* @param method - LSP method name
|
|
39
|
-
* @returns true if allowed, false otherwise
|
|
40
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
41
|
-
*/
|
|
42
28
|
canSendRequest(method: string): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Check if a notification can be sent to the client
|
|
45
|
-
*
|
|
46
|
-
* @param method - LSP method name
|
|
47
|
-
* @returns true if allowed, false otherwise
|
|
48
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
49
|
-
*/
|
|
50
29
|
canSendNotification(method: string): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Get list of capabilities the client declared
|
|
53
|
-
*/
|
|
54
30
|
getClientCapabilities(): Partial<ClientCapabilities>;
|
|
55
31
|
}
|
|
56
32
|
//# sourceMappingURL=capability-guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-guard.d.ts","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capability-guard.d.ts","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa5C;;;GAGG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHzB,YACmB,YAAY,EAAE,OAAO,CAAC,kBAAkB,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAe,EACtC;IAEJ,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAe1C;CACF;AAED;;GAEG;AACH,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHzB,YACmB,YAAY,EAAE,OAAO,CAAC,kBAAkB,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAe,EACtC;IAEJ,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAWtC;IAED,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAW3C;IAED,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAEnD;CACF"}
|
package/dist/capability-guard.js
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for server handlers
|
|
3
3
|
*
|
|
4
|
-
* Ensures handlers can only be registered for declared capabilities
|
|
4
|
+
* Ensures handlers can only be registered for declared server capabilities,
|
|
5
|
+
* and that server-to-client messages respect declared client capabilities.
|
|
5
6
|
*/
|
|
6
|
-
import {
|
|
7
|
-
function buildMethodSets(capabilityKey) {
|
|
8
|
-
const all = new Set();
|
|
9
|
-
const alwaysAllowed = new Set();
|
|
10
|
-
for (const namespaceDefinitions of Object.values(LSPRequest)) {
|
|
11
|
-
for (const definition of Object.values(namespaceDefinitions)) {
|
|
12
|
-
const entry = definition;
|
|
13
|
-
all.add(entry.Method);
|
|
14
|
-
if (!entry[capabilityKey]) {
|
|
15
|
-
alwaysAllowed.add(entry.Method);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
for (const namespaceDefinitions of Object.values(LSPNotification)) {
|
|
20
|
-
for (const definition of Object.values(namespaceDefinitions)) {
|
|
21
|
-
const entry = definition;
|
|
22
|
-
all.add(entry.Method);
|
|
23
|
-
if (!entry[capabilityKey]) {
|
|
24
|
-
alwaysAllowed.add(entry.Method);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return { all, alwaysAllowed };
|
|
29
|
-
}
|
|
30
|
-
const SERVER_METHODS = buildMethodSets('ServerCapability');
|
|
31
|
-
const CLIENT_METHODS = buildMethodSets('ClientCapability');
|
|
7
|
+
import { SERVER_METHODS, CLIENT_METHODS, checkMethod, getClientCapabilityForNotificationMethod, getClientCapabilityForRequestMethod, hasServerCapability, hasClientCapability, getCapabilityForNotificationMethod, getCapabilityForRequestMethod } from '@lspeasy/core';
|
|
32
8
|
/**
|
|
33
9
|
* Validates that a handler can be registered for a method
|
|
34
10
|
* based on declared server capabilities
|
|
@@ -42,66 +18,19 @@ export class CapabilityGuard {
|
|
|
42
18
|
this.logger = logger;
|
|
43
19
|
this.strict = strict;
|
|
44
20
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Check if handler registration is allowed for this method
|
|
47
|
-
*
|
|
48
|
-
* @param method - LSP method name
|
|
49
|
-
* @returns true if allowed, false otherwise
|
|
50
|
-
* @throws Error if strict mode enabled and capability not declared
|
|
51
|
-
*/
|
|
52
21
|
canRegisterHandler(method) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (SERVER_METHODS.alwaysAllowed.has(method)) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
// Check if method requires a capability (try both request and notification)
|
|
69
|
-
let capabilityKey = getCapabilityForRequestMethod(method);
|
|
70
|
-
if (!capabilityKey) {
|
|
71
|
-
capabilityKey = getCapabilityForNotificationMethod(method);
|
|
72
|
-
}
|
|
73
|
-
if (!capabilityKey) {
|
|
74
|
-
// Unknown method - allow in non-strict mode
|
|
75
|
-
if (!this.strict) {
|
|
76
|
-
this.logger.debug(`Unknown method ${method}, allowing in non-strict mode`);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
const error = `Cannot register handler for unknown method: ${method}`;
|
|
80
|
-
this.logger.error(error);
|
|
81
|
-
if (this.strict) {
|
|
82
|
-
throw new Error(error);
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (capabilityKey === 'alwaysOn') {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
// Check if capability is declared
|
|
90
|
-
if (!hasServerCapability(this.capabilities, capabilityKey)) {
|
|
91
|
-
const error = `Cannot register handler for ${method}: server capability '${capabilityKey}' not declared`;
|
|
92
|
-
this.logger.warn(error);
|
|
93
|
-
if (this.strict) {
|
|
94
|
-
throw new Error(error);
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
getAllowedMethods() {
|
|
101
|
-
// This would require iterating through all LSP methods
|
|
102
|
-
// For now, return an empty array - can be enhanced if needed
|
|
103
|
-
this.logger.warn('getAllowedMethods not fully implemented - returns empty array');
|
|
104
|
-
return [];
|
|
22
|
+
return checkMethod({
|
|
23
|
+
method,
|
|
24
|
+
methodSets: SERVER_METHODS,
|
|
25
|
+
getCapabilityKey: (m) => {
|
|
26
|
+
return (getCapabilityForRequestMethod(m) ?? getCapabilityForNotificationMethod(m));
|
|
27
|
+
},
|
|
28
|
+
hasCapability: (key) => hasServerCapability(this.capabilities, key),
|
|
29
|
+
actionLabel: 'register handler',
|
|
30
|
+
capabilityLabel: 'server capability',
|
|
31
|
+
logger: this.logger,
|
|
32
|
+
strict: this.strict
|
|
33
|
+
});
|
|
105
34
|
}
|
|
106
35
|
}
|
|
107
36
|
/**
|
|
@@ -116,95 +45,30 @@ export class ClientCapabilityGuard {
|
|
|
116
45
|
this.logger = logger;
|
|
117
46
|
this.strict = strict;
|
|
118
47
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Check if a request can be sent to the client
|
|
121
|
-
*
|
|
122
|
-
* @param method - LSP method name
|
|
123
|
-
* @returns true if allowed, false otherwise
|
|
124
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
125
|
-
*/
|
|
126
48
|
canSendRequest(method) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
const capabilityKey = getClientCapabilityForRequestMethod(method);
|
|
140
|
-
if (!capabilityKey) {
|
|
141
|
-
if (!this.strict) {
|
|
142
|
-
this.logger.debug(`Unknown request method ${method}, allowing in non-strict mode`);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
const error = `Cannot send request for unknown method: ${method}`;
|
|
146
|
-
this.logger.error(error);
|
|
147
|
-
throw new Error(error);
|
|
148
|
-
}
|
|
149
|
-
if (capabilityKey === 'alwaysOn') {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
153
|
-
const error = `Cannot send request ${method}: client capability '${capabilityKey}' not declared`;
|
|
154
|
-
this.logger.warn(error);
|
|
155
|
-
if (this.strict) {
|
|
156
|
-
throw new Error(error);
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
return true;
|
|
49
|
+
return checkMethod({
|
|
50
|
+
method,
|
|
51
|
+
methodSets: CLIENT_METHODS,
|
|
52
|
+
getCapabilityKey: (m) => getClientCapabilityForRequestMethod(m),
|
|
53
|
+
hasCapability: (key) => hasClientCapability(this.capabilities, key),
|
|
54
|
+
actionLabel: 'send request',
|
|
55
|
+
capabilityLabel: 'client capability',
|
|
56
|
+
logger: this.logger,
|
|
57
|
+
strict: this.strict
|
|
58
|
+
});
|
|
161
59
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Check if a notification can be sent to the client
|
|
164
|
-
*
|
|
165
|
-
* @param method - LSP method name
|
|
166
|
-
* @returns true if allowed, false otherwise
|
|
167
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
168
|
-
*/
|
|
169
60
|
canSendNotification(method) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
const capabilityKey = getClientCapabilityForNotificationMethod(method);
|
|
183
|
-
if (!capabilityKey) {
|
|
184
|
-
if (!this.strict) {
|
|
185
|
-
this.logger.debug(`Unknown notification method ${method}, allowing in non-strict mode`);
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
const error = `Cannot send notification for unknown method: ${method}`;
|
|
189
|
-
this.logger.error(error);
|
|
190
|
-
throw new Error(error);
|
|
191
|
-
}
|
|
192
|
-
if (capabilityKey === 'alwaysOn') {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
196
|
-
const error = `Cannot send notification ${method}: client capability '${capabilityKey}' not declared`;
|
|
197
|
-
this.logger.warn(error);
|
|
198
|
-
if (this.strict) {
|
|
199
|
-
throw new Error(error);
|
|
200
|
-
}
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
61
|
+
return checkMethod({
|
|
62
|
+
method,
|
|
63
|
+
methodSets: CLIENT_METHODS,
|
|
64
|
+
getCapabilityKey: (m) => getClientCapabilityForNotificationMethod(m),
|
|
65
|
+
hasCapability: (key) => hasClientCapability(this.capabilities, key),
|
|
66
|
+
actionLabel: 'send notification',
|
|
67
|
+
capabilityLabel: 'client capability',
|
|
68
|
+
logger: this.logger,
|
|
69
|
+
strict: this.strict
|
|
70
|
+
});
|
|
204
71
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Get list of capabilities the client declared
|
|
207
|
-
*/
|
|
208
72
|
getClientCapabilities() {
|
|
209
73
|
return { ...this.capabilities };
|
|
210
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-guard.js","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capability-guard.js","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,wCAAwC,EACxC,mCAAmC,EACnC,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,6BAA6B,EAC9B,MAAM,eAAe,CAAC;AAEvB;;;GAGG;AACH,MAAM,OAAO,eAAe;IAEP,YAAY;IACZ,MAAM;IACN,MAAM;IAHzB,YACmB,YAAyC,EACzC,MAAc,EACd,MAAM,GAAY,KAAK;4BAFvB,YAAY;sBACZ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AC,CAAC,EAAE,EAAE,CAAC,wCAAwC,CAAC,CAAQ,CAAC;YAC3E,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAU,CAAC;YAC1E,WAAW,EAAE,mBAAmB;YAChC,eAAe,EAAE,mBAAmB;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;IAED,qBAAqB;QACnB,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-proxy.js","sourceRoot":"","sources":["../src/capability-proxy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAA+B
|
|
1
|
+
{"version":3,"file":"capability-proxy.js","sourceRoot":"","sources":["../src/capability-proxy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAA+B;IAE/B,MAAM,YAAY,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAEpD,gDAAgD;IAChD,KAAK,MAAM,CAAC,aAAa,EAAE,oBAAoB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/E,MAAM,kBAAkB,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,SAAS,GAAG,EAAS,CAAC;QAE5B,KAAK,MAA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AAC,SAAS,KAAK,MAAM,EAAE,CAAC;gBACnE,SAAS;YACX,CAAC;YAED,qBAAqB;YACrB,MAAM,cAAc,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;YAC5C,SAAS,CAAC,cAAc,CAAC,GAAG,KAAK,WAAW,MAAW;gBACrD,OAAQ,MAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC9D,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/dispatcher.d.ts
CHANGED
|
@@ -4,7 +4,26 @@
|
|
|
4
4
|
import type { Message, Transport, Logger, ClientCapabilities } from '@lspeasy/core';
|
|
5
5
|
import type { RequestHandler, NotificationHandler } from './types.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Routes incoming JSON-RPC requests and notifications to their registered handlers.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* `MessageDispatcher` is an internal component of `LSPServer`. It maintains
|
|
11
|
+
* separate handler registries for requests (which require a response) and
|
|
12
|
+
* notifications (fire-and-forget), and handles cancellation via `AbortController`.
|
|
13
|
+
*
|
|
14
|
+
* Most users should interact with `LSPServer.onRequest` / `LSPServer.onNotification`
|
|
15
|
+
* instead of using `MessageDispatcher` directly.
|
|
16
|
+
*
|
|
17
|
+
* @never
|
|
18
|
+
* NEVER register the same method in both the request and notification handler
|
|
19
|
+
* registries — the dispatcher uses separate lookup tables and the method will
|
|
20
|
+
* only match one path, silently ignoring the other.
|
|
21
|
+
*
|
|
22
|
+
* NEVER call `dispatch` before calling `setClientCapabilities` if your handler
|
|
23
|
+
* reads `context.clientCapabilities` — the value will be `undefined` until
|
|
24
|
+
* the `initialize` request is processed.
|
|
25
|
+
*
|
|
26
|
+
* @category Server
|
|
8
27
|
*/
|
|
9
28
|
export declare class MessageDispatcher {
|
|
10
29
|
private readonly logger;
|
|
@@ -14,19 +33,33 @@ export declare class MessageDispatcher {
|
|
|
14
33
|
private clientCapabilities?;
|
|
15
34
|
constructor(logger: Logger);
|
|
16
35
|
/**
|
|
17
|
-
* Register a request handler
|
|
36
|
+
* Register a typed request handler for the given LSP method.
|
|
37
|
+
*
|
|
38
|
+
* @param method - The LSP method string (e.g. `'textDocument/hover'`).
|
|
39
|
+
* @param handler - The handler function to invoke for matching requests.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link RequestHandler} for the handler signature.
|
|
18
42
|
*/
|
|
19
43
|
registerRequest<Params, Result>(method: string, handler: RequestHandler<Params, Result>): void;
|
|
20
44
|
/**
|
|
21
|
-
* Register a notification handler
|
|
45
|
+
* Register a typed notification handler for the given LSP method.
|
|
46
|
+
*
|
|
47
|
+
* @param method - The LSP method string (e.g. `'textDocument/didOpen'`).
|
|
48
|
+
* @param handler - The handler function to invoke for matching notifications.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link NotificationHandler} for the handler signature.
|
|
22
51
|
*/
|
|
23
52
|
registerNotification<Params>(method: string, handler: NotificationHandler<Params>): void;
|
|
24
53
|
/**
|
|
25
|
-
* Unregister a request handler
|
|
54
|
+
* Unregister a request handler.
|
|
55
|
+
*
|
|
56
|
+
* @param method - The LSP method string whose handler should be removed.
|
|
26
57
|
*/
|
|
27
58
|
unregisterRequest(method: string): void;
|
|
28
59
|
/**
|
|
29
|
-
* Unregister a notification handler
|
|
60
|
+
* Unregister a notification handler.
|
|
61
|
+
*
|
|
62
|
+
* @param method - The LSP method string whose handler should be removed.
|
|
30
63
|
*/
|
|
31
64
|
unregisterNotification(method: string): void;
|
|
32
65
|
/**
|
|
@@ -34,14 +67,20 @@ export declare class MessageDispatcher {
|
|
|
34
67
|
*/
|
|
35
68
|
setClientCapabilities(capabilities: ClientCapabilities): void;
|
|
36
69
|
/**
|
|
37
|
-
* Dispatch an incoming message
|
|
70
|
+
* Dispatch an incoming message to the registered handler.
|
|
71
|
+
*
|
|
72
|
+
* @param message - The incoming JSON-RPC message to route.
|
|
73
|
+
* @param transport - The transport to send the response or error on.
|
|
74
|
+
* @param cancellationTokens - Map of pending request IDs to their `AbortController`s.
|
|
38
75
|
*/
|
|
39
76
|
dispatch(message: Message, transport: Transport, cancellationTokens: Map<number | string, AbortController>): Promise<void>;
|
|
40
77
|
private dispatchRequest;
|
|
41
78
|
private dispatchNotification;
|
|
42
79
|
private sendError;
|
|
43
80
|
/**
|
|
44
|
-
* Cancel a pending request
|
|
81
|
+
* Cancel a pending request.
|
|
82
|
+
*
|
|
83
|
+
* @param id - The request ID to cancel.
|
|
45
84
|
*/
|
|
46
85
|
cancelRequest(id: number | string): void;
|
|
47
86
|
/**
|
package/dist/dispatcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,OAAO,EAGP,SAAS,EAET,MAAM,EACN,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAEpB
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,OAAO,EAGP,SAAS,EAET,MAAM,EACN,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,iBAAiB;IAUhB,OAAO,CAAC,QAAQ,CAAC,MAAM;IATnC,OAAO,CAAC,eAAe,CAInB;IACJ,OAAO,CAAC,oBAAoB,CAA+D;IAC3F,OAAO,CAAC,eAAe,CAA+C;IACtE,OAAO,CAAC,kBAAkB,CAAC,CAAqB;IAEhD,YAA6B,MAAM,EAAE,MAAM,EAAI;IAE/C;;;;;;;OAOG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAG7F;IAED;;;;;;;OAOG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,IAAI,CAGvF;IAED;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED;;;;OAIG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAG3C;IAED;;OAEG;IACH,qBAAqB,CAAC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAE5D;IAED;;;;;;OAMG;IACG,QAAQ,CACZ,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,eAAe,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAMf;YAKa,eAAe;YA8Df,oBAAoB;YAuBpB,SAAS;IAgBvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOvC;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAIZ;CACF"}
|
package/dist/dispatcher.js
CHANGED
|
@@ -4,7 +4,26 @@
|
|
|
4
4
|
import { ResponseError, isRequestMessage, isNotificationMessage } from '@lspeasy/core';
|
|
5
5
|
import { HandlerRegistry } from '@lspeasy/core/utils';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Routes incoming JSON-RPC requests and notifications to their registered handlers.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* `MessageDispatcher` is an internal component of `LSPServer`. It maintains
|
|
11
|
+
* separate handler registries for requests (which require a response) and
|
|
12
|
+
* notifications (fire-and-forget), and handles cancellation via `AbortController`.
|
|
13
|
+
*
|
|
14
|
+
* Most users should interact with `LSPServer.onRequest` / `LSPServer.onNotification`
|
|
15
|
+
* instead of using `MessageDispatcher` directly.
|
|
16
|
+
*
|
|
17
|
+
* @never
|
|
18
|
+
* NEVER register the same method in both the request and notification handler
|
|
19
|
+
* registries — the dispatcher uses separate lookup tables and the method will
|
|
20
|
+
* only match one path, silently ignoring the other.
|
|
21
|
+
*
|
|
22
|
+
* NEVER call `dispatch` before calling `setClientCapabilities` if your handler
|
|
23
|
+
* reads `context.clientCapabilities` — the value will be `undefined` until
|
|
24
|
+
* the `initialize` request is processed.
|
|
25
|
+
*
|
|
26
|
+
* @category Server
|
|
8
27
|
*/
|
|
9
28
|
export class MessageDispatcher {
|
|
10
29
|
logger;
|
|
@@ -16,28 +35,42 @@ export class MessageDispatcher {
|
|
|
16
35
|
this.logger = logger;
|
|
17
36
|
}
|
|
18
37
|
/**
|
|
19
|
-
* Register a request handler
|
|
38
|
+
* Register a typed request handler for the given LSP method.
|
|
39
|
+
*
|
|
40
|
+
* @param method - The LSP method string (e.g. `'textDocument/hover'`).
|
|
41
|
+
* @param handler - The handler function to invoke for matching requests.
|
|
42
|
+
*
|
|
43
|
+
* @see {@link RequestHandler} for the handler signature.
|
|
20
44
|
*/
|
|
21
45
|
registerRequest(method, handler) {
|
|
22
46
|
this.requestHandlers.register(method, handler);
|
|
23
47
|
this.logger.debug(`Registered request handler: ${method}`);
|
|
24
48
|
}
|
|
25
49
|
/**
|
|
26
|
-
* Register a notification handler
|
|
50
|
+
* Register a typed notification handler for the given LSP method.
|
|
51
|
+
*
|
|
52
|
+
* @param method - The LSP method string (e.g. `'textDocument/didOpen'`).
|
|
53
|
+
* @param handler - The handler function to invoke for matching notifications.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link NotificationHandler} for the handler signature.
|
|
27
56
|
*/
|
|
28
57
|
registerNotification(method, handler) {
|
|
29
58
|
this.notificationHandlers.register(method, handler);
|
|
30
59
|
this.logger.debug(`Registered notification handler: ${method}`);
|
|
31
60
|
}
|
|
32
61
|
/**
|
|
33
|
-
* Unregister a request handler
|
|
62
|
+
* Unregister a request handler.
|
|
63
|
+
*
|
|
64
|
+
* @param method - The LSP method string whose handler should be removed.
|
|
34
65
|
*/
|
|
35
66
|
unregisterRequest(method) {
|
|
36
67
|
this.requestHandlers.unregister(method);
|
|
37
68
|
this.logger.debug(`Unregistered request handler: ${method}`);
|
|
38
69
|
}
|
|
39
70
|
/**
|
|
40
|
-
* Unregister a notification handler
|
|
71
|
+
* Unregister a notification handler.
|
|
72
|
+
*
|
|
73
|
+
* @param method - The LSP method string whose handler should be removed.
|
|
41
74
|
*/
|
|
42
75
|
unregisterNotification(method) {
|
|
43
76
|
this.notificationHandlers.unregister(method);
|
|
@@ -50,7 +83,11 @@ export class MessageDispatcher {
|
|
|
50
83
|
this.clientCapabilities = capabilities;
|
|
51
84
|
}
|
|
52
85
|
/**
|
|
53
|
-
* Dispatch an incoming message
|
|
86
|
+
* Dispatch an incoming message to the registered handler.
|
|
87
|
+
*
|
|
88
|
+
* @param message - The incoming JSON-RPC message to route.
|
|
89
|
+
* @param transport - The transport to send the response or error on.
|
|
90
|
+
* @param cancellationTokens - Map of pending request IDs to their `AbortController`s.
|
|
54
91
|
*/
|
|
55
92
|
async dispatch(message, transport, cancellationTokens) {
|
|
56
93
|
if (isRequestMessage(message)) {
|
|
@@ -152,7 +189,9 @@ export class MessageDispatcher {
|
|
|
152
189
|
}
|
|
153
190
|
}
|
|
154
191
|
/**
|
|
155
|
-
* Cancel a pending request
|
|
192
|
+
* Cancel a pending request.
|
|
193
|
+
*
|
|
194
|
+
* @param id - The request ID to cancel.
|
|
156
195
|
*/
|
|
157
196
|
cancelRequest(id) {
|
|
158
197
|
const controller = this.pendingRequests.get(id);
|
package/dist/dispatcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA;;GAE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AC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LSP server package for hosting Language Server Protocol (LSP) servers.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Use `@lspeasy/server` when you need to build the **provider** side of the
|
|
6
|
+
* Language Server Protocol — a daemon that editors and language-client tooling
|
|
7
|
+
* connect to in order to get diagnostics, completions, hover, go-to-definition,
|
|
8
|
+
* and other language intelligence features.
|
|
9
|
+
*
|
|
10
|
+
* The primary entry point is {@link LSPServer}. Construct it with
|
|
11
|
+
* {@link ServerOptions}, call `registerCapabilities(caps)` to declare what
|
|
12
|
+
* the server supports, register handlers with `onRequest` / `onNotification`,
|
|
13
|
+
* then call `listen(transport)` to accept the first client connection.
|
|
14
|
+
*
|
|
15
|
+
* ### Transport Decision Tree
|
|
16
|
+
*
|
|
17
|
+
* **Stdio** (`StdioTransport` from `@lspeasy/core/node`)
|
|
18
|
+
* — Use when: the client spawns your server as a child process (the canonical
|
|
19
|
+
* VS Code extension pattern). No network, no port management. Failure mode:
|
|
20
|
+
* `ConsoleLogger` writes to stdout and corrupts the LSP stream — always use
|
|
21
|
+
* `NullLogger` or a file-based logger with stdio.
|
|
22
|
+
*
|
|
23
|
+
* **WebSocket** (`WebSocketTransport` from `@lspeasy/core`)
|
|
24
|
+
* — Use when: multiple clients connect over a network, or the server must be
|
|
25
|
+
* browser-accessible. Each accepted WebSocket connection needs its own
|
|
26
|
+
* `LSPServer` instance. Failure mode: one client crash should not affect
|
|
27
|
+
* others — wrap each `wss.on('connection')` callback in try/catch and
|
|
28
|
+
* create a fresh `LSPServer` per socket.
|
|
29
|
+
*
|
|
30
|
+
* **TCP** (`TcpTransport` from `@lspeasy/core/node`)
|
|
31
|
+
* — Use when: building a persistent local daemon (e.g. a formatting server
|
|
32
|
+
* shared across editor sessions). Failure mode: client disconnect fires
|
|
33
|
+
* `close()` on the server instance — use `mode: 'server'` and create a new
|
|
34
|
+
* `LSPServer` on each reconnect.
|
|
35
|
+
*
|
|
36
|
+
* **DedicatedWorkerTransport** (`DedicatedWorkerTransport` from `@lspeasy/core`)
|
|
37
|
+
* — Use when: running the server logic in a Web Worker for in-process browser
|
|
38
|
+
* isolation. Zero serialization overhead. Failure mode: worker crash is
|
|
39
|
+
* silent from the server side — monitor the worker's `onerror` in the host.
|
|
40
|
+
*
|
|
41
|
+
* ### Typed capability namespaces
|
|
42
|
+
* After `registerCapabilities({ hoverProvider: true })`, TypeScript exposes
|
|
43
|
+
* `server.textDocument.onHover(handler)` — methods that are absent unless the
|
|
44
|
+
* corresponding capability is declared. This prevents accidentally registering
|
|
45
|
+
* handlers for capabilities the server never advertised.
|
|
46
|
+
*
|
|
47
|
+
* ### Handler conventions
|
|
48
|
+
* - {@link RequestHandler} — async, throws {@link ResponseError} for
|
|
49
|
+
* structured errors, checks `token.isCancellationRequested` for early exit.
|
|
50
|
+
* - {@link NotificationHandler} — fire-and-forget; unhandled rejections
|
|
51
|
+
* surface via `server.onError()`.
|
|
52
|
+
*
|
|
53
|
+
* @packageDocumentation
|
|
3
54
|
*/
|
|
4
55
|
export { LSPServer } from './server.js';
|
|
5
56
|
export type { ServerOptions, RequestHandler, NotificationHandler, NotebookDocumentHandlerNamespace, RequestContext, NotificationContext, Server } from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,YAAY,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,gCAAgC,EAChC,cAAc,EACd,mBAAmB,EACnB,MAAM,EACP,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAG1E,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,MAAM,EACN,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,KAAK,EACL,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,UAAU,EAEV,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|