mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
15b867b5db
commit
b2f6fd4f96
217 changed files with 12639 additions and 3059 deletions
|
@ -206,7 +206,7 @@ fn assert_expand(
|
|||
let cond = cond.clone();
|
||||
let panic_args = itertools::Itertools::intersperse(panic_args.iter().cloned(), comma);
|
||||
quote! {{
|
||||
if !#cond {
|
||||
if !(#cond) {
|
||||
#DOLLAR_CRATE::panic!(##panic_args);
|
||||
}
|
||||
}}
|
||||
|
|
|
@ -771,6 +771,15 @@ impl<T> InFile<Option<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<L, R> InFile<Either<L, R>> {
|
||||
pub fn transpose(self) -> Either<InFile<L>, InFile<R>> {
|
||||
match self.value {
|
||||
Either::Left(l) => Either::Left(InFile::new(self.file_id, l)),
|
||||
Either::Right(r) => Either::Right(InFile::new(self.file_id, r)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> InFile<&'a SyntaxNode> {
|
||||
pub fn ancestors_with_macros(
|
||||
self,
|
||||
|
@ -806,7 +815,7 @@ impl<'a> InFile<&'a SyntaxNode> {
|
|||
/// Falls back to the macro call range if the node cannot be mapped up fully.
|
||||
///
|
||||
/// For attributes and derives, this will point back to the attribute only.
|
||||
/// For the entire item `InFile::use original_file_range_full`.
|
||||
/// For the entire item use [`InFile::original_file_range_full`].
|
||||
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||
match self.file_id.repr() {
|
||||
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
||||
|
@ -821,6 +830,21 @@ impl<'a> InFile<&'a SyntaxNode> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Falls back to the macro call range if the node cannot be mapped up fully.
|
||||
pub fn original_file_range_full(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||
match self.file_id.repr() {
|
||||
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
||||
HirFileIdRepr::MacroFile(mac_file) => {
|
||||
if let Some(res) = self.original_file_range_opt(db) {
|
||||
return res;
|
||||
}
|
||||
// Fall back to whole macro call.
|
||||
let loc = db.lookup_intern_macro_call(mac_file.macro_call_id);
|
||||
loc.kind.original_call_range_with_body(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to map the syntax node back up its macro calls.
|
||||
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
|
||||
match ascend_node_border_tokens(db, self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue