@@ -115,16 +115,6 @@ function logTelemetry(notificationBody: TelemetryPayload): void {
115
115
telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
116
116
}
117
117
118
- /**
119
- * listen for logging messages from the language server and print them to the Output window
120
- */
121
- function setupOutputHandlers ( ) : void {
122
- console . assert ( languageClient !== undefined , "This method must not be called until this.languageClient is set in \"onReady\"" ) ;
123
-
124
- languageClient . onNotification ( DebugProtocolNotification , logDebugProtocol ) ;
125
- languageClient . onNotification ( DebugLogNotification , logLocalized ) ;
126
- }
127
-
128
118
/** Note: We should not await on the following functions,
129
119
* or any function that returns a promise acquired from them,
130
120
* vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
@@ -537,7 +527,11 @@ export interface TextDocumentWillSaveParams {
537
527
reason : vscode . TextDocumentSaveReason ;
538
528
}
539
529
540
- interface InitializationOptions {
530
+ interface LspInitializationOptions {
531
+ loggingLevel : number ;
532
+ }
533
+
534
+ interface CppInitializationParams {
541
535
packageVersion : string ;
542
536
extensionPath : string ;
543
537
cacheStoragePath : string ;
@@ -559,6 +553,7 @@ interface TagParseStatus {
559
553
}
560
554
561
555
// Requests
556
+ const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
562
557
const QueryCompilerDefaultsRequest : RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > = new RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > ( 'cpptools/queryCompilerDefaults' ) ;
563
558
const QueryTranslationUnitSourceRequest : RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void > = new RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void > ( 'cpptools/queryTranslationUnitSource' ) ;
564
559
const SwitchHeaderSourceRequest : RequestType < SwitchHeaderSourceParams , string , void > = new RequestType < SwitchHeaderSourceParams , string , void > ( 'cpptools/didSwitchHeaderSource' ) ;
@@ -597,7 +592,6 @@ const PreviewReferencesNotification: NotificationType<void> = new NotificationTy
597
592
const RescanFolderNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/rescanFolder' ) ;
598
593
const FinishedRequestCustomConfig : NotificationType < FinishedRequestCustomConfigParams > = new NotificationType < FinishedRequestCustomConfigParams > ( 'cpptools/finishedRequestCustomConfig' ) ;
599
594
const DidChangeSettingsNotification : NotificationType < SettingsParams > = new NotificationType < SettingsParams > ( 'cpptools/didChangeSettings' ) ;
600
- const InitializationNotification : NotificationType < InitializationOptions > = new NotificationType < InitializationOptions > ( 'cpptools/initialize' ) ;
601
595
602
596
const CodeAnalysisNotification : NotificationType < CodeAnalysisParams > = new NotificationType < CodeAnalysisParams > ( 'cpptools/runCodeAnalysis' ) ;
603
597
const PauseCodeAnalysisNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/pauseCodeAnalysis' ) ;
@@ -828,7 +822,7 @@ export class DefaultClient implements Client {
828
822
private isSupported : boolean = true ;
829
823
private inactiveRegionsDecorations = new Map < string , DecorationRangesPair > ( ) ;
830
824
private settingsTracker : SettingsTracker ;
831
- private loggingLevel : string | undefined ;
825
+ private loggingLevel : number = 1 ;
832
826
private configurationProvider ?: string ;
833
827
834
828
public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
@@ -1522,7 +1516,7 @@ export class DefaultClient implements Client {
1522
1516
const databaseStoragePath : string = ( cacheStoragePath . length > 0 ) && ( workspaceHash . length > 0 ) ?
1523
1517
path . join ( cacheStoragePath , workspaceHash ) : "" ;
1524
1518
1525
- const initializationOptions : InitializationOptions = {
1519
+ const cppInitializationParams : CppInitializationParams = {
1526
1520
packageVersion : util . packageJson . version ,
1527
1521
extensionPath : util . extensionPath ,
1528
1522
databaseStoragePath : databaseStoragePath ,
@@ -1538,12 +1532,18 @@ export class DefaultClient implements Client {
1538
1532
settings : this . getAllSettings ( )
1539
1533
} ;
1540
1534
1535
+ this . loggingLevel = util . getNumericLoggingLevel ( cppInitializationParams . settings . loggingLevel ) ;
1536
+ const lspInitializationOptions : LspInitializationOptions = {
1537
+ loggingLevel : this . loggingLevel
1538
+ } ;
1539
+
1541
1540
const clientOptions : LanguageClientOptions = {
1542
1541
documentSelector : [
1543
1542
{ scheme : 'file' , language : 'c' } ,
1544
1543
{ scheme : 'file' , language : 'cpp' } ,
1545
1544
{ scheme : 'file' , language : 'cuda-cpp' }
1546
1545
] ,
1546
+ initializationOptions : lspInitializationOptions ,
1547
1547
middleware : createProtocolFilter ( ) ,
1548
1548
errorHandler : {
1549
1549
error : ( _error , _message , _count ) => ( { action : ErrorAction . Continue } ) ,
@@ -1576,13 +1576,16 @@ export class DefaultClient implements Client {
1576
1576
} ;
1577
1577
1578
1578
// Create the language client
1579
- this . loggingLevel = initializationOptions . settings . loggingLevel ;
1580
1579
languageClient = new LanguageClient ( `cpptools` , serverOptions , clientOptions ) ;
1581
- setupOutputHandlers ( ) ;
1580
+ languageClient . onNotification ( DebugProtocolNotification , logDebugProtocol ) ;
1581
+ languageClient . onNotification ( DebugLogNotification , logLocalized ) ;
1582
1582
languageClient . registerProposedFeatures ( ) ;
1583
1583
await languageClient . start ( ) ;
1584
+
1584
1585
// Move initialization to a separate message, so we can see log output from it.
1585
- await languageClient . sendNotification ( InitializationNotification , initializationOptions ) ;
1586
+ // A request is used in order to wait for completion and ensure that no subsequent
1587
+ // higher priority message may be processed before the Initialization request.
1588
+ await languageClient . sendRequest ( InitializationRequest , cppInitializationParams ) ;
1586
1589
}
1587
1590
1588
1591
public async sendDidChangeSettings ( ) : Promise < void > {
@@ -1607,9 +1610,9 @@ export class DefaultClient implements Client {
1607
1610
updateLanguageConfigurations ( ) ;
1608
1611
}
1609
1612
if ( changedSettings . loggingLevel ) {
1610
- const oldLoggingLevelLogged : boolean = ! ! this . loggingLevel && this . loggingLevel !== "None" && this . loggingLevel !== "Error" ;
1613
+ const oldLoggingLevelLogged : boolean = ! ! this . loggingLevel && this . loggingLevel !== 0 && this . loggingLevel !== 1 ;
1611
1614
const newLoggingLevel : string | undefined = changedSettings . loggingLevel ;
1612
- this . loggingLevel = newLoggingLevel ;
1615
+ this . loggingLevel = util . getNumericLoggingLevel ( newLoggingLevel ) ;
1613
1616
const newLoggingLevelLogged : boolean = ! ! newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error" ;
1614
1617
if ( oldLoggingLevelLogged || newLoggingLevelLogged ) {
1615
1618
const out : Logger = getOutputChannelLogger ( ) ;
0 commit comments