@@ -33,7 +33,8 @@ import { NamespaceManager } from './scope';
3333import { ParseCancellationException } from 'antlr4ng' ;
3434import { getFormattingEdits } from './formatter' ;
3535import { VbaFmtListener } from './parser/vbaListener' ;
36- import { LspLogger } from '../logger' ;
36+ import { LspLogger } from '../utils/logger' ;
37+ import { returnDefaultOnCancelClientRequest } from '../utils/wrappers' ;
3738
3839
3940/**
@@ -93,17 +94,13 @@ export class Workspace {
9394
9495 // Exceptions thrown by the parser should be ignored.
9596 try {
96- this . logger . debug ( `Parsing document: ${ this . activeDocument . name } ` ) ;
9797 await this . activeDocument . parseAsync ( this . parseCancellationTokenSource . token ) ;
9898 this . logger . info ( `Parsed ${ this . activeDocument . name } ` ) ;
9999 } catch ( e ) {
100- if ( e instanceof ParseCancellationException ) {
101- this . logger . debug ( 'Parse cancelled successfully.' )
102- } else if ( e instanceof Error ) {
103- this . logger . stack ( e ) ;
104- } else {
105- this . logger . error ( `Parse failed: ${ e } ` )
106- }
100+ // Swallow cancellation exceptions. They're good. We like these.
101+ if ( e instanceof ParseCancellationException ) { }
102+ else if ( e instanceof Error ) { this . logger . stack ( e ) ; }
103+ else { this . logger . error ( 'Something went wrong.' ) }
107104 }
108105
109106 this . parseCancellationTokenSource = undefined ;
@@ -116,7 +113,6 @@ export class Workspace {
116113 // Exceptions thrown by the parser should be ignored.
117114 let result : VbaFmtListener | undefined ;
118115 try {
119- this . logger . debug ( `Format parsing document: ${ document . uri } ` ) ;
120116 result = await this . activeDocument ?. formatParseAsync ( this . parseCancellationTokenSource . token ) ;
121117 this . logger . info ( `Formatted ${ document . uri } ` ) ;
122118 }
@@ -244,19 +240,31 @@ class WorkspaceEvents {
244240 }
245241
246242 private initialiseConnectionEvents ( connection : _Connection ) {
243+ const cancellableOnDocSymbol = returnDefaultOnCancelClientRequest (
244+ ( p : DocumentSymbolParams , t ) => this . onDocumentSymbolAsync ( p , t ) , [ ] , this . workspace . logger , 'Document Symbols' ) ;
245+
246+ const cancellableOnDiagnostics = returnDefaultOnCancelClientRequest (
247+ ( p : DocumentDiagnosticParams , t ) => this . onDiagnosticAsync ( p , t ) ,
248+ { kind : DocumentDiagnosticReportKind . Full , items : [ ] } ,
249+ this . workspace . logger ,
250+ 'Diagnostics' ) ;
251+
252+ const cancellableOnFoldingRanges = returnDefaultOnCancelClientRequest (
253+ ( p : FoldingRangeParams , t ) => this . onFoldingRangesAsync ( p , t ) , [ ] , this . workspace . logger , 'Folding Range' )
254+
247255 connection . onInitialized ( ( ) => this . onInitialized ( ) ) ;
248256 connection . onDidOpenTextDocument ( params => this . onDidOpenTextDocumentAsync ( params ) ) ;
249257 connection . onCompletion ( params => this . onCompletion ( params ) ) ;
250258 connection . onCompletionResolve ( item => this . onCompletionResolve ( item ) ) ;
251259 connection . onDidChangeConfiguration ( _ => this . workspace . clearDocumentsConfiguration ( ) ) ;
252260 connection . onDidChangeWatchedFiles ( params => this . onDidChangeWatchedFiles ( params ) ) ;
253- connection . onDocumentSymbol ( async ( params , token ) => await this . onDocumentSymbolAsync ( params , token ) ) ;
261+ connection . onDocumentSymbol ( async ( params , token ) => await cancellableOnDocSymbol ( params , token ) ) ;
254262 connection . onHover ( params => this . onHover ( params ) ) ;
255- connection . languages . diagnostics . on ( async ( params , token ) => await this . onDiagnosticAsync ( params , token ) ) ;
263+ connection . languages . diagnostics . on ( async ( params , token ) => await cancellableOnDiagnostics ( params , token ) ) ;
256264 connection . onDocumentFormatting ( params => this . onDocumentFormatting ( params ) ) ;
257265
258266 if ( hasConfigurationCapability ( this . configuration ) ) {
259- connection . onFoldingRanges ( async ( params , token ) => this . onFoldingRangesAsync ( params , token ) ) ;
267+ connection . onFoldingRanges ( async ( params , token ) => await cancellableOnFoldingRanges ( params , token ) ) ;
260268 }
261269
262270 connection . onRequest ( ( method : string , params : object | object [ ] | any ) => {
@@ -303,6 +311,7 @@ class WorkspaceEvents {
303311 }
304312
305313 private async onDiagnosticAsync ( params : DocumentDiagnosticParams , token : CancellationToken ) : Promise < DocumentDiagnosticReport > {
314+ // const document = await this.withTimeout(this.activeParsedDocument(0, token), 10000).catch(() => null);
306315 const document = await this . activeParsedDocument ( 0 , token ) ;
307316 return document ?. languageServerDiagnostics ( ) ?? {
308317 kind : DocumentDiagnosticReportKind . Full ,
0 commit comments