Skip to content

Commit 2d3cac0

Browse files
authored
Move status bar icons into the Language Status (#10126)
1 parent 0fcc415 commit 2d3cac0

File tree

5 files changed

+712
-42
lines changed

5 files changed

+712
-42
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { CodeActionProvider } from './Providers/codeActionProvider';
2121
import { InlayHintsProvider } from './Providers/inlayHintProvider';
2222
// End provider imports
2323

24-
import { LanguageClientOptions, NotificationType, TextDocumentIdentifier, RequestType, ErrorAction, CloseAction, DidOpenTextDocumentParams, Range, Position, DocumentFilter } from 'vscode-languageclient';
24+
import { LanguageClientOptions, NotificationType, TextDocumentIdentifier, RequestType, ErrorAction, CloseAction, DidOpenTextDocumentParams, Range, Position } from 'vscode-languageclient';
2525
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
2626
import { SourceFileConfigurationItem, WorkspaceBrowseConfiguration, SourceFileConfiguration, Version } from 'vscode-cpptools';
2727
import { Status, IntelliSenseStatus } from 'vscode-cpptools/out/testApi';
@@ -731,7 +731,8 @@ export interface Client {
731731
handleConfigurationSelectCommand(): Promise<void>;
732732
handleConfigurationProviderSelectCommand(): Promise<void>;
733733
handleShowParsingCommands(): Promise<void>;
734-
handleShowCodeAnalysisCommands(): Promise<void>;
734+
handleShowActiveCodeAnalysisCommands(): Promise<void>;
735+
handleShowIdleCodeAnalysisCommands(): Promise<void>;
735736
handleReferencesIcon(): void;
736737
handleConfigurationEditCommand(viewColumn?: vscode.ViewColumn): void;
737738
handleConfigurationEditJSONCommand(viewColumn?: vscode.ViewColumn): void;
@@ -784,11 +785,6 @@ export class DefaultClient implements Client {
784785
private settingsTracker: SettingsTracker;
785786
private loggingLevel: string | undefined;
786787
private configurationProvider?: string;
787-
private documentSelector: DocumentFilter[] = [
788-
{ scheme: 'file', language: 'c' },
789-
{ scheme: 'file', language: 'cpp' },
790-
{ scheme: 'file', language: 'cuda-cpp' }
791-
];
792788

793789
public static referencesParams: RenameParams | FindAllReferencesParams | undefined;
794790
public static referencesRequestPending: boolean = false;
@@ -928,11 +924,11 @@ export class DefaultClient implements Client {
928924
util.setProgress(util.getProgressExecutableStarted());
929925
isFirstClient = true;
930926
}
931-
ui = getUI();
932-
ui.bind(this);
933927

934928
// requests/notifications are deferred until this.languageClient is set.
935929
this.queueBlockingTask(async () => {
930+
ui = await getUI();
931+
ui.bind(this);
936932
await firstClientStarted;
937933
try {
938934
const workspaceFolder: vscode.WorkspaceFolder | undefined = this.rootFolder;
@@ -961,26 +957,26 @@ export class DefaultClient implements Client {
961957

962958
this.inlayHintsProvider = new InlayHintsProvider(this);
963959

964-
this.disposables.push(vscode.languages.registerInlayHintsProvider(this.documentSelector, this.inlayHintsProvider));
965-
this.disposables.push(vscode.languages.registerRenameProvider(this.documentSelector, new RenameProvider(this)));
966-
this.disposables.push(vscode.languages.registerReferenceProvider(this.documentSelector, new FindAllReferencesProvider(this)));
960+
this.disposables.push(vscode.languages.registerInlayHintsProvider(util.documentSelector, this.inlayHintsProvider));
961+
this.disposables.push(vscode.languages.registerRenameProvider(util.documentSelector, new RenameProvider(this)));
962+
this.disposables.push(vscode.languages.registerReferenceProvider(util.documentSelector, new FindAllReferencesProvider(this)));
967963
this.disposables.push(vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(this)));
968-
this.disposables.push(vscode.languages.registerDocumentSymbolProvider(this.documentSelector, new DocumentSymbolProvider(), undefined));
969-
this.disposables.push(vscode.languages.registerCodeActionsProvider(this.documentSelector, new CodeActionProvider(this), undefined));
964+
this.disposables.push(vscode.languages.registerDocumentSymbolProvider(util.documentSelector, new DocumentSymbolProvider(), undefined));
965+
this.disposables.push(vscode.languages.registerCodeActionsProvider(util.documentSelector, new CodeActionProvider(this), undefined));
970966
// Because formatting and codeFolding can vary per folder, we need to register these providers once
971967
// and leave them registered. The decision of whether to provide results needs to be made on a per folder basis,
972968
// within the providers themselves.
973-
this.documentFormattingProviderDisposable = vscode.languages.registerDocumentFormattingEditProvider(this.documentSelector, new DocumentFormattingEditProvider(this));
974-
this.formattingRangeProviderDisposable = vscode.languages.registerDocumentRangeFormattingEditProvider(this.documentSelector, new DocumentRangeFormattingEditProvider(this));
975-
this.onTypeFormattingProviderDisposable = vscode.languages.registerOnTypeFormattingEditProvider(this.documentSelector, new OnTypeFormattingEditProvider(this), ";", "}", "\n");
969+
this.documentFormattingProviderDisposable = vscode.languages.registerDocumentFormattingEditProvider(util.documentSelector, new DocumentFormattingEditProvider(this));
970+
this.formattingRangeProviderDisposable = vscode.languages.registerDocumentRangeFormattingEditProvider(util.documentSelector, new DocumentRangeFormattingEditProvider(this));
971+
this.onTypeFormattingProviderDisposable = vscode.languages.registerOnTypeFormattingEditProvider(util.documentSelector, new OnTypeFormattingEditProvider(this), ";", "}", "\n");
976972

977973
this.codeFoldingProvider = new FoldingRangeProvider(this);
978-
this.codeFoldingProviderDisposable = vscode.languages.registerFoldingRangeProvider(this.documentSelector, this.codeFoldingProvider);
974+
this.codeFoldingProviderDisposable = vscode.languages.registerFoldingRangeProvider(util.documentSelector, this.codeFoldingProvider);
979975

980976
const settings: CppSettings = new CppSettings();
981977
if (settings.enhancedColorization && semanticTokensLegend) {
982978
this.semanticTokensProvider = new SemanticTokensProvider(this);
983-
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(this.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
979+
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
984980
}
985981
// Listen for messages from the language server.
986982
this.registerNotifications();
@@ -1303,7 +1299,7 @@ export class DefaultClient implements Client {
13031299
if (changedSettings["enhancedColorization"]) {
13041300
if (settings.enhancedColorization && semanticTokensLegend) {
13051301
this.semanticTokensProvider = new SemanticTokensProvider(this);
1306-
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(this.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
1302+
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
13071303
} else if (this.semanticTokensProviderDisposable) {
13081304
this.semanticTokensProviderDisposable.dispose();
13091305
this.semanticTokensProviderDisposable = undefined;
@@ -2174,14 +2170,14 @@ export class DefaultClient implements Client {
21742170
private updateTagParseStatus(notificationBody: LocalizeStringParams): void {
21752171
this.model.parsingWorkspaceStatus.Value = getLocalizedString(notificationBody);
21762172
if (notificationBody.text.startsWith("Workspace parsing paused")) {
2177-
this.model.isParsingWorkspacePausable.Value = true;
21782173
this.model.isParsingWorkspacePaused.Value = true;
2179-
} else if (notificationBody.text.startsWith("Parsing workspace")) {
21802174
this.model.isParsingWorkspacePausable.Value = true;
2175+
} else if (notificationBody.text.startsWith("Parsing workspace")) {
21812176
this.model.isParsingWorkspacePaused.Value = false;
2177+
this.model.isParsingWorkspacePausable.Value = true;
21822178
} else {
2183-
this.model.isParsingWorkspacePausable.Value = false;
21842179
this.model.isParsingWorkspacePaused.Value = false;
2180+
this.model.isParsingWorkspacePausable.Value = false;
21852181
}
21862182
}
21872183

@@ -2748,13 +2744,24 @@ export class DefaultClient implements Client {
27482744
}
27492745
}
27502746

2751-
public async handleShowCodeAnalysisCommands(): Promise<void> {
2747+
public async handleShowActiveCodeAnalysisCommands(): Promise<void> {
27522748
await this.awaitUntilLanguageClientReady();
2753-
const index: number = await ui.showCodeAnalysisCommands();
2749+
const index: number = await ui.showActiveCodeAnalysisCommands();
27542750
switch (index) {
27552751
case 0: this.CancelCodeAnalysis(); break;
27562752
case 1: this.PauseCodeAnalysis(); break;
27572753
case 2: this.ResumeCodeAnalysis(); break;
2754+
case 3: this.handleShowIdleCodeAnalysisCommands(); break;
2755+
}
2756+
}
2757+
2758+
public async handleShowIdleCodeAnalysisCommands(): Promise<void> {
2759+
await this.awaitUntilLanguageClientReady();
2760+
const index: number = await ui.showIdleCodeAnalysisCommands();
2761+
switch (index) {
2762+
case 0: this.handleRunCodeAnalysisOnActiveFile(); break;
2763+
case 1: this.handleRunCodeAnalysisOnAllFiles(); break;
2764+
case 2: this.handleRunCodeAnalysisOnOpenFiles(); break;
27582765
}
27592766
}
27602767

@@ -3269,7 +3276,8 @@ class NullClient implements Client {
32693276
handleConfigurationSelectCommand(): Promise<void> { return Promise.resolve(); }
32703277
handleConfigurationProviderSelectCommand(): Promise<void> { return Promise.resolve(); }
32713278
handleShowParsingCommands(): Promise<void> { return Promise.resolve(); }
3272-
handleShowCodeAnalysisCommands(): Promise<void> { return Promise.resolve(); }
3279+
handleShowActiveCodeAnalysisCommands(): Promise<void> { return Promise.resolve(); }
3280+
handleShowIdleCodeAnalysisCommands(): Promise<void> { return Promise.resolve(); }
32733281
handleReferencesIcon(): void { }
32743282
handleConfigurationEditCommand(viewColumn?: vscode.ViewColumn): void { }
32753283
handleConfigurationEditJSONCommand(viewColumn?: vscode.ViewColumn): void { }

Extension/src/LanguageServer/extension.ts

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export async function activate(): Promise<void> {
174174

175175
console.log("starting language server");
176176
clients = new ClientCollection();
177-
ui = getUI();
177+
ui = await getUI();
178178

179179
// There may have already been registered CustomConfigurationProviders.
180180
// Request for configurations from those providers.
@@ -403,7 +403,8 @@ export function registerCommands(enabled: boolean): void {
403403
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ResumeCodeAnalysis', enabled ? onResumeCodeAnalysis : onDisabledCommand));
404404
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CancelCodeAnalysis', enabled ? onCancelCodeAnalysis : onDisabledCommand));
405405
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowParsingCommands', enabled ? onShowParsingCommands : onDisabledCommand));
406-
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowCodeAnalysisCommands', enabled ? onShowCodeAnalysisCommands : onDisabledCommand));
406+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowActiveCodeAnalysisCommands', enabled ? onShowActiveCodeAnalysisCommands : onDisabledCommand));
407+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowIdleCodeAnalysisCommands', enabled ? onShowIdleCodeAnalysisCommands : onDisabledCommand));
407408
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowReferencesProgress', enabled ? onShowReferencesProgress : onDisabledCommand));
408409
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.TakeSurvey', enabled ? onTakeSurvey : onDisabledCommand));
409410
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.LogDiagnostics', enabled ? onLogDiagnostics : onDisabledCommand));
@@ -433,6 +434,73 @@ export function registerCommands(enabled: boolean): void {
433434
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RestartIntelliSenseForFile', enabled ? onRestartIntelliSenseForFile : onDisabledCommand));
434435
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.GenerateDoxygenComment', enabled ? onGenerateDoxygenComment : onDisabledCommand));
435436
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CreateDeclarationOrDefinition', enabled ? onCreateDeclarationOrDefinition : onDisabledCommand));
437+
// ---------------- Wrappers -------------
438+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationSelectUI_Telemetry', enabled ?
439+
() => {
440+
logForUIExperiment("ConfigurationSelect");
441+
onSelectConfiguration();
442+
}
443+
: onDisabledCommand));
444+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RescanWorkspaceUI_Telemetry', enabled ?
445+
() => {
446+
logForUIExperiment("RescanWorkspace");
447+
onRescanWorkspace();
448+
}
449+
: onDisabledCommand));
450+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowIdleCodeAnalysisCommandsUI_Telemetry', enabled ?
451+
() => {
452+
logForUIExperiment("ShowIdleCodeAnalysisCommands");
453+
onShowIdleCodeAnalysisCommands();
454+
}
455+
: onDisabledCommand));
456+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowActiveCodeAnalysisCommandsUI_Telemetry', enabled ?
457+
() => {
458+
logForUIExperiment("ShowActiveCodeAnalysisCommands");
459+
onShowActiveCodeAnalysisCommands();
460+
}
461+
: onDisabledCommand));
462+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.PauseParsingUI_Telemetry', enabled ?
463+
() => {
464+
logForUIExperiment("ParsingCommands");
465+
onPauseParsing();
466+
}
467+
: onDisabledCommand));
468+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ResumeParsingUI_Telemetry', enabled ?
469+
() => {
470+
logForUIExperiment("ParsingCommands");
471+
onResumeParsing();
472+
}
473+
: onDisabledCommand));
474+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.CheckForCompilerUI_Telemetry', enabled ?
475+
() => {
476+
logForUIExperiment("CheckForCompiler");
477+
onCheckForCompiler();
478+
}
479+
: onDisabledCommand));
480+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.RestartIntelliSenseForFileUI_Telemetry', enabled ?
481+
() => {
482+
logForUIExperiment("RestartIntelliSenseForFile");
483+
onRestartIntelliSenseForFile();
484+
}
485+
: onDisabledCommand));
486+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowReferencesProgressUI_Telemetry', enabled ?
487+
() => {
488+
logForUIExperiment("ShowReferencesProgress");
489+
onShowReferencesProgress();
490+
}
491+
: onDisabledCommand));
492+
commandDisposables.push(vscode.commands.registerCommand('C_Cpp.ShowParsingCommandsUI_Telemetry', enabled ?
493+
() => {
494+
logForUIExperiment("ParsingCommands");
495+
onShowParsingCommands();
496+
}
497+
: onDisabledCommand));
498+
// ----------------------------------------
499+
}
500+
501+
async function logForUIExperiment(command: string): Promise<void> {
502+
const isNewUI: string = ui.isNewUI.toString();
503+
telemetry.logLanguageServerEvent(`experiment${command}`, { newUI: isNewUI });
436504
}
437505

438506
function onDisabledCommand(): void {
@@ -510,8 +578,8 @@ async function selectClient(): Promise<Client> {
510578
if (clients.Count === 1) {
511579
return clients.ActiveClient;
512580
} else {
513-
const key: string = await ui.showWorkspaces(clients.Names);
514-
if (key !== "") {
581+
const key: string | undefined = await ui.showWorkspaces(clients.Names);
582+
if (key !== undefined && key !== "") {
515583
const client: Client | undefined = clients.get(key);
516584
if (client) {
517585
return client;
@@ -730,8 +798,12 @@ function onShowParsingCommands(): void {
730798
clients.ActiveClient.handleShowParsingCommands();
731799
}
732800

733-
function onShowCodeAnalysisCommands(): void {
734-
clients.ActiveClient.handleShowCodeAnalysisCommands();
801+
function onShowActiveCodeAnalysisCommands(): void {
802+
clients.ActiveClient.handleShowActiveCodeAnalysisCommands();
803+
}
804+
805+
function onShowIdleCodeAnalysisCommands(): void {
806+
clients.ActiveClient.handleShowIdleCodeAnalysisCommands();
735807
}
736808

737809
function onShowReferencesProgress(): void {

0 commit comments

Comments
 (0)