Skip to content

Commit 710da5a

Browse files
committed
Better logging for cancellable calls
1 parent 16f51e6 commit 710da5a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

server/src/project/workspace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ class WorkspaceEvents {
259259

260260
private initialiseConnectionEvents(connection: _Connection) {
261261
const cancellableOnDocSymbol = returnDefaultOnCancelClientRequest(
262-
(p: DocumentSymbolParams, t) => this.onDocumentSymbolAsync(p, t), [], Services.logger, 'Document Symbols');
262+
(p: DocumentSymbolParams, t) => this.onDocumentSymbolAsync(p, t), [], 'Document Symbols');
263263

264264
const cancellableOnFoldingRanges = returnDefaultOnCancelClientRequest(
265-
(p: FoldingRangeParams, t) => this.onFoldingRangesAsync(p, t), [], Services.logger, 'Folding Range');
265+
(p: FoldingRangeParams, t) => this.onFoldingRangesAsync(p, t), [], 'Folding Range');
266266

267267
connection.onInitialized(() => this.onInitialized());
268268
connection.onCompletion(params => this.onCompletion(params));

server/src/utils/wrappers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CancellationToken } from 'vscode-languageserver';
22
import { LspLogger } from './logger';
33
import { Logger } from '../injection/interface';
4+
import { Services } from '../injection/services';
45

56
type signature<T,A extends any[]> = (token: CancellationToken, ...args: A) => Promise<T|void>;
67
type paramsSignature<T,P> = (params: P, token: CancellationToken) => Promise<T>;
@@ -35,25 +36,24 @@ function returnDefaultOnCancel<T, A extends any[]>(fn: signature<T,A>, logger?:
3536
* @param fn An async function that requires cancellation token handling.
3637
* @param defaultValue The value to return when cancelled.
3738
*/
38-
export function returnDefaultOnCancelClientRequest<T, P>(fn: paramsSignature<T,P>, defaultValue: T, logger: Logger | undefined, name: string): paramsSignature<T,P> {
39+
export function returnDefaultOnCancelClientRequest<T, P>(fn: paramsSignature<T,P>, defaultValue: T, name: string): paramsSignature<T,P> {
3940
return async (params: P, token: CancellationToken): Promise<T> => {
4041
if (token.isCancellationRequested) {
41-
// The logger has started dereferencing since I added the parseTokenSource.dispose() to parseDocumentAsync.
4242
const msg = `Cancellation requested before start for ${name}. Returning default.`;
43-
if (logger) logger.debug(msg);
44-
else console.debug(msg);
43+
Services.logger.debug(msg);
4544
return defaultValue;
4645
}
4746

4847
return new Promise<T>((resolve) => {
4948
const onCancel = () =>{
5049
const msg = `Cancellation requested during processing for ${name}. Returning default.`;
51-
if (logger) logger.debug(msg);
52-
else console.debug(msg);
50+
Services.logger.debug(msg);
5351
resolve(defaultValue);
5452
}
5553
token.onCancellationRequested(onCancel);
5654
fn(params, token).then(resolve).catch(() => resolve(defaultValue));
55+
token.onCancellationRequested(() => undefined);
56+
Services.logger.debug(`Finished processing ${name}`);
5757
});
5858
};
5959
}

0 commit comments

Comments
 (0)