consulo / consulo-csharp

Languages: C#
Apache License 2.0
50 stars 6 forks source link

Local ref's & readonly ref (in) support (C# 7 & 8) #587

Open airzocker opened 2 years ago

airzocker commented 2 years ago

Hi, since I started a project with DOTS, I've been getting wrong syntax error highlighting in Entities.ForEach() lambda calls.

Code example:

Entities
.WithoutBurst()
.ForEach(
  (in DynamicBuffer<EntityPrefabElement> prefabBuffer) =>
  {
    for (int i = 0; i < PrefabIDs.PREFAB_COUNT; i++)
    {
      prefabs[i] = prefabBuffer[i];
    }
    prefabsReady = true;
  }
).Run();

Consulo marks the "in" keyword as red, with the errors "Identifier expected" and "Expected comma".

Maybe it's just some .NET framework version not matching or something, but I can't figure it out.

EDIT: Also I had some syntax error highlighting issues with a using var x = y; + following code using x, and generally when working with refs.

VISTALL commented 2 years ago

Hello. this constructions is not supported in C# plugin.

airzocker commented 2 years ago

Hello. this constructions is not supported in C# plugin.

Oh ok, so is it because the C# plugin is not updated for the newer C#/.Net Framework version or because Unity did something special? I don't know much about this kind of construct other than it's a lambda function.

VISTALL commented 2 years ago

yeap. I'm not implemented this features yet

airzocker commented 2 years ago

I just remembered that it could be something special from Unity, because as far as I remember, the Entities.ForEach() gets some code gen before compile time, so it might not even be completely valid C# code in the correct Framework...

VISTALL commented 2 years ago

using var

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/using

It's C# 8.0 feature (almost all C# 8 features not implemented yet)

airzocker commented 2 years ago

Ok thanks, and for the ref part, I'm not sure if it's also a C# 8.0 feature, but here is an example that works in Unity perfectly fine.

image

And if I try to access the itemDataArray by index later:

image

VISTALL commented 2 years ago

Looks like the same. Ref locals C# (C# 7 missed)

Since it's var, type inference is broken and this[] not resolved.

I will review this issues, but need time, I'm very busy with new branch.

Thanks for reporting

VISTALL commented 2 years ago

About in