Skip to content

Commit 69c53b8

Browse files
committed
Add workspace status item to the Language Status bar.
1 parent 88bbc90 commit 69c53b8

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

l10n/bundle.l10n.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"Reload Window": "Reload Window",
131131
"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?",
132132
"Restart Language Server": "Restart Language Server",
133+
"Workspace projects": "Workspace projects",
133134
"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.",
134135
"Choose": "Choose",
135136
"Choose and set default": "Choose and set default",
@@ -144,6 +145,8 @@
144145
"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?",
145146
"Nested Code Action": "Nested Code Action",
146147
"Fix All: ": "Fix All: ",
148+
"C# Workspace Status": "C# Workspace Status",
149+
"Open solution": "Open solution",
147150
"Pick a fix all scope": "Pick a fix all scope",
148151
"Fix All Code Action": "Fix All Code Action",
149152
"pipeArgs must be a string or a string array type": "pipeArgs must be a string or a string array type",

src/lsptoolshost/languageStatusBar.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { RoslynLanguageServer } from './roslynLanguageServer';
8+
import { RoslynLanguageServerEvents } from './languageServerEvents';
9+
import { languageServerOptions } from '../shared/options';
10+
import { ServerStateChange } from './serverStateChange';
11+
12+
export function registerLanguageStatusItems(
13+
context: vscode.ExtensionContext,
14+
languageServer: RoslynLanguageServer,
15+
languageServerEvents: RoslynLanguageServerEvents
16+
) {
17+
WorkspaceStatus.createStatusItem(context, languageServer, languageServerEvents);
18+
}
19+
20+
class WorkspaceStatus {
21+
static createStatusItem(
22+
context: vscode.ExtensionContext,
23+
languageServer: RoslynLanguageServer,
24+
languageServerEvents: RoslynLanguageServerEvents
25+
) {
26+
const item = vscode.languages.createLanguageStatusItem(
27+
'csharp.workspaceStatus',
28+
languageServerOptions.documentSelector
29+
);
30+
item.name = vscode.l10n.t('C# Workspace Status');
31+
item.command = {
32+
command: 'dotnet.openSolution',
33+
title: vscode.l10n.t('Open solution'),
34+
};
35+
context.subscriptions.push(item);
36+
37+
languageServerEvents.onServerStateChange((e) => {
38+
if (e === ServerStateChange.ProjectInitializationStarted) {
39+
item.text = languageServer.workspaceDisplayName();
40+
item.busy = true;
41+
} else if (e === ServerStateChange.ProjectInitializationComplete) {
42+
item.text = languageServer.workspaceDisplayName();
43+
item.busy = false;
44+
}
45+
});
46+
47+
languageServer.
48+
}
49+
}

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { registerRestoreCommands } from './restore';
6464
import { BuildDiagnosticsService } from './buildDiagnosticsService';
6565
import { getComponentPaths } from './builtInComponents';
6666
import { OnAutoInsertFeature } from './onAutoInsertFeature';
67+
import { registerLanguageStatusItems } from './languageStatusBar';
6768

6869
let _channel: vscode.OutputChannel;
6970
let _traceChannel: vscode.OutputChannel;
@@ -115,7 +116,7 @@ export class RoslynLanguageServer {
115116
) {
116117
this.registerSetTrace();
117118
this.registerSendOpenSolution();
118-
this.registerOnProjectInitializationComplete();
119+
this.registerProjectInitialization();
119120
this.registerReportProjectConfiguration();
120121
this.registerExtensionsChanged();
121122
this.registerTelemetryChanged();
@@ -162,7 +163,11 @@ export class RoslynLanguageServer {
162163
});
163164
}
164165

165-
private registerOnProjectInitializationComplete() {
166+
private registerProjectInitialization() {
167+
this._languageClient.onNotification(RoslynProtocol.ProjectInitializationStartedNotification.type, () => {
168+
this._languageServerEvents.onServerStateChangeEmitter.fire(ServerStateChange.ProjectInitializationStarted);
169+
});
170+
166171
this._languageClient.onNotification(RoslynProtocol.ProjectInitializationCompleteNotification.type, () => {
167172
this._languageServerEvents.onServerStateChangeEmitter.fire(ServerStateChange.ProjectInitializationComplete);
168173
});
@@ -262,6 +267,16 @@ export class RoslynLanguageServer {
262267
await this._languageClient.restart();
263268
}
264269

270+
public workspaceDisplayName(): string {
271+
if (this._solutionFile !== undefined) {
272+
return path.basename(this._solutionFile.fsPath);
273+
} else if (this._projectFiles?.length > 0) {
274+
return vscode.l10n.t('Workspace projects');
275+
}
276+
277+
return '';
278+
}
279+
265280
/**
266281
* Returns whether or not the underlying LSP server is running or not.
267282
*/
@@ -978,6 +993,8 @@ export async function activateRoslynLanguageServer(
978993
languageServerEvents
979994
);
980995

996+
registerLanguageStatusItems(context, languageServer, languageServerEvents);
997+
981998
// Register any commands that need to be handled by the extension.
982999
registerCommands(context, languageServer, hostExecutableResolver, _channel);
9831000
registerNestedCodeActionCommands(context, languageServer, _channel);

src/lsptoolshost/roslynProtocol.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ export namespace RegisterSolutionSnapshotRequest {
210210
export const type = new lsp.RequestType0<RegisterSolutionSnapshotResponseItem, void>(method);
211211
}
212212

213+
export namespace ProjectInitializationStartedNotification {
214+
export const method = 'workspace/projectInitializationStarted';
215+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
216+
export const type = new lsp.NotificationType(method);
217+
}
218+
213219
export namespace ProjectInitializationCompleteNotification {
214220
export const method = 'workspace/projectInitializationComplete';
215221
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;

src/lsptoolshost/serverStateChange.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
export enum ServerStateChange {
77
Started = 0,
8-
ProjectInitializationComplete = 1,
8+
ProjectInitializationStarted = 1,
9+
ProjectInitializationComplete = 2,
910
}

0 commit comments

Comments
 (0)