mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Rename ra_tt -> tt
This commit is contained in:
parent
208b7bd7ba
commit
550d7fbe3c
22 changed files with 77 additions and 77 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -939,8 +939,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"ra_mbe",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"rustc-hash",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -950,11 +950,11 @@ dependencies = [
|
|||
"profile",
|
||||
"ra_cfg",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"rustc-hash",
|
||||
"salsa",
|
||||
"stdx",
|
||||
"test_utils",
|
||||
"tt",
|
||||
"vfs",
|
||||
]
|
||||
|
||||
|
@ -1004,11 +1004,11 @@ dependencies = [
|
|||
"ra_hir_expand",
|
||||
"ra_mbe",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"rustc-hash",
|
||||
"smallvec",
|
||||
"stdx",
|
||||
"test_utils",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1023,9 +1023,9 @@ dependencies = [
|
|||
"ra_mbe",
|
||||
"ra_parser",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"rustc-hash",
|
||||
"test_utils",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1107,10 +1107,10 @@ dependencies = [
|
|||
"log",
|
||||
"ra_parser",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"rustc-hash",
|
||||
"smallvec",
|
||||
"test_utils",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1127,9 +1127,9 @@ dependencies = [
|
|||
"crossbeam-channel",
|
||||
"jod-thread",
|
||||
"log",
|
||||
"ra_tt",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1144,9 +1144,9 @@ dependencies = [
|
|||
"ra_mbe",
|
||||
"ra_proc_macro",
|
||||
"ra_toolchain",
|
||||
"ra_tt",
|
||||
"serde_derive",
|
||||
"test_utils",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1217,14 +1217,6 @@ dependencies = [
|
|||
"home",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ra_tt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"smol_str",
|
||||
"stdx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.3.1"
|
||||
|
@ -1329,7 +1321,6 @@ dependencies = [
|
|||
"ra_syntax",
|
||||
"ra_text_edit",
|
||||
"ra_toolchain",
|
||||
"ra_tt",
|
||||
"rayon",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
|
@ -1337,6 +1328,7 @@ dependencies = [
|
|||
"stdx",
|
||||
"test_utils",
|
||||
"threadpool",
|
||||
"tt",
|
||||
"vfs",
|
||||
"vfs-notify",
|
||||
"winapi 0.3.9",
|
||||
|
@ -1706,6 +1698,14 @@ dependencies = [
|
|||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tt"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"smol_str",
|
||||
"stdx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ungrammar"
|
||||
version = "1.1.1"
|
||||
|
|
|
@ -12,7 +12,7 @@ doctest = false
|
|||
rustc-hash = "1.1.0"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
|
||||
[dev-dependencies]
|
||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
||||
|
|
|
@ -15,7 +15,7 @@ rustc-hash = "1.1.0"
|
|||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_cfg = { path = "../ra_cfg" }
|
||||
profile = { path = "../profile" }
|
||||
ra_tt = { path = "../ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
test_utils = { path = "../test_utils" }
|
||||
vfs = { path = "../vfs" }
|
||||
stdx = { path = "../stdx" }
|
||||
|
|
|
@ -10,8 +10,8 @@ use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
|
|||
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_syntax::SmolStr;
|
||||
use ra_tt::TokenExpander;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use tt::TokenExpander;
|
||||
use vfs::file_set::FileSet;
|
||||
|
||||
pub use vfs::FileId;
|
||||
|
@ -156,7 +156,7 @@ impl CrateGraph {
|
|||
display_name: Option<String>,
|
||||
cfg_options: CfgOptions,
|
||||
env: Env,
|
||||
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
|
||||
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
|
||||
) -> CrateId {
|
||||
let proc_macro =
|
||||
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
|
||||
|
|
|
@ -30,7 +30,7 @@ hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
|
|||
test_utils = { path = "../test_utils" }
|
||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
||||
ra_cfg = { path = "../ra_cfg" }
|
||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
|
||||
[dev-dependencies]
|
||||
expect = { path = "../expect" }
|
||||
|
|
|
@ -18,6 +18,6 @@ ra_db = { path = "../ra_db" }
|
|||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_parser = { path = "../ra_parser" }
|
||||
profile = { path = "../profile" }
|
||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
||||
test_utils = { path = "../test_utils"}
|
||||
|
|
|
@ -11,7 +11,7 @@ doctest = false
|
|||
[dependencies]
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_parser = { path = "../ra_parser" }
|
||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
rustc-hash = "1.1.0"
|
||||
smallvec = "1.2.0"
|
||||
log = "0.4.8"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//! `mbe` (short for Macro By Example) crate contains code for handling
|
||||
//! `macro_rules` macros. It uses `TokenTree` (from `ra_tt` package) as the
|
||||
//! `macro_rules` macros. It uses `TokenTree` (from `tt` package) as the
|
||||
//! interface, although it contains some code to bridge `SyntaxNode`s and
|
||||
//! `TokenTree`s as well!
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
ra_tt = { path = "../ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
log = "0.4.8"
|
||||
|
|
|
@ -9,8 +9,6 @@ mod rpc;
|
|||
mod process;
|
||||
pub mod msg;
|
||||
|
||||
use process::{ProcMacroProcessSrv, ProcMacroProcessThread};
|
||||
use ra_tt::{SmolStr, Subtree};
|
||||
use std::{
|
||||
ffi::OsStr,
|
||||
io,
|
||||
|
@ -18,6 +16,10 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use tt::{SmolStr, Subtree};
|
||||
|
||||
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
|
||||
|
||||
pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -36,12 +38,12 @@ impl PartialEq for ProcMacroProcessExpander {
|
|||
}
|
||||
}
|
||||
|
||||
impl ra_tt::TokenExpander for ProcMacroProcessExpander {
|
||||
impl tt::TokenExpander for ProcMacroProcessExpander {
|
||||
fn expand(
|
||||
&self,
|
||||
subtree: &Subtree,
|
||||
_attr: Option<&Subtree>,
|
||||
) -> Result<Subtree, ra_tt::ExpansionError> {
|
||||
) -> Result<Subtree, tt::ExpansionError> {
|
||||
self.process.custom_derive(&self.dylib_path, subtree, &self.name)
|
||||
}
|
||||
}
|
||||
|
@ -72,10 +74,7 @@ impl ProcMacroClient {
|
|||
ProcMacroClient { kind: ProcMacroClientKind::Dummy }
|
||||
}
|
||||
|
||||
pub fn by_dylib_path(
|
||||
&self,
|
||||
dylib_path: &Path,
|
||||
) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> {
|
||||
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc<dyn tt::TokenExpander>)> {
|
||||
match &self.kind {
|
||||
ProcMacroClientKind::Dummy => vec![],
|
||||
ProcMacroClientKind::Process { process, .. } => {
|
||||
|
@ -94,7 +93,7 @@ impl ProcMacroClient {
|
|||
match kind {
|
||||
ProcMacroKind::CustomDerive => {
|
||||
let name = SmolStr::new(&name);
|
||||
let expander: Arc<dyn ra_tt::TokenExpander> =
|
||||
let expander: Arc<dyn tt::TokenExpander> =
|
||||
Arc::new(ProcMacroProcessExpander {
|
||||
process: process.clone(),
|
||||
name: name.clone(),
|
||||
|
|
|
@ -5,11 +5,12 @@ use std::{
|
|||
io::{self, BufRead, Write},
|
||||
};
|
||||
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
rpc::{ListMacrosResult, ListMacrosTask},
|
||||
ExpansionResult, ExpansionTask,
|
||||
};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum Request {
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
//! Handle process life-time and message passing for proc-macro client
|
||||
|
||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||
use ra_tt::Subtree;
|
||||
|
||||
use crate::msg::{ErrorCode, Message, Request, Response, ResponseError};
|
||||
use crate::rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind};
|
||||
|
||||
use io::{BufRead, BufReader};
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
ffi::{OsStr, OsString},
|
||||
io::{self, Write},
|
||||
io::{self, BufRead, BufReader, Write},
|
||||
path::{Path, PathBuf},
|
||||
process::{Child, Command, Stdio},
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
|
||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||
use tt::Subtree;
|
||||
|
||||
use crate::{
|
||||
msg::{ErrorCode, Message, Request, Response, ResponseError},
|
||||
rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind},
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct ProcMacroProcessSrv {
|
||||
inner: Option<Weak<Sender<Task>>>,
|
||||
|
@ -50,7 +51,7 @@ impl ProcMacroProcessSrv {
|
|||
pub fn find_proc_macros(
|
||||
&self,
|
||||
dylib_path: &Path,
|
||||
) -> Result<Vec<(String, ProcMacroKind)>, ra_tt::ExpansionError> {
|
||||
) -> Result<Vec<(String, ProcMacroKind)>, tt::ExpansionError> {
|
||||
let task = ListMacrosTask { lib: dylib_path.to_path_buf() };
|
||||
|
||||
let result: ListMacrosResult = self.send_task(Request::ListMacro(task))?;
|
||||
|
@ -62,7 +63,7 @@ impl ProcMacroProcessSrv {
|
|||
dylib_path: &Path,
|
||||
subtree: &Subtree,
|
||||
derive_name: &str,
|
||||
) -> Result<Subtree, ra_tt::ExpansionError> {
|
||||
) -> Result<Subtree, tt::ExpansionError> {
|
||||
let task = ExpansionTask {
|
||||
macro_body: subtree.clone(),
|
||||
macro_name: derive_name.to_string(),
|
||||
|
@ -74,38 +75,35 @@ impl ProcMacroProcessSrv {
|
|||
Ok(result.expansion)
|
||||
}
|
||||
|
||||
pub fn send_task<R>(&self, req: Request) -> Result<R, ra_tt::ExpansionError>
|
||||
pub fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
|
||||
where
|
||||
R: TryFrom<Response, Error = &'static str>,
|
||||
{
|
||||
let sender = match &self.inner {
|
||||
None => return Err(ra_tt::ExpansionError::Unknown("No sender is found.".to_string())),
|
||||
None => return Err(tt::ExpansionError::Unknown("No sender is found.".to_string())),
|
||||
Some(it) => it,
|
||||
};
|
||||
|
||||
let (result_tx, result_rx) = bounded(0);
|
||||
let sender = match sender.upgrade() {
|
||||
None => {
|
||||
return Err(ra_tt::ExpansionError::Unknown("Proc macro process is closed.".into()))
|
||||
return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into()))
|
||||
}
|
||||
Some(it) => it,
|
||||
};
|
||||
sender.send(Task { req, result_tx }).unwrap();
|
||||
let res = result_rx
|
||||
.recv()
|
||||
.map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?;
|
||||
.map_err(|_| tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?;
|
||||
|
||||
match res {
|
||||
Some(Response::Error(err)) => {
|
||||
return Err(ra_tt::ExpansionError::ExpansionError(err.message));
|
||||
return Err(tt::ExpansionError::ExpansionError(err.message));
|
||||
}
|
||||
Some(res) => Ok(res.try_into().map_err(|err| {
|
||||
ra_tt::ExpansionError::Unknown(format!(
|
||||
"Fail to get response, reason : {:#?} ",
|
||||
err
|
||||
))
|
||||
tt::ExpansionError::Unknown(format!("Fail to get response, reason : {:#?} ", err))
|
||||
})?),
|
||||
None => Err(ra_tt::ExpansionError::Unknown("Empty result".into())),
|
||||
None => Err(tt::ExpansionError::Unknown("Empty result".into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
//! Data struture serialization related stuff for RPC
|
||||
//!
|
||||
//! Defines all necessary rpc serialization data structures,
|
||||
//! which includes `ra_tt` related data and some task messages.
|
||||
//! Although adding `Serialize` and `Deserialize` traits to `ra_tt` directly seems
|
||||
//! to be much easier, we deliberately duplicate `ra_tt` structs with `#[serde(with = "XXDef")]`
|
||||
//! which includes `tt` related data and some task messages.
|
||||
//! Although adding `Serialize` and `Deserialize` traits to `tt` directly seems
|
||||
//! to be much easier, we deliberately duplicate `tt` structs with `#[serde(with = "XXDef")]`
|
||||
//! for separation of code responsibility.
|
||||
|
||||
use ra_tt::{
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tt::{
|
||||
Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, SmolStr, Spacing, Subtree, TokenId,
|
||||
TokenTree,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct ListMacrosTask {
|
||||
|
|
|
@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
ra_tt = { path = "../ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
ra_mbe = { path = "../ra_mbe" }
|
||||
ra_proc_macro = { path = "../ra_proc_macro" }
|
||||
goblin = "0.2.1"
|
||||
|
|
|
@ -128,9 +128,9 @@ impl Expander {
|
|||
pub fn expand(
|
||||
&self,
|
||||
macro_name: &str,
|
||||
macro_body: &ra_tt::Subtree,
|
||||
attributes: Option<&ra_tt::Subtree>,
|
||||
) -> Result<ra_tt::Subtree, bridge::PanicMessage> {
|
||||
macro_body: &tt::Subtree,
|
||||
attributes: Option<&tt::Subtree>,
|
||||
) -> Result<tt::Subtree, bridge::PanicMessage> {
|
||||
let parsed_body = TokenStream::with_subtree(macro_body.clone());
|
||||
|
||||
let parsed_attributes = attributes
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//!
|
||||
//! But we adapt it to better fit RA needs:
|
||||
//!
|
||||
//! * We use `ra_tt` for proc-macro `TokenStream` server, it is easier to manipulate and interact with
|
||||
//! * We use `tt` for proc-macro `TokenStream` server, it is easier to manipulate and interact with
|
||||
//! RA than `proc-macro2` token stream.
|
||||
//! * By **copying** the whole rustc `lib_proc_macro` code, we are able to build this with `stable`
|
||||
//! rustc rather than `unstable`. (Although in gerenal ABI compatibility is still an issue)
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
//! Rustc proc-macro server implementation with ra_tt
|
||||
//! Rustc proc-macro server implementation with tt
|
||||
//!
|
||||
//! Based on idea from https://github.com/fedochet/rust-proc-macro-expander
|
||||
//! The lib-proc-macro server backend is `TokenStream`-agnostic, such that
|
||||
//! we could provide any TokenStream implementation.
|
||||
//! The original idea from fedochet is using proc-macro2 as backend,
|
||||
//! we use ra_tt instead for better intergation with RA.
|
||||
//! we use tt instead for better intergation with RA.
|
||||
//!
|
||||
//! FIXME: No span and source file information is implemented yet
|
||||
|
||||
use crate::proc_macro::bridge::{self, server};
|
||||
use ra_tt as tt;
|
||||
|
||||
use std::collections::{Bound, HashMap};
|
||||
use std::hash::Hash;
|
||||
|
@ -153,9 +152,10 @@ pub struct TokenStreamBuilder {
|
|||
|
||||
/// Public implementation details for the `TokenStream` type, such as iterators.
|
||||
pub mod token_stream {
|
||||
use super::{tt, TokenStream, TokenTree};
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::{TokenStream, TokenTree};
|
||||
|
||||
/// An iterator over `TokenStream`'s `TokenTree`s.
|
||||
/// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups,
|
||||
/// and returns whole groups as token trees.
|
||||
|
|
|
@ -61,4 +61,4 @@ winapi = "0.3.8"
|
|||
expect = { path = "../expect" }
|
||||
test_utils = { path = "../test_utils" }
|
||||
mbe = { path = "../ra_mbe", package = "ra_mbe" }
|
||||
tt = { path = "../ra_tt", package = "ra_tt" }
|
||||
tt = { path = "../tt" }
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "ra_tt"
|
||||
version = "0.1.0"
|
||||
authors = ["rust-analyzer developers"]
|
||||
name = "tt"
|
||||
version = "0.0.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
authors = ["rust-analyzer developers"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
stdx = { path = "../stdx" }
|
||||
# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here
|
||||
# to reduce number of compilations
|
||||
smol_str = { version = "0.1.15", features = ["serde"] }
|
||||
|
||||
stdx = { path = "../stdx" }
|
|
@ -200,7 +200,7 @@ impl TidyDocs {
|
|||
"profile",
|
||||
"ra_project_model",
|
||||
"ra_syntax",
|
||||
"ra_tt",
|
||||
"tt",
|
||||
"ra_hir_ty",
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue