Make Fix/Message/TAST range types independent of FSharp.Compiler.Service#288
Closed
Make Fix/Message/TAST range types independent of FSharp.Compiler.Service#288
Conversation
…d TAST API Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
…cting Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Make F# Analyzer API independent of FCS
Make Fix/Message/TAST range types independent of FSharp.Compiler.Service
Feb 27, 2026
Member
|
didn't get far, but wanted to see what it would try |
Contributor
|
@TheAngryByrd Are you interested in me trying this with Claude? I've wanted this feature for a long time. |
Member
|
Yeah, I’d very much wanna see what an LLM can to |
Contributor
|
I think #289 is directionally correct; it may even be actually correct modulo some design decisions like "should we continue exposing a tree-walking style API for convenience of migration". Feel free not to read it for now though, because I haven't carefully reviewed it so it's still not far from being raw slop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Binary coupling to FCS types in the public analyzer API (
Fix,Message,TASTCollecting) means every analyzer must referenceFSharp.Compiler.Service, blocking binary compatibility across different tooling hosts.Changes
New SDK-owned position/range types
Positionstruct (Line,Column) andRangestruct (FileName,Start,End,StartLine/Column/EndLine/Column)Position.mkPosandRange.mkRange— so existing call sites need minimal changesFixandMessageupdatedFix.FromRangeandMessage.Rangenow useFSharp.Analyzers.SDK.Rangeinstead ofFSharp.Compiler.Text.range. Analyzers that only produce diagnostics no longer need a reference to FCS at all.TASTCollectingwalker API updatedWalkCallandWalkNewRecordnow receiveexprRange: Range(SDK type). Conversion fromFSharpExpr.Rangehappens inside the SDK via the newRangeConversionsmodule.RangeConversionsmodule (public)Bridge for analyzers that work directly with FCS types and need to produce SDK messages.
Sample updated
OptionAnalyzernow has zero directFSharp.Compiler.Textimports — the typed-tree range flows through as an SDKRangeend-to-end:File ordering
FSharp.Analyzers.SDK.fsi/fsnow compiles beforeTASTCollecting.fsi/fssoPosition/Rangeare in scope for the TAST signatures.Original prompt
This section details on the original issue you should resolve
<issue_title>Make F# Analyzer API independent of FCS?</issue_title>
<issue_description>
I've been thinking about the problem of binary compatibility for F# analyzers, in the context of trying to get F# analyzers available in all F# tooling.
This is a blocking problem for incorporation of analyzers into the Visual F# Tools. This applies even if those tools switch to FsAutoComplete - all analyzers must still be loadable into all future iterations of F# tooling.
The main issue is binary compatibility for the information being drawn from the FCS API (FSharpSymbol etc.). I am wondering if we might consider making this F# Analyzer API completely independent of FCS. When hosted, FSharpAutoComplete would provide necessary shims.
This would mean the F# Analyzer API would include abstract types like IFSharpSymbol, ISyntaxTree and so on. It would be a complete self-contained, zero-dependency facade over all the information analyzers typically require.
FCS could then take a dependency on this component (which I called FSharp.Compiler.Analyzers in the link above).
</issue_description>
<agent_instructions>Give this a good old college try</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@baronfel Something like this would be great for another reason: incorporating some kind of stable view of the syntax nodes into an interface would make it easier for tools like sharp lab to bind to multiple versions of the compiler, which would make before and after analysis and comparisons much easier. It would potentially also support work in progress comparisons for interesting feature branches of compiler work. @dsyme It might, yes - it partly depends how often we revise the API, whether an analysis application can host mutiple versions (do we use naming `FSharp.Compiler.Analysis.v1.0`, `FSharp.Compiler.Analysis.v2.0` etc.), and who provides the implementations of the shims.It's really a hard problem - the need for binary compat means the API would have to be really, really stable. But the nature of the FCS API means it gets enriched on every language update, even without taking into account bug fixes. Even yesterday I added more information for witness passing, for example.
-
-
-
-
@dsyme I'll link this discussion in the RFC (am happy to keep discussing here) @dsyme It's curious that one way to make the Analyzer API both binary compatible and simple and stable and extensible would be to transact all context information via an untyped format like JSON. Perhaps it would even be fast enough. (I'm not saying we should do that, I'm just thinking aloud)If information is missing from the API (e.g. new language features are added or the SyntaxTree changes) then the API would also need to be revamped.
If we got it right I'd be ok with FCS taking a dependency on this and promising to always provide shims going forward, including progressing forward as the API is revised and providing backwards compat shims.
The API must serve as a binary-compatible view into FCS - there's no point having it if it's not going to be 100% binary compat forever - we may as well just depend on FCS in that case.
From an engineering point of view something like this should likely sit in dotnet/fsharp, at least if FCS takes a dependency on it and implements the shims.
The annoying thing here is that this kind of tooling ...
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.