Skip to content

fix(tools): symbol_workspace TotalCount is capped at about twice maxResults #115

Closed

Description

@CalvinAllen

Problem

symbol_workspace returns a TotalCount that looks like the number of matching symbols, but it stops counting at about twice maxResults.

In VisualStudioService.SearchWorkspaceSymbolsAsync:

  • The search stops once maxResults * 2 matching symbols have been collected (the maxResults * 2 limit passed to CollectProjectSymbols, and the break after it). Symbols after that are never looked at.
  • TotalCount is set to allSymbols.Count, so it can't go much above 2 * maxResults.
  • The limit is only checked when the search starts a project item or a list of code elements, not after each symbol is added. So the search runs a variable amount past the limit, and TotalCount isn't even a fixed cap.

So with 1,000 symbols matching the query and the default maxResults = 100, TotalCount comes back as about 200 instead of 1,000.

Truncated is correct. Only matching symbols are collected, so allSymbols.Count > maxResults is true exactly when more symbols matched than were returned.

Repro

  1. Open a solution with many symbols matching a short query (for example Get).
  2. Call symbol_workspace with query: "Get" and maxResults: 5.
  3. TotalCount is about 10, however many symbols actually match.

Expected

TotalCount should not look like a total when it isn't. Two ways to fix it:

  • Count every match. Search the whole solution, but only build SymbolInfo for the first maxResults. This is accurate, but it can be slow: reading FileCodeModel for every file is expensive, and the maxResults description ("Use lower values for faster results on large solutions") suggests the early stop is deliberate.
  • Keep the early stop and say so. Document TotalCount as a lower bound, or rename or drop it, so callers don't read it as the real total.

Also

  • maxResults: 0 or below makes the limit 0 or negative, so nothing is collected. The tool then says "No symbols matching '...' found in the solution." even when there are matches. These values should be rejected or handled.
  • SearchWorkspaceSymbolsAsync runs the name filter (.Where(...)) a second time on allSymbols. CollectCodeElements already only adds matching symbols, so the second filter changes nothing.

Related

#113 (fixed in #114) was the same kind of problem in errors_list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions