mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
Auto merge of #14100 - Veykril:load_cargo-proc-macro-srv-config, r=Veykril
Allow specifying what proc-macro server to run in rust_analyzer::load_cargo API Closes https://github.com/rust-lang/rust-analyzer/issues/10516
This commit is contained in:
commit
512a93ac94
7 changed files with 42 additions and 29 deletions
|
@ -33,7 +33,7 @@ use vfs::{AbsPathBuf, Vfs, VfsPath};
|
|||
|
||||
use crate::cli::{
|
||||
flags::{self, OutputFormat},
|
||||
load_cargo::{load_workspace, LoadCargoConfig},
|
||||
load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice},
|
||||
print_memory_usage,
|
||||
progress_report::ProgressReport,
|
||||
report_metric, Result, Verbosity,
|
||||
|
@ -59,11 +59,6 @@ impl flags::AnalysisStats {
|
|||
true => None,
|
||||
false => Some(RustcSource::Discover),
|
||||
};
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: !self.disable_build_scripts,
|
||||
with_proc_macro: !self.disable_proc_macros,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let no_progress = &|_| ();
|
||||
|
||||
let mut db_load_sw = self.stop_watch();
|
||||
|
@ -73,6 +68,11 @@ impl flags::AnalysisStats {
|
|||
|
||||
let mut workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
|
||||
let metadata_time = db_load_sw.elapsed();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: !self.disable_build_scripts,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: false,
|
||||
};
|
||||
|
||||
let build_scripts_time = if self.disable_build_scripts {
|
||||
None
|
||||
|
|
|
@ -9,7 +9,7 @@ use ide_db::base_db::SourceDatabaseExt;
|
|||
|
||||
use crate::cli::{
|
||||
flags,
|
||||
load_cargo::{load_workspace_at, LoadCargoConfig},
|
||||
load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice},
|
||||
};
|
||||
|
||||
impl flags::Diagnostics {
|
||||
|
@ -17,7 +17,7 @@ impl flags::Diagnostics {
|
|||
let cargo_config = Default::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: !self.disable_build_scripts,
|
||||
with_proc_macro: !self.disable_proc_macros,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let (host, _vfs, _proc_macro) =
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Loads a Cargo project into a static instance of analysis, without support
|
||||
//! for incorporating changes.
|
||||
use std::{path::Path, sync::Arc};
|
||||
use std::{convert::identity, path::Path, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use crossbeam_channel::{unbounded, Receiver};
|
||||
|
@ -17,10 +17,17 @@ use crate::reload::{load_proc_macro, ProjectFolders, SourceRootConfig};
|
|||
// what otherwise would be `pub(crate)` has to be `pub` here instead.
|
||||
pub struct LoadCargoConfig {
|
||||
pub load_out_dirs_from_check: bool,
|
||||
pub with_proc_macro: bool,
|
||||
pub with_proc_macro_server: ProcMacroServerChoice,
|
||||
pub prefill_caches: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ProcMacroServerChoice {
|
||||
Sysroot,
|
||||
Explicit(AbsPathBuf, Vec<String>),
|
||||
None,
|
||||
}
|
||||
|
||||
// Note: Since this function is used by external tools that use rust-analyzer as a library
|
||||
// what otherwise would be `pub(crate)` has to be `pub` here instead.
|
||||
pub fn load_workspace_at(
|
||||
|
@ -59,15 +66,17 @@ pub fn load_workspace(
|
|||
Box::new(loader)
|
||||
};
|
||||
|
||||
let proc_macro_client = if load_config.with_proc_macro {
|
||||
let (server_path, args): (_, &[_]) = match ws.find_sysroot_proc_macro_srv() {
|
||||
Some(server_path) => (server_path, &[]),
|
||||
None => (AbsPathBuf::assert(std::env::current_exe()?), &["proc-macro"]),
|
||||
};
|
||||
|
||||
ProcMacroServer::spawn(server_path, args).map_err(|e| e.to_string())
|
||||
} else {
|
||||
Err("proc macro server disabled".to_owned())
|
||||
let proc_macro_client = match &load_config.with_proc_macro_server {
|
||||
ProcMacroServerChoice::Sysroot => ws
|
||||
.find_sysroot_proc_macro_srv()
|
||||
.ok_or_else(|| "failed to find sysroot proc-macro server".to_owned())
|
||||
.and_then(|it| {
|
||||
ProcMacroServer::spawn(it, identity::<&[&str]>(&[])).map_err(|e| e.to_string())
|
||||
}),
|
||||
ProcMacroServerChoice::Explicit(path, args) => {
|
||||
ProcMacroServer::spawn(path.clone(), args).map_err(|e| e.to_string())
|
||||
}
|
||||
ProcMacroServerChoice::None => Err("proc macro server disabled".to_owned()),
|
||||
};
|
||||
|
||||
let crate_graph = ws.to_crate_graph(
|
||||
|
@ -157,7 +166,7 @@ mod tests {
|
|||
let cargo_config = CargoConfig::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: false,
|
||||
with_proc_macro: false,
|
||||
with_proc_macro_server: ProcMacroServerChoice::None,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let (host, _vfs, _proc_macro) =
|
||||
|
|
|
@ -15,6 +15,7 @@ use lsp_types::{self, lsif};
|
|||
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
|
||||
use vfs::{AbsPathBuf, Vfs};
|
||||
|
||||
use crate::cli::load_cargo::ProcMacroServerChoice;
|
||||
use crate::cli::{
|
||||
flags,
|
||||
load_cargo::{load_workspace, LoadCargoConfig},
|
||||
|
@ -291,7 +292,7 @@ impl flags::Lsif {
|
|||
let no_progress = &|_| ();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: true,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let path = AbsPathBuf::assert(env::current_dir()?.join(&self.path));
|
||||
|
|
|
@ -5,7 +5,10 @@ use std::{
|
|||
time::Instant,
|
||||
};
|
||||
|
||||
use crate::line_index::{LineEndings, LineIndex, PositionEncoding};
|
||||
use crate::{
|
||||
cli::load_cargo::ProcMacroServerChoice,
|
||||
line_index::{LineEndings, LineIndex, PositionEncoding},
|
||||
};
|
||||
use hir::Name;
|
||||
use ide::{
|
||||
LineCol, MonikerDescriptorKind, StaticIndex, StaticIndexedFile, TextRange, TokenId,
|
||||
|
@ -31,7 +34,7 @@ impl flags::Scip {
|
|||
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: true,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: true,
|
||||
};
|
||||
let path = vfs::AbsPathBuf::assert(env::current_dir()?.join(&self.path));
|
||||
|
|
|
@ -5,7 +5,7 @@ use project_model::CargoConfig;
|
|||
|
||||
use crate::cli::{
|
||||
flags,
|
||||
load_cargo::{load_workspace_at, LoadCargoConfig},
|
||||
load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice},
|
||||
Result,
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@ impl flags::Ssr {
|
|||
let cargo_config = CargoConfig::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: true,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let (host, vfs, _proc_macro) = load_workspace_at(
|
||||
|
@ -51,7 +51,7 @@ impl flags::Search {
|
|||
let cargo_config = CargoConfig::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: true,
|
||||
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
|
||||
prefill_caches: false,
|
||||
};
|
||||
let (host, _vfs, _proc_macro) = load_workspace_at(
|
||||
|
|
|
@ -21,7 +21,7 @@ use project_model::CargoConfig;
|
|||
use test_utils::project_root;
|
||||
use vfs::{AbsPathBuf, VfsPath};
|
||||
|
||||
use crate::cli::load_cargo::{load_workspace_at, LoadCargoConfig};
|
||||
use crate::cli::load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
||||
|
||||
#[test]
|
||||
fn integrated_highlighting_benchmark() {
|
||||
|
@ -36,7 +36,7 @@ fn integrated_highlighting_benchmark() {
|
|||
let cargo_config = CargoConfig::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: false,
|
||||
with_proc_macro_server: ProcMacroServerChoice::None,
|
||||
prefill_caches: false,
|
||||
};
|
||||
|
||||
|
@ -90,7 +90,7 @@ fn integrated_completion_benchmark() {
|
|||
let cargo_config = CargoConfig::default();
|
||||
let load_cargo_config = LoadCargoConfig {
|
||||
load_out_dirs_from_check: true,
|
||||
with_proc_macro: false,
|
||||
with_proc_macro_server: ProcMacroServerChoice::None,
|
||||
prefill_caches: true,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue