Skip to content

Commit

Permalink
Merge pull request #7628 from dotnet/dev/jorobich/warn-misc-files
Browse files Browse the repository at this point in the history
Warn in the statusbar when the active file is not part of the open workspace.
  • Loading branch information
JoeRobich authored Oct 10, 2024
2 parents 8dd4dfc + 3562921 commit 8c32259
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)

# Latest
* Warn when the active file is not part of the open workspace (PR: [#7628](https://github.com/dotnet/vscode-csharp/pull/7628))
* Update Roslyn to 4.13.0-1.24509.4 (PR: [#7628](https://github.com/dotnet/vscode-csharp/pull/7628))
* Add a WorkspaceKind property to ProjectContext. (PR: [#75384](https://github.com/dotnet/roslyn/pull/75384))
* Convert more lambda rude edits to runtime rude edits (PR: [#75285](https://github.com/dotnet/roslyn/pull/75285))

# 2.51.x
* Bumped xamltools to 17.12.35403.211 (PR: [#7629](https://github.com/dotnet/vscode-csharp/pull/7629))
* Update Roslyn to 4.13.0-1.24503.11 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618))
* LSP hover responses escape backticks within inline code (PR: [#75364](https://github.com/dotnet/roslyn/pull/75364))
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
},
"defaults": {
"roslyn": "4.13.0-1.24503.11",
"roslyn": "4.13.0-1.24509.4",
"omniSharp": "1.39.11",
"razor": "9.0.0-preview.24480.1",
"razorOmnisharp": "7.0.0-preview.23363.1",
Expand Down Expand Up @@ -5597,4 +5597,4 @@
}
}
}
}
}
21 changes: 20 additions & 1 deletion src/lsptoolshost/languageStatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import { ServerState } from './serverStateChange';
import { getCSharpDevKit } from '../utils/getCSharpDevKit';
import { RazorLanguage } from '../razor/src/razorLanguage';

let currentServerState: ServerState = ServerState.Stopped;

export function registerLanguageStatusItems(
context: vscode.ExtensionContext,
languageServer: RoslynLanguageServer,
languageServerEvents: RoslynLanguageServerEvents
) {
// Track the current server state.
languageServerEvents.onServerStateChange((e) => {
currentServerState = e.state;
});

// DevKit will provide an equivalent workspace status item.
if (!getCSharpDevKit()) {
WorkspaceStatus.createStatusItem(context, languageServerEvents);
Expand Down Expand Up @@ -44,14 +51,16 @@ class WorkspaceStatus {

const item = vscode.languages.createLanguageStatusItem('csharp.workspaceStatus', documentSelector);
item.name = vscode.l10n.t('C# Workspace Status');
item.severity = vscode.LanguageStatusSeverity.Error;
item.command = openSolutionCommand;
context.subscriptions.push(item);

languageServerEvents.onServerStateChange((e) => {
item.text = e.workspaceLabel;
item.busy = e.state === ServerState.ProjectInitializationStarted;
item.severity =
e.state === ServerState.Stopped
? vscode.LanguageStatusSeverity.Warning
? vscode.LanguageStatusSeverity.Error
: vscode.LanguageStatusSeverity.Information;
item.command = e.state === ServerState.Stopped ? restartServerCommand : openSolutionCommand;
});
Expand All @@ -73,6 +82,16 @@ class ProjectContextStatus {

projectContextService.onActiveFileContextChanged((e) => {
item.text = e.context._vs_label;

// Show a warning when the active file is part of the Miscellaneous File workspace and
// project initialization is complete.
if (currentServerState === ServerState.ProjectInitializationComplete) {
item.severity = e.context._vs_is_miscellaneous
? vscode.LanguageStatusSeverity.Warning
: vscode.LanguageStatusSeverity.Information;
} else {
item.severity = vscode.LanguageStatusSeverity.Information;
}
});

// Trigger a refresh, but don't block creation on the refresh completing.
Expand Down
1 change: 1 addition & 0 deletions src/lsptoolshost/roslynProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface VSProjectContext {
_vs_label: string;
_vs_id: string;
_vs_kind: string;
_vs_is_miscellaneous: boolean;
}

export interface VSTextDocumentIdentifier extends lsp.TextDocumentIdentifier {
Expand Down
1 change: 1 addition & 0 deletions src/lsptoolshost/services/projectContextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ProjectContextService {
_vs_id: '',
_vs_kind: '',
_vs_label: '',
_vs_is_miscellaneous: false,
};

constructor(private _languageServer: RoslynLanguageServer, _languageServerEvents: LanguageServerEvents) {
Expand Down

0 comments on commit 8c32259

Please sign in to comment.