-
Notifications
You must be signed in to change notification settings - Fork 685
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
Add miscellaneous file open notifications #7652
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 | ||
) { | ||
languageServer._projectContextService.onActiveFileContextChanged((e) => { | ||
// Only warn for miscellaneous files when the workspace is fully initialized. | ||
if (!e.context._vs_is_miscellaneous || languageServer.state !== ServerState.ProjectInitializationComplete) { | ||
return; | ||
} | ||
|
||
// Check settings and workspaceState to see if we should suppress the toast. | ||
if ( | ||
languageServerOptions.suppressMiscellaneousFilesToasts || | ||
context.workspaceState.get<boolean>(SuppressMiscellaneousFilesToastsOption, false) | ||
) { | ||
return; | ||
} | ||
|
||
// Check to see if we have already notified the user about this document. | ||
const hash = createHash(e.uri.toString(/*skipEncoding:*/ true)); | ||
if (NotifiedDocuments.has(hash)) { | ||
return; | ||
} else { | ||
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.' | ||
); | ||
const dismissItem = vscode.l10n.t('Dismiss'); | ||
// Provide the user a way to easily disable the toast without changing settings. | ||
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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 comment
The 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.