Skip to content

Add StandardRB LSP #25

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

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
4 changes: 4 additions & 0 deletions extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ languages = ["Ruby", "ERB"]
name = "Rubocop"
languages = ["Ruby"]

[language_servers.standardrb]
name = "Standardrb"
languages = ["Ruby"]

[grammars.ruby]
repository = "https://github.com/tree-sitter/tree-sitter-ruby"
commit = "7dbc1e2d0e2d752577655881f73b4573f3fe85d4"
Expand Down
2 changes: 2 additions & 0 deletions src/language_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ mod language_server;
mod rubocop;
mod ruby_lsp;
mod solargraph;
mod standard;

pub use language_server::LanguageServer;
pub use rubocop::*;
pub use ruby_lsp::*;
pub use solargraph::*;
pub use standard::*;
58 changes: 58 additions & 0 deletions src/language_servers/standard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use super::language_server::LanguageServer;
use zed_extension_api::{self as zed, LanguageServerId, Result};

pub struct Standard {}

impl LanguageServer for Standard {
const SERVER_ID: &str = "standardrb";
const EXECUTABLE_NAME: &str = "standardrb";

fn get_executable_args() -> Vec<String> {
vec!["--lsp".into()]
}
}

impl Standard {
pub fn new() -> Self {
Self {}
}

pub fn language_server_command(
&mut self,
language_server_id: &LanguageServerId,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
let binary = self.language_server_binary(language_server_id, worktree)?;

Ok(zed::Command {
command: binary.path,
args: binary.args.unwrap_or(Self::get_executable_args()),
env: Default::default(),
})
}
}

#[cfg(test)]
mod tests {
use crate::language_servers::{LanguageServer, Standard};

#[test]
fn test_server_id() {
assert_eq!(Standard::SERVER_ID, "standardrb");
}

#[test]
fn test_executable_name() {
assert_eq!(Standard::EXECUTABLE_NAME, "standardrb");
}

#[test]
fn test_executable_args() {
assert_eq!(Standard::get_executable_args(), vec!["--lsp"]);
}

#[test]
fn test_default_use_bundler() {
assert!(Standard::default_use_bundler());
}
}
7 changes: 6 additions & 1 deletion src/ruby.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod language_servers;
use language_servers::{LanguageServer, Rubocop, RubyLsp, Solargraph};
use language_servers::{LanguageServer, Rubocop, RubyLsp, Solargraph, Standard};

use zed::lsp::{Completion, Symbol};
use zed::settings::LspSettings;
Expand All @@ -11,6 +11,7 @@ struct RubyExtension {
solargraph: Option<Solargraph>,
ruby_lsp: Option<RubyLsp>,
rubocop: Option<Rubocop>,
standard: Option<Standard>,
}

impl zed::Extension for RubyExtension {
Expand All @@ -36,6 +37,10 @@ impl zed::Extension for RubyExtension {
let rubocop = self.rubocop.get_or_insert_with(Rubocop::new);
rubocop.language_server_command(language_server_id, worktree)
}
Standard::SERVER_ID => {
let standard = self.standard.get_or_insert_with(Standard::new);
standard.language_server_command(language_server_id, worktree)
}
language_server_id => Err(format!("unknown language server: {language_server_id}")),
}
}
Expand Down