Skip to content

Commit 92d5d93

Browse files
committed
Build ion-lsp before cargo test in CI so LSP protocol tests can spawn the server. Make the test helper find the binary under debug or release with a clearer error when it is missing.
1 parent 7539d3c commit 92d5d93

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- uses: Swatinem/rust-cache@v2
2222

2323
- run: cargo fmt --check
24+
- run: cargo build --bin ion-lsp
2425
- run: cargo test
2526
- run: cargo clippy -- -D warnings
2627

src/lsp/tests.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,29 @@ impl LspSession {
162162

163163
fn ion_lsp_binary() -> PathBuf {
164164
if let Ok(path) = std::env::var("CARGO_BIN_EXE_ion-lsp") {
165-
return PathBuf::from(path);
165+
let path = PathBuf::from(&path);
166+
if path.exists() {
167+
return path;
168+
}
166169
}
167-
let profile = if cfg!(debug_assertions) {
168-
"debug"
169-
} else {
170-
"release"
171-
};
172-
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
173-
.join("target")
174-
.join(profile)
175-
.join(format!("ion-lsp{}", std::env::consts::EXE_SUFFIX))
170+
171+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
172+
let target_dir = std::env::var("CARGO_TARGET_DIR")
173+
.map(PathBuf::from)
174+
.unwrap_or_else(|_| manifest_dir.join("target"));
175+
let exe = format!("ion-lsp{}", std::env::consts::EXE_SUFFIX);
176+
177+
for profile in ["debug", "release"] {
178+
let path = target_dir.join(profile).join(&exe);
179+
if path.exists() {
180+
return path;
181+
}
182+
}
183+
184+
panic!(
185+
"ion-lsp binary not found under {}; run `cargo build --bin ion-lsp`",
186+
target_dir.display()
187+
);
176188
}
177189

178190
fn read_lsp_message<R: BufRead>(reader: &mut R) -> std::io::Result<Option<Value>> {

0 commit comments

Comments
 (0)