@@ -24,11 +24,19 @@ import { FolderContext } from "../FolderContext";
24
24
import { LanguageClient } from "vscode-languageclient/node" ;
25
25
import { ArgumentFilter , BuildFlags } from "../toolchain/BuildFlags" ;
26
26
import { DiagnosticsManager } from "../DiagnosticsManager" ;
27
+ import { LSPLogger , LSPOutputChannel } from "./LSPOutputChannel" ;
28
+
29
+ interface SourceKitLogMessageParams extends langclient . LogMessageParams {
30
+ logName ?: string ;
31
+ }
27
32
28
33
/** Manages the creation and destruction of Language clients as we move between
29
34
* workspace folders
30
35
*/
31
36
export class LanguageClientManager {
37
+ // known log names
38
+ static indexingLogName = "SourceKit-LSP: Indexing" ;
39
+
32
40
// document selector used by language client
33
41
static appleLangDocumentSelector = [
34
42
{ scheme : "file" , language : "swift" } ,
@@ -112,6 +120,7 @@ export class LanguageClientManager {
112
120
// used by single server support to keep a record of the project folders
113
121
// that are not at the root of their workspace
114
122
public subFolderWorkspaces : vscode . Uri [ ] ;
123
+ private namedOutputChannels : Map < string , LSPOutputChannel > = new Map ( ) ;
115
124
/** Get the current state of the underlying LanguageClient */
116
125
public get state ( ) : langclient . State {
117
126
if ( ! this . languageClient ) {
@@ -121,6 +130,10 @@ export class LanguageClientManager {
121
130
}
122
131
123
132
constructor ( public workspaceContext : WorkspaceContext ) {
133
+ this . namedOutputChannels . set (
134
+ LanguageClientManager . indexingLogName ,
135
+ new LSPOutputChannel ( LanguageClientManager . indexingLogName , false , true )
136
+ ) ;
124
137
this . singleServerSupport = workspaceContext . swiftVersion . isGreaterThanOrEqual (
125
138
new Version ( 5 , 7 , 0 )
126
139
) ;
@@ -232,6 +245,7 @@ export class LanguageClientManager {
232
245
this . legacyInlayHints ?. dispose ( ) ;
233
246
this . subscriptions . forEach ( item => item . dispose ( ) ) ;
234
247
this . languageClient ?. stop ( ) ;
248
+ this . namedOutputChannels . forEach ( channel => channel . dispose ( ) ) ;
235
249
}
236
250
237
251
/**
@@ -556,6 +570,10 @@ export class LanguageClientManager {
556
570
this . workspaceContext . outputChannel . log ( `SourceKit-LSP setup` ) ;
557
571
}
558
572
573
+ client . onNotification ( langclient . LogMessageNotification . type , params => {
574
+ this . logMessage ( client , params as SourceKitLogMessageParams ) ;
575
+ } ) ;
576
+
559
577
// start client
560
578
this . clientReadyPromise = client
561
579
. start ( )
@@ -578,6 +596,34 @@ export class LanguageClientManager {
578
596
579
597
return this . clientReadyPromise ;
580
598
}
599
+
600
+ private logMessage ( client : langclient . LanguageClient , params : SourceKitLogMessageParams ) {
601
+ let logger : LSPLogger = client ;
602
+ if ( params . logName ) {
603
+ const outputChannel =
604
+ this . namedOutputChannels . get ( params . logName ) ??
605
+ new LSPOutputChannel ( params . logName ) ;
606
+ this . namedOutputChannels . set ( params . logName , outputChannel ) ;
607
+ logger = outputChannel ;
608
+ }
609
+ switch ( params . type ) {
610
+ case langclient . MessageType . Info :
611
+ logger . info ( params . message ) ;
612
+ break ;
613
+ case langclient . MessageType . Debug :
614
+ logger . debug ( params . message ) ;
615
+ break ;
616
+ case langclient . MessageType . Warning :
617
+ logger . warn ( params . message ) ;
618
+ break ;
619
+ case langclient . MessageType . Error :
620
+ logger . error ( params . message ) ;
621
+ break ;
622
+ case langclient . MessageType . Log :
623
+ logger . info ( params . message ) ;
624
+ break ;
625
+ }
626
+ }
581
627
}
582
628
583
629
/**
0 commit comments