Skip to content

fix(tools): drop symbol_workspace's capped TotalCount and stop early - #118

Merged
CalvinAllen merged 1 commit into
mainfrom
fix/tools/symbol-workspace-total-count
Oct 1, 2026
Merged

CalvinAllen merged 1 commit into
mainfrom
fix/tools/symbol-workspace-total-count

Conversation

@CalvinAllen

Copy link
Copy Markdown
Contributor

Description

symbol_workspace returned a TotalCount that looked like the number of matching symbols, but it stopped counting at about twice maxResults. With 1,000 matches and the default maxResults = 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:

  • TotalCount is removed from WorkspaceSymbolResult. Truncated already tells the caller that more symbols matched than were returned, and the tool description now says to narrow the query or raise maxResults.
  • The walk stops at exactly maxResults + 1 matches. That's the fewest that settle Truncated, 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.
  • maxResults below 1 is rejected with a message. Before, it collected nothing and reported "No symbols matching '...' found" even when there were matches.
  • The redundant second name filter is gone. Matching uses OrdinalIgnoreCase instead 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 in VisualStudioService checks IsComplete before each element.

test_run and test_debug resolve their target through the same search with the default maxResults. They see the same first 100 matches as before.

Type of Change

  • feat - New feature
  • fix - Bug fix
  • docs - Documentation only
  • refactor - Code change that neither fixes a bug nor adds a feature
  • test - Adding or updating tests
  • chore - Maintenance tasks
  • ci - CI/CD changes

Related Issues

Related to #115. This needs testing inside Visual Studio before the issue can be closed.

Checklist

  • My code follows the project's code style
  • I have tested my changes locally (automated tests pass; not yet tried inside a running Visual Studio, see below)
  • I have updated documentation if needed
  • My commits follow the conventional commit format
  • This PR has a descriptive title using conventional commit format

Additional Notes

  • dotnet build (Release): 0 warnings, 0 errors
  • dotnet test: 233 passed, including 12 new tests in WorkspaceSymbolSearchTests.cs. They cover case-insensitive matching on name or full name, stopping at one match past the cap, the Truncated boundary, empty results, adds after completion being ignored, rejecting maxResults below 1, and int.MaxValue not overflowing.

Still to test inside Visual Studio. The code-model walk itself can't run without Visual Studio:

  • symbol_workspace with query: "Get" and maxResults: 5 returns 5 symbols and Truncated: true, and no TotalCount
  • A query with fewer matches than maxResults returns them all with Truncated: false
  • maxResults: 0 returns the invalid-value message
  • test_run with a class or method name still finds its target

Removing TotalCount changes the JSON output. Nothing in the codebase reads it; only symbol_workspace's output contains it.

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.
@CalvinAllen
CalvinAllen merged commit c67c5e3 into main Oct 1, 2026
2 checks passed
@CalvinAllen
CalvinAllen deleted the fix/tools/symbol-workspace-total-count branch October 1, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant