bufbuild / buf

The best way of working with Protocol Buffers.
https://buf.build
Apache License 2.0
9.07k stars 275 forks source link

`buf beta lsp` doesn't work with an empty cache #3360

Open stefanvanburen opened 1 month ago

stefanvanburen commented 1 month ago

GitHub repository with your minimal reproducible example (do not fill out this field with "github.com/bufbuild/buf" or we will automatically close your issue, see the instructions above!)

https://github.com/bufbuild/registry-proto

Commands

buf registry cc
nvim buf/registry/module/v1/module_service.proto

Output

From :messages:

Client bufls quit with exit code 2 and signal 0. Check log for errors: /Users/stefanvanburen/.local/state/nvim/lsp.log                                                                                                                                                                                                                                                                                                                    
13 lines yanked                                                                                                                                                                                                                                                                                                                                                                                                                           
Press ENTER or type command to continue  

From :LspLog:

[START][2024-10-01 10:19:29] LSP logging initiated
[ERROR][2024-10-01 10:19:29] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[34mINFO\27[0m\tnew file version: file:///Users/stefanvanburen/src/registry-proto/buf/registry/module/v1/module_service.proto, 0 -> 0\n\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n\27[34mINFO\27[0m\tparsing AST for file:///Users/stefanvanburen/src/registry-proto/buf/registry/module/v1/module_service.proto, 0\n'
[ERROR][2024-10-01 10:19:29] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n'
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    "\27[34mINFO\27[0m\tparsing AST for file:///Users/stefanvanburen/src/registry-proto/buf/registry/module/v1/module.proto, -1\n"
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    "\27[34mINFO\27[0m\tparsing AST for file:///Users/stefanvanburen/src/registry-proto/buf/registry/owner/v1/owner.proto, -1\n"
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[33mWARN\27[0m\tcould not load import import "file://" from disk: %!w(*fmt.wrapError=&{could not read file "file://" from disk: open : no such file or directory 0x140007d9380})\n'
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    "\27[34mINFO\27[0m\tparsing AST for file:///Users/stefanvanburen/.cache/buf/v3/wellknowntypes/27.0/google/protobuf/descriptor.proto, -1\n"
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n'
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n'
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    '\27[33mWARN\27[0m\tnotify returned\t{"method": "$/progress"}\n'
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    "panic: runtime error: invalid memory address or nil pointer dereference\n[signal SIGSEGV: segmentation violation code=0x2"
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    " addr=0x30 pc=0x104e58848]\n\ngoroutine 12 [running]:\ngithub.com/bufbuild/buf/private/buf/buflsp.(*symbol).ResolveCrossFile(0x14000c56870, {0x1057e4a58, 0x14000b01bd0})\n\tgithub.com/bufbuild/buf/private/buf/buflsp/symbol.go:322 +0x1098\ngithub.com/bufbuild/buf/private/buf/buflsp.(*file).IndexSymbols(0x140002f04b8, {0x1057e4a58, 0x14000b01bd0})\n\tgithub.com/bufbuild/buf/private/buf/buflsp/file.go:"
[ERROR][2024-10-01 10:19:30] .../vim/lsp/rpc.lua:770    "rpc"   "/opt/homebrew/bin/buf" "stderr"    "641 +0x3b0\ngithub.com/bufbuild/buf/private/buf/buflsp.(*file).Refresh(0x140002f04b8, {0x1057e4a58, 0x14000b01bd0})\n\tgithub.com/bufbuild/buf/private/buf/buflsp/file.go:209 +0x164\ncreated by github.com/bufbuild/buf/private/buf/buflsp.(*server).DidOpen in goroutine 11\n\tgithub.com/bufbuild/buf/private/buf/buflsp/server.go:176 +0xe0\n"

Expected Output

No panic.

Anything else?

Ideally, the LSP should handle downloading required modules to the cache.

mcy commented 3 weeks ago

I followed the reproduction steps and cannot reproduce. Can you try this again with your setup but with a CLI built from HEAD?

stefanvanburen commented 3 weeks ago

Yeah, the panic is seemingly fixed with the latest HEAD. However, it does look like things seemingly spin with an empty module cache (i.e., after running a buf registry cc). My nvim instance shows LSP notifications, and without the cache populated the LSP seemingly will just spin trying to resolve the non-existent images. (Not sure if this relates to #3397 or not.)

Some example logs, from :LspLog, that seemingly just spin over and over:

{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"textDocument/publishDiagnostics"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"notify returned","method":"$/progress"}
{"level":"warn","time":"2024-10-14T10:49:09.882-0400","message":"could not find image for \\"file:///Users/stefanvanburen/.cache/buf/v3/modules/b5/buf.build/bufbuild/protovalidate/b983156c5e994cc9892e0ce3e64e17e0/files/buf/validate/priv/private.proto\\""}}

Anyway — perhaps worth a separate issue, as it seems like the LSP should be able to manage the cache, but happy if you want to close this particular one out.

mcy commented 1 week ago

Yeah I don't think this is quite as much of an issue. Let's close it.

akshayjshah commented 1 week ago

Let's keep this open, but retitle the issue - while the panic is fixed, the LSP still doesn't function with an empty cache. The rest of the CLI populates the cache on demand, without explicit intervention from the user, and the LSP ought to do the same.