Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: Add language server support #18763

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ members = [
"extensions/php",
"extensions/perplexity",
"extensions/prisma",
"extensions/proto",
"extensions/purescript",
"extensions/ruff",
"extensions/ruby",
Expand Down
16 changes: 16 additions & 0 deletions extensions/proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "zed_protobuf"
version = "0.0.1"
edition = "2021"
publish = false
license = "Apache-2.0"

[lints]
workspace = true

[lib]
path = "src/proto.rs"
crate-type = ["cdylib"]

[dependencies]
zed_extension_api = "0.1.0"
4 changes: 4 additions & 0 deletions extensions/proto/extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ repository = "https://github.com/zed-industries/zed"
[grammars.proto]
repository = "https://github.com/zed-industries/tree-sitter-proto"
commit = "0848bd30a64be48772e15fbb9d5ba8c0cc5772ad"

[language_servers.protobuf-ls]
name = "Protobuf Language Server"
languages = ["Proto"]
61 changes: 61 additions & 0 deletions extensions/proto/src/proto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use zed_extension_api::{self as zed, settings::LspSettings, Result};

const DEFAULT_BINARY_NAME: &str = "protobuf-language-server";

struct ProtobufLspBinary {
path: String,
args: Option<Vec<String>>,
}

struct ProtobufExtension {}

impl ProtobufExtension {
fn language_server_binary(
&self,
_language_server_id: &zed::LanguageServerId,
worktree: &zed::Worktree,
) -> Result<ProtobufLspBinary> {
let binary_settings = LspSettings::for_worktree("omnisharp", worktree)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/omnisharp/protobuf-language-server/

.ok()
.and_then(|lsp_settings| lsp_settings.binary);
let binary_args = binary_settings
.as_ref()
.and_then(|binary_settings| binary_settings.arguments.clone());

if let Some(path) = binary_settings.and_then(|binary_settings| binary_settings.path) {
return Ok(ProtobufLspBinary {
path,
args: binary_args,
});
}

if let Some(path) = worktree.which(DEFAULT_BINARY_NAME) {
return Ok(ProtobufLspBinary { path, args: None });
}

return Err(format!("{} not found in PATH", DEFAULT_BINARY_NAME));
}
}

impl zed::Extension for ProtobufExtension {
fn new() -> Self {
Self {}
}

fn language_server_command(
&mut self,
language_server_id: &zed_extension_api::LanguageServerId,
worktree: &zed_extension_api::Worktree,
) -> zed_extension_api::Result<zed_extension_api::Command> {
let binary = self.language_server_binary(language_server_id, worktree)?;
Ok(zed::Command {
command: binary.path,
args: binary
.args
.unwrap_or_else(|| vec!["-logs".into(), "".into()]),
env: Default::default(),
})
}
}

zed::register_extension!(ProtobufExtension);