forked from microsoft/vscode-cpptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.ts
4133 lines (3730 loc) · 214 KB
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as path from 'path';
import * as vscode from 'vscode';
// Start provider imports
import { CallHierarchyProvider } from './Providers/callHierarchyProvider';
import { CodeActionProvider } from './Providers/codeActionProvider';
import { DocumentFormattingEditProvider } from './Providers/documentFormattingEditProvider';
import { DocumentRangeFormattingEditProvider } from './Providers/documentRangeFormattingEditProvider';
import { DocumentSymbolProvider } from './Providers/documentSymbolProvider';
import { FindAllReferencesProvider } from './Providers/findAllReferencesProvider';
import { FoldingRangeProvider } from './Providers/foldingRangeProvider';
import { CppInlayHint, InlayHintsProvider } from './Providers/inlayHintProvider';
import { OnTypeFormattingEditProvider } from './Providers/onTypeFormattingEditProvider';
import { RenameProvider } from './Providers/renameProvider';
import { SemanticToken, SemanticTokensProvider } from './Providers/semanticTokensProvider';
import { WorkspaceSymbolProvider } from './Providers/workspaceSymbolProvider';
// End provider imports
import { ok } from 'assert';
import * as fs from 'fs';
import * as os from 'os';
import { SourceFileConfiguration, SourceFileConfigurationItem, Version, WorkspaceBrowseConfiguration } from 'vscode-cpptools';
import { IntelliSenseStatus, Status } from 'vscode-cpptools/out/testApi';
import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOptions, NotificationType, Position, Range, RequestType, ResponseError, TextDocumentIdentifier, TextDocumentPositionParams } from 'vscode-languageclient';
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
import * as nls from 'vscode-nls';
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';
import { CustomConfigurationProvider1, getCustomConfigProviders, isSameProviderExtensionId } from '../LanguageServer/customProviders';
import { ManualPromise } from '../Utility/Async/manualPromise';
import { ManualSignal } from '../Utility/Async/manualSignal';
import { logAndReturn } from '../Utility/Async/returns';
import { is } from '../Utility/System/guards';
import * as util from '../common';
import { isWindows } from '../constants';
import { DebugProtocolParams, Logger, ShowWarningParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, logLocalized, showWarning } from '../logger';
import { localizedStringCount, lookupString } from '../nativeStrings';
import { SessionState } from '../sessionState';
import * as telemetry from '../telemetry';
import { TestHook, getTestHook } from '../testHook';
import { HoverProvider } from './Providers/HoverProvider';
import {
CodeAnalysisDiagnosticIdentifiersAndUri,
RegisterCodeAnalysisNotifications,
RemoveCodeAnalysisProblemsParams,
removeAllCodeAnalysisProblems,
removeCodeAnalysisProblems
} from './codeAnalysis';
import { Location, TextEdit, WorkspaceEdit } from './commonTypes';
import * as configs from './configurations';
import { DataBinding } from './dataBinding';
import { cachedEditorConfigSettings, getEditorConfigSettings } from './editorConfig';
import { CppSourceStr, clients, configPrefix, updateLanguageConfigurations, usesCrashHandler, watchForCrashes } from './extension';
import { LocalizeStringParams, getLocaleId, getLocalizedString } from './localization';
import { PersistentFolderState, PersistentWorkspaceState } from './persistentState';
import { RequestCancelled, ServerCancelled, createProtocolFilter } from './protocolFilter';
import * as refs from './references';
import { CppSettings, OtherSettings, SettingsParams, WorkspaceFolderSettingsParams } from './settings';
import { SettingsTracker } from './settingsTracker';
import { ConfigurationType, LanguageStatusUI, getUI } from './ui';
import { handleChangedFromCppToC, makeLspRange, makeVscodeLocation, makeVscodeRange, withCancellation } from './utils';
import minimatch = require("minimatch");
function deepCopy(obj: any) {
return JSON.parse(JSON.stringify(obj));
}
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
let ui: LanguageStatusUI;
let timeStamp: number = 0;
const configProviderTimeout: number = 2000;
let initializedClientCount: number = 0;
// Compiler paths that are known to be acceptable to execute.
const trustedCompilerPaths: string[] = [];
export function hasTrustedCompilerPaths(): boolean {
return trustedCompilerPaths.length !== 0;
}
// Data shared by all clients.
let languageClient: LanguageClient;
let firstClientStarted: Promise<void>;
let languageClientCrashedNeedsRestart: boolean = false;
const languageClientCrashTimes: number[] = [];
let compilerDefaults: configs.CompilerDefaults | undefined;
let diagnosticsCollectionIntelliSense: vscode.DiagnosticCollection;
let diagnosticsCollectionRefactor: vscode.DiagnosticCollection;
interface ConfigStateReceived {
compilers: boolean;
compileCommands: boolean;
configProviders?: CustomConfigurationProvider1[];
timeout: boolean;
}
let workspaceHash: string = "";
let workspaceDisposables: vscode.Disposable[] = [];
export let workspaceReferences: refs.ReferencesManager;
export const openFileVersions: Map<string, number> = new Map<string, number>();
export const cachedEditorConfigLookups: Map<string, boolean> = new Map<string, boolean>();
export let semanticTokensLegend: vscode.SemanticTokensLegend | undefined;
export function disposeWorkspaceData(): void {
workspaceDisposables.forEach((d) => d.dispose());
workspaceDisposables = [];
}
/** Note: We should not await on the following functions,
* or any function that returns a promise acquired from them,
* vscode.window.showInformationMessage, vscode.window.showWarningMessage, vscode.window.showErrorMessage
*/
function showMessageWindow(params: ShowMessageWindowParams): void {
const message: string = getLocalizedString(params.localizeStringParams);
switch (params.type) {
case 1: // Error
void vscode.window.showErrorMessage(message);
break;
case 2: // Warning
void vscode.window.showWarningMessage(message);
break;
case 3: // Info
void vscode.window.showInformationMessage(message);
break;
default:
console.assert("Unrecognized type for showMessageWindow");
break;
}
}
function publishRefactorDiagnostics(params: PublishRefactorDiagnosticsParams): void {
if (!diagnosticsCollectionRefactor) {
diagnosticsCollectionRefactor = vscode.languages.createDiagnosticCollection(configPrefix + "Refactor");
}
const newDiagnostics: vscode.Diagnostic[] = [];
params.diagnostics.forEach((d) => {
const message: string = getLocalizedString(d.localizeStringParams);
const diagnostic: vscode.Diagnostic = new vscode.Diagnostic(makeVscodeRange(d.range), message, d.severity);
diagnostic.code = d.code;
diagnostic.source = CppSourceStr;
if (d.relatedInformation) {
diagnostic.relatedInformation = [];
for (const info of d.relatedInformation) {
diagnostic.relatedInformation.push(new vscode.DiagnosticRelatedInformation(makeVscodeLocation(info.location), info.message));
}
}
newDiagnostics.push(diagnostic);
});
const fileUri: vscode.Uri = vscode.Uri.parse(params.uri);
diagnosticsCollectionRefactor.set(fileUri, newDiagnostics);
}
interface WorkspaceFolderParams {
workspaceFolderUri?: string;
}
interface SelectionParams {
uri: string;
range: Range;
}
export interface VsCodeUriAndRange {
uri: vscode.Uri;
range: vscode.Range;
}
interface WorkspaceEditResult {
workspaceEdits: WorkspaceEdit[];
errorText?: string;
}
interface TelemetryPayload {
event: string;
properties?: Record<string, string>;
metrics?: Record<string, number>;
}
interface ReportStatusNotificationBody extends WorkspaceFolderParams {
status: string;
}
interface QueryDefaultCompilerParams {
newTrustedCompilerPath: string;
}
interface CppPropertiesParams extends WorkspaceFolderParams {
currentConfiguration: number;
configurations: configs.Configuration[];
isReady?: boolean;
}
interface FolderSelectedSettingParams extends WorkspaceFolderParams {
currentConfiguration: number;
}
interface SwitchHeaderSourceParams extends WorkspaceFolderParams {
switchHeaderSourceFileName: string;
}
interface FileChangedParams extends WorkspaceFolderParams {
uri: string;
}
interface InputRegion {
startLine: number;
endLine: number;
}
interface DecorationRangesPair {
decoration: vscode.TextEditorDecorationType;
ranges: vscode.Range[];
}
interface InternalSourceFileConfiguration extends SourceFileConfiguration {
compilerArgsLegacy?: string[];
}
interface InternalWorkspaceBrowseConfiguration extends WorkspaceBrowseConfiguration {
compilerArgsLegacy?: string[];
}
// Need to convert vscode.Uri to a string before sending it to the language server.
interface SourceFileConfigurationItemAdapter {
uri: string;
configuration: InternalSourceFileConfiguration;
}
interface CustomConfigurationParams extends WorkspaceFolderParams {
configurationItems: SourceFileConfigurationItemAdapter[];
}
interface CustomBrowseConfigurationParams extends WorkspaceFolderParams {
browseConfiguration: InternalWorkspaceBrowseConfiguration;
}
interface CompileCommandsPaths extends WorkspaceFolderParams {
paths: string[];
}
interface GetDiagnosticsResult {
diagnostics: string;
}
interface IntelliSenseDiagnosticRelatedInformation {
location: Location;
message: string;
}
interface RefactorDiagnosticRelatedInformation {
location: Location;
message: string;
}
interface IntelliSenseDiagnostic {
range: Range;
code?: number;
severity: vscode.DiagnosticSeverity;
localizeStringParams: LocalizeStringParams;
relatedInformation?: IntelliSenseDiagnosticRelatedInformation[];
}
interface RefactorDiagnostic {
range: Range;
code?: number;
severity: vscode.DiagnosticSeverity;
localizeStringParams: LocalizeStringParams;
relatedInformation?: RefactorDiagnosticRelatedInformation[];
}
interface PublishRefactorDiagnosticsParams {
uri: string;
diagnostics: RefactorDiagnostic[];
}
export interface CreateDeclarationOrDefinitionParams extends SelectionParams {
formatParams: FormatParams;
copyToClipboard: boolean;
}
export interface CreateDeclarationOrDefinitionResult extends WorkspaceEditResult {
clipboardText?: string;
}
export interface ExtractToFunctionParams extends SelectionParams {
extractAsGlobal: boolean;
name: string;
}
interface ShowMessageWindowParams {
type: number;
localizeStringParams: LocalizeStringParams;
}
export interface GetDocumentSymbolRequestParams {
uri: string;
}
export interface WorkspaceSymbolParams extends WorkspaceFolderParams {
query: string;
experimentEnabled: boolean;
}
export enum SymbolScope {
Public = 0,
Protected = 1,
Private = 2
}
export interface LocalizeDocumentSymbol {
name: string;
detail: LocalizeStringParams;
kind: vscode.SymbolKind;
scope: SymbolScope;
range: Range;
selectionRange: Range;
children: LocalizeDocumentSymbol[];
}
export interface GetDocumentSymbolResult {
symbols: LocalizeDocumentSymbol[];
}
export interface LocalizeSymbolInformation {
name: string;
kind: vscode.SymbolKind;
scope: SymbolScope;
location: Location;
containerName: string;
suffix: LocalizeStringParams;
}
export interface FormatParams extends SelectionParams {
character: string;
insertSpaces: boolean;
tabSize: number;
editorConfigSettings: any;
useVcFormat: boolean;
onChanges: boolean;
}
export interface FormatResult {
edits: TextEdit[];
}
export interface GetFoldingRangesParams {
uri: string;
}
export enum FoldingRangeKind {
None = 0,
Comment = 1,
Imports = 2,
Region = 3
}
export interface CppFoldingRange {
kind: FoldingRangeKind;
range: InputRegion;
}
export interface GetFoldingRangesResult {
ranges: CppFoldingRange[];
}
export interface IntelliSenseResult {
uri: string;
fileVersion: number;
diagnostics: IntelliSenseDiagnostic[];
inactiveRegions: InputRegion[];
semanticTokens: SemanticToken[];
inlayHints: CppInlayHint[];
clearExistingDiagnostics: boolean;
clearExistingInactiveRegions: boolean;
clearExistingSemanticTokens: boolean;
clearExistingInlayHint: boolean;
isCompletePass: boolean;
}
enum SemanticTokenTypes {
// These are camelCase as the enum names are used directly as strings in our legend.
macro = 0,
enumMember = 1,
variable = 2,
parameter = 3,
type = 4,
referenceType = 5,
valueType = 6,
function = 7,
method = 8,
property = 9,
cliProperty = 10,
event = 11,
genericType = 12,
templateFunction = 13,
templateType = 14,
namespace = 15,
label = 16,
customLiteral = 17,
numberLiteral = 18,
stringLiteral = 19,
operatorOverload = 20,
memberOperatorOverload = 21,
newOperator = 22
}
enum SemanticTokenModifiers {
// These are camelCase as the enum names are used directly as strings in our legend.
static = 0b001,
global = 0b010,
local = 0b100
}
interface IntelliSenseSetup {
uri: string;
}
interface GoToDirectiveInGroupParams {
uri: string;
position: Position;
next: boolean;
}
export interface GenerateDoxygenCommentParams {
uri: string;
position: Position;
isCodeAction: boolean;
isCursorAboveSignatureLine: boolean | undefined;
}
export interface GenerateDoxygenCommentResult {
contents: string;
initPosition: Position;
finalInsertionLine: number;
finalCursorPosition: Position;
fileVersion: number;
isCursorAboveSignatureLine: boolean;
}
export interface IndexableQuickPickItem extends vscode.QuickPickItem {
index: number;
}
export interface UpdateTrustedCompilerPathsResult {
compilerPath: string;
}
export interface DoxygenCodeActionCommandArguments {
initialCursor: Position;
adjustedCursor: Position;
isCursorAboveSignatureLine: boolean;
}
interface SetTemporaryTextDocumentLanguageParams {
uri: string;
isC: boolean;
isCuda: boolean;
}
enum CodeAnalysisScope {
ActiveFile,
OpenFiles,
AllFiles,
ClearSquiggles
}
interface CodeAnalysisParams {
scope: CodeAnalysisScope;
}
interface FinishedRequestCustomConfigParams {
uri: string;
}
export interface TextDocumentWillSaveParams {
textDocument: TextDocumentIdentifier;
reason: vscode.TextDocumentSaveReason;
}
interface LspInitializationOptions {
loggingLevel: number;
}
interface CppInitializationParams {
packageVersion: string;
extensionPath: string;
cacheStoragePath: string;
workspaceStoragePath: string;
databaseStoragePath: string;
vcpkgRoot: string;
intelliSenseCacheDisabled: boolean;
caseSensitiveFileSupport: boolean;
resetDatabase: boolean;
edgeMessagesDirectory: string;
localizedStrings: string[];
settings: SettingsParams;
}
interface TagParseStatus {
localizeStringParams: LocalizeStringParams;
isPaused: boolean;
}
interface DidChangeVisibleTextEditorsParams {
activeUri?: string;
activeSelection?: Range;
visibleRanges?: { [uri: string]: Range[] };
}
interface DidChangeTextEditorVisibleRangesParams {
uri: string;
visibleRanges: Range[];
}
interface DidChangeActiveEditorParams {
uri?: string;
selection?: Range;
}
interface GetIncludesParams {
maxDepth: number;
}
export interface GetIncludesResult {
includedFiles: string[];
}
export interface ChatContextResult {
language: string;
standardVersion: string;
compiler: string;
targetPlatform: string;
targetArchitecture: string;
}
// Requests
const PreInitializationRequest: RequestType<void, string, void> = new RequestType<void, string, void>('cpptools/preinitialize');
const InitializationRequest: RequestType<CppInitializationParams, void, void> = new RequestType<CppInitializationParams, void, void>('cpptools/initialize');
const QueryCompilerDefaultsRequest: RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void> = new RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void>('cpptools/queryCompilerDefaults');
const SwitchHeaderSourceRequest: RequestType<SwitchHeaderSourceParams, string, void> = new RequestType<SwitchHeaderSourceParams, string, void>('cpptools/didSwitchHeaderSource');
const GetDiagnosticsRequest: RequestType<void, GetDiagnosticsResult, void> = new RequestType<void, GetDiagnosticsResult, void>('cpptools/getDiagnostics');
export const GetDocumentSymbolRequest: RequestType<GetDocumentSymbolRequestParams, GetDocumentSymbolResult, void> = new RequestType<GetDocumentSymbolRequestParams, GetDocumentSymbolResult, void>('cpptools/getDocumentSymbols');
export const GetSymbolInfoRequest: RequestType<WorkspaceSymbolParams, LocalizeSymbolInformation[], void> = new RequestType<WorkspaceSymbolParams, LocalizeSymbolInformation[], void>('cpptools/getWorkspaceSymbols');
export const GetFoldingRangesRequest: RequestType<GetFoldingRangesParams, GetFoldingRangesResult, void> = new RequestType<GetFoldingRangesParams, GetFoldingRangesResult, void>('cpptools/getFoldingRanges');
export const FormatDocumentRequest: RequestType<FormatParams, FormatResult, void> = new RequestType<FormatParams, FormatResult, void>('cpptools/formatDocument');
export const FormatRangeRequest: RequestType<FormatParams, FormatResult, void> = new RequestType<FormatParams, FormatResult, void>('cpptools/formatRange');
export const FormatOnTypeRequest: RequestType<FormatParams, FormatResult, void> = new RequestType<FormatParams, FormatResult, void>('cpptools/formatOnType');
export const HoverRequest: RequestType<TextDocumentPositionParams, vscode.Hover, void> = new RequestType<TextDocumentPositionParams, vscode.Hover, void>('cpptools/hover');
const CreateDeclarationOrDefinitionRequest: RequestType<CreateDeclarationOrDefinitionParams, CreateDeclarationOrDefinitionResult, void> = new RequestType<CreateDeclarationOrDefinitionParams, CreateDeclarationOrDefinitionResult, void>('cpptools/createDeclDef');
const ExtractToFunctionRequest: RequestType<ExtractToFunctionParams, WorkspaceEditResult, void> = new RequestType<ExtractToFunctionParams, WorkspaceEditResult, void>('cpptools/extractToFunction');
const GoToDirectiveInGroupRequest: RequestType<GoToDirectiveInGroupParams, Position | undefined, void> = new RequestType<GoToDirectiveInGroupParams, Position | undefined, void>('cpptools/goToDirectiveInGroup');
const GenerateDoxygenCommentRequest: RequestType<GenerateDoxygenCommentParams, GenerateDoxygenCommentResult | undefined, void> = new RequestType<GenerateDoxygenCommentParams, GenerateDoxygenCommentResult, void>('cpptools/generateDoxygenComment');
const ChangeCppPropertiesRequest: RequestType<CppPropertiesParams, void, void> = new RequestType<CppPropertiesParams, void, void>('cpptools/didChangeCppProperties');
const IncludesRequest: RequestType<GetIncludesParams, GetIncludesResult, void> = new RequestType<GetIncludesParams, GetIncludesResult, void>('cpptools/getIncludes');
const CppContextRequest: RequestType<void, ChatContextResult, void> = new RequestType<void, ChatContextResult, void>('cpptools/getChatContext');
// Notifications to the server
const DidOpenNotification: NotificationType<DidOpenTextDocumentParams> = new NotificationType<DidOpenTextDocumentParams>('textDocument/didOpen');
const FileCreatedNotification: NotificationType<FileChangedParams> = new NotificationType<FileChangedParams>('cpptools/fileCreated');
const FileChangedNotification: NotificationType<FileChangedParams> = new NotificationType<FileChangedParams>('cpptools/fileChanged');
const FileDeletedNotification: NotificationType<FileChangedParams> = new NotificationType<FileChangedParams>('cpptools/fileDeleted');
const ResetDatabaseNotification: NotificationType<void> = new NotificationType<void>('cpptools/resetDatabase');
const PauseParsingNotification: NotificationType<void> = new NotificationType<void>('cpptools/pauseParsing');
const ResumeParsingNotification: NotificationType<void> = new NotificationType<void>('cpptools/resumeParsing');
const DidChangeActiveEditorNotification: NotificationType<DidChangeActiveEditorParams> = new NotificationType<DidChangeActiveEditorParams>('cpptools/didChangeActiveEditor');
const RestartIntelliSenseForFileNotification: NotificationType<TextDocumentIdentifier> = new NotificationType<TextDocumentIdentifier>('cpptools/restartIntelliSenseForFile');
const DidChangeTextEditorSelectionNotification: NotificationType<Range> = new NotificationType<Range>('cpptools/didChangeTextEditorSelection');
const ChangeCompileCommandsNotification: NotificationType<FileChangedParams> = new NotificationType<FileChangedParams>('cpptools/didChangeCompileCommands');
const ChangeSelectedSettingNotification: NotificationType<FolderSelectedSettingParams> = new NotificationType<FolderSelectedSettingParams>('cpptools/didChangeSelectedSetting');
const IntervalTimerNotification: NotificationType<void> = new NotificationType<void>('cpptools/onIntervalTimer');
const CustomConfigurationHighPriorityNotification: NotificationType<CustomConfigurationParams> = new NotificationType<CustomConfigurationParams>('cpptools/didChangeCustomConfigurationHighPriority');
const CustomConfigurationNotification: NotificationType<CustomConfigurationParams> = new NotificationType<CustomConfigurationParams>('cpptools/didChangeCustomConfiguration');
const CustomBrowseConfigurationNotification: NotificationType<CustomBrowseConfigurationParams> = new NotificationType<CustomBrowseConfigurationParams>('cpptools/didChangeCustomBrowseConfiguration');
const ClearCustomConfigurationsNotification: NotificationType<WorkspaceFolderParams> = new NotificationType<WorkspaceFolderParams>('cpptools/clearCustomConfigurations');
const ClearCustomBrowseConfigurationNotification: NotificationType<WorkspaceFolderParams> = new NotificationType<WorkspaceFolderParams>('cpptools/clearCustomBrowseConfiguration');
const PreviewReferencesNotification: NotificationType<void> = new NotificationType<void>('cpptools/previewReferences');
const RescanFolderNotification: NotificationType<void> = new NotificationType<void>('cpptools/rescanFolder');
const FinishedRequestCustomConfig: NotificationType<FinishedRequestCustomConfigParams> = new NotificationType<FinishedRequestCustomConfigParams>('cpptools/finishedRequestCustomConfig');
const DidChangeSettingsNotification: NotificationType<SettingsParams> = new NotificationType<SettingsParams>('cpptools/didChangeSettings');
const DidChangeVisibleTextEditorsNotification: NotificationType<DidChangeVisibleTextEditorsParams> = new NotificationType<DidChangeVisibleTextEditorsParams>('cpptools/didChangeVisibleTextEditors');
const DidChangeTextEditorVisibleRangesNotification: NotificationType<DidChangeTextEditorVisibleRangesParams> = new NotificationType<DidChangeTextEditorVisibleRangesParams>('cpptools/didChangeTextEditorVisibleRanges');
const CodeAnalysisNotification: NotificationType<CodeAnalysisParams> = new NotificationType<CodeAnalysisParams>('cpptools/runCodeAnalysis');
const PauseCodeAnalysisNotification: NotificationType<void> = new NotificationType<void>('cpptools/pauseCodeAnalysis');
const ResumeCodeAnalysisNotification: NotificationType<void> = new NotificationType<void>('cpptools/resumeCodeAnalysis');
const CancelCodeAnalysisNotification: NotificationType<void> = new NotificationType<void>('cpptools/cancelCodeAnalysis');
const RemoveCodeAnalysisProblemsNotification: NotificationType<RemoveCodeAnalysisProblemsParams> = new NotificationType<RemoveCodeAnalysisProblemsParams>('cpptools/removeCodeAnalysisProblems');
// Notifications from the server
const ReloadWindowNotification: NotificationType<void> = new NotificationType<void>('cpptools/reloadWindow');
const UpdateTrustedCompilersNotification: NotificationType<UpdateTrustedCompilerPathsResult> = new NotificationType<UpdateTrustedCompilerPathsResult>('cpptools/updateTrustedCompilersList');
const LogTelemetryNotification: NotificationType<TelemetryPayload> = new NotificationType<TelemetryPayload>('cpptools/logTelemetry');
const ReportTagParseStatusNotification: NotificationType<TagParseStatus> = new NotificationType<TagParseStatus>('cpptools/reportTagParseStatus');
const ReportStatusNotification: NotificationType<ReportStatusNotificationBody> = new NotificationType<ReportStatusNotificationBody>('cpptools/reportStatus');
const DebugProtocolNotification: NotificationType<DebugProtocolParams> = new NotificationType<DebugProtocolParams>('cpptools/debugProtocol');
const DebugLogNotification: NotificationType<LocalizeStringParams> = new NotificationType<LocalizeStringParams>('cpptools/debugLog');
const CompileCommandsPathsNotification: NotificationType<CompileCommandsPaths> = new NotificationType<CompileCommandsPaths>('cpptools/compileCommandsPaths');
const ReferencesNotification: NotificationType<refs.ReferencesResult> = new NotificationType<refs.ReferencesResult>('cpptools/references');
const ReportReferencesProgressNotification: NotificationType<refs.ReportReferencesProgressNotification> = new NotificationType<refs.ReportReferencesProgressNotification>('cpptools/reportReferencesProgress');
const RequestCustomConfig: NotificationType<string> = new NotificationType<string>('cpptools/requestCustomConfig');
const PublishRefactorDiagnosticsNotification: NotificationType<PublishRefactorDiagnosticsParams> = new NotificationType<PublishRefactorDiagnosticsParams>('cpptools/publishRefactorDiagnostics');
const ShowMessageWindowNotification: NotificationType<ShowMessageWindowParams> = new NotificationType<ShowMessageWindowParams>('cpptools/showMessageWindow');
const ShowWarningNotification: NotificationType<ShowWarningParams> = new NotificationType<ShowWarningParams>('cpptools/showWarning');
const ReportTextDocumentLanguage: NotificationType<string> = new NotificationType<string>('cpptools/reportTextDocumentLanguage');
const IntelliSenseSetupNotification: NotificationType<IntelliSenseSetup> = new NotificationType<IntelliSenseSetup>('cpptools/IntelliSenseSetup');
const SetTemporaryTextDocumentLanguageNotification: NotificationType<SetTemporaryTextDocumentLanguageParams> = new NotificationType<SetTemporaryTextDocumentLanguageParams>('cpptools/setTemporaryTextDocumentLanguage');
const ReportCodeAnalysisProcessedNotification: NotificationType<number> = new NotificationType<number>('cpptools/reportCodeAnalysisProcessed');
const ReportCodeAnalysisTotalNotification: NotificationType<number> = new NotificationType<number>('cpptools/reportCodeAnalysisTotal');
const DoxygenCommentGeneratedNotification: NotificationType<GenerateDoxygenCommentResult> = new NotificationType<GenerateDoxygenCommentResult>('cpptools/insertDoxygenComment');
const CanceledReferencesNotification: NotificationType<void> = new NotificationType<void>('cpptools/canceledReferences');
const IntelliSenseResultNotification: NotificationType<IntelliSenseResult> = new NotificationType<IntelliSenseResult>('cpptools/intelliSenseResult');
let failureMessageShown: boolean = false;
class ClientModel {
public isInitializingWorkspace: DataBinding<boolean>;
public isIndexingWorkspace: DataBinding<boolean>;
public isParsingWorkspace: DataBinding<boolean>;
public isParsingWorkspacePaused: DataBinding<boolean>;
public isParsingFiles: DataBinding<boolean>;
public isUpdatingIntelliSense: DataBinding<boolean>;
public isRunningCodeAnalysis: DataBinding<boolean>;
public isCodeAnalysisPaused: DataBinding<boolean>;
public codeAnalysisProcessed: DataBinding<number>;
public codeAnalysisTotal: DataBinding<number>;
public referencesCommandMode: DataBinding<refs.ReferencesCommandMode>;
public parsingWorkspaceStatus: DataBinding<string>;
public activeConfigName: DataBinding<string>;
constructor() {
this.isInitializingWorkspace = new DataBinding<boolean>(false);
this.isIndexingWorkspace = new DataBinding<boolean>(false);
// The following elements add a delay of 500ms before notitfying the UI that the icon can hide itself.
this.isParsingWorkspace = new DataBinding<boolean>(false, 500, false);
this.isParsingWorkspacePaused = new DataBinding<boolean>(false, 500, false);
this.isParsingFiles = new DataBinding<boolean>(false, 500, false);
this.isUpdatingIntelliSense = new DataBinding<boolean>(false, 500, false);
this.isRunningCodeAnalysis = new DataBinding<boolean>(false);
this.isCodeAnalysisPaused = new DataBinding<boolean>(false);
this.codeAnalysisProcessed = new DataBinding<number>(0);
this.codeAnalysisTotal = new DataBinding<number>(0);
this.referencesCommandMode = new DataBinding<refs.ReferencesCommandMode>(refs.ReferencesCommandMode.None);
this.parsingWorkspaceStatus = new DataBinding<string>("");
this.activeConfigName = new DataBinding<string>("");
}
public activate(): void {
this.isInitializingWorkspace.activate();
this.isIndexingWorkspace.activate();
this.isParsingWorkspace.activate();
this.isParsingWorkspacePaused.activate();
this.isParsingFiles.activate();
this.isUpdatingIntelliSense.activate();
this.isRunningCodeAnalysis.activate();
this.isCodeAnalysisPaused.activate();
this.codeAnalysisProcessed.activate();
this.codeAnalysisTotal.activate();
this.referencesCommandMode.activate();
this.parsingWorkspaceStatus.activate();
this.activeConfigName.activate();
}
public deactivate(): void {
this.isInitializingWorkspace.deactivate();
this.isIndexingWorkspace.deactivate();
this.isParsingWorkspace.deactivate();
this.isParsingWorkspacePaused.deactivate();
this.isParsingFiles.deactivate();
this.isUpdatingIntelliSense.deactivate();
this.isRunningCodeAnalysis.deactivate();
this.isCodeAnalysisPaused.deactivate();
this.codeAnalysisProcessed.deactivate();
this.codeAnalysisTotal.deactivate();
this.referencesCommandMode.deactivate();
this.parsingWorkspaceStatus.deactivate();
this.activeConfigName.deactivate();
}
public dispose(): void {
this.isInitializingWorkspace.dispose();
this.isIndexingWorkspace.dispose();
this.isParsingWorkspace.dispose();
this.isParsingWorkspacePaused.dispose();
this.isParsingFiles.dispose();
this.isUpdatingIntelliSense.dispose();
this.isRunningCodeAnalysis.dispose();
this.isCodeAnalysisPaused.dispose();
this.codeAnalysisProcessed.dispose();
this.codeAnalysisTotal.dispose();
this.referencesCommandMode.dispose();
this.parsingWorkspaceStatus.dispose();
this.activeConfigName.dispose();
}
}
export interface Client {
readonly ready: Promise<void>;
enqueue<T>(task: () => Promise<T>): Promise<T>;
InitializingWorkspaceChanged: vscode.Event<boolean>;
IndexingWorkspaceChanged: vscode.Event<boolean>;
ParsingWorkspaceChanged: vscode.Event<boolean>;
ParsingWorkspacePausedChanged: vscode.Event<boolean>;
ParsingFilesChanged: vscode.Event<boolean>;
IntelliSenseParsingChanged: vscode.Event<boolean>;
RunningCodeAnalysisChanged: vscode.Event<boolean>;
CodeAnalysisPausedChanged: vscode.Event<boolean>;
CodeAnalysisProcessedChanged: vscode.Event<number>;
CodeAnalysisTotalChanged: vscode.Event<number>;
ReferencesCommandModeChanged: vscode.Event<refs.ReferencesCommandMode>;
TagParserStatusChanged: vscode.Event<string>;
ActiveConfigChanged: vscode.Event<string>;
RootPath: string;
RootRealPath: string;
RootUri?: vscode.Uri;
RootFolder?: vscode.WorkspaceFolder;
Name: string;
TrackedDocuments: Map<string, vscode.TextDocument>;
onDidChangeSettings(event: vscode.ConfigurationChangeEvent): Promise<Record<string, string>>;
onDidOpenTextDocument(document: vscode.TextDocument): void;
onDidCloseTextDocument(document: vscode.TextDocument): void;
onDidChangeVisibleTextEditors(editors: readonly vscode.TextEditor[]): Promise<void>;
onDidChangeTextEditorVisibleRanges(uri: vscode.Uri): Promise<void>;
onDidChangeTextDocument(textDocumentChangeEvent: vscode.TextDocumentChangeEvent): void;
onRegisterCustomConfigurationProvider(provider: CustomConfigurationProvider1): Thenable<void>;
updateCustomConfigurations(requestingProvider?: CustomConfigurationProvider1): Thenable<void>;
updateCustomBrowseConfiguration(requestingProvider?: CustomConfigurationProvider1): Thenable<void>;
provideCustomConfiguration(docUri: vscode.Uri): Promise<void>;
logDiagnostics(): Promise<void>;
rescanFolder(): Promise<void>;
toggleReferenceResultsView(): void;
setCurrentConfigName(configurationName: string): Thenable<void>;
getCurrentConfigName(): Thenable<string | undefined>;
getCurrentConfigCustomVariable(variableName: string): Thenable<string>;
getVcpkgInstalled(): Thenable<boolean>;
getVcpkgEnabled(): Thenable<boolean>;
getCurrentCompilerPathAndArgs(): Thenable<util.CompilerPathAndArgs | undefined>;
getKnownCompilers(): Thenable<configs.KnownCompiler[] | undefined>;
takeOwnership(document: vscode.TextDocument): void;
sendDidOpen(document: vscode.TextDocument): Promise<void>;
requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string): Thenable<string>;
updateActiveDocumentTextOptions(): void;
didChangeActiveEditor(editor?: vscode.TextEditor, selection?: Range): Promise<void>;
restartIntelliSenseForFile(document: vscode.TextDocument): Promise<void>;
activate(): void;
selectionChanged(selection: Range): void;
resetDatabase(): void;
deactivate(): void;
promptSelectIntelliSenseConfiguration(sender?: any): Promise<void>;
rescanCompilers(sender?: any): Promise<void>;
pauseParsing(): void;
resumeParsing(): void;
PauseCodeAnalysis(): void;
ResumeCodeAnalysis(): void;
CancelCodeAnalysis(): void;
handleConfigurationSelectCommand(): Promise<void>;
handleConfigurationProviderSelectCommand(): Promise<void>;
handleShowActiveCodeAnalysisCommands(): Promise<void>;
handleShowIdleCodeAnalysisCommands(): Promise<void>;
handleReferencesIcon(): void;
handleConfigurationEditCommand(viewColumn?: vscode.ViewColumn): void;
handleConfigurationEditJSONCommand(viewColumn?: vscode.ViewColumn): void;
handleConfigurationEditUICommand(viewColumn?: vscode.ViewColumn): void;
handleAddToIncludePathCommand(path: string): void;
handleGoToDirectiveInGroup(next: boolean): Promise<void>;
handleGenerateDoxygenComment(args: DoxygenCodeActionCommandArguments | vscode.Uri | undefined): Promise<void>;
handleRunCodeAnalysisOnActiveFile(): Promise<void>;
handleRunCodeAnalysisOnOpenFiles(): Promise<void>;
handleRunCodeAnalysisOnAllFiles(): Promise<void>;
handleRemoveAllCodeAnalysisProblems(): Promise<void>;
handleRemoveCodeAnalysisProblems(refreshSquigglesOnSave: boolean, identifiersAndUris: CodeAnalysisDiagnosticIdentifiersAndUri[]): Promise<void>;
handleFixCodeAnalysisProblems(workspaceEdit: vscode.WorkspaceEdit, refreshSquigglesOnSave: boolean, identifiersAndUris: CodeAnalysisDiagnosticIdentifiersAndUri[]): Promise<void>;
handleDisableAllTypeCodeAnalysisProblems(code: string, identifiersAndUris: CodeAnalysisDiagnosticIdentifiersAndUri[]): Promise<void>;
handleCreateDeclarationOrDefinition(isCopyToClipboard: boolean, codeActionRange?: Range): Promise<void>;
handleExtractToFunction(extractAsGlobal: boolean): Promise<void>;
onInterval(): void;
dispose(): void;
addFileAssociations(fileAssociations: string, languageId: string): void;
sendDidChangeSettings(): void;
isInitialized(): boolean;
getShowConfigureIntelliSenseButton(): boolean;
setShowConfigureIntelliSenseButton(show: boolean): void;
addTrustedCompiler(path: string): Promise<void>;
getIncludes(maxDepth: number, token: vscode.CancellationToken): Promise<GetIncludesResult>;
getChatContext(token: vscode.CancellationToken): Promise<ChatContextResult>;
}
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
return new DefaultClient(workspaceFolder);
}
export function createNullClient(): Client {
return new NullClient();
}
export class DefaultClient implements Client {
private innerLanguageClient?: LanguageClient; // The "client" that launches and communicates with our language "server" process.
private disposables: vscode.Disposable[] = [];
private documentFormattingProviderDisposable: vscode.Disposable | undefined;
private formattingRangeProviderDisposable: vscode.Disposable | undefined;
private onTypeFormattingProviderDisposable: vscode.Disposable | undefined;
private codeFoldingProvider: FoldingRangeProvider | undefined;
private codeFoldingProviderDisposable: vscode.Disposable | undefined;
private inlayHintsProvider: InlayHintsProvider | undefined;
private semanticTokensProvider: SemanticTokensProvider | undefined;
private semanticTokensProviderDisposable: vscode.Disposable | undefined;
private innerConfiguration?: configs.CppProperties;
private rootPathFileWatcher?: vscode.FileSystemWatcher;
private rootFolder?: vscode.WorkspaceFolder;
private rootRealPath: string;
private workspaceStoragePath: string;
private trackedDocuments = new Map<string, vscode.TextDocument>();
private isSupported: boolean = true;
private inactiveRegionsDecorations = new Map<string, DecorationRangesPair>();
private settingsTracker: SettingsTracker;
private loggingLevel: number = 1;
private configurationProvider?: string;
public lastCustomBrowseConfiguration: PersistentFolderState<WorkspaceBrowseConfiguration | undefined> | undefined;
public lastCustomBrowseConfigurationProviderId: PersistentFolderState<string | undefined> | undefined;
public lastCustomBrowseConfigurationProviderVersion: PersistentFolderState<Version> | undefined;
public currentCaseSensitiveFileSupport: PersistentWorkspaceState<boolean> | undefined;
private registeredProviders: PersistentFolderState<string[]> | undefined;
private configStateReceived: ConfigStateReceived = { compilers: false, compileCommands: false, configProviders: undefined, timeout: false };
private showConfigureIntelliSenseButton: boolean = false;
/** A queue of asynchronous tasks that need to be processed befofe ready is considered active. */
private static queue = new Array<[ManualPromise<unknown>, () => Promise<unknown>] | [ManualPromise<unknown>]>();
/** returns a promise that waits initialization and/or a change to configuration to complete (i.e. language client is ready-to-use) */
private static readonly isStarted = new ManualSignal<void>(true);
/**
* Indicates if the blocking task dispatcher is currently running
*
* This will be in the Set state when the dispatcher is not running (i.e. if you await this it will be resolved immediately)
* If the dispatcher is running, this will be in the Reset state (i.e. if you await this it will be resolved when the dispatcher is done)
*/
private static readonly dispatching = new ManualSignal<void>();
// The "model" that is displayed via the UI (status bar).
private model: ClientModel = new ClientModel();
public get InitializingWorkspaceChanged(): vscode.Event<boolean> { return this.model.isInitializingWorkspace.ValueChanged; }
public get IndexingWorkspaceChanged(): vscode.Event<boolean> { return this.model.isIndexingWorkspace.ValueChanged; }
public get ParsingWorkspaceChanged(): vscode.Event<boolean> { return this.model.isParsingWorkspace.ValueChanged; }
public get ParsingWorkspacePausedChanged(): vscode.Event<boolean> { return this.model.isParsingWorkspacePaused.ValueChanged; }
public get ParsingFilesChanged(): vscode.Event<boolean> { return this.model.isParsingFiles.ValueChanged; }
public get IntelliSenseParsingChanged(): vscode.Event<boolean> { return this.model.isUpdatingIntelliSense.ValueChanged; }
public get RunningCodeAnalysisChanged(): vscode.Event<boolean> { return this.model.isRunningCodeAnalysis.ValueChanged; }
public get CodeAnalysisPausedChanged(): vscode.Event<boolean> { return this.model.isCodeAnalysisPaused.ValueChanged; }
public get CodeAnalysisProcessedChanged(): vscode.Event<number> { return this.model.codeAnalysisProcessed.ValueChanged; }
public get CodeAnalysisTotalChanged(): vscode.Event<number> { return this.model.codeAnalysisTotal.ValueChanged; }
public get ReferencesCommandModeChanged(): vscode.Event<refs.ReferencesCommandMode> { return this.model.referencesCommandMode.ValueChanged; }
public get TagParserStatusChanged(): vscode.Event<string> { return this.model.parsingWorkspaceStatus.ValueChanged; }
public get ActiveConfigChanged(): vscode.Event<string> { return this.model.activeConfigName.ValueChanged; }
public isInitialized(): boolean { return this.innerLanguageClient !== undefined; }
public getShowConfigureIntelliSenseButton(): boolean { return this.showConfigureIntelliSenseButton; }
public setShowConfigureIntelliSenseButton(show: boolean): void { this.showConfigureIntelliSenseButton = show; }
/**
* don't use this.rootFolder directly since it can be undefined
*/
public get RootPath(): string {
return this.rootFolder ? this.rootFolder.uri.fsPath : "";
}
public get RootRealPath(): string {
return this.rootRealPath;
}
public get RootUri(): vscode.Uri | undefined {
return this.rootFolder ? this.rootFolder.uri : undefined;
}
public get RootFolder(): vscode.WorkspaceFolder | undefined {
return this.rootFolder;
}
public get Name(): string {
return this.getName(this.rootFolder);
}
public get TrackedDocuments(): Map<string, vscode.TextDocument> {
return this.trackedDocuments;
}
public get IsTagParsing(): boolean {
return this.model.isParsingWorkspace.Value || this.model.isParsingFiles.Value || this.model.isInitializingWorkspace.Value || this.model.isIndexingWorkspace.Value;
}
public get ReferencesCommandMode(): refs.ReferencesCommandMode {
return this.model.referencesCommandMode.Value;
}
public get languageClient(): LanguageClient {
if (!this.innerLanguageClient) {
throw new Error("Attempting to use languageClient before initialized");
}
return this.innerLanguageClient;
}
public get configuration(): configs.CppProperties {
if (!this.innerConfiguration) {
throw new Error("Attempting to use configuration before initialized");
}
return this.innerConfiguration;
}
public get AdditionalEnvironment(): Record<string, string | string[]> {
return {
workspaceFolderBasename: this.Name,
workspaceStorage: this.workspaceStoragePath,
execPath: process.execPath,
pathSeparator: (os.platform() === 'win32') ? "\\" : "/"
};
}
private getName(workspaceFolder?: vscode.WorkspaceFolder): string {
return workspaceFolder ? workspaceFolder.name : "untitled";
}
public static updateClientConfigurations(): void {
clients.forEach(client => {
if (client instanceof DefaultClient) {
const defaultClient: DefaultClient = client as DefaultClient;
if (!client.isInitialized() || !compilerDefaults) {
// This can randomly get hit when adding/removing workspace folders.
return;
}
defaultClient.configuration.CompilerDefaults = compilerDefaults;
defaultClient.configuration.handleConfigurationChange();
}
});
}
private static readonly configurationProvidersLabel: string = "configuration providers";
private static readonly compileCommandsLabel: string = "compile_commands.json";
private static readonly compilersLabel: string = "compilers";
public async showSelectIntelliSenseConfiguration(paths: string[], compilersOnly?: boolean): Promise<number> {
const options: vscode.QuickPickOptions = {};
options.placeHolder = compilersOnly || !vscode.workspace.workspaceFolders || !this.RootFolder ?
localize("select.compiler", "Select a compiler to configure for IntelliSense") :
vscode.workspace.workspaceFolders.length > 1 ?
localize("configure.intelliSense.forFolder", "How would you like to configure IntelliSense for the '{0}' folder?", this.RootFolder.name) :
localize("configure.intelliSense.thisFolder", "How would you like to configure IntelliSense for this folder?");
const items: IndexableQuickPickItem[] = [];
let isCompilerSection: boolean = false;
for (let i: number = 0; i < paths.length; i++) {
const compilerName: string = path.basename(paths[i]);
const isCompiler: boolean = isCompilerSection && compilerName !== paths[i];
if (isCompiler) {
const path: string | undefined = paths[i].replace(compilerName, "");
const description: string = localize("found.string", "Found at {0}", path);
const label: string = localize("use.compiler", "Use {0}", compilerName);
items.push({ label: label, description: description, index: i });
} else if (paths[i] === DefaultClient.configurationProvidersLabel) {
items.push({ label: localize("configuration.providers", "configuration providers"), index: i, kind: vscode.QuickPickItemKind.Separator });
} else if (paths[i] === DefaultClient.compileCommandsLabel) {
items.push({ label: paths[i], index: i, kind: vscode.QuickPickItemKind.Separator });
} else if (paths[i] === DefaultClient.compilersLabel) {
isCompilerSection = true;
items.push({ label: localize("compilers", "compilers"), index: i, kind: vscode.QuickPickItemKind.Separator });
} else {
items.push({ label: paths[i], index: i });
}
}
const selection: IndexableQuickPickItem | undefined = await vscode.window.showQuickPick(items, options);
return selection ? selection.index : -1;
}
public async showPrompt(sender?: any): Promise<void> {
const buttonMessage: string = localize("selectIntelliSenseConfiguration.string", "Select IntelliSense Configuration...");
const value: string | undefined = await vscode.window.showInformationMessage(localize("setCompiler.message", "You do not have IntelliSense configured. Unless you set your own configurations, IntelliSense may not be functional."), buttonMessage);
if (value === buttonMessage) {
return this.handleIntelliSenseConfigurationQuickPick(sender);
}
}
public async handleIntelliSenseConfigurationQuickPick(sender?: any, showCompilersOnly?: boolean): Promise<void> {
const settings: CppSettings = new CppSettings(showCompilersOnly ? undefined : this.RootUri);
const paths: string[] = [];
const configProviders: CustomConfigurationProvider1[] | undefined = showCompilersOnly ? undefined : this.configStateReceived.configProviders;
if (configProviders && configProviders.length > 0) {
paths.push(DefaultClient.configurationProvidersLabel);
for (const provider of configProviders) {
paths.push(localize("use.provider", "Use {0}", provider.name));
}
}
const configProvidersIndex: number = paths.length;
const configProviderCount: number = configProvidersIndex === 0 ? 0 : configProvidersIndex - 1;
if (!showCompilersOnly && this.compileCommandsPaths.length > 0) {
paths.push(DefaultClient.compileCommandsLabel);