@@ -24,7 +24,7 @@ import { InlayHintsProvider } from './Providers/inlayHintProvider';
2424import { LanguageClient , LanguageClientOptions , ServerOptions , NotificationType , TextDocumentIdentifier , RequestType , ErrorAction , CloseAction , DidOpenTextDocumentParams , Range , Position , DocumentFilter } from 'vscode-languageclient' ;
2525import { SourceFileConfigurationItem , WorkspaceBrowseConfiguration , SourceFileConfiguration , Version } from 'vscode-cpptools' ;
2626import { Status , IntelliSenseStatus } from 'vscode-cpptools/out/testApi' ;
27- import { getLocalizedString , LocalizeStringParams } from './localization' ;
27+ import { getLocaleId , getLocalizedString , LocalizeStringParams } from './localization' ;
2828import { Location , TextEdit } from './commonTypes' ;
2929import { makeVscodeRange , makeVscodeLocation } from './utils' ;
3030import * as util from '../common' ;
@@ -37,7 +37,6 @@ import { ClientCollection } from './clientCollection';
3737import { createProtocolFilter } from './protocolFilter' ;
3838import { DataBinding } from './dataBinding' ;
3939import minimatch = require( "minimatch" ) ;
40- import * as logger from '../logger' ;
4140import { updateLanguageConfigurations , CppSourceStr } from './extension' ;
4241import { SettingsTracker , getTracker } from './settingsTracker' ;
4342import { getTestHook , TestHook } from '../testHook' ;
@@ -49,6 +48,7 @@ import * as nls from 'vscode-nls';
4948import { lookupString , localizedStringCount } from '../nativeStrings' ;
5049import { CodeAnalysisDiagnosticIdentifiersAndUri , RegisterCodeAnalysisNotifications , removeAllCodeAnalysisProblems ,
5150 removeCodeAnalysisProblems , RemoveCodeAnalysisProblemsParams } from './codeAnalysis' ;
51+ import { DebugProtocolParams , getDiagnosticsChannel , getOutputChannelLogger , logDebugProtocol , Logger , logLocalized , showWarning , ShowWarningParams } from '../logger' ;
5252
5353nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
5454const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
@@ -64,10 +64,6 @@ const languageClientCrashTimes: number[] = [];
6464let clientCollection : ClientCollection ;
6565let pendingTask : util . BlockingTask < any > | undefined ;
6666let compilerDefaults : configs . CompilerDefaults ;
67- let diagnosticsChannel : vscode . OutputChannel ;
68- let outputChannel : vscode . OutputChannel ;
69- let debugChannel : vscode . OutputChannel ;
70- let warningChannel : vscode . OutputChannel ;
7167let diagnosticsCollectionIntelliSense : vscode . DiagnosticCollection ;
7268
7369let workspaceDisposables : vscode . Disposable [ ] = [ ] ;
@@ -91,32 +87,10 @@ function logTelemetry(notificationBody: TelemetryPayload): void {
9187function setupOutputHandlers ( ) : void {
9288 console . assert ( languageClient !== undefined , "This method must not be called until this.languageClient is set in \"onReady\"" ) ;
9389
94- languageClient . onNotification ( DebugProtocolNotification , ( output ) => {
95- if ( ! debugChannel ) {
96- debugChannel = vscode . window . createOutputChannel ( `${ localize ( "c.cpp.debug.protocol" , "C/C++ Debug Protocol" ) } ` ) ;
97- workspaceDisposables . push ( debugChannel ) ;
98- }
99- debugChannel . appendLine ( "" ) ;
100- debugChannel . appendLine ( "************************************************************************************************************************" ) ;
101- debugChannel . append ( `${ output } ` ) ;
102- } ) ;
103-
90+ languageClient . onNotification ( DebugProtocolNotification , logDebugProtocol ) ;
10491 languageClient . onNotification ( DebugLogNotification , logLocalized ) ;
10592}
10693
107- function log ( output : string ) : void {
108- if ( ! outputChannel ) {
109- outputChannel = logger . getOutputChannel ( ) ;
110- workspaceDisposables . push ( outputChannel ) ;
111- }
112- outputChannel . appendLine ( `${ output } ` ) ;
113- }
114-
115- function logLocalized ( params : LocalizeStringParams ) : void {
116- const output : string = getLocalizedString ( params ) ;
117- log ( output ) ;
118- }
119-
12094/** Note: We should not await on the following functions,
12195 * or any funstion that returns a promise acquired from them,
12296 * vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
@@ -139,21 +113,6 @@ function showMessageWindow(params: ShowMessageWindowParams): void {
139113 }
140114}
141115
142- function showWarning ( params : ShowWarningParams ) : void {
143- const message : string = getLocalizedString ( params . localizeStringParams ) ;
144- let showChannel : boolean = false ;
145- if ( ! warningChannel ) {
146- warningChannel = vscode . window . createOutputChannel ( `${ localize ( "c.cpp.warnings" , "C/C++ Configuration Warnings" ) } ` ) ;
147- workspaceDisposables . push ( warningChannel ) ;
148- showChannel = true ;
149- }
150- // Append before showing the channel, to avoid a delay.
151- warningChannel . appendLine ( `[${ new Date ( ) . toLocaleString ( ) } ] ${ message } ` ) ;
152- if ( showChannel ) {
153- warningChannel . show ( true ) ;
154- }
155- }
156-
157116function publishIntelliSenseDiagnostics ( params : PublishIntelliSenseDiagnosticsParams ) : void {
158117 if ( ! diagnosticsCollectionIntelliSense ) {
159118 diagnosticsCollectionIntelliSense = vscode . languages . createDiagnosticCollection ( CppSourceStr ) ;
@@ -192,12 +151,6 @@ interface TelemetryPayload {
192151 metrics ?: { [ key : string ] : number } ;
193152}
194153
195- interface DebugProtocolParams {
196- jsonrpc : string ;
197- method : string ;
198- params ?: any ;
199- }
200-
201154interface ReportStatusNotificationBody extends WorkspaceFolderParams {
202155 status : string ;
203156}
@@ -301,10 +254,6 @@ interface ShowMessageWindowParams {
301254 localizeStringParams : LocalizeStringParams ;
302255}
303256
304- interface ShowWarningParams {
305- localizeStringParams : LocalizeStringParams ;
306- }
307-
308257export interface GetDocumentSymbolRequestParams {
309258 uri : string ;
310259}
@@ -1378,7 +1327,7 @@ export class DefaultClient implements Client {
13781327 } ,
13791328 vcpkg_root : util . getVcpkgRoot ( ) ,
13801329 experimentalFeatures : workspaceSettings . experimentalFeatures ,
1381- edgeMessagesDirectory : path . join ( util . getExtensionFilePath ( "bin" ) , "messages" , util . getLocaleId ( ) ) ,
1330+ edgeMessagesDirectory : path . join ( util . getExtensionFilePath ( "bin" ) , "messages" , getLocaleId ( ) ) ,
13821331 localizedStrings : localizedStrings ,
13831332 packageVersion : util . packageJson . version ,
13841333 legacyCompilerArgsBehavior : settings_legacyCompilerArgsBehavior
@@ -1518,7 +1467,7 @@ export class DefaultClient implements Client {
15181467 this . loggingLevel = newLoggingLevel ;
15191468 const newLoggingLevelLogged : boolean = ! ! newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error" ;
15201469 if ( oldLoggingLevelLogged || newLoggingLevelLogged ) {
1521- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
1470+ const out : Logger = getOutputChannelLogger ( ) ;
15221471 out . appendLine ( localize ( { key : "loggingLevel.changed" , comment : [ "{0} is the setting name 'loggingLevel', {1} is a string value such as 'Debug'" ] } , "{0} has changed to: {1}" , "loggingLevel" , changedSettings [ "loggingLevel" ] ) ) ;
15231472 }
15241473 }
@@ -1810,12 +1759,8 @@ export class DefaultClient implements Client {
18101759
18111760 public async logDiagnostics ( ) : Promise < void > {
18121761 const response : GetDiagnosticsResult = await this . requestWhenReady ( ( ) => this . languageClient . sendRequest ( GetDiagnosticsRequest , null ) ) ;
1813- if ( ! diagnosticsChannel ) {
1814- diagnosticsChannel = vscode . window . createOutputChannel ( localize ( "c.cpp.diagnostics" , "C/C++ Diagnostics" ) ) ;
1815- workspaceDisposables . push ( diagnosticsChannel ) ;
1816- } else {
1817- diagnosticsChannel . clear ( ) ;
1818- }
1762+ const diagnosticsChannel : vscode . OutputChannel = getDiagnosticsChannel ( ) ;
1763+ diagnosticsChannel . clear ( ) ;
18191764
18201765 const header : string = `-------- Diagnostics - ${ new Date ( ) . toLocaleString ( ) } \n` ;
18211766 const version : string = `Version: ${ util . packageJson . version } \n` ;
@@ -2352,7 +2297,7 @@ export class DefaultClient implements Client {
23522297 } else if ( message . endsWith ( "IntelliSense done" ) ) {
23532298 const settings : CppSettings = new CppSettings ( ) ;
23542299 if ( settings . loggingLevel === "Debug" ) {
2355- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2300+ const out : Logger = getOutputChannelLogger ( ) ;
23562301 const duration : number = Date . now ( ) - timeStamp ;
23572302 out . appendLine ( localize ( "update.intellisense.time" , "Update IntelliSense time (sec): {0}" , duration / 1000 ) ) ;
23582303 }
@@ -2425,7 +2370,7 @@ export class DefaultClient implements Client {
24252370 }
24262371
24272372 private updateTagParseStatus ( notificationBody : LocalizeStringParams ) : void {
2428- this . model . parsingWorkspaceStatus . Value = util . getLocalizedString ( notificationBody ) ;
2373+ this . model . parsingWorkspaceStatus . Value = getLocalizedString ( notificationBody ) ;
24292374 if ( notificationBody . text . startsWith ( "Workspace parsing paused" ) ) {
24302375 this . model . isParsingWorkspacePausable . Value = true ;
24312376 this . model . isParsingWorkspacePaused . Value = true ;
@@ -2768,7 +2713,7 @@ export class DefaultClient implements Client {
27682713 }
27692714
27702715 const settings : CppSettings = new CppSettings ( ) ;
2771- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2716+ const out : Logger = getOutputChannelLogger ( ) ;
27722717 if ( settings . loggingLevel === "Debug" ) {
27732718 out . appendLine ( localize ( "configurations.received" , "Custom configurations received:" ) ) ;
27742719 }
@@ -2872,7 +2817,7 @@ export class DefaultClient implements Client {
28722817
28732818 const settings : CppSettings = new CppSettings ( ) ;
28742819 if ( settings . loggingLevel === "Debug" ) {
2875- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2820+ const out : Logger = getOutputChannelLogger ( ) ;
28762821 out . appendLine ( localize ( "browse.configuration.received" , "Custom browse configuration received: {0}" , JSON . stringify ( sanitized , null , 2 ) ) ) ;
28772822 }
28782823
0 commit comments