dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
498 stars 191 forks source link

[VS Code] Diff view fails with "Request textDocument/inlayHint failed." #10437

Open aaronpowell opened 4 months ago

aaronpowell commented 4 months ago

Going through the process of reviewing this PR and when I open a razor file, such as EventList.razor, I get an error notification in VS Code Request textDocument/inlayHint failed..

Opening the Razor log I see this:

[Info  - 2:43:49 AM] [CLaSP] Using default language handler for textDocument/inlayHint: 
[Info  - 2:43:49 AM] [CLaSP] [StartContext] textDocument/inlayHint
[Error - 2:43:49 AM] [CLaSP] [null]: 
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (55,97) matches or exceeds SourceText boundary 50.')
   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.RazorCodeDocumentExtensions.TryGetMinimalCSharpRange(RazorCodeDocument codeDocument, LinePositionSpan razorRange, LinePositionSpan& csharpRange) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs:line 97
   at Microsoft.AspNetCore.Razor.LanguageServer.InlayHints.InlayHintService.GetInlayHintsAsync(IClientConnection clientConnection, VersionedDocumentContext documentContext, Range range, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlayHints/InlayHintService.cs:line 35
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, IMethodHandler handler, CancellationToken cancellationToken)
[Error - 2:43:49 AM] Request textDocument/inlayHint failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (55,97) matches or exceeds SourceText boundary 50.')
  Code: -32004 
[object Object]
[Info  - 2:43:49 AM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 2:43:49 AM] [CLaSP] Using default language handler for textDocument/inlayHint: 
[Info  - 2:43:49 AM] [CLaSP] [StartContext] textDocument/inlayHint
[Client - 2:43:50 AM] (Warning) razor/inlayHint failed with Error: Range={ Start={ Line=93, Character=37 }, End={ Line=749, Character=18 } }. text.Length=7819. text.Lines.Count=197
[Info  - 2:43:50 AM] [CLaSP] [EndContext] textDocument/inlayHint
[Info  - 2:43:50 AM] [CLaSP] Using default language handler for textDocument/semanticTokens/range: 
[Info  - 2:43:50 AM] [CLaSP] [StartContext] textDocument/semanticTokens/range
[Error - 2:43:50 AM] [CLaSP] [null]: 
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (25,97) matches or exceeds SourceText boundary 50.')
   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 71
   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 - 2:43:50 AM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (25,97) matches or exceeds SourceText boundary 50.')
  Code: -32004 
[object Object]
[Info  - 2:43:50 AM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 2:43:50 AM] [CLaSP] Using default language handler for textDocument/semanticTokens/range: 
[Info  - 2:43:50 AM] [CLaSP] [StartContext] textDocument/semanticTokens/range
[Warn  - 2:43:50 AM] [LSP][LanguageServer.Semantic.LSPCSharpSemanticTokensProvider] Didn't get C# tokens because the virtual document wasn't found, or other problem. We were wanting 1 but C# could not get any version.
[Info  - 2:43:50 AM] [LSP][LanguageServer.Semantic.RazorSemanticTokensInfoService] Returned no semantic tokens for span (0,0)-(25,72) in review:/workspaces/azure-openai-service-proxy/src/AzureOpenAIProxy.Management/Components/Pages/EventList.razor?{"path"%3A"src%2FAzureOpenAIProxy.Management%2FComponents%2FPages%2FEventList.razor"%2C"commit"%3A"ede091de7317424f844c3563d786c9aae50738f4"%2C"base"%3Atrue%2C"isOutdated"%3Afalse%2C"rootPath"%3A"%2Fworkspaces%2Fazure-openai-service-proxy"}.
[Info  - 2:43:50 AM] [CLaSP] [EndContext] textDocument/semanticTokens/range
[Info  - 2:46:22 AM] [LSP][LanguageServer.ProjectConfigurationStateSynchronizer] Configuration file removed for project 'ProjectKey { IsUnknown = False, Id = /workspaces/azure-openai-service-proxy/src/AzureOpenAIProxy.Management/obj/Debug/net8.0/ }'.
[Info  - 2:46:22 AM] [LSP][LanguageServer.ProjectConfigurationStateSynchronizer] Configuration file added for project '/workspaces/azure-openai-service-proxy/src/AzureOpenAIProxy.Management/obj/Debug/net8.0/'.
[Info  - 2:46:23 AM] [LSP][LanguageServer.ProjectConfigurationStateSynchronizer] Updating /workspaces/azure-openai-service-proxy/src/AzureOpenAIProxy.Management/obj/Debug/net8.0/.
[Info  - 2:46:23 AM] [LSP][LanguageServer.ProjectSystem.RazorProjectService] Updating project 'ProjectKey { IsUnknown = False, Id = /workspaces/azure-openai-service-proxy/src/AzureOpenAIProxy.Management/obj/Debug/net8.0/ }' TagHelpers (1217) and C# Language Version (CSharp12).

This is an example of what the screen looks like when the error appears:

image

Every scroll action results in a new version of the error.

Environment

aaronpowell commented 4 months ago

Tried upgrading to the prerelease C# + CDK extensions (v2.32.14 (pre-release) and v1.7.4 (pre-release) respectively) and the problem still exists.

phil-allen-msft commented 4 months ago

Sounds like a previous issue, and the fix https://github.com/dotnet/razor/pull/9407 may need an augmentation.

phil-allen-msft commented 4 months ago

@aaronpowell , we see in the logs that the URL of the file has the protocol of "review:". To make sure we are addressing the same issue you are seeing, how precisely are you getting to the diff view in question?

aaronpowell commented 4 months ago

I used the GitHub PR extension in VS Code to check out the PR, then I clicked on a file from the PR file list (see the original screenshot) and it loads a diff view.

artemkoloskov commented 4 months ago

Hitting this also, for months now