Add more C# language features and syntax sugar to highlightning
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Read the linked github/linguist issue 5838 and compare the listed C# features with current grammar behavior. Use the supplied examples, including extension-method resolving, as acceptance cases; done means the requested syntax is highlighted correctly.
Written by the indexing model from the issue text.
Description
See https://github.com/github/linguist/issues/5838
Describe the enhancement
Currently not all syntax features of C# are highlighted.
My suggestion includes the following (if you would find something missing, feel free to add):
Missing features
For the sake of completeness, I have tried to explicitly assign a feature to a language version here. I could not find the associated standard/proposal for each feature but they do exist.
Standard (Draft v6)
C# language standard - ECMA-TC49-TG2
Unsafe blocks (ECMA Draftv6 22.2)
public void Method() {
unsafe {
// Unsafe operations
}
}
Pointers & pointer fixture (ECMA Draftv6 22.7)
public unsafe void Method() {
fixed(int* ptr = &refVar) {
// Some cool pointer operations
}
}
C# 9
Native Integer Primitives (CSharp 9.0 Proposal)
public void Method() {
nint myNativeInteger = -123;
nuint myNativeUnsignedInteger = 123;
}
public void Method(nint param1, nuint param2) {}
Function pointers (CSharp 9.0 Proposal)
public void Method() {
delegate* managed<int, int>;
delegate* unmanaged<int, int>;
delegate* unmanaged[Cdecl] <int, int>;
delegate* unmanaged[Stdcall, SuppressGCTransition] <int, int>;
}
Static anonymous functions (CSharp 9.0 Proposal)
public void X() {
Y(static (i) => i + 1);
Y(static i => i + 1);
}
public void Y(Func<int, int> x) {}
With expressions (CSharp 9.0 Proposal)
public record MyRecord(string Name);
public MyRecord ModifyName(MyRecord rec) {
return rec with { Name = "My new name" };
}
C# 10
Global Using Directives (CSharp 10.0 Proposal)
global using System;
global using System.Linq;
global using System.Runtime.CompilerServices;
Records (CSharp 10.0 Proposal)
public partial record struct Record {}
public partial sealed record Record {}
public record struct Record {}
public sealed record Record {}
Enhanced Pattern Matching (CSharp 9.0 Proposal + CSharp 10.0 Proposal)
void M(object o1, object o2)
{
var t = (o1, o2);
if (t is (int, string)) {}
switch (o1) {
case int: break;
case string: break;
}
}
bool IsLetter(char c) => c is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z');
Null checks
public void Method(object? nullable) {
if(nullable is null) {}
if(nullable is not null) {}
}
Defaults
public void X() {
int x = default;
}
implicit new
public void Method() {
MyKnownType value = new();
}
Wrong implemented features
Extension method resolving
namespace N1
{
public static class D
{
public static void F(this int i) => Console.WriteLine($"D.F({i})");
}
}
namespace N2
{
using N1;
class Test
{
static void Main(string[] args)
{
1.F();
// ^^ Why is this red?
}
}
}
- Dominant language
- TypeScript
- Stars
- 78
- Forks
- 43
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/csharp-tmLanguage
-
C# syntax highlighting broken with collection expressions and string interpolation in method callsOpen
Difficulty 3/5 1-2 days Newbie friendliness 35/100
dotnet/csharp-tmLanguage#332 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
dotnet/csharp-tmLanguage#336 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
dotnet/csharp-tmLanguage#306 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
dotnet/csharp-tmLanguage#304 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
dotnet/csharp-tmLanguage#303 ·
All issues in dotnet/csharp-tmLanguage
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
opengovsg/FormSG#10118 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-driven-qa bug claude
Difficulty 1/5 Under an hour Newbie friendliness 75/100
linagora/twake-calendar-frontend#1434 · 1 comment ·
Maintainers usually reply within 1 day
-
check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
iptv-org/iptv#52824 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 78/100
jaegertracing/jaeger-ui#4512 ·
Maintainers usually reply within 1 day
-
area:ide documentation enhancement platform:macos platform:vscode
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
anthropics/claude-code#97389 ·
Maintainers usually reply within 1 day