Skip to content

Commit 6485452

Browse files
committed
Make cargo_ workspace again
1 parent 248a557 commit 6485452

File tree

8 files changed

+190
-157
lines changed

8 files changed

+190
-157
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl flags::Scip {
5151
// FIXME @alibektas : What happens to errors without logging?
5252
error!(?error_sink, "Config Error(s)");
5353
}
54-
let cargo_config = config.cargo();
54+
let cargo_config = config.cargo(None);
5555
let (db, vfs, _) = load_workspace_at(
5656
root.as_path().as_ref(),
5757
&cargo_config,

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 140 additions & 135 deletions
Large diffs are not rendered by default.

src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ impl GlobalStateSnapshot {
631631
file_id_to_url(&self.vfs_read(), id)
632632
}
633633

634+
pub(crate) fn vfs_path_to_file_id(&self, vfs_path: &VfsPath) -> anyhow::Result<FileId> {
635+
vfs_path_to_file_id(&self.vfs_read(), vfs_path)
636+
}
637+
634638
pub(crate) fn file_line_index(&self, file_id: FileId) -> Cancellable<LineIndex> {
635639
let endings = self.vfs.read().1[&file_id];
636640
let index = self.analysis.file_line_index(file_id)?;
@@ -725,3 +729,9 @@ pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> anyhow::Result<FileId
725729
let res = vfs.file_id(&path).ok_or_else(|| anyhow::format_err!("file not found: {path}"))?;
726730
Ok(res)
727731
}
732+
733+
pub(crate) fn vfs_path_to_file_id(vfs: &vfs::Vfs, vfs_path: &VfsPath) -> anyhow::Result<FileId> {
734+
let res =
735+
vfs.file_id(vfs_path).ok_or_else(|| anyhow::format_err!("file not found: {vfs_path}"))?;
736+
Ok(res)
737+
}

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,21 @@ pub(crate) fn handle_did_save_text_document(
145145
state: &mut GlobalState,
146146
params: DidSaveTextDocumentParams,
147147
) -> anyhow::Result<()> {
148-
if state.config.script_rebuild_on_save() && state.build_deps_changed {
149-
state.build_deps_changed = false;
150-
state
151-
.fetch_build_data_queue
152-
.request_op("build_deps_changed - save notification".to_owned(), ());
153-
}
148+
let mut deps_change_processed = false;
154149

155150
if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) {
151+
let snap = state.snapshot();
152+
let file_id = snap.vfs_path_to_file_id(&vfs_path)?;
153+
let sr = snap.analysis.source_root_id(file_id)?;
154+
deps_change_processed = true;
155+
156+
if state.config.script_rebuild_on_save(Some(sr)) && state.build_deps_changed {
157+
state.build_deps_changed = false;
158+
state
159+
.fetch_build_data_queue
160+
.request_op("build_deps_changed - save notification".to_owned(), ());
161+
}
162+
156163
// Re-fetch workspaces if a workspace related file has changed
157164
if let Some(path) = vfs_path.as_path() {
158165
let additional_files = &state
@@ -191,6 +198,17 @@ pub(crate) fn handle_did_save_text_document(
191198
flycheck.restart_workspace(None);
192199
}
193200
}
201+
202+
if !deps_change_processed
203+
&& state.config.script_rebuild_on_save(None)
204+
&& state.build_deps_changed
205+
{
206+
state.build_deps_changed = false;
207+
state
208+
.fetch_build_data_queue
209+
.request_op("build_deps_changed - save notification".to_owned(), ());
210+
}
211+
194212
Ok(())
195213
}
196214

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub(crate) fn handle_run_test(
256256

257257
let handle = CargoTestHandle::new(
258258
test_path,
259-
state.config.cargo_test_options(),
259+
state.config.cargo_test_options(None),
260260
cargo.workspace_root(),
261261
test_target,
262262
state.test_run_sender.clone(),
@@ -2119,7 +2119,7 @@ fn run_rustfmt(
21192119
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
21202120
// FIXME: Set RUSTUP_TOOLCHAIN
21212121
let mut cmd = process::Command::new(toolchain::Tool::Rustfmt.path());
2122-
cmd.envs(snap.config.extra_env());
2122+
cmd.envs(snap.config.extra_env(source_root_id));
21232123
cmd.args(extra_args);
21242124

21252125
if let Some(edition) = edition {
@@ -2177,7 +2177,7 @@ fn run_rustfmt(
21772177
_ => process::Command::new(cmd),
21782178
};
21792179

2180-
cmd.envs(snap.config.extra_env());
2180+
cmd.envs(snap.config.extra_env(source_root_id));
21812181
cmd.args(args);
21822182
cmd
21832183
}

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl GlobalState {
455455
}
456456
}
457457

458-
if self.config.cargo_autoreload_config()
458+
if self.config.cargo_autoreload_config(None)
459459
|| self.config.discover_workspace_config().is_some()
460460
{
461461
if let Some((cause, FetchWorkspaceRequest { path, force_crate_graph_reload })) =
@@ -973,9 +973,9 @@ impl GlobalState {
973973
// When we're running multiple flychecks, we have to include a disambiguator in
974974
// the title, or the editor complains. Note that this is a user-facing string.
975975
let title = if self.flycheck.len() == 1 {
976-
format!("{}", self.config.flycheck())
976+
format!("{}", self.config.flycheck(None))
977977
} else {
978-
format!("{} (#{})", self.config.flycheck(), id + 1)
978+
format!("{} (#{})", self.config.flycheck(None), id + 1)
979979
};
980980
self.report_progress(
981981
&title,

src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl GlobalState {
100100
{
101101
let req = FetchWorkspaceRequest { path: None, force_crate_graph_reload: false };
102102
self.fetch_workspaces_queue.request_op("discovered projects changed".to_owned(), req)
103-
} else if self.config.flycheck() != old_config.flycheck() {
103+
} else if self.config.flycheck(None) != old_config.flycheck(None) {
104104
self.reload_flycheck();
105105
}
106106

@@ -122,7 +122,7 @@ impl GlobalState {
122122
};
123123
let mut message = String::new();
124124

125-
if !self.config.cargo_autoreload()
125+
if !self.config.cargo_autoreload(None)
126126
&& self.is_quiescent()
127127
&& self.fetch_workspaces_queue.op_requested()
128128
&& self.config.discover_workspace_config().is_none()
@@ -264,7 +264,7 @@ impl GlobalState {
264264
.map(ManifestPath::try_from)
265265
.filter_map(Result::ok)
266266
.collect();
267-
let cargo_config = self.config.cargo();
267+
let cargo_config = self.config.cargo(None);
268268
let discover_command = self.config.discover_workspace_config().cloned();
269269
let is_quiescent = !(self.discover_workspace_queue.op_in_progress()
270270
|| self.vfs_progress_config_version < self.vfs_config_version
@@ -357,7 +357,7 @@ impl GlobalState {
357357
pub(crate) fn fetch_build_data(&mut self, cause: Cause) {
358358
info!(%cause, "will fetch build data");
359359
let workspaces = Arc::clone(&self.workspaces);
360-
let config = self.config.cargo();
360+
let config = self.config.cargo(None);
361361
let root_path = self.config.root_path().clone();
362362

363363
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, move |sender| {
@@ -507,7 +507,7 @@ impl GlobalState {
507507
// FIXME: can we abort the build scripts here if they are already running?
508508
self.workspaces = Arc::new(workspaces);
509509

510-
if self.config.run_build_scripts() {
510+
if self.config.run_build_scripts(None) {
511511
self.build_deps_changed = false;
512512
self.fetch_build_data_queue.request_op("workspace updated".to_owned(), ());
513513
}
@@ -627,7 +627,7 @@ impl GlobalState {
627627
..
628628
} => cargo_config_extra_env
629629
.iter()
630-
.chain(self.config.extra_env())
630+
.chain(self.config.extra_env(None))
631631
.map(|(a, b)| (a.clone(), b.clone()))
632632
.chain(
633633
ws.sysroot
@@ -702,7 +702,7 @@ impl GlobalState {
702702
vfs.file_id(&vfs_path)
703703
};
704704

705-
ws_to_crate_graph(&self.workspaces, self.config.extra_env(), load)
705+
ws_to_crate_graph(&self.workspaces, self.config.extra_env(None), load)
706706
};
707707
let mut change = ChangeWithProcMacros::new();
708708
if self.config.expand_proc_macros() {
@@ -791,7 +791,7 @@ impl GlobalState {
791791

792792
fn reload_flycheck(&mut self) {
793793
let _p = tracing::info_span!("GlobalState::reload_flycheck").entered();
794-
let config = self.config.flycheck();
794+
let config = self.config.flycheck(None);
795795
let sender = self.flycheck_sender.clone();
796796
let invocation_strategy = match config {
797797
FlycheckConfig::CargoCommand { .. } => {

src/tools/rust-analyzer/crates/rust-analyzer/src/target_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl CargoTargetSpec {
168168
(Default::default(), Default::default())
169169
};
170170

171-
let cargo_config = snap.config.cargo();
171+
let cargo_config = snap.config.cargo(None);
172172

173173
match &cargo_config.features {
174174
CargoFeatures::All => {

0 commit comments

Comments
 (0)