Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using "Rename symbol" corrupts semantic highlighting with 'random' color patterns #4128

Closed
rjgotten opened this issue Oct 21, 2020 · 9 comments · Fixed by #4133
Closed

Using "Rename symbol" corrupts semantic highlighting with 'random' color patterns #4128

rjgotten opened this issue Oct 21, 2020 · 9 comments · Fixed by #4133

Comments

@rjgotten
Copy link

Issue Description

Using "Rename symbol (F2)" - i.e. refactor renaming - corrupts syntax highlighting with random color patterns

Steps to Reproduce

Rename anything in a .cs file.

Expected Behavior

Syntax highlighting remains intact.

Actual Behavior

Syntax highlighting becomes a randomly corrupted mess.

Logs

OmniSharp log

A long repeating list of the same error, reported after each rename:
[fail]: OmniSharp.Stdio.Host
        ************  Response ************ 
{
  "Request_seq": 69,
  "Command": "/v2/highlight",
  "Running": true,
  "Success": false,
  "Message": "\"System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.\\r\\nParameter name: character\\r\\n   at Microsoft.CodeAnalysis.Text.LinePosition..ctor(Int32 line, Int32 character)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.SemanticHighlight.SemanticHighlightService.d__1.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\SemanticHighlight\\\\SemanticHighlightService.cs:line 36\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.d__19.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.d__16.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 131\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Stdio.Host.d__13.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:line 215\"",
  "Body": null,
  "Seq": 281,
  "Type": "response"
}

C# log

(empty)

Environment information

VSCode version: 1.50.1
C# Extension: 1.23.4

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.403 Commit: 9e895200cd

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.403\

Host (useful for support):
Version: 3.1.9
Commit: 774fc3d6a9

.NET Core SDKs installed:
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.508 [C:\Program Files\dotnet\sdk]
2.1.509 [C:\Program Files\dotnet\sdk]
2.2.107 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
alignment annsk 0.3.0
csharp ms-dotnettools 1.23.4
DocFX ms-docfx 0.1.3
material-icon-theme PKief 4.3.0
vetur octref 0.28.0
vscode-eslint dbaeumer 2.1.13
@rjgotten rjgotten changed the title Using "Rename symbol" corrupts syntax highlighting with random color patterns Using "Rename symbol" corrupts syntax highlighting with 'random' color patterns Oct 21, 2020
@rjgotten
Copy link
Author

rjgotten commented Oct 21, 2020

As a workaround, downgrading to 1.23.2 works.
1.23.3 is also a busted release, so downgrading to that is ill-advised.

@filipw
Copy link
Contributor

filipw commented Oct 21, 2020

could you set omnisharp.logginglevel: "trace" and capture the output? that would show the requests and responses
it's weird that you are running into this, because it's been several months since semantic highlighting has been modified. Perhaps something changed in VS Code with one of the recent releases

@JoeRobich do you know about this?

@filipw filipw changed the title Using "Rename symbol" corrupts syntax highlighting with 'random' color patterns Using "Rename symbol" corrupts semantic highlighting with 'random' color patterns Oct 21, 2020
@filipw
Copy link
Contributor

filipw commented Oct 21, 2020

@rjgotten do you have a project that reproduces it? I am having hard time reproducing it. Also, please point a full log, that could give us some more insights about this problem

@rjgotten
Copy link
Author

do you have a project that reproduces it?

I do, but I am not a liberty to share it. Company code.

please point a full log

The information in the previous log message is all that's there, aside from the standard messages that projects have loaded and are being processed by the analyzer queue.

The log I've posted is repeated each time a rename is done and the syntax highlighter corrupts. What I've posted is what you get from a single instance of the problem occuring:

  1. Open VSCode on a folder containing a .NET Core 3.1 C# project.
  2. Open a .cs file from that project.
  3. Wait for the analyzer to finish initializing and initial 'inteliisense' to be available.
  4. Rename a symbol
  5. Highlight corruption and cited error is logged.

Of other note may be the fact that when this happens the "Problems" panel temporarily notes a number of syntax erorrs that seem to hint at errors being detected midway through the rename operation? These are transient and resolve and disappear after a few seconds, but the corrupted syntax highlighting remains.

@filipw
Copy link
Contributor

filipw commented Oct 21, 2020

I tried to reproduce it and unfortunately I am not able to. Perhaps it is related to the type of syntactic structures you are using or otherwise related to the set up of your project. Would it possible for you to try to isolate a repro on an empty project?

The information in the previous log message is all that's there, aside from the standard messages that projects have loaded and are being processed by the analyzer queue.

could you set omnisharp.logginglevel: "trace" and capture the output?
this logs every request and response, including those to the highlighting service. It is clear from the snippet you posted that it fails, but that would show us what are the input values into the service. I am guessing the line/column somehow ends up being negative values, but that is just my speculation.

thanks

@rjgotten
Copy link
Author

rjgotten commented Oct 21, 2020

If I set loglevel to trace then I don't get aforementioned exception in the logs, but the semantic highlighting is still corrupted.

A snippit I can share of what this corruption looks like:
image

Of note though is the following bit I did spot in the logs:

{
        "LogLevel": "Error",
        "Id": "CS0103",
        "Tags": [],
        "FileName": "<redacted>\\SearchEngine.cs",
        "Line": 108,
        "Column": 34,
        "EndLine": 108,
        "EndColumn": 56,
        "Text": "The name '_peakworkOpndposintUrl' does not exist in the current context",
        "Projects": [
          "<redacted>"
        ]
      }

The identfier in question is supposed to be _peakworkOptions.EndpointUrl.
image

Looks like something is screwing around with text buffers and corrupting them. Concurrent write issue, maybe?
(And as you can see here, the line numbers reported for the errors are somewhat bogus as well; off-by-one.)

...
It's actually not just the syntax highlighting which is broken. Positioning of code-lenses is broken as well:
image

Of further note: as long as I do not touch the file in any further way, these errors do not automatically resolve and disappear again. As soon as I change the file in any further way they do. (But again; the syntax highlighting remains broken.)

I am guessing the line/column somehow ends up being negative values, but that is just my speculation.

Did a quick regex search for the sequence -\d through the massive 200,000+ lines of log output from loading the project that has this error occur reproducibly for me. It doesn't turn up a reference to a negative column or line number. (It doesn't turn up a reference to any kind of negative number at all, actually.)

@JoeRobich
Copy link
Member

@333fred Wonder if this is another case where incremental update is broken.

@333fred
Copy link
Member

333fred commented Oct 21, 2020

This worked for me in testing... :(.

333fred added a commit to 333fred/vscode-csharp that referenced this issue Oct 21, 2020
The code action provider and rename provider were expecting the server to apply the file changes, which then messes up incremental buffer changes. This sends for false for these parameters, and refactors the handling of code action responses to do the renames locally. As part of that, I also refactored the protocol to accurately reflect O#'s hierarchy, and share the edit building between the fixAllProvider and the runCodeAction provider. Fixes dotnet#4128.
@rjgotten
Copy link
Author

rjgotten commented Oct 22, 2020

(And as you can see here, the line numbers reported for the errors are somewhat bogus as well; off-by-one.)

Bloody hell. I just noticed: the highlight corruption is not random. It's shifted by one text line!

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

Successfully merging a pull request may close this issue.

4 participants