Skip to content

Add symbol and type highlighting to F# diagnostics - #20097

Open
auduchinok wants to merge 14 commits into
dotnet:mainfrom
auduchinok:richDiagnostics
Open

Add symbol and type highlighting to F# diagnostics#20097
auduchinok wants to merge 14 commits into
dotnet:mainfrom
auduchinok:richDiagnostics

Conversation

@auduchinok

Copy link
Copy Markdown
Member

Implements highlighting for symbols and types in diagnostic messages to be used by IDEs and tools like F# Interactive.

To make it possible, this PR introduces RichText type which wraps TaggedText[] uses and making the code simpler to work with in existing FCS APIs like tooltips.

The FSComp helpers generation is changed in a way that the same format works without changes, and only an additional RichText flag is needed in the fsproj.

@auduchinok
auduchinok requested a review from a team as a code owner July 29, 2026 16:39
@auduchinok auduchinok changed the title Diagnostics: classify errors using RichText Add symbol and type highlighting to F# diagnostics Jul 29, 2026
@github-actions github-actions Bot added ⚠️ Affects-Bootstrap Tooling check: PR touches compiler bootstrap chain ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure labels Jul 29, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the ⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen label Jul 29, 2026
@github-actions

This comment has been minimized.

@auduchinok

Copy link
Copy Markdown
Member Author

This is ready.

<Link>FSStrings.resx</Link>
<LogicalName>FSStrings.resources</LogicalName>
</EmbeddedResource>
<Compile Include="Utilities\NullHelpers.fs" CompileOrder="CompileFirst" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is the CompileOrder necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Otherwise RichText is not available in the generated error helpers.

[<Fact>]
let ``Can get help for FSComp.SR.considerUpcast`` () =
match FSharp.Compiler.Interactive.FsiHelp.Logic.Quoted.tryGetHelp <@ FSComp.SR.considerUpcast @> with
match FSharp.Compiler.Interactive.FsiHelp.Logic.Quoted.tryGetHelp <@ (FSComp.SR.considerUpcast: string * string -> int * string) @> with

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we have to type annotate now?
Is this change source-breaking for some code relying on type inference?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

An AI-generated response:

Why the annotation: FSComp.txt entries with %s holes now generate two overloads (string and RichText). The test uses the accessor as a first-class value in a quotation, which F# only allows for non-overloaded methods — without the annotation it fails with FS0503: ... 'considerUpcast' taking 1 arguments is not accessible ... All accessible versions take 2 arguments. The annotation picks the string overload.

Not source-breaking for consumers: the generated type is type internal SR, so the overloads are invisible outside the assembly, and they're opt-in per resource file (true, set only for FSComp.txt — FSIstrings generates none). In-repo cost is 5 type annotations plus this quotation.

What is breaking: members moved from TaggedText[] to RichText, and FormatLayout, FormatLayoutWithConstraints, GetReturnTypeLayout were renamed to the …RichText forms — source- and binary-breaking for tooling.

Non-AI: I expect tools like Ionide and Rider will update usages for RichText, like we always do it when FCS updates.

Comment thread FSharpBuild.Directory.Build.targets Outdated
Comment thread src/Compiler/Facilities/DiagnosticsLogger.fsi Outdated
Comment thread src/Compiler/Facilities/RichText.fs Outdated
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ Release notes required, but author opted out

Warning

Author opted out of release notes, check is disabled for this pull request.
cc @dotnet/fsharp-team-msft

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Bootstrap, Affects-Build-Infra, Affects-Compiler-Output
Affects-Bootstrap: modifies proto.proj, lex.fsl, pars.fsy
Affects-Build-Infra: modifies FSharpBuild.Directory.Build.targets, FSharpEmbedResourceText.fs
Affects-Compiler-Output: modifies IlxGen.fs, ilwrite.fs, ilreflect.fs

Generated by PR Tooling Safety Check · opus46 3.1M ·

@auduchinok auduchinok added the NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Bootstrap Tooling check: PR touches compiler bootstrap chain ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure ⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants