Skip to content
Closed
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
47 changes: 35 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct CucumberExtension {
const SERVER_BINARY: &str = "cucumber-language-server";
const SERVER_PATH: &str =
"node_modules/@cucumber/language-server/bin/cucumber-language-server.cjs";
// Use the fork that adds Kotlin support and fixes the reindex crash.
// npm install interprets "user/repo#branch" as a GitHub install; the package
// still installs under node_modules/@cucumber/language-server because that is
// the name in the fork's package.json.
const PACKAGE_NAME: &str = "@cucumber/language-server";

/// Step keywords mapped to their tree-sitter highlight group.
Expand Down Expand Up @@ -43,19 +47,28 @@ impl CucumberExtension {

fn server_script_path(&mut self, id: &zed::LanguageServerId) -> zed::Result<String> {
let server_exists = self.server_exists();
eprintln!("[cucumber] server_script_path: server_exists={server_exists}, did_find_server={}", self.did_find_server);
if self.did_find_server && server_exists {
eprintln!("[cucumber] reusing cached server at {SERVER_PATH}");
return Ok(SERVER_PATH.to_string());
}

zed::set_language_server_installation_status(
id,
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
);

zed::set_language_server_installation_status(
id,
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
);
let version = zed::npm_package_latest_version(PACKAGE_NAME)?;
eprintln!("[cucumber] latest npm version: {version}");

if !server_exists
|| zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version)
{
eprintln!("[cucumber] installing {PACKAGE_NAME}@{version}");
zed::set_language_server_installation_status(
id,
&zed::LanguageServerInstallationStatus::Downloading,
Expand All @@ -64,12 +77,16 @@ impl CucumberExtension {
match result {
Ok(()) => {
if !self.server_exists() {
Err(format!(
let msg = format!(
"installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'",
))?;
);
eprintln!("[cucumber] ERROR: {msg}");
Err(msg)?;
}
eprintln!("[cucumber] npm install succeeded");
}
Err(error) => {
eprintln!("[cucumber] npm install error: {error}");
if !self.server_exists() {
Err(error)?;
}
Expand Down Expand Up @@ -99,21 +116,27 @@ impl zed::Extension for CucumberExtension {
) -> zed::Result<zed::Command> {
let lsp_args = vec!["--stdio".into()];
let (command, args) = match worktree.which(SERVER_BINARY) {
Some(command) => (command, lsp_args),
Some(path) => {
eprintln!("[cucumber] found {SERVER_BINARY} in PATH at: {path}");
(path, lsp_args)
}
None => {
eprintln!("[cucumber] {SERVER_BINARY} not found in PATH, falling back to npm install");
let script_path = self.server_script_path(language_server_id)?;
let mut args = lsp_args.clone();
args.insert(
0,
env::current_dir()
.unwrap()
.join(&script_path)
.to_string_lossy()
.to_string(),
);
(zed::node_binary_path()?, args)
let abs_path = env::current_dir()
.unwrap()
.join(&script_path)
.to_string_lossy()
.to_string();
eprintln!("[cucumber] using script at: {abs_path}");
args.insert(0, abs_path);
let node = zed::node_binary_path()?;
eprintln!("[cucumber] node binary: {node}");
(node, args)
}
};
eprintln!("[cucumber] launching: {command} {}", args.join(" "));
Ok(zed::Command {
command,
args,
Expand Down