This commit is contained in:
Lukas Wirth 2024-06-30 16:41:52 +02:00
parent 9d09bc0619
commit 7c7c0cbffb
7 changed files with 17 additions and 19 deletions

1
Cargo.lock generated
View file

@ -1337,7 +1337,6 @@ dependencies = [
"stdx",
"text-size",
"tracing",
"triomphe",
"tt",
]

View file

@ -15,7 +15,6 @@ doctest = false
serde.workspace = true
serde_json = { workspace = true, features = ["unbounded_depth"] }
tracing.workspace = true
triomphe.workspace = true
rustc-hash.workspace = true
indexmap.workspace = true

View file

@ -9,9 +9,7 @@ pub mod msg;
mod process;
use base_db::Env;
use indexmap::IndexSet;
use paths::{AbsPath, AbsPathBuf};
use rustc_hash::FxHashMap;
use span::Span;
use std::{fmt, io, sync::Arc};
use tt::SmolStr;
@ -21,7 +19,8 @@ use serde::{Deserialize, Serialize};
use crate::{
msg::{
deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro,
ExpnGlobals, FlatTree, PanicMessage, HAS_GLOBAL_SPANS, RUST_ANALYZER_SPAN_SUPPORT,
ExpnGlobals, FlatTree, PanicMessage, SpanDataIndexMap, HAS_GLOBAL_SPANS,
RUST_ANALYZER_SPAN_SUPPORT,
},
process::ProcMacroProcessSrv,
};
@ -101,7 +100,8 @@ impl ProcMacroServer {
/// Spawns an external process as the proc macro server and returns a client connected to it.
pub fn spawn(
process_path: &AbsPath,
env: &FxHashMap<String, String>,
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
+ Clone,
) -> io::Result<ProcMacroServer> {
let process = ProcMacroProcessSrv::run(process_path, env)?;
Ok(ProcMacroServer { process: Arc::new(process), path: process_path.to_owned() })
@ -151,7 +151,7 @@ impl ProcMacro {
let version = self.process.version();
let current_dir = env.get("CARGO_MANIFEST_DIR");
let mut span_data_table = IndexSet::default();
let mut span_data_table = SpanDataIndexMap::default();
let def_site = span_data_table.insert_full(def_site).0;
let call_site = span_data_table.insert_full(call_site).0;
let mixed_site = span_data_table.insert_full(mixed_site).0;

View file

@ -37,7 +37,6 @@
use std::collections::VecDeque;
use indexmap::IndexSet;
use la_arena::RawIdx;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
@ -46,7 +45,8 @@ use text_size::TextRange;
use crate::msg::ENCODE_CLOSE_SPAN_VERSION;
pub type SpanDataIndexMap = IndexSet<Span>;
pub type SpanDataIndexMap =
indexmap::IndexSet<Span, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
pub fn serialize_span_data_index_map(map: &SpanDataIndexMap) -> Vec<u32> {
map.iter()
@ -328,7 +328,7 @@ impl InternableSpan for TokenId {
}
}
impl InternableSpan for Span {
type Table = IndexSet<Span>;
type Table = SpanDataIndexMap;
fn token_id_of(table: &mut Self::Table, span: Self) -> TokenId {
TokenId(table.insert_full(span).0 as u32)
}

View file

@ -7,7 +7,6 @@ use std::{
};
use paths::AbsPath;
use rustc_hash::FxHashMap;
use stdx::JodChild;
use crate::{
@ -36,10 +35,11 @@ struct ProcessSrvState {
impl ProcMacroProcessSrv {
pub(crate) fn run(
process_path: &AbsPath,
env: &FxHashMap<String, String>,
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
+ Clone,
) -> io::Result<ProcMacroProcessSrv> {
let create_srv = |null_stderr| {
let mut process = Process::run(process_path, env, null_stderr)?;
let mut process = Process::run(process_path, env.clone(), null_stderr)?;
let (stdin, stdout) = process.stdio().expect("couldn't access child stdio");
io::Result::Ok(ProcMacroProcessSrv {
@ -158,7 +158,7 @@ struct Process {
impl Process {
fn run(
path: &AbsPath,
env: &FxHashMap<String, String>,
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
null_stderr: bool,
) -> io::Result<Process> {
let child = JodChild(mk_child(path, env, null_stderr)?);
@ -176,7 +176,7 @@ impl Process {
fn mk_child(
path: &AbsPath,
env: &FxHashMap<String, String>,
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
null_stderr: bool,
) -> io::Result<Child> {
let mut cmd = Command::new(path);

View file

@ -8,8 +8,6 @@ extern crate rustc_driver as _;
use std::io;
use proc_macro_api::msg::ServerConfig;
fn main() -> std::io::Result<()> {
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
match v.as_deref() {
@ -48,7 +46,9 @@ fn run() -> io::Result<()> {
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
}
msg::Request::SetConfig(_) => {
msg::Response::SetConfig(ServerConfig { span_mode: msg::SpanMode::Id })
msg::Response::SetConfig(proc_macro_api::msg::ServerConfig {
span_mode: msg::SpanMode::Id,
})
}
};
write_response(res)?

View file

@ -529,7 +529,7 @@ impl GlobalState {
None => ws.find_sysroot_proc_macro_srv()?,
};
let env = match &ws.kind {
let env: FxHashMap<_, _> = match &ws.kind {
ProjectWorkspaceKind::Cargo { cargo_config_extra_env, .. }
| ProjectWorkspaceKind::DetachedFile {
cargo: Some(_),