@@ -33,6 +33,7 @@ import { NamespaceManager } from './scope';
3333import { ParseCancellationException } from 'antlr4ng' ;
3434import { getFormattingEdits } from './formatter' ;
3535import { VbaFmtListener } from './parser/vbaListener' ;
36+ import { LspLogger } from '../logger' ;
3637
3738
3839/**
@@ -47,6 +48,8 @@ export class Workspace {
4748 private _activeDocument ?: BaseProjectDocument ;
4849 private readonly _hasConfigurationCapability : boolean ;
4950
51+ logger : LspLogger ;
52+
5053 get hasConfigurationCapability ( ) {
5154 return this . _hasConfigurationCapability ;
5255 }
@@ -63,6 +66,7 @@ export class Workspace {
6366
6467 constructor ( params : { connection : _Connection , capabilities : LanguageServerConfiguration } ) {
6568 this . connection = params . connection ;
69+ this . logger = new LspLogger ( this . connection ) ;
6670 this . _hasConfigurationCapability = hasConfigurationCapability ( params . capabilities ) ;
6771 this . events = new WorkspaceEvents ( {
6872 workspace : this ,
@@ -82,11 +86,24 @@ export class Workspace {
8286 this . parseCancellationTokenSource ?. cancel ( ) ;
8387 this . parseCancellationTokenSource = new CancellationTokenSource ( ) ;
8488
89+ if ( ! this . activeDocument ) {
90+ this . logger . error ( 'No active document.' ) ;
91+ return ;
92+ }
93+
8594 // Exceptions thrown by the parser should be ignored.
8695 try {
87- await this . activeDocument ?. parseAsync ( this . parseCancellationTokenSource . token ) ;
88- } catch ( error ) {
89- this . connection . console . log ( `Parser error: ${ error } ` )
96+ this . logger . debug ( `Parsing document: ${ this . activeDocument . name } ` ) ;
97+ await this . activeDocument . parseAsync ( this . parseCancellationTokenSource . token ) ;
98+ this . logger . info ( `Parsed ${ this . activeDocument . name } ` ) ;
99+ } 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+ }
90107 }
91108
92109 this . parseCancellationTokenSource = undefined ;
@@ -98,8 +115,20 @@ export class Workspace {
98115
99116 // Exceptions thrown by the parser should be ignored.
100117 let result : VbaFmtListener | undefined ;
101- try { result = await this . activeDocument ?. formatParseAsync ( this . parseCancellationTokenSource . token ) ; }
102- catch ( error ) { this . connection . console . log ( `Parser error: ${ error } ` ) }
118+ try {
119+ this . logger . debug ( `Format parsing document: ${ document . uri } ` ) ;
120+ result = await this . activeDocument ?. formatParseAsync ( this . parseCancellationTokenSource . token ) ;
121+ this . logger . info ( `Formatted ${ document . uri } ` ) ;
122+ }
123+ catch ( e ) {
124+ if ( e instanceof ParseCancellationException ) {
125+ this . logger . debug ( 'Parse cancelled successfully.' )
126+ } else if ( e instanceof Error ) {
127+ this . logger . stack ( e ) ;
128+ } else {
129+ this . logger . error ( `Parse failed: ${ e } ` )
130+ }
131+ }
103132
104133 this . parseCancellationTokenSource = undefined ;
105134 return result ;
@@ -240,7 +269,7 @@ class WorkspaceEvents {
240269 return this . activeDocument ?. languageServerSemanticTokens ( rangeParams . range ) ;
241270 }
242271 default :
243- console . error ( `Unresolved request path: ${ method } ` ) ;
272+ this . workspace . logger . error ( `Unresolved request path: ${ method } ` ) ;
244273 }
245274 } ) ;
246275 }
@@ -265,7 +294,7 @@ class WorkspaceEvents {
265294
266295 // TODO: Should trigger a full workspace refresh.
267296 private onDidChangeWorkspaceFolders ( e : WorkspaceFoldersChangeEvent ) {
268- this . workspace . connection . console . log ( `Workspace folder change event received.\n${ e } ` ) ;
297+ this . workspace . logger . debug ( `Workspace folder change event received.\n${ e } ` ) ;
269298 }
270299
271300 private async onDocumentSymbolAsync ( params : DocumentSymbolParams , token : CancellationToken ) : Promise < SymbolInformation [ ] > {
@@ -297,7 +326,7 @@ class WorkspaceEvents {
297326 }
298327
299328 private onHover ( params : HoverParams ) : Hover {
300- console . debug ( `onHover` ) ;
329+ this . workspace . logger . debug ( `onHover` ) ;
301330 return { contents : '' } ;
302331 }
303332
0 commit comments