Skip to content

Report XML doc parameter names as related symbol uses - #20637

Open
xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:fix/xmldoc-param-symbol-uses
Open

xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:fix/xmldoc-param-symbol-uses

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Fixes #15134

Renaming a parameter in Visual Studio leaves <param name="x">, <paramref>, <typeparam> and <typeparamref> in the declaration's /// comment untouched (#20630), because the compiler kept a single range for the whole comment and reported nothing inside it. XmlDoc now keeps the range of every /// line and lists its name and cref attribute values with their source ranges, and the checker reports each name that matches a parameter or type parameter of the declaration as a RelatedSymbolUseKind.XmlDocParameter use — for let-bound functions, members, primary constructors, union case fields and signature-file vals.

The new kind is opt-in: GetUsesOfSymbolInFile returns it only when asked for, and Find All References and semantic classification never see it, so symbol search stays free of documentation hits. The editor change that turns it into a rename of the tags follows in a separate PR.

🤖 Generated with Claude Code

`XmlDoc` keeps the range of every `///` line and lists the `name` and
`cref` attribute values it contains with their source ranges. The
checker reports each `<param>`, `<paramref>`, `<typeparam>` and
`<typeparamref>` name that matches a parameter or type parameter of
the documented declaration as a `RelatedSymbolUseKind.XmlDocParameter`
use, for let-bound functions, members, primary constructors, union
case fields and signature-file vals.

The kind is opt-in: `GetUsesOfSymbolInFile` returns it only when asked
for, the `ItemKeyStore` behind Find All References never receives it,
and semantic classification ignores it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 26, 2026 01:38
@xperiandri
xperiandri requested a review from a team as a code owner September 26, 2026 01:38
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@xperiandri

Copy link
Copy Markdown
Contributor Author

Covered cases (FSharpChecker/FindReferences.fs, module XmlDocParameters; each asserts that the default GetUsesOfSymbolInFile excludes the doc ranges, that relatedSymbolKinds = XmlDocParameter includes them at the exact ranges, and that UnionCaseTester ||| CopyAndUpdateRecord still excludes them):

  • <param> and <paramref> of a let-bound function
  • <param> of a member, not confused with this
  • <param> of a primary constructor, documented on the type
  • <param> of a union case field
  • <param> of a signature-file val: the code use is found, the doc use stays out of the findAllReferences workflow (the ItemKeyStore path)
  • <typeparam> of a generic type; <typeparam> and <typeparamref> of an explicitly generic function ('T matches name="T")
  • a backticked parameter is matched by its bare name
  • a duplicated name reports every occurrence
  • an unknown name reports nothing and does not break the others
  • <inheritdoc> and <include> do not disturb the scan

Scanner (FSharp.Compiler.Service.Tests/XmlDocTests.fs, module XmlDocRefs): spaces around =, single-quoted values, attribute order, self-closing tags, a tag split across /// lines, malformed XML, and an XmlDoc without line ranges ([||]). SemanticClassificationRegressions: nothing inside the /// block is classified.

Reverting the emission in ReportXmlDocRefUses fails 10 of the 11 FindReferences tests; removing the ItemKeyStore filter fails the signature-file one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

XML scanning and parameter collection miss valid cases and can produce incorrect references.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds opt-in XML documentation parameter references to compiler symbol-use data for future rename support.

Changes:

  • Tracks XML documentation ranges and attribute references.
  • Reports matching parameter and type-parameter references.
  • Updates filtering, tests, API baseline, and release notes.
File Description
tests/​FSharp.Compiler.Service.Tests/​XmlDocTests.fs XML reference scanning tests
tests/​FSharp.Compiler.Service.Tests/​FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl API baseline update
tests/​FSharp.Compiler.ComponentTests/​FSharpChecker/​SemanticClassificationRegressions.fs Classification regression tests
tests/​FSharp.Compiler.ComponentTests/​FSharpChecker/​FindReferences.fs Related-use tests
src/​Compiler/​SyntaxTree/​XmlDoc.fsi XML documentation reference API
src/​Compiler/​SyntaxTree/​XmlDoc.fs XML documentation scanning and ranges
src/​Compiler/​Service/​TransparentCompiler.fs Filters documentation uses
src/​Compiler/​Service/​SemanticClassification.fs Excludes documentation classification
src/​Compiler/​Service/​IncrementalBuild.fs Filters documentation uses
src/​Compiler/​Checking/​RelatedSymbolUse.fs Adds XML documentation use kind
src/​Compiler/​Checking/​NameResolution.fsi Reporting API declaration
src/​Compiler/​Checking/​NameResolution.fs Reports matching documentation references
src/​Compiler/​Checking/​Expressions/​CheckExpressions.fs Reports function and member parameter references
src/​Compiler/​Checking/​CheckIncrementalClasses.fs Reports constructor references
src/​Compiler/​Checking/​CheckDeclarations.fs Reports type and union-case references
docs/​release-notes/​.FSharp.Compiler.Service/​11.0.200.md Release note

Comment thread src/Compiler/SyntaxTree/XmlDoc.fs Outdated
Comment on lines +69 to +75
let rec find i =
match text.IndexOf(attribute, i, StringComparison.Ordinal) with
| -1 -> ValueNone
| at when at >= close -> ValueNone
| at ->
let mutable j = at + attribute.Length

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed: <param notname="wrong" name="x"> reported wrong. The scanner now walks each tag's attributes as tokens and compares whole names, which also keeps a > inside a quoted value from ending the tag. Covered by only a whole attribute name matches, and a quoted > does not end the tag. Fixed in 008cb20.

Comment thread src/Compiler/SyntaxTree/XmlDoc.fs Outdated
Comment on lines +97 to +101
let scan (lines: string[]) (lineRanges: range[]) =
[|
for i in 0 .. lines.Length - 1 do
let text = lines[i]
let m = lineRanges[i]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed: a name on the line after <param was missed. The whole comment is now scanned as one text and each value is mapped back to its /// line. A value that itself runs over a line break has no single-line range, so it is still skipped. Covered by a tag whose attributes run over several lines and a value that runs over a line break yields nothing. Fixed in 008cb20.

@github-actions github-actions Bot added the ⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager label Sep 26, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

The scanner looked for the attribute name as a substring of each line,
so `<param notname="wrong" name="x">` reported `wrong`, and a tag whose
`name` sat on the next `///` line reported nothing. It now walks the
attributes of each tag one at a time over the whole comment, keeps a
`>` inside a quoted value from ending the tag, maps each value back to
its line, and skips a value that runs over a line break.

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

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Design-Time
Affects-Design-Time: Editor-service changes affect IDE behavior.

Generated by PR Tooling Safety Check · gpt56 685K · ◷

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

⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Have PreXmlDoc/XmlDoc track names and ranges for param/paramref children

2 participants