|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import * as vscode from 'vscode'; |
| 7 | +import * as crypto from 'crypto'; |
7 | 8 | import { RoslynLanguageServer } from './roslynLanguageServer'; |
8 | 9 | import { ActionOption, showWarningMessage } from '../shared/observers/utils/showMessage'; |
9 | 10 | import { ServerState } from './serverStateChange'; |
10 | | -import path = require('path'); |
| 11 | +import { languageServerOptions } from '../shared/options'; |
11 | 12 |
|
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>(); |
15 | 15 |
|
16 | 16 | export function registerMiscellaneousFileNotifier( |
17 | 17 | context: vscode.ExtensionContext, |
18 | 18 | languageServer: RoslynLanguageServer |
19 | 19 | ) { |
20 | | - context.workspaceState.update(NotifyMiscellaneousFilesOption, undefined); |
21 | | - context.globalState.update(NotifyMiscellaneousFilesOption, undefined); |
| 20 | + context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, undefined); |
22 | 21 |
|
23 | 22 | languageServer._projectContextService.onActiveFileContextChanged((e) => { |
24 | | - if (RecentlyNotifiedDocuments.has(e.uri)) { |
| 23 | + const hash = createHash(e.uri.toString(/*skipEncoding:*/ true)); |
| 24 | + if (NotifiedDocuments.has(hash)) { |
25 | 25 | return; |
26 | 26 | } |
27 | 27 |
|
28 | 28 | if (!e.context._vs_is_miscellaneous || languageServer.state !== ServerState.ProjectInitializationComplete) { |
29 | 29 | return; |
30 | 30 | } |
31 | 31 |
|
32 | | - if (!context.globalState.get<boolean>(NotifyMiscellaneousFilesOption, true)) { |
| 32 | + if (languageServerOptions.suppressMiscellaneousFilesToasts) { |
33 | 33 | return; |
34 | 34 | } |
35 | 35 |
|
36 | | - if (!context.workspaceState.get<boolean>(NotifyMiscellaneousFilesOption, true)) { |
| 36 | + if (context.workspaceState.get<boolean>(SuppressMiscellaneousFilesToastsOption, false)) { |
37 | 37 | return; |
38 | 38 | } |
39 | 39 |
|
40 | | - RecentlyNotifiedDocuments.add(e.uri); |
| 40 | + NotifiedDocuments.add(hash); |
41 | 41 |
|
42 | 42 | 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.' |
45 | 44 | ); |
46 | 45 | const dismissItem = vscode.l10n.t('Dismiss'); |
47 | 46 | const disableWorkspace: ActionOption = { |
48 | 47 | title: vscode.l10n.t('Do not show for this workspace'), |
49 | 48 | action: async () => { |
50 | | - context.workspaceState.update(NotifyMiscellaneousFilesOption, false); |
| 49 | + context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, true); |
51 | 50 | }, |
52 | 51 | }; |
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); |
64 | 53 | }); |
65 | 54 | } |
| 55 | + |
| 56 | +function createHash(data: string): string { |
| 57 | + return crypto.createHash('sha256').update(data).digest('hex'); |
| 58 | +} |
0 commit comments