ruby: Add support for "rubocop" language server (#14661)
Hi, this pull request adds support for `rubocop` language server. I noticed that `ruby-lsp` LS is becoming more popular but it still lacks diagnostics support in Zed. To cover that missing feature, it could be good to use `rubocop` LS to show diagnostics alongside with the running Ruby LSP. Release Notes: - N/A --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
344e315174
commit
75775292b3
6 changed files with 76 additions and 3 deletions
|
@ -14,6 +14,10 @@ language = "Ruby"
|
|||
name = "Ruby LSP"
|
||||
language = "Ruby"
|
||||
|
||||
[language_servers.rubocop]
|
||||
name = "Rubocop"
|
||||
language = "Ruby"
|
||||
|
||||
[grammars.ruby]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-ruby"
|
||||
commit = "dc2d7d6b50f9975bc3c35bbec0ba11b2617b736b"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
mod rubocop;
|
||||
mod ruby_lsp;
|
||||
mod solargraph;
|
||||
|
||||
pub use rubocop::*;
|
||||
pub use ruby_lsp::*;
|
||||
pub use solargraph::*;
|
||||
|
|
19
extensions/ruby/src/language_servers/rubocop.rs
Normal file
19
extensions/ruby/src/language_servers/rubocop.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
pub struct Rubocop {}
|
||||
|
||||
impl Rubocop {
|
||||
pub const LANGUAGE_SERVER_ID: &'static str = "rubocop";
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn server_script_path(&mut self, worktree: &zed::Worktree) -> Result<String> {
|
||||
let path = worktree.which("rubocop").ok_or_else(|| {
|
||||
"rubocop must be installed manually. Install it with `gem install rubocop` or specify the 'binary' path to it via local settings.".to_string()
|
||||
})?;
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
}
|
|
@ -5,11 +5,12 @@ use zed::settings::LspSettings;
|
|||
use zed::{serde_json, CodeLabel, LanguageServerId};
|
||||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
use crate::language_servers::{RubyLsp, Solargraph};
|
||||
use crate::language_servers::{Rubocop, RubyLsp, Solargraph};
|
||||
|
||||
struct RubyExtension {
|
||||
solargraph: Option<Solargraph>,
|
||||
ruby_lsp: Option<RubyLsp>,
|
||||
rubocop: Option<Rubocop>,
|
||||
}
|
||||
|
||||
impl zed::Extension for RubyExtension {
|
||||
|
@ -17,6 +18,7 @@ impl zed::Extension for RubyExtension {
|
|||
Self {
|
||||
solargraph: None,
|
||||
ruby_lsp: None,
|
||||
rubocop: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +46,15 @@ impl zed::Extension for RubyExtension {
|
|||
env: worktree.shell_env(),
|
||||
})
|
||||
}
|
||||
Rubocop::LANGUAGE_SERVER_ID => {
|
||||
let rubocop = self.rubocop.get_or_insert_with(|| Rubocop::new());
|
||||
|
||||
Ok(zed::Command {
|
||||
command: rubocop.server_script_path(worktree)?,
|
||||
args: vec!["--lsp".into()],
|
||||
env: worktree.shell_env(),
|
||||
})
|
||||
}
|
||||
language_server_id => Err(format!("unknown language server: {language_server_id}")),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue