Skip to content

F# - syntax highlighting #96

Open
Open

Description

@knocte

Hello, I'm planning to create a PR that adds F# support (only syntax highlighting for now, can leave more features for later).

Can you give any hints on where the changes should be done? Would it be possible for the F#-related bits to be implemented in its own assembly (so that the source can be in F# itself, this way it would be easier to get more potential contributions later)?

Activity

  1. lextm commented on Mar 28, 2026

    @lextm

    @MattParkerDev I think this is another call on extensibility API.

    Ideally, you provide the LSP common interface and then any other languages and their LSP implementations can be integrated in a standard way.

  2. lextm commented on Mar 28, 2026

    @lextm

    Related to #18 which is also about F#.

  3. lextm commented on Mar 29, 2026

    @lextm

    @knocte My investigation shows that if a few gaps are filled, you don't need a pull request to this main repo, but can safely keep an extension compatible with both VS for Windows and SharpIDE.

    #99 shows how T4 support can be added by simply importing the T4 language extension from VS for Windows. I believe that is enough for your initial request.

    I plan to do more experiments and see how an existing language server can be imported in a similar way. Currently SharpIDE directly couple with Roslyn, so it doesn't speak LSP yet.

  4. knocte commented on Mar 30, 2026

    @knocte
    ContributorAuthor

    @lextm sorry man but you're a bit exhausting. After posting this issue, you have placed 3 comments here, posted another issue linking to this, and posted 2 comments in other issue. Can you just let the maintainer say something?

  5. lextm commented on Mar 30, 2026

    @lextm

    @knocte I’ve been following this repo since the initial Reddit announcement and have been watching its progress for quite a while.

    So while my comments may look like they arrived in a single batch, the thoughts behind them had actually been forming over time.

    I also intentionally left my work as a [WIP] pull request, because as you said, it is ultimately up to the maintainer to decide what to do next. At this point, I’m interested to see what direction he wants to take.

  6. MattParkerDev commented on Mar 30, 2026

    @MattParkerDev
    Owner

    Hi @knocte,
    Regarding F# syntax highlighting, completions etc support, unfortunately it does not look as straightforward as adding VB.NET support, as F# does not use roslyn. F# does not participate in the roslyn workspace (AdHocWorkspace).

    For VB.NET you would add the equivalents of e.g. Microsoft.CodeAnalysis.CSharp.Workspaces, so Microsoft.CodeAnalysis.VisualBasic.Workspaces. This doesn't exist for FSharp.

    It seems like FSharp support would need to co-exist with the roslyn workspace for C#.
    FSharp has a nuget package called FSharp.Compiler.Service, which I believe has traditionally been used for relevant functionality.

    There is also the Microsoft.FSharp.Compiler, available on the roslyn-compiler nuget feed in SharpIDE (source here)

    There also seems to be ongoing work regarding a LanguageServer for FSharp - source, epic

    FSharp.VisualStudio.Extension and FSharp.Compiler.LanguageServer use the FSharpWorkspace, which may be the layer we wish to use, if we wish to avoid the overhead of using the LSP?

    That being said, I think adding LSP support to SharpIDE is going to be inevitable, e.g. for html, javascript syntax highlighting, completions etc. It may be more pragmatic to implement F# support via its LSP, although I have no idea what that entails regarding a solution, project references etc.

  7. knocte commented on Mar 30, 2026

    @knocte
    ContributorAuthor

    Hi Matt thanks for your answer. I already know the ecosystem quite well (e.g. I know Roslyn doesn't have support of F#, that's why we don't use it in FSharpLint, the proj I'm maintainer of, for example; and indeed we use FCS instead). My question was more aimed at the source code of SharpIDE, where is C# syntax highlighting currently living, where would I start looking? Thanks

  8. MattParkerDev commented on Mar 30, 2026

    @MattParkerDev
    Owner

    RoslynAnalysis currently contains all of the Roslyn workspace stuff, including retrieving syntax highlighting.

    public partial class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildService, AnalyzerFileWatcher analyzerFileWatcher)

    public async Task<ImmutableArray<SharpIdeClassifiedSpan>> GetDocumentSyntaxHighlighting(SharpIdeFile fileModel, CancellationToken cancellationToken = default)

    SharpIdeCodeEdit is an editor tab for a file.

    public partial class SharpIdeCodeEdit : CodeEdit

    It has a

    private CustomHighlighter _syntaxHighlighter = new();

    Implemented here:

    public partial class CustomHighlighter : SyntaxHighlighter

    CustomHighlighter is the last step.

    Hopefully that is helpful, happy to answer any further questions here or on discord :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions