@@ -24,7 +24,7 @@ import { InlayHintsProvider } from './Providers/inlayHintProvider';
24
24
import { LanguageClient , LanguageClientOptions , ServerOptions , NotificationType , TextDocumentIdentifier , RequestType , ErrorAction , CloseAction , DidOpenTextDocumentParams , Range , Position , DocumentFilter } from 'vscode-languageclient' ;
25
25
import { SourceFileConfigurationItem , WorkspaceBrowseConfiguration , SourceFileConfiguration , Version } from 'vscode-cpptools' ;
26
26
import { Status , IntelliSenseStatus } from 'vscode-cpptools/out/testApi' ;
27
- import { getLocalizedString , LocalizeStringParams } from './localization' ;
27
+ import { getLocaleId , getLocalizedString , LocalizeStringParams } from './localization' ;
28
28
import { Location , TextEdit } from './commonTypes' ;
29
29
import { makeVscodeRange , makeVscodeLocation } from './utils' ;
30
30
import * as util from '../common' ;
@@ -37,7 +37,6 @@ import { ClientCollection } from './clientCollection';
37
37
import { createProtocolFilter } from './protocolFilter' ;
38
38
import { DataBinding } from './dataBinding' ;
39
39
import minimatch = require( "minimatch" ) ;
40
- import * as logger from '../logger' ;
41
40
import { updateLanguageConfigurations , CppSourceStr } from './extension' ;
42
41
import { SettingsTracker , getTracker } from './settingsTracker' ;
43
42
import { getTestHook , TestHook } from '../testHook' ;
@@ -49,6 +48,7 @@ import * as nls from 'vscode-nls';
49
48
import { lookupString , localizedStringCount } from '../nativeStrings' ;
50
49
import { CodeAnalysisDiagnosticIdentifiersAndUri , RegisterCodeAnalysisNotifications , removeAllCodeAnalysisProblems ,
51
50
removeCodeAnalysisProblems , RemoveCodeAnalysisProblemsParams } from './codeAnalysis' ;
51
+ import { DebugProtocolParams , getDiagnosticsChannel , getOutputChannelLogger , logDebugProtocol , Logger , logLocalized , showWarning , ShowWarningParams } from '../logger' ;
52
52
53
53
nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
54
54
const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
@@ -64,10 +64,6 @@ const languageClientCrashTimes: number[] = [];
64
64
let clientCollection : ClientCollection ;
65
65
let pendingTask : util . BlockingTask < any > | undefined ;
66
66
let compilerDefaults : configs . CompilerDefaults ;
67
- let diagnosticsChannel : vscode . OutputChannel ;
68
- let outputChannel : vscode . OutputChannel ;
69
- let debugChannel : vscode . OutputChannel ;
70
- let warningChannel : vscode . OutputChannel ;
71
67
let diagnosticsCollectionIntelliSense : vscode . DiagnosticCollection ;
72
68
73
69
let workspaceDisposables : vscode . Disposable [ ] = [ ] ;
@@ -91,32 +87,10 @@ function logTelemetry(notificationBody: TelemetryPayload): void {
91
87
function setupOutputHandlers ( ) : void {
92
88
console . assert ( languageClient !== undefined , "This method must not be called until this.languageClient is set in \"onReady\"" ) ;
93
89
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 ) ;
104
91
languageClient . onNotification ( DebugLogNotification , logLocalized ) ;
105
92
}
106
93
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
-
120
94
/** Note: We should not await on the following functions,
121
95
* or any funstion that returns a promise acquired from them,
122
96
* vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
@@ -139,21 +113,6 @@ function showMessageWindow(params: ShowMessageWindowParams): void {
139
113
}
140
114
}
141
115
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
-
157
116
function publishIntelliSenseDiagnostics ( params : PublishIntelliSenseDiagnosticsParams ) : void {
158
117
if ( ! diagnosticsCollectionIntelliSense ) {
159
118
diagnosticsCollectionIntelliSense = vscode . languages . createDiagnosticCollection ( CppSourceStr ) ;
@@ -192,12 +151,6 @@ interface TelemetryPayload {
192
151
metrics ?: { [ key : string ] : number } ;
193
152
}
194
153
195
- interface DebugProtocolParams {
196
- jsonrpc : string ;
197
- method : string ;
198
- params ?: any ;
199
- }
200
-
201
154
interface ReportStatusNotificationBody extends WorkspaceFolderParams {
202
155
status : string ;
203
156
}
@@ -301,10 +254,6 @@ interface ShowMessageWindowParams {
301
254
localizeStringParams : LocalizeStringParams ;
302
255
}
303
256
304
- interface ShowWarningParams {
305
- localizeStringParams : LocalizeStringParams ;
306
- }
307
-
308
257
export interface GetDocumentSymbolRequestParams {
309
258
uri : string ;
310
259
}
@@ -1378,7 +1327,7 @@ export class DefaultClient implements Client {
1378
1327
} ,
1379
1328
vcpkg_root : util . getVcpkgRoot ( ) ,
1380
1329
experimentalFeatures : workspaceSettings . experimentalFeatures ,
1381
- edgeMessagesDirectory : path . join ( util . getExtensionFilePath ( "bin" ) , "messages" , util . getLocaleId ( ) ) ,
1330
+ edgeMessagesDirectory : path . join ( util . getExtensionFilePath ( "bin" ) , "messages" , getLocaleId ( ) ) ,
1382
1331
localizedStrings : localizedStrings ,
1383
1332
packageVersion : util . packageJson . version ,
1384
1333
legacyCompilerArgsBehavior : settings_legacyCompilerArgsBehavior
@@ -1518,7 +1467,7 @@ export class DefaultClient implements Client {
1518
1467
this . loggingLevel = newLoggingLevel ;
1519
1468
const newLoggingLevelLogged : boolean = ! ! newLoggingLevel && newLoggingLevel !== "None" && newLoggingLevel !== "Error" ;
1520
1469
if ( oldLoggingLevelLogged || newLoggingLevelLogged ) {
1521
- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
1470
+ const out : Logger = getOutputChannelLogger ( ) ;
1522
1471
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" ] ) ) ;
1523
1472
}
1524
1473
}
@@ -1810,12 +1759,8 @@ export class DefaultClient implements Client {
1810
1759
1811
1760
public async logDiagnostics ( ) : Promise < void > {
1812
1761
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 ( ) ;
1819
1764
1820
1765
const header : string = `-------- Diagnostics - ${ new Date ( ) . toLocaleString ( ) } \n` ;
1821
1766
const version : string = `Version: ${ util . packageJson . version } \n` ;
@@ -2352,7 +2297,7 @@ export class DefaultClient implements Client {
2352
2297
} else if ( message . endsWith ( "IntelliSense done" ) ) {
2353
2298
const settings : CppSettings = new CppSettings ( ) ;
2354
2299
if ( settings . loggingLevel === "Debug" ) {
2355
- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2300
+ const out : Logger = getOutputChannelLogger ( ) ;
2356
2301
const duration : number = Date . now ( ) - timeStamp ;
2357
2302
out . appendLine ( localize ( "update.intellisense.time" , "Update IntelliSense time (sec): {0}" , duration / 1000 ) ) ;
2358
2303
}
@@ -2425,7 +2370,7 @@ export class DefaultClient implements Client {
2425
2370
}
2426
2371
2427
2372
private updateTagParseStatus ( notificationBody : LocalizeStringParams ) : void {
2428
- this . model . parsingWorkspaceStatus . Value = util . getLocalizedString ( notificationBody ) ;
2373
+ this . model . parsingWorkspaceStatus . Value = getLocalizedString ( notificationBody ) ;
2429
2374
if ( notificationBody . text . startsWith ( "Workspace parsing paused" ) ) {
2430
2375
this . model . isParsingWorkspacePausable . Value = true ;
2431
2376
this . model . isParsingWorkspacePaused . Value = true ;
@@ -2768,7 +2713,7 @@ export class DefaultClient implements Client {
2768
2713
}
2769
2714
2770
2715
const settings : CppSettings = new CppSettings ( ) ;
2771
- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2716
+ const out : Logger = getOutputChannelLogger ( ) ;
2772
2717
if ( settings . loggingLevel === "Debug" ) {
2773
2718
out . appendLine ( localize ( "configurations.received" , "Custom configurations received:" ) ) ;
2774
2719
}
@@ -2872,7 +2817,7 @@ export class DefaultClient implements Client {
2872
2817
2873
2818
const settings : CppSettings = new CppSettings ( ) ;
2874
2819
if ( settings . loggingLevel === "Debug" ) {
2875
- const out : logger . Logger = logger . getOutputChannelLogger ( ) ;
2820
+ const out : Logger = getOutputChannelLogger ( ) ;
2876
2821
out . appendLine ( localize ( "browse.configuration.received" , "Custom browse configuration received: {0}" , JSON . stringify ( sanitized , null , 2 ) ) ) ;
2877
2822
}
2878
2823
0 commit comments