Skip to content

Commit 1f603f4

Browse files
authored
Fixes #1488: _WindowMiddleware - wrong definition for showDocument (#1489)
1 parent bafd287 commit 1f603f4

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ After cloning the repository, run `npm install` to install dependencies and `npm
4040
- snippet support in Workspace edits
4141
- support to control the parallelism of the dispatch requests and notification. This is a breaking change since it allows notification handlers to return a promise to control this.
4242
- make client browser implementation consistent with the node implementation in terms of arguments. This is a breaking change since it re-ordered parameter declarations.
43+
- Added a `CancellationToken` to the show document middleware to make it consistent with the other middleware. This is a breaking change since it added a required parameter.
4344

4445
## 3.17.5 Protocol, 9.0.1 Client and 9.0.1 Server
4546

client/src/common/client.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ type _WorkspaceMiddleware = {
292292
export type WorkspaceMiddleware = _WorkspaceMiddleware & ConfigurationMiddleware & DidChangeConfigurationMiddleware & WorkspaceFolderMiddleware & FileOperationsMiddleware;
293293

294294
interface _WindowMiddleware {
295-
showDocument?: (this: void, params: ShowDocumentParams, next: ShowDocumentRequest.HandlerSignature) => Promise<ShowDocumentResult>;
295+
showDocument?: ShowDocumentRequest.MiddlewareSignature;
296296
}
297297
export type WindowMiddleware = _WindowMiddleware;
298298

@@ -1153,7 +1153,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
11531153
connection.onNotification(TelemetryEventNotification.type, (data) => {
11541154
this._telemetryEmitter.fire(data);
11551155
});
1156-
connection.onRequest(ShowDocumentRequest.type, async (params): Promise<ShowDocumentResult> => {
1156+
connection.onRequest(ShowDocumentRequest.type, async (params, token) => {
11571157
const showDocument = async (params: ShowDocumentParams): Promise<ShowDocumentResult> => {
11581158
const uri = this.protocol2CodeConverter.asUri(params.uri);
11591159
try {
@@ -1179,7 +1179,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
11791179
};
11801180
const middleware = this._clientOptions.middleware.window?.showDocument;
11811181
if (middleware !== undefined) {
1182-
return middleware(params, showDocument);
1182+
return middleware(params, token, showDocument);
11831183
} else {
11841184
return showDocument(params);
11851185
}
@@ -2151,12 +2151,30 @@ interface Connection {
21512151

21522152
listen(): void;
21532153

2154+
sendRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, token?: CancellationToken): Promise<R>;
2155+
sendRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, params: P, token?: CancellationToken): Promise<R>;
2156+
sendRequest<R, E>(type: RequestType0<R, E>, token?: CancellationToken): Promise<R>;
2157+
sendRequest<P, R, E>(type: RequestType<P, R, E>, params: P, token?: CancellationToken): Promise<R>;
21542158
sendRequest<R>(type: string | MessageSignature, ...params: any[]): Promise<R>;
2159+
2160+
onRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, handler: RequestHandler0<R, E>): Disposable;
2161+
onRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, handler: RequestHandler<P, R, E>): Disposable;
2162+
onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): Disposable;
2163+
onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): Disposable;
21552164
onRequest<R, E>(method: string | MessageSignature, handler: GenericRequestHandler<R, E>): Disposable;
21562165

21572166
hasPendingResponse(): boolean;
21582167

2168+
sendNotification<RO>(type: ProtocolNotificationType0<RO>): Promise<void>;
2169+
sendNotification<P, RO>(type: ProtocolNotificationType<P, RO>, params?: P): Promise<void>;
2170+
sendNotification(type: NotificationType0): Promise<void>;
2171+
sendNotification<P>(type: NotificationType<P>, params?: P): Promise<void>;
21592172
sendNotification(method: string | MessageSignature, params?: any): Promise<void>;
2173+
2174+
onNotification<RO>(type: ProtocolNotificationType0<RO>, handler: NotificationHandler0): Disposable;
2175+
onNotification<P, RO>(type: ProtocolNotificationType<P, RO>, handler: NotificationHandler<P>): Disposable;
2176+
onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
2177+
onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): Disposable;
21602178
onNotification(method: string | MessageSignature, handler: GenericNotificationHandler): Disposable;
21612179

21622180
onProgress<P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable;

package-lock.json

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"shx": "^0.3.4",
2929
"source-map-support": "^0.5.21",
3030
"ts-json-schema-generator": "^1.4.0",
31-
"typescript": "^5.2.2",
31+
"typescript": "^5.4.5",
3232
"webpack": "^5.89.0",
3333
"webpack-cli": "^5.1.4",
3434
"node-polyfill-webpack-plugin": "^2.0.1"

protocol/src/common/protocol.showDocument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
* ------------------------------------------------------------------------------------------ */
55

6-
import { HandlerResult, RequestHandler } from 'vscode-jsonrpc';
6+
import { CancellationToken, HandlerResult, RequestHandler } from 'vscode-jsonrpc';
77
import { Range, URI } from 'vscode-languageserver-types';
88
import { MessageDirection, ProtocolRequestType } from './messages';
99

@@ -80,5 +80,5 @@ export namespace ShowDocumentRequest {
8080
export const messageDirection: MessageDirection = MessageDirection.serverToClient;
8181
export const type = new ProtocolRequestType<ShowDocumentParams, ShowDocumentResult, void, void, void>(method);
8282
export type HandlerSignature = RequestHandler<ShowDocumentParams, ShowDocumentResult, void>;
83-
export type MiddlewareSignature = (params: ShowDocumentParams, next: HandlerSignature) => HandlerResult<ShowDocumentResult, void>;
83+
export type MiddlewareSignature = (params: ShowDocumentParams, token: CancellationToken, next: HandlerSignature) => HandlerResult<ShowDocumentResult, void>;
8484
}

0 commit comments

Comments
 (0)