mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Simplify
This commit is contained in:
parent
9d09bc0619
commit
7c7c0cbffb
7 changed files with 17 additions and 19 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1337,7 +1337,6 @@ dependencies = [
|
||||||
"stdx",
|
"stdx",
|
||||||
"text-size",
|
"text-size",
|
||||||
"tracing",
|
"tracing",
|
||||||
"triomphe",
|
|
||||||
"tt",
|
"tt",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ doctest = false
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json = { workspace = true, features = ["unbounded_depth"] }
|
serde_json = { workspace = true, features = ["unbounded_depth"] }
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
triomphe.workspace = true
|
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
indexmap.workspace = true
|
indexmap.workspace = true
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,7 @@ pub mod msg;
|
||||||
mod process;
|
mod process;
|
||||||
|
|
||||||
use base_db::Env;
|
use base_db::Env;
|
||||||
use indexmap::IndexSet;
|
|
||||||
use paths::{AbsPath, AbsPathBuf};
|
use paths::{AbsPath, AbsPathBuf};
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use span::Span;
|
use span::Span;
|
||||||
use std::{fmt, io, sync::Arc};
|
use std::{fmt, io, sync::Arc};
|
||||||
use tt::SmolStr;
|
use tt::SmolStr;
|
||||||
|
@ -21,7 +19,8 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::{
|
use crate::{
|
||||||
msg::{
|
msg::{
|
||||||
deserialize_span_data_index_map, flat::serialize_span_data_index_map, ExpandMacro,
|
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,
|
process::ProcMacroProcessSrv,
|
||||||
};
|
};
|
||||||
|
@ -101,7 +100,8 @@ impl ProcMacroServer {
|
||||||
/// Spawns an external process as the proc macro server and returns a client connected to it.
|
/// Spawns an external process as the proc macro server and returns a client connected to it.
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
process_path: &AbsPath,
|
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> {
|
) -> io::Result<ProcMacroServer> {
|
||||||
let process = ProcMacroProcessSrv::run(process_path, env)?;
|
let process = ProcMacroProcessSrv::run(process_path, env)?;
|
||||||
Ok(ProcMacroServer { process: Arc::new(process), path: process_path.to_owned() })
|
Ok(ProcMacroServer { process: Arc::new(process), path: process_path.to_owned() })
|
||||||
|
@ -151,7 +151,7 @@ impl ProcMacro {
|
||||||
let version = self.process.version();
|
let version = self.process.version();
|
||||||
let current_dir = env.get("CARGO_MANIFEST_DIR");
|
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 def_site = span_data_table.insert_full(def_site).0;
|
||||||
let call_site = span_data_table.insert_full(call_site).0;
|
let call_site = span_data_table.insert_full(call_site).0;
|
||||||
let mixed_site = span_data_table.insert_full(mixed_site).0;
|
let mixed_site = span_data_table.insert_full(mixed_site).0;
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use indexmap::IndexSet;
|
|
||||||
use la_arena::RawIdx;
|
use la_arena::RawIdx;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -46,7 +45,8 @@ use text_size::TextRange;
|
||||||
|
|
||||||
use crate::msg::ENCODE_CLOSE_SPAN_VERSION;
|
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> {
|
pub fn serialize_span_data_index_map(map: &SpanDataIndexMap) -> Vec<u32> {
|
||||||
map.iter()
|
map.iter()
|
||||||
|
@ -328,7 +328,7 @@ impl InternableSpan for TokenId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl InternableSpan for Span {
|
impl InternableSpan for Span {
|
||||||
type Table = IndexSet<Span>;
|
type Table = SpanDataIndexMap;
|
||||||
fn token_id_of(table: &mut Self::Table, span: Self) -> TokenId {
|
fn token_id_of(table: &mut Self::Table, span: Self) -> TokenId {
|
||||||
TokenId(table.insert_full(span).0 as u32)
|
TokenId(table.insert_full(span).0 as u32)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use paths::AbsPath;
|
use paths::AbsPath;
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use stdx::JodChild;
|
use stdx::JodChild;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -36,10 +35,11 @@ struct ProcessSrvState {
|
||||||
impl ProcMacroProcessSrv {
|
impl ProcMacroProcessSrv {
|
||||||
pub(crate) fn run(
|
pub(crate) fn run(
|
||||||
process_path: &AbsPath,
|
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> {
|
) -> io::Result<ProcMacroProcessSrv> {
|
||||||
let create_srv = |null_stderr| {
|
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");
|
let (stdin, stdout) = process.stdio().expect("couldn't access child stdio");
|
||||||
|
|
||||||
io::Result::Ok(ProcMacroProcessSrv {
|
io::Result::Ok(ProcMacroProcessSrv {
|
||||||
|
@ -158,7 +158,7 @@ struct Process {
|
||||||
impl Process {
|
impl Process {
|
||||||
fn run(
|
fn run(
|
||||||
path: &AbsPath,
|
path: &AbsPath,
|
||||||
env: &FxHashMap<String, String>,
|
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
|
||||||
null_stderr: bool,
|
null_stderr: bool,
|
||||||
) -> io::Result<Process> {
|
) -> io::Result<Process> {
|
||||||
let child = JodChild(mk_child(path, env, null_stderr)?);
|
let child = JodChild(mk_child(path, env, null_stderr)?);
|
||||||
|
@ -176,7 +176,7 @@ impl Process {
|
||||||
|
|
||||||
fn mk_child(
|
fn mk_child(
|
||||||
path: &AbsPath,
|
path: &AbsPath,
|
||||||
env: &FxHashMap<String, String>,
|
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
|
||||||
null_stderr: bool,
|
null_stderr: bool,
|
||||||
) -> io::Result<Child> {
|
) -> io::Result<Child> {
|
||||||
let mut cmd = Command::new(path);
|
let mut cmd = Command::new(path);
|
||||||
|
|
|
@ -8,8 +8,6 @@ extern crate rustc_driver as _;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use proc_macro_api::msg::ServerConfig;
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
|
let v = std::env::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
|
||||||
match v.as_deref() {
|
match v.as_deref() {
|
||||||
|
@ -48,7 +46,9 @@ fn run() -> io::Result<()> {
|
||||||
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
|
msg::Response::ApiVersionCheck(proc_macro_api::msg::CURRENT_API_VERSION)
|
||||||
}
|
}
|
||||||
msg::Request::SetConfig(_) => {
|
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)?
|
write_response(res)?
|
||||||
|
|
|
@ -529,7 +529,7 @@ impl GlobalState {
|
||||||
None => ws.find_sysroot_proc_macro_srv()?,
|
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::Cargo { cargo_config_extra_env, .. }
|
||||||
| ProjectWorkspaceKind::DetachedFile {
|
| ProjectWorkspaceKind::DetachedFile {
|
||||||
cargo: Some(_),
|
cargo: Some(_),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue