Skip to content

Language server can't find method definition which generated by source generator. #6684

@zhen8838

Description

@zhen8838

Type: Bug

Issue Description

when using source generator, the language server request textDocument/definition failed.

Steps to Reproduce

using vscode open my repo, try goto definition on the Sudoku.Solver/Program.cs:L11 HelloFrom(file) method.

Expected Behavior

open the generated source file.

Actual Behavior

got the error: Request textDocument/definition failed.

Logs

[object Object]
Using dotnet configured on PATH
[Error - 16:09:01] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.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 477
   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 442
   at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 61
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 16:09:01] Request textDocument/definition failed.
  Message: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'
  Code: -32000 
[object Object]

C# log

[object Object] [LanguageServerHost] [08:13:44.842][End]textDocument/definition [LanguageServerHost] /Users/lisa/Documents/Sudoku/Sudoku.Solver/Program.cs found in workspace Host [LanguageServerHost] [08:13:45.010][Start]textDocument/codeAction [LanguageServerHost] [08:13:45.061][End]textDocument/codeAction [LanguageServerHost] /Users/lisa/Documents/Sudoku/Sudoku.Solver/Program.cs found in workspace Host [LanguageServerHost] [08:13:47.998][Start]textDocument/definition [LanguageServerHost] [08:13:48.001][End]textDocument/definition [LanguageServerHost] /Users/lisa/Documents/Sudoku/Sudoku.Solver/Program.cs found in workspace Host [LanguageServerHost] [08:13:48.186][Start]textDocument/hover [LanguageServerHost] [08:13:48.188][End]textDocument/hover [LanguageServerHost] /Users/lisa/Documents/Sudoku/Sudoku.Solver/Program.cs found in workspace Host [LanguageServerHost] [08:13:48.236][Start]textDocument/definition [Error - 16:13:48] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.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 System.Uri..ctor(String uriString, UriKind uriKind) at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 178 --- 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.g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 477 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 442 at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 61 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) [Error - 16:13:48] Request textDocument/definition failed. Message: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs' Code: -32000 [object Object]

C# LSP Trace Logs

[Trace - 16:14:40] Received notification 'window/logMessage'.
Params: {
"type": 1,
"message": "[LanguageServerHost] System.UriFormatException: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'\n ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.\n at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)\n at System.Uri..ctor(String uriString, UriKind uriKind)\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in //src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 178\n --- End of inner exception stack trace ---\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in //src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 477\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(Document document, TextSpan textSpan, Boolean isStale, Nullable1 context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 442\n at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 61\n at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)"
}

[Trace - 16:14:40] Received response 'textDocument/definition - (41)' in 3ms. Request failed: Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs' (-32000).
Error data: {
"type": "System.UriFormatException",
"message": "Failed create URI from 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'; original string: 'Sudoku.SourceGenerator/SourceGenerator.HelloSourceGenerator/Program.g.cs'",
"stack": " at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in //src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in //src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 477\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(Document document, TextSpan textSpan, Boolean isStale, Nullable1 context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 442\n at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 61\n at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)\n at Microsoft.CommonLanguageServerProtocol.Framework.AbstractLanguageServer`1.DelegatingEntryPoint.EntryPointAsync[TRequest,TResponse](TRequest request, CancellationToken cancellationToken) in //src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs:line 198",
"code": -2146233033,
"inner": {
"type": "System.UriFormatException",
"message": "Invalid URI: The format of the URI could not be determined.",
"stack": " at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)\n at System.Uri..ctor(String uriString, UriKind uriKind)\n at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /
/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 178",
"code": -2146233033
}
}

Environment information

VSCode version: 1.84.2
C# Extension: 2.10.28
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 7.0.306 Commit: f500069cb7

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.306/

Host:
Version: 7.0.9
Architecture: arm64
Commit: 8e9a17b221

.NET SDKs installed:
7.0.306 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
x64 [/usr/local/share/dotnet/x64]
registered at [/etc/dotnet/install_location_x64]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
autopep8 ms-python 2023.8.0 ms-python.autopep8-2023.8.0
better-comments aaron-bond 3.0.2 aaron-bond.better-comments-3.0.2
change-case wmaurer 1.0.0 wmaurer.change-case-1.0.0
csdevkit ms-dotnettools 1.0.14 ms-dotnettools.csdevkit-1.0.14-darwin-arm64
csharp ms-dotnettools 2.10.28 ms-dotnettools.csharp-2.10.28-darwin-arm64
doxdocgen cschlosser 1.4.0 cschlosser.doxdocgen-1.4.0
file-icons file-icons 1.1.0 file-icons.file-icons-1.1.0
git-graph mhutchie 1.30.0 mhutchie.git-graph-1.30.0
gitlens eamodio 14.5.0 eamodio.gitlens-14.5.0
graphviz-interactive-preview tintinweb 0.3.5 tintinweb.graphviz-interactive-preview-0.3.5
hexeditor ms-vscode 1.9.12 ms-vscode.hexeditor-1.9.12
icons-carbon antfu 0.2.6 antfu.icons-carbon-0.2.6
increment-selection albymor 0.2.0 albymor.increment-selection-0.2.0
intellicode-api-usage-examples VisualStudioExptTeam 0.2.8 visualstudioexptteam.intellicode-api-usage-examples-0.2.8
isort ms-python 2023.10.1 ms-python.isort-2023.10.1
jupyter ms-toolsai 2023.10.1100000000 ms-toolsai.jupyter-2023.10.1100000000-darwin-arm64
jupyter-keymap ms-toolsai 1.1.2 ms-toolsai.jupyter-keymap-1.1.2
jupyter-renderers ms-toolsai 1.0.17 ms-toolsai.jupyter-renderers-1.0.17
material-theme zhuangtongfa 3.16.2 zhuangtongfa.material-theme-3.16.2
pdf tomoki1207 1.2.2 tomoki1207.pdf-1.2.2
python ms-python 2023.20.0 ms-python.python-2023.20.0
remote-containers ms-vscode-remote 0.321.0 ms-vscode-remote.remote-containers-0.321.0
remote-explorer ms-vscode 0.4.1 ms-vscode.remote-explorer-0.4.1
remote-ssh ms-vscode-remote 0.107.0 ms-vscode-remote.remote-ssh-0.107.0
remote-ssh-edit ms-vscode-remote 0.86.0 ms-vscode-remote.remote-ssh-edit-0.86.0
test-adapter-converter ms-vscode 0.1.8 ms-vscode.test-adapter-converter-0.1.8
todo-tree Gruntfuggly 0.0.226 gruntfuggly.todo-tree-0.0.226
vscode-custom-css be5invis 7.2.1 be5invis.vscode-custom-css-7.2.1
vscode-dotnet-runtime ms-dotnettools 2.0.0 ms-dotnettools.vscode-dotnet-runtime-2.0.0
vscode-github-actions github 0.26.2 github.vscode-github-actions-0.26.2
vscode-jupyter-cell-tags ms-toolsai 0.1.8 ms-toolsai.vscode-jupyter-cell-tags-0.1.8
vscode-jupyter-slideshow ms-toolsai 0.1.5 ms-toolsai.vscode-jupyter-slideshow-0.1.5
vscode-lldb vadimcn 1.10.0 vadimcn.vscode-lldb-1.10.0
vscode-mlir llvm-vs-code-extensions 0.0.11 llvm-vs-code-extensions.vscode-mlir-0.0.11
vscode-pylance ms-python 2023.11.10 ms-python.vscode-pylance-2023.11.10
vscode-test-explorer hbenl 2.21.1 hbenl.vscode-test-explorer-2.21.1
vscode-wakatime WakaTime 24.4.0 wakatime.vscode-wakatime-24.4.0
vscode-yaml redhat 1.14.0 redhat.vscode-yaml-1.14.0
vscodeintellicode VisualStudioExptTeam 1.2.30 visualstudioexptteam.vscodeintellicode-1.2.30
vscodeintellicode-csharp ms-dotnettools 0.1.26 ms-dotnettools.vscodeintellicode-csharp-0.1.26-darwin-arm64
vsliveshare ms-vsliveshare 1.0.5892 ms-vsliveshare.vsliveshare-1.0.5892

Extension version: 2.10.28
VS Code version: Code 1.84.2 (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:52:57.054Z)
OS version: Darwin arm64 23.1.0
Modes:

System Info
Item Value
CPUs Apple M2 Pro (12 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 1
Memory (System) 32.00GB (1.79GB free)
Process Argv --crash-reporter-id efe2778d-60f4-4b14-91c3-5938f30e4c19
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30880072
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
89544117:30613380
a9j8j154:30646983
showlangstatbar:30737416
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30869155
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixt:30871694
pythonregdiag2:30871582
pyreplss2:30886141
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:30885897
pythontbext0:30879054
accentitlementsc:30887149
dsvsc016:30886110
dsvsc017cf:30886113
dsvsc018cf:30886115
aa_t_chat:30882232

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions