C# file-based apps syntax highlighting · Issue #431 · tree-sitter/tree-sitter-c-sharp · GitHub
Skip to content

C# file-based apps syntax highlighting #431

Description

@RikkiGibson

We've recently added file-based apps to C#. Here's a sample:

#!/usr/bin/env dotnet
#:sdk Microsoft.Net.Sdk
#:package Newtonsoft.Json@13.0.3
#:property LangVersion=preview

using Newtonsoft.Json;

Main();

void Main()
{
    if (args is not [_, var jsonPath, ..])
    {
        Console.Error.WriteLine("Usage: app <json-file>");
        return;
    }

    var json = File.ReadAllText(jsonPath);
    var data = JsonConvert.DeserializeObject<Data>(json);
    // ...
}

record Data(string field1, int field2);

The above can be pasted into a .cs file and run with dotnet run app.cs, or on unix systems, the execute bit can be set and dotnet used as the "interpreter" to compile and build it.

See also dotnet-run-file.md.

We'd like to ensure that the tree-sitter grammar is updated to handle the new #! and #: elements nicely, including the sub-parts of specific directives such as #:package Name@Version, #:property Name=Value, etc. See VS Code's highlighting for example:

Image

We merged dotnet/csharp-tmLanguage#337 and dotnet/roslyn#82627 to do this in the TextMate grammar and in Roslyn. Possibly those would be useful as a reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions