Skip to content
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

Ensure discards are initially soft selected in VSCode #75655

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

dibarbet
Copy link
Member

Resolves dotnet/vscode-csharp#7623

Unfortunately LSP doesn't give servers much control over filtering. Servers do not generally get callbacks as filter text is typed - meaning we generally are not able to modify hard vs soft selection after the initial list is presented.

However, we can force VSCode to call us back in some scenarios using the isIncomplete flag on the completion list. For this case, when we see only punctuation typed (_), we set the isIncomplete flag and unset the commit characters to mimic soft selection.

As the user continues typing (e.g. _o) we get called again and we can update to hard selection if they are completing a variable.

However - this does not cover every case of switching between hard/soft selection. It could be covered by always setting isIncomplete but that would be expensive as we're re-computing and reserializing the entire list.

@dibarbet dibarbet requested a review from genlu October 28, 2024 22:10
@dibarbet dibarbet requested a review from a team as a code owner October 28, 2024 22:10
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 28, 2024
@@ -363,6 +363,82 @@ internal static void FilterItems(
}
}

internal static bool IsHardSelection(CompletionItem item, bool matchedFilterText, bool hasSuggestionModeItem, string filterText)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything in this file is moved unchanged

if (matchResultsBuilder.Count > 0)
{
var bestResult = GetBestCompletionItemSelectionFromFilteredResults(matchResultsBuilder);
isHardSelection = CompletionService.IsHardSelection(bestResult.CompletionItem, bestResult.ShouldBeConsideredMatchingFilterText, completionList.SuggestionModeItem != null, filterText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this part needed to handle soft-selecting _? I think we could just use the result of IsAllPunctuation(filterText) to decide both selection mode and isIncomplete

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, I can make that change

@dibarbet dibarbet requested a review from genlu October 29, 2024 18:30
@dibarbet dibarbet merged commit 6979896 into dotnet:main Oct 30, 2024
25 checks passed
@dibarbet dibarbet deleted the completion_soft_selection_lsp branch October 30, 2024 18:22
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A single _ (underscore/discard) gets auto-completed to something else
2 participants