dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

Syntax coloring bug #4271

Open songyang-dev opened 3 years ago

songyang-dev commented 3 years ago

Issue Type: Bug

Hello, the syntax color for C# has a small bug in identifying the keyword "this" as a left hand side expression. This bug was found when coding C# scripts for Unity.

Required extensions: Unity snippets and documentation

Reproduction:

  1. Copy paste this code into a Unity project script folder. You need to have Unity generate a .csproj file for VS Code to parse successfully.
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

///

/// Component that connects the COR skinning algorithm to the Unity engine /// [RequireComponent(typeof(Animator))] public class AnimatorCOR : MonoBehaviour {

public SkinnedMeshRenderer[] skinnedMeshRenderers;

public Transform rootBone;
private GameObject skeletonRoot;

// Start is called before the first frame update
void Start()
{
    // build the skeleton
    int boneCount;
    (this.skeletonRoot, boneCount) = BuildSkeleton(rootBone, 0); // <------ this line
    Debug.Log($"The mesh has {boneCount} bones explored by the skeleton builder"); 
}

private (GameObject, int) BuildSkeleton(Transform bone, int index)
{ return (new GameObject(), 0); }

}



Expected behavior:
On the screenshot, the keyword "this" is not colored and is gray. Note that even the syntax coloring on the GitHub isn't identifying "this". Maybe it is supposed to be gray? Yet there are places "this" is blue.

I simplified the code snippet above by replacing `SkeletalRigNode` by `GameObject`. It is a user defined class and `GameObject` should yield the same behavior.

![image](https://user-images.githubusercontent.com/10444460/101307383-4ea77c80-3815-11eb-8adc-f7fb5ba07a24.png)

Extension version: 1.23.6
VS Code version: Code 1.51.1 (e5a624b788d92b8d34d1392e4c4d9789406efe8f, 2020-11-10T23:34:32.027Z)
OS version: Windows_NT x64 10.0.19041

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Celeron(R) CPU  N3060  @ 1.60GHz (2 x 1600)|
|GPU Status|2d_canvas: enabled<br>flash_3d: enabled<br>flash_stage3d: enabled<br>flash_stage3d_baseline: enabled<br>gpu_compositing: enabled<br>multiple_raster_threads: disabled_off<br>oop_rasterization: disabled_off<br>opengl: enabled_on<br>protected_video_decode: unavailable_off<br>rasterization: enabled<br>skia_renderer: disabled_off_ok<br>video_decode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled|
|Load (avg)|undefined|
|Memory (System)|7.85GB (1.61GB free)|
|Process Argv|C:/Users/Song/Documents/UDEM/ift6113/project/skinning_cor/Skinning with COR -g C:\Users\Song\Documents\UDEM\ift6113\project\skinning_cor\Skinning with COR\Assets\Scripts\SkinnedMesh.cs:1:0 --crash-reporter-id 07503e60-69c5-4288-acbc-bf9a6f6262c3|
|Screen Reader|no|
|VM|0%|
</details>
<!-- generated by issue reporter -->
JoeRobich commented 3 years ago

@XsongyangX This is likely an issue with the textmate grammar and tuples. If you enable chsarp.semanticHighlighting.enabled and editor.semanticHighlighting.enabled, do you see the expected results after restarting OmniSharp?

songyang-dev commented 3 years ago

Great! I enabled the csharp setting for semantic highlighting and it worked! I kept the editor one on default. image

songyang-dev commented 3 years ago

I realized that if I only enable one option, my /// comments with </tags> are no longer colored. After enabling both options, I get back to square one. So nothing changed. Comment tags are more important to me than the color of this in some places. 💭 So it'd be nice to have a solution that doesn't remove those colors.

JoeRobich commented 3 years ago

@XsongyangX Can you share screenshots of the highlighting that isn't working the way you expect? If you are using C# semantic colors, we recommend the included Visual Studio 2019 Dark/Light themes.

songyang-dev commented 3 years ago

This is what happens to /// comments, while this keyword gets a correct coloring. image