zed icon indicating copy to clipboard operation
zed copied to clipboard

Protobuf support doesn't work out-of-the-box…?

Open hedefalk opened this issue 1 year ago • 14 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

It sounds to me that protobuf "should just work". Docs link to "protols" https://github.com/coder3101/protols while the code references:

protobuf-language-server:

https://github.com/zed-industries/zed/blob/114c4621433eb948b87fa5f4f41df8af6601f66e/extensions/proto/src/proto.rs

With this plugin installed I just get

Language server error: protobuf-language-server

protobuf-language-server not found in PATH
-- stderr--

I now installed a "protols" unto path with nix:

which protols
/run/current-system/sw/bin/protols

and stuck that into settings as:

"lsp": {
    ...
    "protobuf-language-server": {
      "binary": {
        "path": "protols"
      }
    }
}

Am I misunderstanding what's needed here? Otherwise, maybe that should go into the docs page over at https://zed.dev/docs/languages/proto

Environment

Zed: v0.162.5 (Zed) OS: macOS 15.1.0 Memory: 64 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

hedefalk avatar Nov 22 '24 12:11 hedefalk

its an extension called proto IIRC

SturdyFool10 avatar Nov 23 '24 03:11 SturdyFool10

Yeah, docs need some love. I tried to add some formatting docs as the docs very sparse but I incorrectly added the link to ProtoLS (oops).

Extension was originally written with protobuf-language-server in mind, protols is not super well tested. I've commented out the part of the docs I'm less sure about until I have a chance to test further next week.

Thanks for reporting.

notpeter avatar Nov 23 '24 06:11 notpeter

Is there any option to use other lsp binary other than protols (e.g.: bufls) ? Here is some context in https://github.com/zed-industries/extensions/issues/146

scbizu avatar Nov 29 '24 10:11 scbizu

I haven't tested, but others have and it should work. Specify bufls and the lsp binary or create a symlink in your path to bufls named "protobuf-language-server". Then specify "language_server" as the formatter.

https://zed.dev/docs/configuring-languages#configuring-formatters

notpeter avatar Nov 29 '24 12:11 notpeter

Yep , I correct my config with:

"lsp": {
    "protobuf-language-server": {
      "binary": {
        "path": "buf",
        "arguments": ["beta", "lsp"]
      }
    }
}

And then the protobuf-language-server not found in PATH do not show again

scbizu avatar Nov 29 '24 15:11 scbizu

In proto, can we add a command to automatically sort the variable IDs in the message?

orange-juzipi avatar Dec 12 '24 04:12 orange-juzipi

In proto, can we add a command to automatically sort the variable IDs in the message?

@orange-juzipi This is largely dependent on the language server exposing these a custom actions to Zed. You can see these via editor: toggle code actions (cmd-.).

For example a number of language servers expose a organizeImports action (gopls, ruff, etc) and you can even configure Zed to trigger those as part of formatting configuration. But there are many additional language-server specific actions which are available depending on context. For example rust analyzer has like a hundred.

protobuf-language-server does not implement any of these and appears not to be have much in the way of active development.

bufbuild/buf is newer, but also doesn't have anything like this.

notpeter avatar Dec 13 '24 21:12 notpeter

"lsp": { "protobuf-language-server": { "binary": { "path": "/home/{UserName}/go/bin/protobuf-language-server" } } } When the binary path is configured to the absolute path of the protobuf-language-server, it works.

MarkusPersad avatar Feb 09 '25 14:02 MarkusPersad

i've been running into this and it hasn't been clear how i should proceed.

all other extensions i've tried set up the language server themselves. why does this fail? why do i need to install it manually or mess around with configs / paths / other servers at all?

since buf seems to be the better maintained one, i tried the above config and it just crashes whenever i save. i'm assuming buf isn't fully compatible with protobuf-language-server?

andrewbanchich avatar Feb 13 '25 17:02 andrewbanchich

since buf seems to be the better maintained one, i tried the above config and it just crashes whenever i save. i'm assuming buf isn't fully compatible with protobuf-language-server?

@andrewbanchich compatible , but not fully . It still in beta for years or two , if you'd like to try buf , you can use buf beta which I mentioned above . See buf docs for details .

scbizu avatar Feb 14 '25 09:02 scbizu

@scbizu i did try the config you provided, but it crashes when i save.

cannot format file "/path/to/schema.proto", 25 error(s) found

when i run buf format schema.proto in the CLI it does output the formatted text to stdout.

andrewbanchich avatar Feb 14 '25 14:02 andrewbanchich

@andrewbanchich yep , I tried with formatting , the result is the same as you . I have raised the issue to buf. You should try to fix the buf lint errors before formatting.

scbizu avatar Mar 20 '25 09:03 scbizu

There's now also the protols.

It does work, if specified via the lsp setting. Requires clang-format for formatting, though.

VasiliyS avatar Apr 06 '25 14:04 VasiliyS

@notpeter Sorry to disturb , I use buf language server to navigate , but it always be broken when I do some quick jumping . And I found some other language server issues about 'cannot read LSP message headers' , so I searched Zed's codebase to find why , and I found that Zed will close the language server if they reported with some malformed headers (maybe result in the communication issue in Zed client side), I think it matches my log:

2025-05-14T14:10:46+08:00 ERROR [*unknown*] oneshot canceled
2025-05-14T14:10:46+08:00 ERROR [*unknown*] oneshot canceled
2025-05-14T14:11:11+08:00 INFO  [db] Opening main db
2025-05-14T14:14:29+08:00 ERROR [*unknown*] cannot read LSP message headers
2025-05-14T14:14:37+08:00 WARN  [project::lsp_store] Get definition via protobuf-language-server failed: server shut down
2025-05-14T14:14:37+08:00 ERROR [*unknown*] Get definition via protobuf-language-server failed: server shut down

In my opinion , Zed should notify developers (after retries) what happened about the lsp server (and maybe restart the lsp server)rather than close it by force.

https://github.com/zed-industries/zed/blob/ed361ff6a2fa76aa791b881ce2c338ea5b3dbbf8/crates/lsp/src/input_handler.rs#L77 👆 here will returns a error with the 'cannot read LSP message headers'

https://github.com/zed-industries/zed/blob/1077f2771e6bfbcf9ed16dc0d18386dfbd4d4425/crates/lsp/src/lsp.rs#L511-L532

👆 handle_input do not send this error to notification_channel, so that developers do not know what's wrong with the lsp server

And overall what I mean is that how will Zed resolve this malformed LSP server response in the future LSP integration ?

(Maybe this comment should be in the discussion , but I post here for the better context , sorry to disturb again XD)

scbizu avatar May 14 '25 10:05 scbizu

Would it be possible to add a bit more concrete docs about how to set this up? I understand one needs to install something and point the setting there, is this something protols? When doing remote development, I should install it on the remote server, right?

sygi avatar Jul 29 '25 15:07 sygi

can't format any proto file...same error as @andrewbanchich

Master-Y0da avatar Aug 06 '25 20:08 Master-Y0da

Interesting, but not exactly a duplicate of my #40058

I don't see here any mention of Proto v0.2.2 Extension (from Zed Industries) I don't know if the extension is obsolete, or ?

Despite that this issue here has been Open for almost a year, I still don't know how to proceed.

warrenjokinen avatar Oct 12 '25 19:10 warrenjokinen

@warrenjokinen I am using Proto v0.2.2 Extension , Proto Extension allow users to set various LSP servers via protobuf-language-server setting section, such as protols , buf lsp , which Zed extension provided is just a LSP client to interact with these servers via language server protocol.

So , in my opinion , the bug maybe hard to resolved since it depends on 3rd tools , the actual behavior maybe different though.

You can check the extension source code for more details .

(BTW , for highlighting, I think the tree-sitter plugin is stable now)

scbizu avatar Oct 13 '25 09:10 scbizu