From d31f7773c40f2d61e214ff477ebf8f6d29e99289 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Fri, 4 Oct 2024 01:06:16 -0700 Subject: [PATCH 1/3] Warn in the statusbar when the active file is not part of the open workspace. --- src/lsptoolshost/languageStatusBar.ts | 23 ++++++++++++++++++- src/lsptoolshost/roslynProtocol.ts | 7 ++++++ .../services/projectContextService.ts | 8 ++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lsptoolshost/languageStatusBar.ts b/src/lsptoolshost/languageStatusBar.ts index d0d9024c6..b2d50cd3b 100644 --- a/src/lsptoolshost/languageStatusBar.ts +++ b/src/lsptoolshost/languageStatusBar.ts @@ -10,12 +10,20 @@ import { languageServerOptions } from '../shared/options'; import { ServerState } from './serverStateChange'; import { getCSharpDevKit } from '../utils/getCSharpDevKit'; import { RazorLanguage } from '../razor/src/razorLanguage'; +import { VSWorkspaceKind } from './roslynProtocol'; + +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); @@ -44,6 +52,8 @@ 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) => { @@ -51,7 +61,7 @@ class WorkspaceStatus { 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; }); @@ -73,6 +83,17 @@ 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_workspace_kind === VSWorkspaceKind.MiscellaneousFiles + ? vscode.LanguageStatusSeverity.Warning + : vscode.LanguageStatusSeverity.Information; + } else { + item.severity = vscode.LanguageStatusSeverity.Information; + } }); // Trigger a refresh, but don't block creation on the refresh completing. diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index 9ba43d4af..74bafb212 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -13,10 +13,17 @@ export interface VSProjectContextList { _vs_defaultIndex: number; } +export enum VSWorkspaceKind { + Unknown = 0, + Host = 1, + MiscellaneousFiles = 2, +} + export interface VSProjectContext { _vs_label: string; _vs_id: string; _vs_kind: string; + _vs_workspace_kind: VSWorkspaceKind; } export interface VSTextDocumentIdentifier extends lsp.TextDocumentIdentifier { diff --git a/src/lsptoolshost/services/projectContextService.ts b/src/lsptoolshost/services/projectContextService.ts index 577b04f82..4cff70ad6 100644 --- a/src/lsptoolshost/services/projectContextService.ts +++ b/src/lsptoolshost/services/projectContextService.ts @@ -5,7 +5,12 @@ import * as vscode from 'vscode'; import { RoslynLanguageServer } from '../roslynLanguageServer'; -import { VSGetProjectContextsRequest, VSProjectContext, VSProjectContextList } from '../roslynProtocol'; +import { + VSGetProjectContextsRequest, + VSProjectContext, + VSProjectContextList, + VSWorkspaceKind, +} from '../roslynProtocol'; import { TextDocumentIdentifier } from 'vscode-languageserver-protocol'; import { UriConverter } from '../uriConverter'; import { LanguageServerEvents } from '../languageServerEvents'; @@ -26,6 +31,7 @@ export class ProjectContextService { _vs_id: '', _vs_kind: '', _vs_label: '', + _vs_workspace_kind: VSWorkspaceKind.Unknown, }; constructor(private _languageServer: RoslynLanguageServer, _languageServerEvents: LanguageServerEvents) { From 53b5c4dfb255b486588d51543a952bf19009694d Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 8 Oct 2024 00:24:25 -0700 Subject: [PATCH 2/3] Switch to using an IsMiscellaneous propert on ProjectContext --- src/lsptoolshost/languageStatusBar.ts | 8 +++----- src/lsptoolshost/roslynProtocol.ts | 8 +------- src/lsptoolshost/services/projectContextService.ts | 9 ++------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/lsptoolshost/languageStatusBar.ts b/src/lsptoolshost/languageStatusBar.ts index b2d50cd3b..10e258814 100644 --- a/src/lsptoolshost/languageStatusBar.ts +++ b/src/lsptoolshost/languageStatusBar.ts @@ -10,7 +10,6 @@ import { languageServerOptions } from '../shared/options'; import { ServerState } from './serverStateChange'; import { getCSharpDevKit } from '../utils/getCSharpDevKit'; import { RazorLanguage } from '../razor/src/razorLanguage'; -import { VSWorkspaceKind } from './roslynProtocol'; let currentServerState: ServerState = ServerState.Stopped; @@ -87,10 +86,9 @@ class ProjectContextStatus { // 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_workspace_kind === VSWorkspaceKind.MiscellaneousFiles - ? vscode.LanguageStatusSeverity.Warning - : vscode.LanguageStatusSeverity.Information; + item.severity = e.context._vs_is_miscellaneous + ? vscode.LanguageStatusSeverity.Warning + : vscode.LanguageStatusSeverity.Information; } else { item.severity = vscode.LanguageStatusSeverity.Information; } diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index 74bafb212..c9f88c799 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -13,17 +13,11 @@ export interface VSProjectContextList { _vs_defaultIndex: number; } -export enum VSWorkspaceKind { - Unknown = 0, - Host = 1, - MiscellaneousFiles = 2, -} - export interface VSProjectContext { _vs_label: string; _vs_id: string; _vs_kind: string; - _vs_workspace_kind: VSWorkspaceKind; + _vs_is_miscellaneous: boolean; } export interface VSTextDocumentIdentifier extends lsp.TextDocumentIdentifier { diff --git a/src/lsptoolshost/services/projectContextService.ts b/src/lsptoolshost/services/projectContextService.ts index 4cff70ad6..4a5ef0a10 100644 --- a/src/lsptoolshost/services/projectContextService.ts +++ b/src/lsptoolshost/services/projectContextService.ts @@ -5,12 +5,7 @@ import * as vscode from 'vscode'; import { RoslynLanguageServer } from '../roslynLanguageServer'; -import { - VSGetProjectContextsRequest, - VSProjectContext, - VSProjectContextList, - VSWorkspaceKind, -} from '../roslynProtocol'; +import { VSGetProjectContextsRequest, VSProjectContext, VSProjectContextList } from '../roslynProtocol'; import { TextDocumentIdentifier } from 'vscode-languageserver-protocol'; import { UriConverter } from '../uriConverter'; import { LanguageServerEvents } from '../languageServerEvents'; @@ -31,7 +26,7 @@ export class ProjectContextService { _vs_id: '', _vs_kind: '', _vs_label: '', - _vs_workspace_kind: VSWorkspaceKind.Unknown, + _vs_is_miscellaneous: false, }; constructor(private _languageServer: RoslynLanguageServer, _languageServerEvents: LanguageServerEvents) { From 3562921a427107358d4098c9d1f8cfc146808f48 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 9 Oct 2024 23:49:31 -0700 Subject: [PATCH 3/3] Update Roslyn to 4.13.0-1.24509.4 --- CHANGELOG.md | 6 ++++++ package.json | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c979c55c..b3e4f374f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/package.json b/package.json index 530ba20a4..4a4ebb5f2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -5597,4 +5597,4 @@ } } } -} \ No newline at end of file +}