Skip to content

Commit 890919e

Browse files
committed
Add setting to suppress notifications.
1 parent 84eb99f commit 890919e

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

l10n/bundle.l10n.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@
172172
"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?",
173173
"Nested Code Action": "Nested Code Action",
174174
"Fix All: ": "Fix All: ",
175-
"{0} is not part of the open workspace. Not all language features will be available.": "{0} is not part of the open workspace. Not all language features will be available.",
175+
"The active document is not part of the open workspace. Not all language features will be available.": "The active document is not part of the open workspace. Not all language features will be available.",
176176
"Dismiss": "Dismiss",
177177
"Do not show for this workspace": "Do not show for this workspace",
178-
"Do not show again": "Do not show again",
179178
"Open solution": "Open solution",
180179
"Restart server": "Restart server",
181180
"C# Workspace Status": "C# Workspace Status",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,11 @@
14791479
"default": false,
14801480
"description": "%configuration.dotnet.server.suppressLspErrorToasts%"
14811481
},
1482+
"dotnet.server.suppressMiscellaneousFilesToasts": {
1483+
"type": "boolean",
1484+
"default": false,
1485+
"description": "%configuration.dotnet.server.suppressMiscellaneousFilesToasts%"
1486+
},
14821487
"dotnet.server.useServerGC": {
14831488
"type": "boolean",
14841489
"default": true,

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
3636
"configuration.dotnet.server.crashDumpPath": "Sets a folder path where crash dumps are written to if the language server crashes. Must be writeable by the user.",
3737
"configuration.dotnet.server.suppressLspErrorToasts": "Suppresses error toasts from showing up if the server encounters a recoverable error.",
38+
"configuration.dotnet.server.suppressMiscellaneousFilesToasts": "Suppress warning toasts from showing up if the active document is outside the open workspace.",
3839
"configuration.dotnet.server.useServerGC": "Configure the language server to use .NET server garbage collection. Server garbage collection generally provides better performance at the expensive of higher memory consumption.",
3940
"configuration.dotnet.enableXamlTools": "Enables XAML tools when using C# Dev Kit",
4041
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",

src/lsptoolshost/languageStatusBar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class ProjectContextStatus {
8585
} else {
8686
item.severity = vscode.LanguageStatusSeverity.Information;
8787
}
88+
89+
item.detail = e.context._vs_is_miscellaneous
90+
? vscode.l10n.t(
91+
'The active document is not part of the open workspace. Not all language features will be available.'
92+
)
93+
: vscode.l10n.t('Active File Context');
8894
});
8995

9096
// Trigger a refresh, but don't block creation on the refresh completing.

src/lsptoolshost/miscellaneousFileNotifier.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,55 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import * as crypto from 'crypto';
78
import { RoslynLanguageServer } from './roslynLanguageServer';
89
import { ActionOption, showWarningMessage } from '../shared/observers/utils/showMessage';
910
import { ServerState } from './serverStateChange';
10-
import path = require('path');
11+
import { languageServerOptions } from '../shared/options';
1112

12-
const NotifyMiscellaneousFilesOption = 'dotnet.miscellaneousFilesNotification.enabled';
13-
const RecentlyNotifiedDocuments = new Set<vscode.Uri>();
14-
const CooldownTime = 60 * 1000;
13+
const SuppressMiscellaneousFilesToastsOption = 'dotnet.server.suppressMiscellaneousFilesToasts';
14+
const NotifiedDocuments = new Set<string>();
1515

1616
export function registerMiscellaneousFileNotifier(
1717
context: vscode.ExtensionContext,
1818
languageServer: RoslynLanguageServer
1919
) {
20-
context.workspaceState.update(NotifyMiscellaneousFilesOption, undefined);
21-
context.globalState.update(NotifyMiscellaneousFilesOption, undefined);
20+
context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, undefined);
2221

2322
languageServer._projectContextService.onActiveFileContextChanged((e) => {
24-
if (RecentlyNotifiedDocuments.has(e.uri)) {
23+
const hash = createHash(e.uri.toString(/*skipEncoding:*/ true));
24+
if (NotifiedDocuments.has(hash)) {
2525
return;
2626
}
2727

2828
if (!e.context._vs_is_miscellaneous || languageServer.state !== ServerState.ProjectInitializationComplete) {
2929
return;
3030
}
3131

32-
if (!context.globalState.get<boolean>(NotifyMiscellaneousFilesOption, true)) {
32+
if (languageServerOptions.suppressMiscellaneousFilesToasts) {
3333
return;
3434
}
3535

36-
if (!context.workspaceState.get<boolean>(NotifyMiscellaneousFilesOption, true)) {
36+
if (context.workspaceState.get<boolean>(SuppressMiscellaneousFilesToastsOption, false)) {
3737
return;
3838
}
3939

40-
RecentlyNotifiedDocuments.add(e.uri);
40+
NotifiedDocuments.add(hash);
4141

4242
const message = vscode.l10n.t(
43-
'{0} is not part of the open workspace. Not all language features will be available.',
44-
path.basename(e.uri.fsPath)
43+
'The active document is not part of the open workspace. Not all language features will be available.'
4544
);
4645
const dismissItem = vscode.l10n.t('Dismiss');
4746
const disableWorkspace: ActionOption = {
4847
title: vscode.l10n.t('Do not show for this workspace'),
4948
action: async () => {
50-
context.workspaceState.update(NotifyMiscellaneousFilesOption, false);
49+
context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, true);
5150
},
5251
};
53-
const disableGlobal: ActionOption = {
54-
title: vscode.l10n.t('Do not show again'),
55-
action: async () => {
56-
context.globalState.update(NotifyMiscellaneousFilesOption, false);
57-
},
58-
};
59-
showWarningMessage(vscode, message, disableWorkspace, disableGlobal, dismissItem);
60-
61-
setTimeout(() => {
62-
RecentlyNotifiedDocuments.delete(e.uri);
63-
}, CooldownTime);
52+
showWarningMessage(vscode, message, dismissItem, disableWorkspace);
6453
});
6554
}
55+
56+
function createHash(data: string): string {
57+
return crypto.createHash('sha256').update(data).digest('hex');
58+
}

src/shared/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface LanguageServerOptions {
8080
readonly componentPaths: { [key: string]: string } | null;
8181
readonly enableXamlTools: boolean;
8282
readonly suppressLspErrorToasts: boolean;
83+
readonly suppressMiscellaneousFilesToasts: boolean;
8384
readonly useServerGC: boolean;
8485
}
8586

@@ -411,6 +412,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
411412
public get suppressLspErrorToasts() {
412413
return readOption<boolean>('dotnet.server.suppressLspErrorToasts', false);
413414
}
415+
public get suppressMiscellaneousFilesToasts() {
416+
return readOption<boolean>('dotnet.server.suppressMiscellaneousFilesToasts', false);
417+
}
414418
public get useServerGC() {
415419
return readOption<boolean>('dotnet.server.useServerGC', true);
416420
}

0 commit comments

Comments
 (0)