-
Notifications
You must be signed in to change notification settings - Fork 708
Add miscellaneous file open notifications #7652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as crypto from 'crypto'; | ||
import { RoslynLanguageServer } from './roslynLanguageServer'; | ||
import { ActionOption, showWarningMessage } from '../shared/observers/utils/showMessage'; | ||
import { ServerState } from './serverStateChange'; | ||
import { languageServerOptions } from '../shared/options'; | ||
|
||
const SuppressMiscellaneousFilesToastsOption = 'dotnet.server.suppressMiscellaneousFilesToasts'; | ||
const NotifiedDocuments = new Set<string>(); | ||
|
||
export function registerMiscellaneousFileNotifier( | ||
context: vscode.ExtensionContext, | ||
languageServer: RoslynLanguageServer | ||
) { | ||
context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, undefined); | ||
|
||
languageServer._projectContextService.onActiveFileContextChanged((e) => { | ||
const hash = createHash(e.uri.toString(/*skipEncoding:*/ true)); | ||
if (NotifiedDocuments.has(hash)) { | ||
return; | ||
} | ||
|
||
if (!e.context._vs_is_miscellaneous || languageServer.state !== ServerState.ProjectInitializationComplete) { | ||
return; | ||
} | ||
|
||
if (languageServerOptions.suppressMiscellaneousFilesToasts) { | ||
return; | ||
} | ||
|
||
if (context.workspaceState.get<boolean>(SuppressMiscellaneousFilesToastsOption, false)) { | ||
return; | ||
} | ||
|
||
NotifiedDocuments.add(hash); | ||
|
||
const message = vscode.l10n.t( | ||
'The active document is not part of the open workspace. Not all language features will be available.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if we wanted to add like a learn more docs link with how they might tell why the file is in misc. For example, making sure the file is part of a project, making sure the language server has a project loaded, making sure the project is part of the loaded sln, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is a good idea and we can do it in a follow up. @webreidi I see VS has a page on Misc Files. Is that a good one to link to for now? Should we have a C# ext. centric page created? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created draft PR #7654 to explore this further. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the VS Link will only cause confusion. But we can add to the FAQ the specifics of this. |
||
); | ||
const dismissItem = vscode.l10n.t('Dismiss'); | ||
const disableWorkspace: ActionOption = { | ||
title: vscode.l10n.t('Do not show for this workspace'), | ||
action: async () => { | ||
context.workspaceState.update(SuppressMiscellaneousFilesToastsOption, true); | ||
}, | ||
}; | ||
showWarningMessage(vscode, message, dismissItem, disableWorkspace); | ||
}); | ||
} | ||
|
||
function createHash(data: string): string { | ||
return crypto.createHash('sha256').update(data).digest('hex'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move this down below the other checks, since it could be more expensive?