-
Notifications
You must be signed in to change notification settings - Fork 349
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
fix(auto-edit): fix the false notification for auto-edit non eligibility #6899
Merged
+63
−12
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,13 +102,28 @@ export function createAutoEditsProvider({ | |
) | ||
} | ||
|
||
/** | ||
* Displays an error notification to the user about non-eligibility for auto edits, | ||
* but only if the user is currently in the Settings view (to avoid spamming them). | ||
* | ||
* This is because because of the flaky network issues we could evaluate the default feature flag value to false | ||
* and show the non eligibility notification to the user even if they have access to the feature. | ||
* Generally the users should see the notification only when they manully change the vscode config which could be either | ||
* through the settings UI or `settings.json` file. | ||
* | ||
* @param {string | undefined} nonEligibilityReason - The reason why the user is currently not eligible | ||
* for auto edits. If not provided, no notification occurs. | ||
*/ | ||
export async function handleAutoeditsNotificationForNonEligibleUser( | ||
nonEligibilityReason?: string | ||
): Promise<void> { | ||
const switchToAutocompleteText = 'Switch to autocomplete' | ||
if (!nonEligibilityReason || !isSettingsEditorOpen()) { | ||
return | ||
} | ||
|
||
const switchToAutocompleteText = 'Switch to autocomplete' | ||
const selection = await vscode.window.showErrorMessage( | ||
`Error: ${nonEligibilityReason ?? AUTOEDITS_NON_ELIGIBILITY_MESSAGES.FEATURE_FLAG_NOT_ELIGIBLE}`, | ||
`Error: ${nonEligibilityReason}`, | ||
switchToAutocompleteText | ||
) | ||
if (selection === switchToAutocompleteText) { | ||
|
@@ -122,6 +137,42 @@ export async function handleAutoeditsNotificationForNonEligibleUser( | |
} | ||
} | ||
|
||
/** | ||
* Checks whether the current view in VS Code is the Settings editor (JSON or UI). | ||
* | ||
* This function performs two checks: | ||
* 1. Detect if the active text editor points to a known settings file (e.g., settings.json, settings.jsonc). | ||
* 2. If there's no text editor open, examine the "Tab" label to see if it's the built-in Settings UI. | ||
* | ||
* Note: Using the tab's label is locale-specific; if a user runs VS Code in a non-English locale, | ||
* or if the label changes in future VS Code versions, this heuristic may fail. | ||
* | ||
* @returns {boolean} True if the user is most likely viewing the Settings editor (JSON or UI), false otherwise. | ||
*/ | ||
function isSettingsEditorOpen(): boolean { | ||
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. Interesting idea |
||
const activeEditor = vscode.window.activeTextEditor | ||
|
||
// 1) If there's an active text editor, check if the file name matches typical settings files | ||
if (activeEditor) { | ||
const fsPath = activeEditor.document.uri.fsPath | ||
if (fsPath.endsWith('settings.json') || fsPath.endsWith('settings.jsonc')) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// 2) If there's no activeTextEditor, the user might be in the graphical Settings UI or have no editor at all | ||
const activeTab = vscode.window.tabGroups.activeTabGroup?.activeTab | ||
if (!activeTab) { | ||
// No tab at all: definitely not a JSON settings file; | ||
// could be just an empty Editor area, Start page, or something else | ||
return false | ||
} | ||
|
||
// The built-in Settings UI tab typically has the label "Settings" (in English). | ||
return activeTab.label === 'Settings' | ||
} | ||
|
||
export function isUserEligibleForAutoeditsFeature( | ||
autoeditsFeatureFlagEnabled: boolean, | ||
authStatus: AuthStatus, | ||
|
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.
nit :D
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.
done