proto: Add language server support (#18763)
Closes #18762 Release Notes: - N/A --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
200b2bf70a
commit
06bd2431d2
6 changed files with 93 additions and 0 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -14863,6 +14863,13 @@ dependencies = [
|
||||||
"zed_extension_api 0.1.0",
|
"zed_extension_api 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zed_proto"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"zed_extension_api 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed_purescript"
|
name = "zed_purescript"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
|
|
@ -154,6 +154,7 @@ members = [
|
||||||
"extensions/php",
|
"extensions/php",
|
||||||
"extensions/perplexity",
|
"extensions/perplexity",
|
||||||
"extensions/prisma",
|
"extensions/prisma",
|
||||||
|
"extensions/proto",
|
||||||
"extensions/purescript",
|
"extensions/purescript",
|
||||||
"extensions/ruff",
|
"extensions/ruff",
|
||||||
"extensions/ruby",
|
"extensions/ruby",
|
||||||
|
|
16
extensions/proto/Cargo.toml
Normal file
16
extensions/proto/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "zed_proto"
|
||||||
|
version = "0.1.0"
|
||||||
|
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"
|
1
extensions/proto/LICENSE-APACHE
Symbolic link
1
extensions/proto/LICENSE-APACHE
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../LICENSE-APACHE
|
|
@ -9,3 +9,7 @@ repository = "https://github.com/zed-industries/zed"
|
||||||
[grammars.proto]
|
[grammars.proto]
|
||||||
repository = "https://github.com/zed-industries/tree-sitter-proto"
|
repository = "https://github.com/zed-industries/tree-sitter-proto"
|
||||||
commit = "0848bd30a64be48772e15fbb9d5ba8c0cc5772ad"
|
commit = "0848bd30a64be48772e15fbb9d5ba8c0cc5772ad"
|
||||||
|
|
||||||
|
[language_servers.protobuf-language-server]
|
||||||
|
name = "Protobuf Language Server"
|
||||||
|
languages = ["Proto"]
|
||||||
|
|
64
extensions/proto/src/proto.rs
Normal file
64
extensions/proto/src/proto.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use zed_extension_api::{self as zed, settings::LspSettings, Result};
|
||||||
|
|
||||||
|
const PROTOBUF_LANGUAGE_SERVER_NAME: &str = "protobuf-language-server";
|
||||||
|
|
||||||
|
struct ProtobufLanguageServerBinary {
|
||||||
|
path: String,
|
||||||
|
args: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ProtobufExtension;
|
||||||
|
|
||||||
|
impl ProtobufExtension {
|
||||||
|
fn language_server_binary(
|
||||||
|
&self,
|
||||||
|
_language_server_id: &zed::LanguageServerId,
|
||||||
|
worktree: &zed::Worktree,
|
||||||
|
) -> Result<ProtobufLanguageServerBinary> {
|
||||||
|
let binary_settings = LspSettings::for_worktree("protobuf-language-server", worktree)
|
||||||
|
.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(ProtobufLanguageServerBinary {
|
||||||
|
path,
|
||||||
|
args: binary_args,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(path) = worktree.which(PROTOBUF_LANGUAGE_SERVER_NAME) {
|
||||||
|
return Ok(ProtobufLanguageServerBinary {
|
||||||
|
path,
|
||||||
|
args: binary_args,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(format!("{PROTOBUF_LANGUAGE_SERVER_NAME} not found in PATH",))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
Loading…
Add table
Add a link
Reference in a new issue