Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspace status item to the Language Status bar. #7254

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"Reload Window": "Reload Window",
"C# configuration has changed. Would you like to relaunch the Language Server with your changes?": "C# configuration has changed. Would you like to relaunch the Language Server with your changes?",
"Restart Language Server": "Restart Language Server",
"Workspace projects": "Workspace projects",
"Your workspace has multiple Visual Studio Solution files; please select one to get full IntelliSense.": "Your workspace has multiple Visual Studio Solution files; please select one to get full IntelliSense.",
"Choose": "Choose",
"Choose and set default": "Choose and set default",
Expand All @@ -144,6 +145,8 @@
"C# configuration has changed. Would you like to reload the window to apply your changes?": "C# configuration has changed. Would you like to reload the window to apply your changes?",
"Nested Code Action": "Nested Code Action",
"Fix All: ": "Fix All: ",
"C# Workspace Status": "C# Workspace Status",
"Open solution": "Open solution",
"Pick a fix all scope": "Pick a fix all scope",
"Fix All Code Action": "Fix All Code Action",
"pipeArgs must be a string or a string array type": "pipeArgs must be a string or a string array type",
Expand Down
47 changes: 47 additions & 0 deletions src/lsptoolshost/languageStatusBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { RoslynLanguageServer } from './roslynLanguageServer';
import { RoslynLanguageServerEvents } from './languageServerEvents';
import { languageServerOptions } from '../shared/options';
import { ServerStateChange } from './serverStateChange';

export function registerLanguageStatusItems(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant for this PR, but something to check when we do TFMs - can two different extensions register language status items for the same language? Devkit does have a language status item (launch.json stuff).

context: vscode.ExtensionContext,
languageServer: RoslynLanguageServer,
languageServerEvents: RoslynLanguageServerEvents
) {
WorkspaceStatus.createStatusItem(context, languageServer, languageServerEvents);
}

class WorkspaceStatus {
static createStatusItem(
context: vscode.ExtensionContext,
languageServer: RoslynLanguageServer,
languageServerEvents: RoslynLanguageServerEvents
) {
const item = vscode.languages.createLanguageStatusItem(
'csharp.workspaceStatus',
languageServerOptions.documentSelector
);
item.name = vscode.l10n.t('C# Workspace Status');
item.command = {
command: 'dotnet.openSolution',
title: vscode.l10n.t('Open solution'),
};
context.subscriptions.push(item);

languageServerEvents.onServerStateChange((e) => {
if (e === ServerStateChange.ProjectInitializationStarted) {
item.text = languageServer.workspaceDisplayName();
item.busy = true;
} else if (e === ServerStateChange.ProjectInitializationComplete) {
item.text = languageServer.workspaceDisplayName();
item.busy = false;
}
});
}
}
21 changes: 19 additions & 2 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { registerRestoreCommands } from './restore';
import { BuildDiagnosticsService } from './buildDiagnosticsService';
import { getComponentPaths } from './builtInComponents';
import { OnAutoInsertFeature } from './onAutoInsertFeature';
import { registerLanguageStatusItems } from './languageStatusBar';

let _channel: vscode.OutputChannel;
let _traceChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -115,7 +116,7 @@ export class RoslynLanguageServer {
) {
this.registerSetTrace();
this.registerSendOpenSolution();
this.registerOnProjectInitializationComplete();
this.registerProjectInitialization();
this.registerReportProjectConfiguration();
this.registerExtensionsChanged();
this.registerTelemetryChanged();
Expand Down Expand Up @@ -162,7 +163,11 @@ export class RoslynLanguageServer {
});
}

private registerOnProjectInitializationComplete() {
private registerProjectInitialization() {
this._languageClient.onNotification(RoslynProtocol.ProjectInitializationStartedNotification.type, () => {
this._languageServerEvents.onServerStateChangeEmitter.fire(ServerStateChange.ProjectInitializationStarted);
});

this._languageClient.onNotification(RoslynProtocol.ProjectInitializationCompleteNotification.type, () => {
this._languageServerEvents.onServerStateChangeEmitter.fire(ServerStateChange.ProjectInitializationComplete);
});
Expand Down Expand Up @@ -262,6 +267,16 @@ export class RoslynLanguageServer {
await this._languageClient.restart();
}

public workspaceDisplayName(): string {
if (this._solutionFile !== undefined) {
JoeRobich marked this conversation as resolved.
Show resolved Hide resolved
return path.basename(this._solutionFile.fsPath);
} else if (this._projectFiles?.length > 0) {
return vscode.l10n.t('Workspace projects');
}

return '';
}

/**
* Returns whether or not the underlying LSP server is running or not.
*/
Expand Down Expand Up @@ -978,6 +993,8 @@ export async function activateRoslynLanguageServer(
languageServerEvents
);

registerLanguageStatusItems(context, languageServer, languageServerEvents);

// Register any commands that need to be handled by the extension.
registerCommands(context, languageServer, hostExecutableResolver, _channel);
registerNestedCodeActionCommands(context, languageServer, _channel);
Expand Down
6 changes: 6 additions & 0 deletions src/lsptoolshost/roslynProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export namespace RegisterSolutionSnapshotRequest {
export const type = new lsp.RequestType0<RegisterSolutionSnapshotResponseItem, void>(method);
}

export namespace ProjectInitializationStartedNotification {
export const method = 'workspace/projectInitializationStarted';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
export const type = new lsp.NotificationType(method);
}

export namespace ProjectInitializationCompleteNotification {
export const method = 'workspace/projectInitializationComplete';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
Expand Down
3 changes: 2 additions & 1 deletion src/lsptoolshost/serverStateChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

export enum ServerStateChange {
Started = 0,
ProjectInitializationComplete = 1,
ProjectInitializationStarted = 1,
ProjectInitializationComplete = 2,
}
Loading