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
499 stars 191 forks source link

Razor language server crashes when viewing a git diff #9365

Closed timheuer closed 1 year ago

timheuer commented 1 year ago

Describe the Issue

It appears when viewing a cshtml diff in VS code the Razor language service now starts to crash with:

[Error - 8:33:30 AM] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.<GetTextSpan>g__GetAbsoluteIndex|11_0(Int32 line, Int32 character, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 276
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.GetTextSpan(SourceText sourceText, Int32 startLine, Int32 startCharacter, Int32 endLine, Int32 endCharacter) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 267
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 107
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToRazorTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 111
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.TagHelperSemanticRangeVisitor.VisitAllNodes(RazorCodeDocument razorCodeDocument, Range range, RazorSemanticTokensLegend razorSemanticTokensLegend, Boolean colorCodeBackground) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/TagHelperSemanticRangeVisitor.cs:line 40
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.RazorSemanticTokensInfoService.GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs:line 97
   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 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 8:33:30 AM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
  Code: -32000 
[object Object]
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Error - 8:33:33 AM] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.<GetTextSpan>g__GetAbsoluteIndex|11_0(Int32 line, Int32 character, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 276
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.GetTextSpan(SourceText sourceText, Int32 startLine, Int32 startCharacter, Int32 endLine, Int32 endCharacter) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 267
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 107
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToRazorTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 111
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.TagHelperSemanticRangeVisitor.VisitAllNodes(RazorCodeDocument razorCodeDocument, Range range, RazorSemanticTokensLegend razorSemanticTokensLegend, Boolean colorCodeBackground) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/TagHelperSemanticRangeVisitor.cs:line 40
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.RazorSemanticTokensInfoService.GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs:line 97
   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 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 8:33:33 AM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
  Code: -32000 
[object Object]
[Info  - 8:33:33 AM] Returned 46 semantic tokens for range (0,0)-(8,0) in git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}.
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Error - 8:33:39 AM] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.<GetTextSpan>g__GetAbsoluteIndex|11_0(Int32 line, Int32 character, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 276
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.GetTextSpan(SourceText sourceText, Int32 startLine, Int32 startCharacter, Int32 endLine, Int32 endCharacter) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 267
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 107
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToRazorTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 112
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.TagHelperSemanticRangeVisitor.VisitAllNodes(RazorCodeDocument razorCodeDocument, Range range, RazorSemanticTokensLegend razorSemanticTokensLegend, Boolean colorCodeBackground) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/TagHelperSemanticRangeVisitor.cs:line 50
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.RazorSemanticTokensInfoService.GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs:line 97
   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 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 8:33:39 AM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
  Code: -32000 
[object Object]
[Info  - 8:33:39 AM] Returned 46 semantic tokens for range (0,0)-(8,0) in git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}.
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Error - 8:33:39 AM] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.<GetTextSpan>g__GetAbsoluteIndex|11_0(Int32 line, Int32 character, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 276
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.SourceTextExtensions.GetTextSpan(SourceText sourceText, Int32 startLine, Int32 startCharacter, Int32 endLine, Int32 endCharacter) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/SourceTextExtensions.cs:line 267
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 107
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.ToRazorTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 112
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.TagHelperSemanticRangeVisitor.VisitAllNodes(RazorCodeDocument razorCodeDocument, Range range, RazorSemanticTokensLegend razorSemanticTokensLegend, Boolean colorCodeBackground) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/TagHelperSemanticRangeVisitor.cs:line 50
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.RazorSemanticTokensInfoService.GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs:line 97
   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 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 8:33:39 AM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'End (10,0) matches or exceeds SourceText boundary 9.')
  Code: -32000 
[object Object]
[Info  - 8:33:39 AM] Returned 46 semantic tokens for range (0,0)-(8,0) in git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}.
Trying to create DocumentContext for textDocument/didClose for (no project context) for git:/c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CUsers%5C%5CWDAGUtilityAccount%5C%5CDesktop%5C%5Cmvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/documentColor for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Warn  - 8:33:41 AM] Could not create a document context for textDocument/documentColor for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml. Endpoint may crash later if it calls GetRequiredDocumentContext.
Trying to create DocumentContext for textDocument/codeAction for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Warn  - 8:33:41 AM] Could not create a document context for textDocument/codeAction for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml. Endpoint may crash later if it calls GetRequiredDocumentContext.
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml
[Warn  - 8:33:41 AM] Could not create a document context for textDocument/semanticTokens/range for file:///c%3A/Users/WDAGUtilityAccount/Desktop/mvcapp/Views/Home/Index.cshtml. Endpoint may crash later if it calls GetRequiredDocumentContext.
[Error - 8:33:41 AM] System.ArgumentNullException: Value cannot be null. (Parameter 'DocumentContext')
   at Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts.RazorRequestContext.GetRequiredDocumentContext() in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/EndpointContracts/RazorRequestContext.cs:line 47
   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 71
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 8:33:41 AM] Request textDocument/semanticTokens/range failed.
  Message: Value cannot be null. (Parameter 'DocumentContext')
  Code: -32000 

Steps To Reproduce

  1. Setup an environment with .NET 7 SDK and git tools
  2. Install VS Code 1.83.x
  3. Install the C# extension (don't need Dev Kit to repro)
  4. dotnet new mvc -n mymvcapp
  5. git init
  6. dotnet new gitignore
  7. git commit -a -m 'initial commit'
  8. Open the folder for mymvcapp
  9. Open a .cshtml page and make an edit on home/index.cshtml

    
    @{
    ViewData["Title"] = "Home Page";
    
    string WelcomeMessage = "Hello there";
    }

@WelcomeMessage

Learn about building Web apps with ASP.NET Core.


11. Open the git diff view in VS Code

Notification message appears saying an error occurred and the log output is what is shown above.

https://github.com/microsoft/vscode-dotnettools/assets/4821/22c10d85-08c9-4d7f-b71d-8bba85631162

### Expected Behavior

No issues

### Environment Information

Windows 11
All latest C# extension
burkeholland commented 1 year ago

This randomly occurs for me in cshtml files when the markup is malformed. In my case, its because I'm porting Vue to Razor and there is a lot of markup that isn't valid.

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\\f40df8f0-c626-416b-9ca6-080369259b43"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 12:12:32 PM] [Program] Language server initialized
[Warn  - 12:43:19 PM] [LanguageServerHost] Ignoring diagnostics request for untracked document: file:///C:/Users/burke/Dev/BlazorSWA/Client/StateContainer.cs
[Error - 12:50:03 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'; original string: 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'
 ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 491
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(Document document, TextSpan textSpan, Boolean isStale, Nullable`1 context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 503
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.ComputeLocationAsync(Nullable`1 documentSpan, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 246
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.GenerateVSReferenceItemAsync(Int32 definitionId, Int32 id, Nullable`1 documentSpan, ImmutableDictionary`2 properties, ClassifiedTextElement definitionText, Glyph definitionGlyph, Nullable`1 symbolUsageInfo, Boolean isWrittenTo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 201
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 175
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesProgressAdapter.OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs:line 124
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass20_0.<<ProcessDocumentAsync>g__ProcessDocumentAsync|0>d.MoveNext() in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 301
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs:line 68
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 157
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 126
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 105
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindLiteralOrSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindAllReferencesHandler.HandleRequestAsync(ReferenceParams referenceParams, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs:line 72
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 12:50:03 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'; original string: 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'
 ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 491
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(Document document, TextSpan textSpan, Boolean isStale, Nullable`1 context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 503
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.ComputeLocationAsync(Nullable`1 documentSpan, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 246
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.GenerateVSReferenceItemAsync(Int32 definitionId, Int32 id, Nullable`1 documentSpan, ImmutableDictionary`2 properties, ClassifiedTextElement definitionText, Glyph definitionGlyph, Nullable`1 symbolUsageInfo, Boolean isWrittenTo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 201
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 175
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesProgressAdapter.OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs:line 124
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass20_0.<<ProcessDocumentAsync>g__ProcessDocumentAsync|0>d.MoveNext() in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 301
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs:line 68
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 157
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 126
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 105
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindLiteralOrSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindAllReferencesHandler.HandleRequestAsync(ReferenceParams referenceParams, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs:line 72
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 12:50:03 PM] Request textDocument/references failed.
  Message: Failed create URI from 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'; original string: 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'
  Code: -32000 
[object Object]
[Error - 12:50:03 PM] Request textDocument/references failed.
  Message: Failed create URI from 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'; original string: 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'
  Code: -32000 
[object Object]
davidwengier commented 1 year ago

@burkeholland That log appears to be from the C# server, and is related to source generated files I think. Was there a Razor log you meant to include instead?

@jasonmalinowski @tmat Is the Uri issue above known?

jasonmalinowski commented 1 year ago

@davidwengier Yes, that's a duplicate of https://github.com/dotnet/vscode-csharp/issues/6426. Unless you've got something else in this bug to look at as well, we can close it.

davidwengier commented 1 year ago

Thanks @jasonmalinowski. The original issue here (crashing on git diff in Razor files) is still a bug, so will leave it open, but good to know @burkeholland's issue is known.

maryamariyan commented 1 year ago

Thanks @jasonmalinowski. The original issue here (crashing on git diff in Razor files) is still a bug, so will leave it open, but good to know @burkeholland's issue is known.

@davidwengier I'm looking at the current bug. So far, I confirmed:

Trying to create DocumentContext for textDocument/semanticTokens/range for git:/c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CCodeHub%5C%5Crepro-9365%5C%5Cmymvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/semanticTokens/range for file:///c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml
[Info  - 3:26:37 PM] Returned 24 semantic tokens for range (0,0)-(8,0) in git:/c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CCodeHub%5C%5Crepro-9365%5C%5Cmymvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}.
[Info  - 3:26:37 PM] Returned 47 semantic tokens for range (0,0)-(9,6) in file:///c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml.

When just opening document:

Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml
[Info  - 3:36:15 PM] Returned 47 semantic tokens for range (0,0)-(9,6) in file:///c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml.

Open diff file:

Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for git:/c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CCodeHub%5C%5Crepro-9365%5C%5Cmymvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}
Trying to create DocumentContext for textDocument/semanticTokens/range for (no project context) for file:///c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml
[Error - 3:36:55 PM] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'range.End (9,6) matches or exceeds SourceText boundary 9.')
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.<AsTextSpan>g__GetAbsolutePosition|8_0(Position position, SourceText sourceText, String argName) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 151
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.AsTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 138
   at Microsoft.AspNetCore.Razor.LanguageServer.Extensions.RangeExtensions.AsRazorTextSpan(Range range, SourceText sourceText) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/RangeExtensions.cs:line 166
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.TagHelperSemanticRangeVisitor.VisitAllNodes(RazorCodeDocument razorCodeDocument, Range range, RazorSemanticTokensLegend razorSemanticTokensLegend, Boolean colorCodeBackground) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/TagHelperSemanticRangeVisitor.cs:line 40
   at Microsoft.AspNetCore.Razor.LanguageServer.Semantic.RazorSemanticTokensInfoService.GetSemanticTokensAsync(TextDocumentIdentifier textDocumentIdentifier, Range range, VersionedDocumentContext documentContext, RazorSemanticTokensLegend razorSemanticTokensLegend, Guid correlationId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs:line 66
   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 59
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 3:36:55 PM] Request textDocument/semanticTokens/range failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'range.End (9,6) matches or exceeds SourceText boundary 9.')
  Code: -32000 
[object Object]
[Info  - 3:36:55 PM] Returned 46 semantic tokens for range (0,0)-(8,0) in git:/c%3A/CodeHub/repro-9365/mymvcapp/Views/Home/Index.cshtml?{"path"%3A"c%3A%5C%5CCodeHub%5C%5Crepro-9365%5C%5Cmymvcapp%5C%5CViews%5C%5CHome%5C%5CIndex.cshtml"%2C"ref"%3A"~"}.

This narrows down the bug to one of the changes listed in here https://github.com/dotnet/vscode-csharp/compare/v2.1.2...v2.2.10

maryamariyan commented 1 year ago

We are getting ArgumentOutOfRangeException because the SourceText being used inside GetAbsolutePosition is an outdated one (e.g. taken from the left side in the screenshot below)

e.g. image

In this would fail with message: (the requested ranges has 11 lines, but the document it sees has 8 lines)

Specified argument was out of the range of valid values. (Parameter 'range.End (11,0) matches or exceeds SourceText boundary 8.')
davidwengier commented 1 year ago

This issue is most likely nothing to do with semantic tokens, and all to do with our Uri handling. The two requests should resolve to two different documents, but are probably being considered the same file by us. The short term fix would be to hard-code knowledge of git:// uris and make sure they point to documents in the miscellaneous files project. The longer term fix is to fix our uri handling in some way, but it will take some investigation to work out what that way is.