Repository navigation
fix(tools): drop symbol_workspace's capped TotalCount and stop early - #118
Merged
Merged
Conversation
symbol_workspace returned a TotalCount that looked like the number of matching symbols but stopped counting at about twice maxResults. The limit was only checked when the walk started a project item or a list of code elements, so it also overshot by a variable amount. Counting every match would mean walking every file's code model, and the search runs synchronously on the UI thread, so Visual Studio would freeze for the whole walk. TotalCount is dropped instead. Truncated already says when more symbols matched than were returned. The walk now stops at exactly maxResults + 1 matches, the fewest that settle Truncated, checking before every element. That is about half as many as before. The matching, stopping and result rules live in WorkspaceSymbolSearch, which has no Visual Studio types and is unit tested. maxResults below 1 is rejected with a message instead of returning "No symbols matching" when there are matches. The redundant second name filter is gone, and matching uses OrdinalIgnoreCase instead of lowering both strings for every element.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
symbol_workspacereturned aTotalCountthat looked like the number of matching symbols, but it stopped counting at about twicemaxResults. With 1,000 matches and the defaultmaxResults = 100, it reported about 200.Counting every match isn't an option: the search walks every file's code model synchronously on the UI thread, so a full count would freeze Visual Studio for the whole walk on every call. So:
TotalCountis removed fromWorkspaceSymbolResult.Truncatedalready tells the caller that more symbols matched than were returned, and the tool description now says to narrow the query or raisemaxResults.maxResults + 1matches. That's the fewest that settleTruncated, and about half as many as before. The limit used to be checked only when the walk started a project item or a list of code elements, so it overshot by a variable amount. Now it's checked before every element.maxResultsbelow 1 is rejected with a message. Before, it collected nothing and reported "No symbols matching '...' found" even when there were matches.OrdinalIgnoreCaseinstead of lowercasing both strings for every element.The matching, stopping and result rules are in
WorkspaceSymbolSearch, which has no Visual Studio types, so they can be unit tested. The code-model walk inVisualStudioServicechecksIsCompletebefore each element.test_runandtest_debugresolve their target through the same search with the defaultmaxResults. They see the same first 100 matches as before.Type of Change
feat- New featurefix- Bug fixdocs- Documentation onlyrefactor- Code change that neither fixes a bug nor adds a featuretest- Adding or updating testschore- Maintenance tasksci- CI/CD changesRelated Issues
Related to #115. This needs testing inside Visual Studio before the issue can be closed.
Checklist
Additional Notes
dotnet build(Release): 0 warnings, 0 errorsdotnet test: 233 passed, including 12 new tests inWorkspaceSymbolSearchTests.cs. They cover case-insensitive matching on name or full name, stopping at one match past the cap, theTruncatedboundary, empty results, adds after completion being ignored, rejectingmaxResultsbelow 1, andint.MaxValuenot overflowing.Still to test inside Visual Studio. The code-model walk itself can't run without Visual Studio:
symbol_workspacewithquery: "Get"andmaxResults: 5returns 5 symbols andTruncated: true, and noTotalCountmaxResultsreturns them all withTruncated: falsemaxResults: 0returns the invalid-value messagetest_runwith a class or method name still finds its targetRemoving
TotalCountchanges the JSON output. Nothing in the codebase reads it; onlysymbol_workspace's output contains it.