dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 653 forks source link

Request textDocument/foo failed #7187

Open lonix1 opened 1 month ago

lonix1 commented 1 month ago

Environment data

dotnet --info output: 7.0.409 VS Code version: 1.89.1 C# Extension version: 2.31.19

OmniSharp log

n/a

Steps to reproduce

Open Razor Pages cshtml file

Expected behavior

No popups.

Actual behavior

Endless series of popups on the bottom right:

Request textDocument/semanticTokens/range failed.

Additional context

Problem started after upgrading to vscode-csharp2.31.19 released today.

The "C#" log window has this:

[Error - 4:03:11 PM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=133, Character=7 }, End={ Line=932, Character=7 } }. text.Length=51894. text.Lines.Count=823
 ---> System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 823. (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 330
   --- 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 335
   at Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintHandler.HandleRequestAsync(InlayHintParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
Error making textDocument/inlayHint request: Range={ Start={ Line=133, Character=7 }, End={ Line=932, Character=7 } }. text.Length=51894. text.Lines.Count=823
[Error - 4:03:11 PM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 823. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 103
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 67
   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 46
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 44
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
[Error - 4:03:11 PM] Request textDocument/semanticTokens/range failed.
  Message: The requested line number 932 must be less than the number of lines 823. (Parameter 'Line')
  Code: -32000
[object Object]

Even after the popup shows, another then another and another (...) is shown, simply by scrolling in the document.

lonix1 commented 1 month ago

I restarted a few times, and the problem eventually stopped. Weird.

lonix1 commented 1 month ago

It's back. I can get three popups one on top of the other:

Request textDocument/definition failed.

Request textDocument/documentHighlight failed.

Request textDocument/hover failed.

The errors are all different, but it's obviously the same root problem. Only started in latest version.

[Error - 7:13:41 AM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892
 ---> System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (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 330
   --- 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 335
   at Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintHandler.HandleRequestAsync(InlayHintParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
Error making textDocument/inlayHint request: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892

[Error - 7:13:41 AM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 103
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 67
   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 46
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 44
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)

[Error - 7:13:41 AM] Request textDocument/semanticTokens/range failed.
  Message: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
  Code: -32000
[object Object]

[Error - 7:13:42 AM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892
 ---> System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (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 330
   --- 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 335
   at Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintHandler.HandleRequestAsync(InlayHintParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
Error making textDocument/inlayHint request: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892
[Error - 7:13:42 AM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 103
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 67
   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 46
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 44
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
[Error - 7:13:42 AM] Request textDocument/semanticTokens/range failed.
  Message: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
  Code: -32000
[object Object]
[Error - 7:13:42 AM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892
 ---> System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (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 330
   --- 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 335
   at Microsoft.CodeAnalysis.LanguageServer.Handler.InlayHint.InlayHintHandler.HandleRequestAsync(InlayHintParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/InlayHint/InlayHintHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
Error making textDocument/inlayHint request: Range={ Start={ Line=150, Character=261 }, End={ Line=932, Character=7 } }. text.Length=54132. text.Lines.Count=892
[Error - 7:13:42 AM] [LanguageServerHost] System.ArgumentOutOfRangeException: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 103
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(Document document, ImmutableArray`1 spans, Boolean supportsVisualStudioExtensions, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 67
   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 46
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 44
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
[Error - 7:13:42 AM] Request textDocument/semanticTokens/range failed.
  Message: The requested line number 932 must be less than the number of lines 892. (Parameter 'Line')
  Code: -32000
[object Object]
mairaw commented 1 month ago

I get the same error when working on the project for the dot.net website. I can open the project normally and I usually get this error once I start working in one of the .cshtml pages.

VS Code team, you can get the source at https://github.com/dotnet/website.

timheuer commented 1 month ago

@phil-allen-msft

Raevenn commented 4 weeks ago

Same problem here, reverting to version 2.30.28 seems to be a temporary solution until a new update fixes the issue. Extensions > c# > right-click on extension > "Install Another Version" > select "2.30.28" from dropdown.

The original error seems to appear more when also using C# Dev Kit extension, though this is not yet confirmed.

lonix1 commented 4 weeks ago

I get the errors even without the C# DevKit extension.

skyshaver commented 4 weeks ago

I found at least a temporary solution, manually cleaning everything out of of build/obj and rebuilding. It seems the c# ext relies on a bunch of files in there and things like changing file names cause it all sorts of confusion. I still have to restart the language server every once in a while but I managed to get some work done yesterday. On Friday it was basically unusable

phil-allen-msft commented 4 weeks ago

We're sorry you are running into this. We are working on this class of issue, but in the meantime another user reported this as a potential way to get behavior more like what you may expect: https://github.com/microsoft/vscode-dotnettools/issues/722#issuecomment-2126269970

skyshaver commented 2 weeks ago

My temporary solution no longer works, this morning my vs code environment is again very broken. Walls of red/yellow squiggles on working code that weren't there yesterday. After a bit I start getting the pop-ups from the language server again. It makes it very difficult to work

lonix1 commented 2 weeks ago

@skyshaver You can downgrade to the previous version or you can use the workaround:

"dotnet.server.suppressLspErrorToasts": true