@@ -115,16 +115,6 @@ function logTelemetry(notificationBody: TelemetryPayload): void {
115115 telemetry . logLanguageServerEvent ( notificationBody . event , notificationBody . properties , notificationBody . metrics ) ;
116116}
117117
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-
128118/** Note: We should not await on the following functions,
129119 * or any function that returns a promise acquired from them,
130120 * vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
@@ -537,7 +527,11 @@ export interface TextDocumentWillSaveParams {
537527 reason : vscode . TextDocumentSaveReason ;
538528}
539529
540- interface InitializationOptions {
530+ interface LspInitializationOptions {
531+ loggingLevel : number ;
532+ }
533+
534+ interface CppInitializationParams {
541535 packageVersion : string ;
542536 extensionPath : string ;
543537 cacheStoragePath : string ;
@@ -559,6 +553,7 @@ interface TagParseStatus {
559553}
560554
561555// Requests
556+ const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
562557const QueryCompilerDefaultsRequest : RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > = new RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > ( 'cpptools/queryCompilerDefaults' ) ;
563558const QueryTranslationUnitSourceRequest : RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void > = new RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void > ( 'cpptools/queryTranslationUnitSource' ) ;
564559const SwitchHeaderSourceRequest : RequestType < SwitchHeaderSourceParams , string , void > = new RequestType < SwitchHeaderSourceParams , string , void > ( 'cpptools/didSwitchHeaderSource' ) ;
@@ -597,7 +592,6 @@ const PreviewReferencesNotification: NotificationType<void> = new NotificationTy
597592const RescanFolderNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/rescanFolder' ) ;
598593const FinishedRequestCustomConfig : NotificationType < FinishedRequestCustomConfigParams > = new NotificationType < FinishedRequestCustomConfigParams > ( 'cpptools/finishedRequestCustomConfig' ) ;
599594const DidChangeSettingsNotification : NotificationType < SettingsParams > = new NotificationType < SettingsParams > ( 'cpptools/didChangeSettings' ) ;
600- const InitializationNotification : NotificationType < InitializationOptions > = new NotificationType < InitializationOptions > ( 'cpptools/initialize' ) ;
601595
602596const CodeAnalysisNotification : NotificationType < CodeAnalysisParams > = new NotificationType < CodeAnalysisParams > ( 'cpptools/runCodeAnalysis' ) ;
603597const PauseCodeAnalysisNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/pauseCodeAnalysis' ) ;
@@ -828,7 +822,7 @@ export class DefaultClient implements Client {
828822 private isSupported : boolean = true ;
829823 private inactiveRegionsDecorations = new Map < string , DecorationRangesPair > ( ) ;
830824 private settingsTracker : SettingsTracker ;
831- private loggingLevel : string | undefined ;
825+ private loggingLevel : number = 1 ;
832826 private configurationProvider ?: string ;
833827
834828 public lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration | undefined > | undefined ;
@@ -1522,7 +1516,7 @@ export class DefaultClient implements Client {
15221516 const databaseStoragePath : string = ( cacheStoragePath . length > 0 ) && ( workspaceHash . length > 0 ) ?
15231517 path . join ( cacheStoragePath , workspaceHash ) : "" ;
15241518
1525- const initializationOptions : InitializationOptions = {
1519+ const cppInitializationParams : CppInitializationParams = {
15261520 packageVersion : util . packageJson . version ,
15271521 extensionPath : util . extensionPath ,
15281522 databaseStoragePath : databaseStoragePath ,
@@ -1538,12 +1532,18 @@ export class DefaultClient implements Client {
15381532 settings : this . getAllSettings ( )
15391533 } ;
15401534
1535+ this . loggingLevel = util . getNumericLoggingLevel ( cppInitializationParams . settings . loggingLevel ) ;
1536+ const lspInitializationOptions : LspInitializationOptions = {
1537+ loggingLevel : this . loggingLevel
1538+ } ;
1539+
15411540 const clientOptions : LanguageClientOptions = {
15421541 documentSelector : [
15431542 { scheme : 'file' , language : 'c' } ,
15441543 { scheme : 'file' , language : 'cpp' } ,
15451544 { scheme : 'file' , language : 'cuda-cpp' }
15461545 ] ,
1546+ initializationOptions : lspInitializationOptions ,
15471547 middleware : createProtocolFilter ( ) ,
15481548 errorHandler : {
15491549 error : ( _error , _message , _count ) => ( { action : ErrorAction . Continue } ) ,
@@ -1576,13 +1576,16 @@ export class DefaultClient implements Client {
15761576 } ;
15771577
15781578 // Create the language client
1579- this . loggingLevel = initializationOptions . settings . loggingLevel ;
15801579 languageClient = new LanguageClient ( `cpptools` , serverOptions , clientOptions ) ;
1581- setupOutputHandlers ( ) ;
1580+ languageClient . onNotification ( DebugProtocolNotification , logDebugProtocol ) ;
1581+ languageClient . onNotification ( DebugLogNotification , logLocalized ) ;
15821582 languageClient . registerProposedFeatures ( ) ;
15831583 await languageClient . start ( ) ;
1584+
15841585 // 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 ) ;
15861589 }
15871590
15881591 public async sendDidChangeSettings ( ) : Promise < void > {
@@ -1607,9 +1610,9 @@ export class DefaultClient implements Client {
16071610 updateLanguageConfigurations ( ) ;
16081611 }
16091612 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 ;
16111614 const newLoggingLevel : string | undefined = changedSettings . loggingLevel ;
1612- this . loggingLevel = newLoggingLevel ;
1615+ this . loggingLevel = util . getNumericLoggingLevel ( newLoggingLevel ) ;
16131616 const newLoggingLevelLogged : boolean = ! ! newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error" ;
16141617 if ( oldLoggingLevelLogged || newLoggingLevelLogged ) {
16151618 const out : Logger = getOutputChannelLogger ( ) ;
0 commit comments