[VS Code] Diff view fails with "Request textDocument/inlayHint failed."
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:
Every scroll action results in a new version of the error.
Environment
- VS Code Insiders
Version: 1.90.0-insider (user setup) Commit: ca688da9fb6dad00996cee7d5342490daa7bb1fb Date: 2024-05-31T01:05:41.342Z Electron: 29.4.0 ElectronBuildId: 9593362 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Windows_NT x64 10.0.26120 - C# extension: v2.31.19
- C# DevKit: v1.6.8
- OS: opened in a devcontainer
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.
Sounds like a previous issue, and the fix https://github.com/dotnet/razor/pull/9407 may need an augmentation.
@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?
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.
Hitting this also, for months now
Every time this happens to me, my lifespan is shortened. And it happens every time I edit razor.
Every time this happens to me, my lifespan is shortened
For the love of god man, stop using the diff view!
No but seriously, in 2.89.x I'm getting a slightly different exception:
Error: [textDocument/inlayHint] [LSP] System.ArgumentException: Absolute path expected. (Parameter 'baseDirectory')
at Microsoft.CodeAnalysis.SourceFileResolver..ctor(ImmutableArray`1 searchPaths, String baseDirectory, ImmutableArray`1 pathMap) in /_/src/Compilers/Core/Portable/SourceFileResolver.cs:line 49
at Microsoft.CodeAnalysis.Features.Workspaces.MiscellaneousFileUtilities.GetCompilationOptionsWithScriptReferenceResolvers(SolutionServices services, CompilationOptions compilationOptions, String filePath) in /_/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs:line 109
at Microsoft.CodeAnalysis.Features.Workspaces.MiscellaneousFileUtilities.CreateMiscellaneousProjectInfoForDocument(Workspace workspace, String filePath, TextLoader textLoader, LanguageInformation languageInformation, SourceHashAlgorithm checksumAlgorithm, SolutionServices services, ImmutableArray`1 metadataReferences) in /_/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs:line 46
at Microsoft.CodeAnalysis.LanguageServer.FileBasedPrograms.FileBasedProgramsProjectSystem.<AddMiscellaneousDocumentAsync>g__AddPrimordialDocument|7_0(DocumentUri uri, SourceText documentText, String languageId, <>c__DisplayClass7_0&) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs:line 92
at Microsoft.CodeAnalysis.LanguageServer.FileBasedPrograms.FileBasedProgramsProjectSystem.AddMiscellaneousDocumentAsync(DocumentUri uri, SourceText documentText, String languageId, ILspLogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs:line 78
at Microsoft.CodeAnalysis.LanguageServer.LspWorkspaceManager.GetLspDocumentInfoAsync(TextDocumentIdentifier textDocumentIdentifier, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Workspaces/LspWorkspaceManager.cs:line 305
at RO.log (c:\Users\dawengie\.vscode\extensions\ms-dotnettools.csharp-2.89.19-win32-arm64\dist\extension.js:1205:18867)
at c:\Users\dawengie\.vscode\extensions\ms-dotnettools.csharp-2.89.19-win32-arm64\dist\extension.js:1210:33608
at mr (c:\Users\dawengie\.vscode\extensions\ms-dotnettools.csharp-2.89.19-win32-arm64\dist\extension.js:51:1620)
at Mr (c:\Users\dawengie\.vscode\extensions\ms-dotnettools.csharp-2.89.19-win32-arm64\dist\extension.js:50:7629)
at Immediate._onImmediate (c:\Users\dawengie\.vscode\extensions\ms-dotnettools.csharp-2.89.19-win32-arm64\dist\extension.js:50:7324)
at processImmediate (node:internal/timers:485:21)
It doesn't pop up an error for me though, so if I wasn't looking at the Razor output I probably wouldn't have noticed. What versions are you all using?
Obviously any error isn't good, but from v2.88.x onwards (of the C# extension, not devkit) the Uri handling should at least be totally fine.
This happens everytime using Cline to modify .razor files
@aaronpowell @phil-allen-msft @artemkoloskov @fantasticaneer @davidwengier @michael-b-tt0 @douglas-wiliam @moo-the-cow @hba114 @envo @rrajewski @teddybeermaniac @squidward63 @monirtarabishi @averdiere @bharathm03 @tdrxbryar @neorth
A fix for this issue is now available in the next pre-releases of C#DK/C#. If you'd like to try out the fix, please see these instructions to update or try pre-release versions.
@aaronpowell to validate fix
@aaronpowell @phil-allen-msft @artemkoloskov @fantasticaneer @davidwengier @michael-b-tt0 @claudiaregio @douglas-wiliam @moo-the-cow @hba114 @envo @rrajewski @teddybeermaniac @squidward63 @monirtarabishi @averdiere @bharathm03 @tdrxbryar @neorth
This issue has been fixed! Please update to the latest versions of VS Code, C# Dev Kit, and the C# extension.