Change Runnable.bin -> Runnable.kind
As per matklad, we now pass the responsibility for finding the binary to the frontend. Also, added caching for finding the binary path to reduce the amount of filesystem interactions.
This commit is contained in:
@@ -121,12 +121,21 @@ pub struct RunnablesParams {
|
||||
pub position: Option<Position>,
|
||||
}
|
||||
|
||||
// Must strictly correspond to the executable name
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum RunnableKind {
|
||||
Cargo,
|
||||
Rustc,
|
||||
Rustup,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Runnable {
|
||||
pub range: Range,
|
||||
pub label: String,
|
||||
pub bin: String,
|
||||
pub kind: RunnableKind,
|
||||
pub args: Vec<String>,
|
||||
pub extra_args: Vec<String>,
|
||||
pub env: FxHashMap<String, String>,
|
||||
|
||||
@@ -40,7 +40,6 @@ use crate::{
|
||||
world::WorldSnapshot,
|
||||
LspError, Result,
|
||||
};
|
||||
use anyhow::Context;
|
||||
|
||||
pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
|
||||
let _p = profile("handle_analyzer_status");
|
||||
@@ -427,7 +426,7 @@ pub fn handle_runnables(
|
||||
res.push(lsp_ext::Runnable {
|
||||
range: Default::default(),
|
||||
label: format!("cargo {} -p {}", cmd, spec.package),
|
||||
bin: cargo_path()?,
|
||||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
@@ -439,7 +438,7 @@ pub fn handle_runnables(
|
||||
res.push(lsp_ext::Runnable {
|
||||
range: Default::default(),
|
||||
label: "cargo check --workspace".to_string(),
|
||||
bin: cargo_path()?,
|
||||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: vec!["check".to_string(), "--workspace".to_string()],
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
@@ -450,13 +449,6 @@ pub fn handle_runnables(
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn cargo_path() -> Result<String> {
|
||||
Ok(ra_toolchain::cargo()
|
||||
.to_str()
|
||||
.context("Path to `cargo` executable contains invalid UTF8 characters")?
|
||||
.to_owned())
|
||||
}
|
||||
|
||||
pub fn handle_completion(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_types::CompletionParams,
|
||||
@@ -994,7 +986,7 @@ fn to_lsp_runnable(
|
||||
Ok(lsp_ext::Runnable {
|
||||
range: to_proto::range(&line_index, runnable.range),
|
||||
label,
|
||||
bin: cargo_path()?,
|
||||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args,
|
||||
extra_args,
|
||||
env: {
|
||||
|
||||
Reference in New Issue
Block a user