mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
Sends cwd info for runnables and code lenses
This commit is contained in:
parent
3507bcb97a
commit
7c7cfc5f04
8 changed files with 38 additions and 5 deletions
|
@ -263,6 +263,7 @@ pub fn handle_runnables(
|
|||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let offset = params.position.map(|it| it.conv_with(&line_index));
|
||||
let mut res = Vec::new();
|
||||
let workspace_root = world.workspace_root_for(file_id);
|
||||
for runnable in world.analysis().runnables(file_id)? {
|
||||
if let Some(offset) = offset {
|
||||
if !runnable.range.contains_inclusive(offset) {
|
||||
|
@ -287,6 +288,7 @@ pub fn handle_runnables(
|
|||
m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
|
||||
m
|
||||
},
|
||||
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
|
||||
};
|
||||
res.push(r);
|
||||
}
|
||||
|
@ -309,6 +311,7 @@ pub fn handle_runnables(
|
|||
bin: "cargo".to_string(),
|
||||
args: check_args,
|
||||
env: FxHashMap::default(),
|
||||
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
|
||||
});
|
||||
Ok(res)
|
||||
}
|
||||
|
@ -627,6 +630,7 @@ pub fn handle_code_lens(
|
|||
let line_index = world.analysis().file_line_index(file_id);
|
||||
|
||||
let mut lenses: Vec<CodeLens> = Default::default();
|
||||
let workspace_root = world.workspace_root_for(file_id);
|
||||
|
||||
// Gather runnables
|
||||
for runnable in world.analysis().runnables(file_id)? {
|
||||
|
@ -647,6 +651,7 @@ pub fn handle_code_lens(
|
|||
bin: "cargo".into(),
|
||||
args,
|
||||
env: Default::default(),
|
||||
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
|
||||
};
|
||||
|
||||
let lens = CodeLens {
|
||||
|
|
|
@ -163,6 +163,7 @@ pub struct Runnable {
|
|||
pub bin: String,
|
||||
pub args: Vec<String>,
|
||||
pub env: FxHashMap<String, String>,
|
||||
pub cwd: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
|
@ -195,4 +195,9 @@ impl ServerWorld {
|
|||
res.push_str(&self.analysis.status());
|
||||
res
|
||||
}
|
||||
|
||||
pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> {
|
||||
let path = self.vfs.read().file2path(VfsFile(file_id.0.into()));
|
||||
self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue