mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ fn foo() {
|
|||
"args": [ "test", "--", "foo", "--nocapture" ],
|
||||
"bin": "cargo",
|
||||
"env": { "RUST_BACKTRACE": "short" },
|
||||
"cwd": null,
|
||||
"label": "test foo",
|
||||
"range": {
|
||||
"end": { "character": 1, "line": 2 },
|
||||
|
@ -75,6 +76,7 @@ fn foo() {
|
|||
],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"cwd": null,
|
||||
"label": "cargo check --all",
|
||||
"range": {
|
||||
"end": {
|
||||
|
@ -123,7 +125,8 @@ fn test_eggs() {}
|
|||
"range": {
|
||||
"end": { "character": 17, "line": 1 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
}
|
||||
},
|
||||
"cwd": server.path()
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
|
@ -135,6 +138,7 @@ fn test_eggs() {}
|
|||
],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"cwd": server.path(),
|
||||
"label": "cargo check -p foo",
|
||||
"range": {
|
||||
"end": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
fs,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
sync::Once,
|
||||
time::Duration,
|
||||
};
|
||||
|
@ -177,6 +177,10 @@ impl Server {
|
|||
fn send_notification(&self, not: RawNotification) {
|
||||
self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap();
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
self.dir.path()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Server {
|
||||
|
|
|
@ -19,6 +19,7 @@ use crate::Result;
|
|||
pub struct CargoWorkspace {
|
||||
packages: Arena<Package, PackageData>,
|
||||
targets: Arena<Target, TargetData>,
|
||||
pub(crate) workspace_root: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -165,7 +166,7 @@ impl CargoWorkspace {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(CargoWorkspace { packages, targets })
|
||||
Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root })
|
||||
}
|
||||
|
||||
pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a {
|
||||
|
|
|
@ -255,6 +255,18 @@ impl ProjectWorkspace {
|
|||
}
|
||||
crate_graph
|
||||
}
|
||||
|
||||
pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
|
||||
match self {
|
||||
ProjectWorkspace::Cargo { cargo, .. } => {
|
||||
Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root))
|
||||
}
|
||||
ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
|
||||
.iter()
|
||||
.find(|root| path.starts_with(&root.path))
|
||||
.map(|root| root.path.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_rust_project_json(path: &Path) -> Option<PathBuf> {
|
||||
|
|
|
@ -17,6 +17,7 @@ interface Runnable {
|
|||
bin: string;
|
||||
args: string[];
|
||||
env: { [index: string]: string };
|
||||
cwd?: string;
|
||||
}
|
||||
|
||||
class RunnableQuickPick implements vscode.QuickPickItem {
|
||||
|
@ -49,7 +50,7 @@ function createTask(spec: Runnable): vscode.Task {
|
|||
};
|
||||
|
||||
const execOption: vscode.ShellExecutionOptions = {
|
||||
cwd: '.',
|
||||
cwd: spec.cwd || '.',
|
||||
env: definition.env
|
||||
};
|
||||
const exec = new vscode.ShellExecution(
|
||||
|
|
Loading…
Reference in a new issue