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

[BUG] Error message "Request textDocument/semanticTokens/range failed" #722

Closed
Kalkihe opened this issue Nov 15, 2023 · 84 comments
Closed
Assignees
Labels
area-razor bug Something isn't working
Milestone

Comments

@Kalkihe
Copy link

Kalkihe commented Nov 15, 2023

Describe the Issue

This happens on a regular basis, mostly after using the comparison view from git on a C# file. The message "Request textDocument/semanticTokens/range failed" pops up in visual studio code. I can close it, but when scrolling through any C# file, it will just pop up again multiple times. This kind of makes vscode unusable until I restart it. Here are some logs:

Click to show logs `Using dotnet configured on PATH Dotnet path: C:\Program Files\dotnet\dotnet.exe Activating C# + C# Dev Kit + C# IntelliCode... waiting for named pipe information from server... [stdout] {"pipeName":"\\\\.\\pipe\\df844993"} received named pipe information from server attempting to connect client to server... client has connected to server [Info - 2:32:53 PM] [Program] Language server initialized [Info - 2:32:55 PM] [WorkspaceProjectFactoryService] Project D:\Coding\TOOMLE\TOOMLE.csproj loaded by C# Dev Kit [Error - 3:51:34 PM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=526, Character=1 }, End={ Line=692, Character=0 } }. text.Length=18. text.Lines.Count=3 ---> System.ArgumentOutOfRangeException: The requested line number 526 must be less than the number of lines 3. (Parameter 'Line') at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67 at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78 at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 298 --- End of inner exception stack trace --- at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 298 at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 103 at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 63 at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 47 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176 [Error - 3:51:34 PM] Request textDocument/semanticTokens/range failed. Message: Range={ Start={ Line=526, Character=1 }, End={ Line=692, Character=0 } }. text.Length=18. text.Lines.Count=3 Code: -32000 [object Object] [Error - 3:51:40 PM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 663 must be less than the number of lines 4. (Parameter 'Line') at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67 at Microsoft.CodeAnalysis.LanguageServer.Extensions.GetPositionFromLinePositionAsync(TextDocument document, LinePosition linePosition, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/Extensions.cs:line 158 at Microsoft.CodeAnalysis.LanguageServer.Handler.CompletionHandler.HandleRequestAsync(CompletionParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs:line 78 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176 [Error - 3:51:40 PM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 663 must be less than the number of lines 4. (Parameter 'Line') at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67 at Microsoft.CodeAnalysis.LanguageServer.Extensions.GetPositionFromLinePositionAsync(TextDocument document, LinePosition linePosition, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/Extensions.cs:line 158 at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentHighlightsHandler.HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Highlights/DocumentHighlightHandler.cs:line 68 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176 [Error - 3:51:40 PM] Request textDocument/documentHighlight failed. Message: The requested line number 663 must be less than the number of lines 4. (Parameter 'Line') Code: -32000 [object Object] `

I had to shorten the log because it was too long. There are a lots of errors like this within seconds. I have to add that the files I have in my project are not longer than 200 lines. It seems like that line number is set in a completely wrong way.

Steps To Reproduce

No response

Expected Behavior

Not showing that error message

Environment Information

OS: Windows 10
Visual studio code 1.84.2 system setup
C# Dev Kit v1.0.14

@Kalkihe Kalkihe added the bug Something isn't working label Nov 15, 2023
@dibarbet
Copy link
Member

@Kalkihe does this failure happen in only a specific file (what file extension does it have - .cs, .razor, etc)?

If it only happens in a specific file, are you able to share the file contents (feel free to email me if you don't want to share here, my microsoft email is listed on my github profile).

@dibarbet dibarbet added the needs-more-info Needing more information, waiting on OP label Nov 28, 2023
@dibarbet dibarbet added this to the Dec2023 milestone Nov 28, 2023
@dibarbet dibarbet self-assigned this Nov 28, 2023
@Kalkihe
Copy link
Author

Kalkihe commented Dec 5, 2023

It happens on any .razor or .cs file is opened. I recently noticed that it happened when I was in comparison view of git and then checked out a different branch. Unfortunately I'm not able to share any file. But this should not be necessary, as it happened on multiple files.

@dibarbet
Copy link
Member

I've been unable to reproduce this myself. There is a known issue with similar symptoms in .razor files, but if you're seeing it in .cs files then its something else.

Your stack trace looks very similar to the known .razor issue - especially because you mention you don't have any files longer than 200 lines (the error is inside the generated c# for the .razor file which can be very long).

When you encounter it, can you provide details on the type of file, what steps you were doing immediately before the action (e.g. if it was a diff window, how exactly you got there, etc).

@dibarbet dibarbet removed this from the Dec2023 milestone Jan 19, 2024
@artem-iron
Copy link

Experiencing the same issue with .razor files, precisely after using a diff view. Output looks like this:

Using dotnet configured on PATH
Dotnet path: /usr/local/share/dotnet/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"/var/folders/bg/qx65kv1x5bxg3wb31cgnwdfm0000gn/T/1bbfc686.sock"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 10:55:02] [Program] Language server initialized
[Info  - 10:55:05] [WorkspaceProjectFactoryService] Project /Users/artem/iron/repos/**/***.csproj loaded by C# Dev Kit
[Error - 11:00:47] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=82, Character=0 }, End={ Line=233, Character=0 } }. text.Length=5. text.Lines.Count=2
 ---> System.ArgumentOutOfRangeException: The requested line number 82 must be less than the number of lines 2. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 289
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 294
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 88
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 51
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 11:00:47] Request textDocument/semanticTokens/range failed.
  Message: Range={ Start={ Line=82, Character=0 }, End={ Line=233, Character=0 } }. text.Length=5. text.Lines.Count=2
  Code: -32000 
[object Object]
[Error - 11:00:50] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=82, Character=0 }, End={ Line=233, Character=0 } }. text.Length=5. text.Lines.Count=2
 ---> System.ArgumentOutOfRangeException: The requested line number 82 must be less than the number of lines 2. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 289
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 294
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 88
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 51
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 11:00:50] Request textDocument/semanticTokens/range failed.
  Message: Range={ Start={ Line=82, Character=0 }, End={ Line=233, Character=0 } }. text.Length=5. text.Lines.Count=2
  Code: -32000 
[object Object]
[Error - 11:00:53] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=82, Character=0 }, End={ Line=233, Character=0 } }. text.Length=677. text.Lines.Count=9
 ---> System.ArgumentOutOfRangeException: The requested line number 82 must be less than the number of lines 9. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 289
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 294
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 88
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 51
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)

@Einarsson
Copy link

Einarsson commented Feb 1, 2024

Same issue with .cshtml file.

 ---> System.ArgumentOutOfRangeException: The requested line number 275 must be less than the number of lines 83. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 104
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 64
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 47
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 189
[Error - 12:19:45] Request textDocument/semanticTokens/range failed.
  Message: Range={ Start={ Line=50, Character=0 }, End={ Line=275, Character=21 } }. text.Length=5053. text.Lines.Count=83
  Code: -32000 
[object Object]

@Kalkihe
Copy link
Author

Kalkihe commented Feb 19, 2024

I've been unable to reproduce this myself. There is a known issue with similar symptoms in .razor files, but if you're seeing it in .cs files then its something else.

Your stack trace looks very similar to the known .razor issue - especially because you mention you don't have any files longer than 200 lines (the error is inside the generated c# for the .razor file which can be very long).

When you encounter it, can you provide details on the type of file, what steps you were doing immediately before the action (e.g. if it was a diff window, how exactly you got there, etc).

It is obviously hard to remember all the steps that happened before I got to that error when it hits again. But I'll try this time because it just happened again.

So I was working on some files (cs, .razor, json). After finishing my work on those files, I switched to the Source Control view to view the changes made on those files. I single-clicked every one of them and took a short view. This includes my index.razor file, which now is 297 lines long. Then I commited my work, but didn't push it. Then I closed the remaining comparison window and continued working. For this, I created a new .cs file and put some code in it. Then I switched back to my index.razor file and started editing the html code, when the error happened again. Now, on each action or scrolling within this file, the same error message appears over and over again.

Logs of this incident are in the attachement.

errors .net.txt

EDIT: Just had it again. Looked again (with single click) on the changes view on the .razor file, then switched back to the editing tab of that very file and the error occurred again.

@boreys
Copy link

boreys commented Feb 23, 2024

I have this error when editing .razor file, it's annoying and I cannot suppress this pop up in VS Code.

@SonnyRR
Copy link

SonnyRR commented Feb 25, 2024

This behavior is present whenever I edit anything in a razor template, used for a blazor wasm component.

Version: 1.86.2 (user setup)
Commit: 903b1e9d8990623e3d7da1df3d33db3e42d80eda
Date: 2024-02-13T19:40:56.878Z
Electron: 27.2.3
ElectronBuildId: 26908389
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Windows_NT x64 10.0.19045

C# Dev Kit version: v1.3.10
C# Extension version: v2.18.16

[Error - 3:06:14 PM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=144, Character=0 }, End={ Line=504, Character=25 } }. text.Length=3589. text.Lines.Count=43
 ---> System.ArgumentOutOfRangeException: The requested line number 144 must be less than the number of lines 43. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 104
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 64
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 47
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 189
[Error - 3:06:14 PM] Request textDocument/semanticTokens/range failed.

@schaveyt
Copy link

This issue seems to be specific to something. In older blazor projects, I don't have an issue. But in blazor file use v8.0, I get this error constantly. It is definitely some syntax that is throwing it for a loop.

@dvptr
Copy link

dvptr commented Feb 27, 2024

I also get this, editing a .razor page containing MudBlazor items in a Blazor Server app.

Version: 1.86.2 (Universal)
Commit: 903b1e9d8990623e3d7da1df3d33db3e42d80eda
Date: 2024-02-13T19:42:13.651Z (1 wk ago)
Electron: 27.2.3
ElectronBuildId: 26908389
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.3.0

C# plugin is v2.19.13 (pre-release)

Exception:

[Error - 11:17:37] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=96, Character=37 }, End={ Line=501, Character=18 } }. text.Length=3307. text.Lines.Count=118
 ---> System.ArgumentOutOfRangeException: The requested line number 501 must be less than the number of lines 118. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 300
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 104
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 64
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 47
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 189
[Error - 11:17:37] Request textDocument/semanticTokens/range failed.
  Message: Range={ Start={ Line=96, Character=37 }, End={ Line=501, Character=18 } }. text.Length=3307. text.Lines.Count=118
  Code: -32000 

Left lower pop-ups text:

  • Request textDocument/sematicTokens/range failed
  • Request textDocument/documentHighlight failed
  • Request textDocument/hover failed.

@artem-iron
Copy link

MacOS 14.3.1
VSCode 1.86.2
C# DevKit 1.1.16

Persists still, to replicate: have Blazor project, have a .razor file in it, all of it in a git repository, tracked. Open the project through devkit in vs code, make changes to the .razor file, save the file, open the diff view of it in VSCode, close the diff view, open in normal view, try to do any changes - the error pops up. Works every time.

@schaveyt
Copy link

@artem-iron Did you have multiple .razor files open at once. A mix of .cs and razor. I have both situation and always get it as well. If you don't open the diff view, does is still happen?

Side note, I start a component hierarchy the other day which forced me to put put a lot of my c# code that would have been in the .razor file into the code-behind and it dawned on my that I wasn't experience the issue as much. I have have no idea if the two things are related but 🤷 .

@SonnyRR
Copy link

SonnyRR commented Feb 28, 2024

@schaveyt I always use code behind documents, but I still experience this issue whenever I do anything in the razor template. Doesn't matter if I have the template document opened in the diff view or just in the regular edit one.

@artem-iron
Copy link

@schaveyt for me it only happens when a diff view was opened at some point. So now i avoid opening that until i am ready to deal with reloading the vscode after.

@arunchndr arunchndr added area-razor and removed area-roslyn needs-more-info Needing more information, waiting on OP labels Mar 18, 2024
@artemkoloskov
Copy link

Oh god it's hard to believe the nightmare might finally be over.

Thank you everyone ♥️

@douglas-wiliam
Copy link

OHHHHH GOSH FINALLY

@douglas-wiliam
Copy link

@ryzngard it doesn't solve yet :(

image

Follow the code stack bellow

Failed to synchronize document '/file.cshtml__virtual.cs': "System.UnauthorizedAccessException: Access to the path '/root' is denied.\n ---> System.IO.IOException: Permission denied\n   --- End of inner exception stack trace ---\n   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)\n   at System.IO.Enumeration.FileSystemEnumerator`1.DequeueNextDirectory()\n   at System.IO.Enumeration.FileSystemEnumerator`1.DirectoryFinished()\n   at System.IO.Enumeration.FileSystemEnumerator`1.FindNextEntry(Byte* entryBufferPtr, Int32 bufferLength)\n   at System.IO.Enumeration.FileSystemEnumerator`1.MoveNext()\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\n   at System.IO.DirectoryInfo.GetFiles(String searchPattern, EnumerationOptions enumerationOptions)\n   at OmniSharp.Roslyn.EditorConfig.EditorConfigFinder.GetEditorConfigPaths(String path) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/EditorConfig/EditorConfigFinder.cs:line 28\n   at OmniSharp.OmniSharpWorkspace.TryAddMiscellaneousDocument(String filePath, TextLoader loader, String language) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs:line 155\n   at OmniSharp.OmniSharpWorkspace.TryAddMiscellaneousDocument(String filePath, String language) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/OmniSharpWorkspace.cs:line 169\n   at OmniSharp.Roslyn.BufferManager.TryAddTransientDocument(String fileName, String fileContent) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/BufferManager.cs:line 179\n   at OmniSharp.Roslyn.BufferManager.UpdateBufferAsync(Request request, Boolean isCreate) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/BufferManager.cs:line 129\n   at OmniSharp.Roslyn.CSharp.Services.Buffer.UpdateBufferService.Handle(UpdateBufferRequest request) in /home/vsts/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Buffer/UpdateBufferService.cs:line 22\n   at OmniSharp.Endpoint.EndpointHandler`2.GetFirstNotEmptyResponseFromHandlers(ExportHandler`2[] handlers, TRequest request) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 200\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 229\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /home/vsts/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 130\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /home/vsts/work/1/s/src/OmniSharp.Stdio/Host.cs:line 218"

@ryzngard
Copy link
Member

@douglas-wiliam thanks for testing. I'll keep looking.

@ryzngard
Copy link
Member

@douglas-wiliam can you file a separate issue? It looks like you're using a configuration that's different. Specifically omnisharp is enabled where the original issue was reported without. I still believe this issue is resolved and you're hitting a different one with a similar error message.

@douglas-wiliam
Copy link

douglas-wiliam commented Jul 19, 2024

@ryzngard in fact I was with the option "dotnet.server.useOmnisharp": true. But now, even with the the option setted to false, the error persists.

Follow the code stack bellow:

Info  - 10:17:36 PM] [CLaSP] [StartContext] textDocument/semanticTokens/range
[Error - 10:17:36 PM] [CLaSP] [null]: 
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (143,82) matches or exceeds SourceText boundary 1028.')
   at Microsoft.CodeAnalysis.Razor.Workspaces.SourceTextExtensions.<GetTextSpan>g__GetAbsoluteIndex|11_0(Int32 line, Int32 character, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs:line 287
   at Microsoft.CodeAnalysis.Razor.Workspaces.SourceTextExtensions.GetTextSpan(SourceText sourceText, Int32 startLine, Int32 startCharacter, Int32 endLine, Int32 endCharacter) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs:line 273
   at Microsoft.CodeAnalysis.Razor.Workspaces.LinePositionSpanExtensions.ToTextSpan(LinePositionSpan linePositionSpan, SourceText sourceText) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionSpanExtensions.cs:line 18
   at Microsoft.CodeAnalysis.Razor.SemanticTokens.AbstractRazorSemanticTokensInfoService.GetSemanticTokensAsync(VersionedDocumentContext documentContext, LinePositionSpan span, Guid correlationId, Boolean colorBackground, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs:line 69
   at Microsoft.CodeAnalysis.Razor.SemanticTokens.AbstractRazorSemanticTokensInfoService.GetSemanticTokensAsync(VersionedDocumentContext documentContext, LinePositionSpan span, Boolean colorBackground, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs:line 45
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.SemanticTokensRangeEndpoint.HandleRequestAsync(SemanticTokensRangeParams request, RazorRequestContext requestContext, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/SemanticTokensRangeEndpoint.cs:line 54
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
[Error - 10:17:36 PM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (143,82) matches or exceeds SourceText boundary 1028.')
  Code: -32004 
[object Object]
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:36 PM] [LSP][LanguageServer.Semantic.RazorSemanticTokensInfoService] Returned 291 semantic tokens for span (48,0)-(127,0) in review:/some-path-to-file/Detalhes.cshtml?{"path"%3A"Views%2FFile%2FPath%2FDetalhes.cshtml"%2C"commit"%3A"cd28ced196721687e9b0cde861afc67eba13b224"%2C"base"%3Atrue%2C"isOutdated"%3Afalse%2C"rootPath"%3A"%2Fhome%my-personal-directory%2FProjects%2Fsome-project"}.
[Info  - 10:17:36 PM] [LSP][LanguageServer.Semantic.RazorSemanticTokensInfoService] Returned 298 semantic tokens for span (50,0)-(129,0) in file:///some-path-to-file/Detalhes.cshtml.
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:36 PM] [LSP][LanguageServer.Semantic.RazorSemanticTokensInfoService] Returned 298 semantic tokens for span (50,0)-(129,0) in file:///some-path-to-file/Detalhes.cshtml.
[Info  - 10:17:36 PM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 10:17:37 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:37 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:37 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:37 PM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 10:17:37 PM] [LSP][LanguageServer.Semantic.RazorSemanticTokensInfoService] Returned 382 semantic tokens for span (61,0)-(141,90) in review:/some-path-to-file/Detalhes.cshtml?{"path"%3A"Views%2FFile%2FPath%2FDetalhes.cshtml"%2C"commit"%3A"cd28ced196721687e9b0cde861afc67eba13b224"%2C"base"%3Atrue%2C"isOutdated"%3Afalse%2C"rootPath"%3A"%2Fhome%my-personal-directory%2FProjects%2Fsome-project"}.
[Info  - 10:17:37 PM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 10:17:38 PM] [CLaSP] [EndContext] textDocument/inlayHint

image

image

image

@ryzngard
Copy link
Member

@douglas-wiliam I appreciate the extra info and apologize for the slight delay in response (I was on vacation 🏖️ )

Catching back up to this. Do you have a repro project I can use? I wasn't able to reproduce with the test projects I have.

@ryzngard ryzngard modified the milestones: July2024, Aug2024 Aug 12, 2024
@oakad
Copy link

oakad commented Aug 21, 2024

I am having the same problem on C# v2.39.29/VSCode 1.92.2/MacOS. Seems to affect all razor files and won't go away, making the extension less than usable. It used to happen before but couple of reloads would fix it. Now it appears to persist and is always broken.

Curiously enough, the language server appears to always think that there should be 512 lines in any file; I think this should point at the possible culprit. Clearly, not all files have 512 lines. :-D

Example errors:

Request textDocument/semanticTokens/range failed.
Message: The requested line number 1131 must be less than the number of lines 512. (Parameter 'Line')
Code: -32000

System.ArgumentException: Range={ Start={ Line=801, Character=21 }, End={ Line=801, Character=21 } }. text.Length=14693. text.Lines.Count=512

System.ArgumentException: Range={ Start={ Line=72, Character=0 }, End={ Line=1415, Character=22 } }. text.Length=14670. text.Lines.Count=512

System.ArgumentOutOfRangeException: The requested line number 1131 must be less than the number of lines 512. (Parameter 'Line')

And so on.

Full stack trace reported for one of such errors:

System.ArgumentOutOfRangeException: The requested line number 1415 must be less than the number of lines 512. (Parameter 'Line')
at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in //src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /
/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 330
--- End of inner exception stack trace ---
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in //src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 335
at Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintHandler.HandleRequestAsync(InlayHintParams request, RequestContext context, CancellationToken cancellationToken) in /
/src/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs:line 45
at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken)

@oakad
Copy link

oakad commented Aug 21, 2024

Reading through the thread makes it pretty clear, that the line count value for each file gets "aliased" somehow and language server starts thinking that all files should have the same line count from that point on. Moreover, we see that different people get different "wrong line counts" in their session which strongly smells of improperly initialised variable; the wrong value then persists for the duration of the session.

To test the hypothesis I have restarted my VSCode and the value had indeed changed. Now it's 155 instead of 512:

Error making textDocument/inlayHint request: Range={ Start={ Line=72, Character=0 }, End={ Line=245, Character=1 } }. text.Length=5025. text.Lines.Count=155

@oakad
Copy link

oakad commented Aug 21, 2024

And more interesting behaviour:

  1. Close all active editors.
  2. Invoke "Clear editor history" action
  3. Restart VSCode
  4. Issue is temporarily gone
  5. Edit - edit - edit - autocomplete - edit (some minutes)
  6. Issue is back!

@burtonrodman
Copy link

ugh 🙄 so now I have to choose between unit tests not being discovered in the Preview version, or constant error spam in the Release version

@arunchndr
Copy link
Member

ugh 🙄 so now I have to choose between unit tests not being discovered in the Preview version, or constant error spam in the Release version

@AbhitejJohn fyi on the UT discovery comment. If known, lets try to hotfix the preview.

@Ariel798
Copy link

Same issue here, after looking at a git diff file, C# just lost it and keeps displaying this super annoying pop up, the formatter as well seem to stop working, ataching the error in the terminal:
image

Only way to solve it is by restarting VSC, which is not ideal at least

@EightArmCode
Copy link

Message: Request textDocument/diagnostic failed with message: Cannot read properties of undefined (reading 'configs')
Code: -32603

Yep, I am seeing this a lot trying to stumble through the migration to FlatConfig. My experience, which as of late feels extensive, is that it usually indicates something wrong with config. It's a generally unhelpful error. Unsolvable without more information, and frequently used when there is no other obvious error to report. Wish I had better news!

@dibarbet
Copy link
Member

dibarbet commented Aug 22, 2024

Same issue here, after looking at a git diff file, C# just lost it and keeps displaying this super annoying pop up, the formatter as well seem to stop working, ataching the error in the terminal:

There is an issue in the release version with codelens in the diff editor causing the server to crash. Should be fixed in the latest prerelease version of the C# extension, or can workaround the issue by disabling diffEditor.codeLens in vscode settings.

See dotnet/vscode-csharp#5843

@liesahead
Copy link

Still relevant..

@kellyrmartin
Copy link

kellyrmartin commented Sep 17, 2024 via email

@oakad
Copy link

oakad commented Sep 18, 2024

Right now, razor support is totally broken. Moreover, it is broken consistently, on all platforms and installations both old and new. :-)

@rjhind
Copy link

rjhind commented Sep 20, 2024

I'm having the same issue running on macOS with VSCode and C# extension 2.45.25. Constant error popups from the C# extension while editing razor files. I see both

razor/provideSemanticTokensRange failed with TypeError: Cannot read properties of undefined (reading 'data')

and

razor/inlayHint failed with Error: Range={ Start={ Line=62, Character=0 }, End={ Line=372, Character=0 } }. text.Length=13537. text.Lines.Count=359

@phil-allen-msft phil-allen-msft modified the milestones: Aug2024, Oct2024 Sep 24, 2024
@afallingstone
Copy link

How is this not a part of the September / October Iteration plan? This has been going on since before the beginning of the year. 10-20 times a day i have to restart VS Code because of this. Unreal that this is still a problem.

@ryzngard
Copy link
Member

How is this not a part of the September / October Iteration plan? This has been going on since before the beginning of the year. 10-20 times a day i have to restart VS Code because of this. Unreal that this is still a problem.

I'm sorry you're still hitting this issue. There are many root causes to this problem. Some have been fixed, some are currently being worked on. This is high on my list for October to find a better user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-razor bug Something isn't working
Projects
None yet
Development

No branches or pull requests