Skip to content

Rank and highlight F# Navigate To results like C# and VB - #85280

Open
xperiandri wants to merge 7 commits into
dotnet:mainfrom
xperiandri:fsharp-navigateto-secondary-sort
Open

xperiandri wants to merge 7 commits into
dotnet:mainfrom
xperiandri:fsharp-navigateto-secondary-sort

Conversation

@xperiandri

@xperiandri xperiandri commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Navigate To sorts equal F# matches in a different way than equal C# and VB matches. A match in the active file does not come first. The window does not highlight the matched characters. A match that uses the case of the search pattern does not rank above a match with a different case.

This change gives F# results the same secondary sort as C# and VB results. It also lets F# report if the case matched, and which spans matched. Older F# language services load without a change.

The F# side is dotnet/fsharp#20531 and dotnet/fsharp#20532. The second one can merge only after this change reaches Visual Studio.

Details
  • Navigate To sorts results of the same match kind with INavigateToSearchResult.SecondarySort. RoslynNavigateToItem builds this key for C# and VB. The key joins the folder distance to the active document, the parameter count, the type parameter count, the name, and the file name. InternalFSharpNavigateToSearchResult returned null.
  • ComputeSecondarySort moves from RoslynNavigateToItem to NavigateToSearchResultHelpers. It takes the active document, the item document, the two counts, and the name as arguments. Its logic does not change. Both languages call it.
  • InternalFSharpNavigateToSearchResult builds the key from the active document. The searcher already gave this document to FSharpNavigateToSearchService, and the service dropped it. SearchDocumentAsync passes the document that it searches, as AbstractNavigateToSearchService does.
  • FSharpNavigateToSearchResult gets a constructor that also takes isCaseSensitive, nameMatchSpans, parameterCount and typeParameterCount. The old constructor stays. It passes a case-insensitive match, no spans, and zero counts. Results from the old constructor also sort by folder distance.
  • FSharpNavigateToSearchResult is a class. The new constructor is an overload that old binaries never call. The change needs no versioned interface.
  • Before this change, every F# match was case-insensitive and had no spans. The window highlighted nothing. PatternMatch.CompareTo could not prefer a match that uses the case of the pattern.
  • FSharpNavigateToSearchResultTests use the folder layouts of NavigateToPrioritizeResultInCurrentDocument1 to 5 for an F# result. They also test the case flag, the spans, and the old constructor. The test documents use a language that has no Roslyn compilation. The tests compose a language service for it, so the test project needs no new reference.

🤖 Generated with Claude Code

@xperiandri
xperiandri requested a review from a team as a code owner September 13, 2026 17:59
Copilot AI lite review requested due to automatic review settings September 13, 2026 17:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Preserve the existing internal constructor API and record the new external-access API surface.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds C#/VB-equivalent secondary sorting for F# Navigate To results.

Changes:

  • Centralizes secondary-sort computation.
  • Propagates active-document context and declaration counts.
  • Adds sorting tests and C# workspace test support.
File summaries
File Summary
src/VisualStudio/ExternalAccess/Test/Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTests.csproj Adds C# workspace support for tests.
src/VisualStudio/ExternalAccess/Test/FSharp/FSharpNavigateToSearchResultTests.cs Tests F# secondary-sort ordering.
src/VisualStudio/ExternalAccess/Core/FSharp/NavigateTo/FSharpNavigateToSearchResult.cs Adds declaration-count metadata and compatibility overload; documentation and API tracking comments remain.
src/VisualStudio/ExternalAccess/Core/FSharp/Internal/NavigateTo/InternalFSharpNavigateToSearchResult.cs Computes F# secondary-sort keys; existing constructor compatibility requires attention.
src/VisualStudio/ExternalAccess/Core/FSharp/Internal/NavigateTo/FSharpNavigateToSearchService.cs Passes active-document context during conversion.
src/Features/Core/Portable/NavigateTo/RoslynNavigateToItem.cs Uses the shared sorting helper.
src/Features/Core/Portable/NavigateTo/INavigateToSearchResult.cs Provides shared secondary-sort computation.
Review details

Suppressed comments (1)

src/VisualStudio/ExternalAccess/Core/FSharp/NavigateTo/FSharpNavigateToSearchResult.cs:30

  • This project explicitly tracks its IVT surface through InternalAPI.Shipped.txt/InternalAPI.Unshipped.txt, but this new overload and the ParameterCount/TypeParameterCount properties are not added to InternalAPI.Unshipped.txt for either the Unified or VisualStudio F# namespace entries. Please add those corresponding entries so the external-access contract and the F# side's upcoming use are recorded.
    public FSharpNavigateToSearchResult(
        string additionalInformation,
        string kind,
        FSharpNavigateToMatchKind matchKind,
        string name,
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes and accompanying tests address the intended F# sorting behavior with no unresolved blocking issues.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 13, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The F# result constructor contract must be coordinated with the downstream consumer to avoid a compilation failure.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 1
  • Review effort level: Lite

xperiandri added a commit to xperiandri/fsharp that referenced this pull request Sep 22, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Sep 26, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 26, 2026 10:04
@xperiandri
xperiandri force-pushed the fsharp-navigateto-secondary-sort branch from c79eec0 to 8695c61 Compare September 26, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No blocking issues were identified; the remaining feedback is a minor test-coverage suggestion.

Review effort: Lite
Findings: None

Resolved since last review (1)

@xperiandri
xperiandri force-pushed the fsharp-navigateto-secondary-sort branch from 8695c61 to 3ade1a3 Compare September 26, 2026 10:45
Copilot AI review requested due to automatic review settings September 26, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Fix the nullable Document contract and make the test path platform-neutral.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 26, 2026 18:41
@xperiandri

Copy link
Copy Markdown
Contributor Author

Both points from the last Copilot pass are fixed in 9daefb28165:

  • The nullable Document contract. InternalFSharpNavigateToSearchResult takes no active document when the search was not invoked from one — it checks for that — but its file had nullability disabled and the parameter read Document. The file is nullable-enabled now, the parameter is Document?, and the doc comment says when it is absent.
  • The test path. The document was rooted at C:\, and the sort key ends with the parts of the file name, so on a platform where a backslash is not a separator the name would have stayed attached to the drive letter. It is rooted with a forward slash instead.

While there: three files carried no byte order mark, which .editorconfig asks for, and FSharpNavigateToSearchService.cs had lost the one it came with. Restored here and in #85281 (13b854c29c6).

All 189 tests in Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTests pass, built with -p:RunAnalyzersDuringBuild=true and no warnings.

xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 19, 2026
This reverts commit 9eea74ce32. Roslyn now computes the secondary sort from the
active document itself, as it does for C# and VB (dotnet/roslyn#85280), so F#
no longer tracks the focused file for Navigate To.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 19, 2026
… lines

Navigate To results pass the parameter and type parameter counts FCS now
records, which Roslyn sorts equal matches by (dotnet/roslyn#85280); the
persistent index stores them, so its format changes. Find All References
reports each F# reference with its line already classified, as C# and VB do
(dotnet/roslyn#85281).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 19, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
This reverts commit 9eea74ce32. Roslyn now computes the secondary sort from the
active document itself, as it does for C# and VB (dotnet/roslyn#85280), so F#
no longer tracks the focused file for Navigate To.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
… lines

Navigate To results pass the parameter and type parameter counts FCS now
records, which Roslyn sorts equal matches by (dotnet/roslyn#85280); the
persistent index stores them, so its format changes. Find All References
reports each F# reference with its line already classified, as C# and VB do
(dotnet/roslyn#85281).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
This reverts commit 9eea74ce32. Roslyn now computes the secondary sort from the
active document itself, as it does for C# and VB (dotnet/roslyn#85280), so F#
no longer tracks the focused file for Navigate To.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
… lines

Navigate To results pass the parameter and type parameter counts FCS now
records, which Roslyn sorts equal matches by (dotnet/roslyn#85280); the
persistent index stores them, so its format changes. Find All References
reports each F# reference with its line already classified, as C# and VB do
(dotnet/roslyn#85281).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 23, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@xperiandri
xperiandri force-pushed the fsharp-navigateto-secondary-sort branch from 6c2ff65 to ee22f51 Compare October 23, 2026 22:15
@xperiandri

Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi I simplified PR description and fixed all remarks.
Could you review and merge?
cc @T-Gro

xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 29, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 29, 2026
dotnet/roslyn#85280 takes the counts in the same constructor as whether the
match kept the name's case and where in the name it landed, so the results
window can highlight F# names and rank a case-exact match first. The pattern
matcher reports the spans in the candidate it was given, container first, so
they move to the name's own offsets; the substring fallback for operators and
backticked names reports the span it found itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 29, 2026
This reverts commit 9eea74ce32. Roslyn now computes the secondary sort from the
active document itself, as it does for C# and VB (dotnet/roslyn#85280), so F#
no longer tracks the focused file for Navigate To.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 29, 2026
… lines

Navigate To results pass the parameter and type parameter counts FCS now
records, which Roslyn sorts equal matches by (dotnet/roslyn#85280); the
persistent index stores them, so its format changes. Find All References
reports each F# reference with its line already classified, as C# and VB do
(dotnet/roslyn#85281).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Oct 29, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri and others added 7 commits November 2, 2026 13:41
Among results of the same match kind the platform orders by the secondary
sort, which RoslynNavigateToItem builds from the folder distance to the active
document, the parameter and type parameter counts, the name and the file name.
The F# adapter returned null there, so a match in the file being edited was not
listed before the same name elsewhere.

ComputeSecondarySort moves unchanged to NavigateToSearchResultHelpers. The F#
adapter computes it from the active document the searcher already passes, and
FSharpNavigateToSearchResult gets a constructor that takes the counts; the old
constructor stays and passes zero.

The EA test project references the C# workspace layer, because AdhocWorkspace
can only create a document for a language whose services are loaded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Also reword the typeParameterCount documentation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
InternalFSharpNavigateToSearchResult reported every F# match as case-insensitive
and without matched spans. Navigate To ranks a case-sensitive match ahead of an
otherwise equal one (PatternMatch.CompareTo), and highlights the name from the
spans, so F# results lost both.

The constructor that takes the parameter and type parameter counts now takes
isCaseSensitive and nameMatchSpans as well; it has not shipped, so it changes
in place. The five-argument constructor stays and passes a case-insensitive
match without spans.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The tests needed a document, and `AdhocWorkspace.AddProject` needs language services
for the language it names, so they named C# and the test project referenced C#
Workspaces - a dependency nothing in these tests is about. They now compose a language
service of their own for a language Roslyn has no compilation for, which is what F# is
here, and the reference is gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…byte order mark

`InternalFSharpNavigateToSearchResult` takes no active document when the search was not
invoked from a document - it checks for that - but said `Document` in a file with
nullability disabled. The file is nullable-enabled now and the parameter says so.

Three files carried no byte order mark, which `.editorconfig` asks for; one of them had
lost the mark it came with.

The test's document path is rooted with a forward slash: the sort key ends with the
parts of the file name, and a backslash would leave the name attached to the drive
letter where a backslash is not a separator.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ions in the API baseline

The class has been nullable-enabled since the active document became optional, but the baseline still
listed its reference-typed members as oblivious and the constructor with a non-null active document.
Record them as the source declares them: `Document? activeDocument` and `Summary` as `string?`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… fixtures once

The documentation of ComputeSecondarySort and of the active document parameter repeats the names and the
nullable annotation, and the count parameters keep only the part the signature cannot say. The project
already enables nullable, so the file no longer needs its own directive. In the tests, one workspace and
one result factory replace the setup each test repeated, and the shared test language states what it is
without defending why it exists and uses MefConstruction.ImportingConstructorMessage.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xperiandri
xperiandri force-pushed the fsharp-navigateto-secondary-sort branch from ee22f51 to abfd498 Compare November 2, 2026 12:41
Copilot AI lite review requested due to automatic review settings November 2, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change crosses the Roslyn–F# ExternalAccess and IVT boundaries, while downstream compilation, Visual Studio insertion/runtime compatibility, and UI ranking/highlighting remain unverified.

No open issues 🎉

2 resolved since last review

Review effort: Lite

@xperiandri

Copy link
Copy Markdown
Contributor Author

@baronfel could you help with merge?

xperiandri added a commit to xperiandri/fsharp that referenced this pull request Nov 5, 2026
Navigate To orders matches of the same kind by the folder distance to the
file being edited, then by parameter and type parameter count and name, for
C# and VB. Roslyn computes the same key for F# results once they carry the
counts, which NavigableItem now records.

Needs the FSharpNavigateToSearchResult constructor that takes the counts,
from dotnet/roslyn#85280.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xperiandri added a commit to xperiandri/fsharp that referenced this pull request Nov 5, 2026
dotnet/roslyn#85280 takes the counts in the same constructor as whether the
match kept the name's case and where in the name it landed, so the results
window can highlight F# names and rank a case-exact match first. The pattern
matcher reports the spans in the candidate it was given, container first, so
they move to the name's own offsets; the substring fallback for operators and
backticked names reports the span it found itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants