Rename macro descension functions

This commit is contained in:
Lukas Wirth 2024-08-22 16:18:56 +02:00
parent 64064907ce
commit 354ab7a9e8
7 changed files with 16 additions and 19 deletions

View file

@ -188,7 +188,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
}
/// Find an AstNode by offset inside SyntaxNode, if it is inside an attribte macro call,
/// Find an AstNode by offset inside SyntaxNode, if it is inside an attribute macro call,
/// descend it and find again
// FIXME: Rethink this API
pub fn find_nodes_at_offset_with_descend<'slf, N: AstNode + 'slf>(
@ -550,7 +550,7 @@ impl<'db> SemanticsImpl<'db> {
string: &ast::String,
) -> Option<Vec<(TextRange, Option<PathResolution>)>> {
let quote = string.open_quote_text_range()?;
self.descend_into_macros_ng_b(string.syntax().clone(), |token| {
self.descend_into_macros_breakable(string.syntax().clone(), |token| {
(|| {
let token = token.value;
let string = ast::String::cast(token)?;
@ -577,7 +577,7 @@ impl<'db> SemanticsImpl<'db> {
) -> Option<(TextRange, Option<PathResolution>)> {
let original_string = ast::String::cast(original_token.clone())?;
let quote = original_string.open_quote_text_range()?;
self.descend_into_macros_ng_b(original_token.clone(), |token| {
self.descend_into_macros_breakable(original_token.clone(), |token| {
(|| {
let token = token.value;
self.resolve_offset_in_format_args(
@ -664,7 +664,7 @@ impl<'db> SemanticsImpl<'db> {
res
}
pub fn descend_into_macros_ng(
pub fn descend_into_macros_cb(
&self,
token: SyntaxToken,
mut cb: impl FnMut(InFile<SyntaxToken>),
@ -675,7 +675,7 @@ impl<'db> SemanticsImpl<'db> {
});
}
pub fn descend_into_macros_ng_v(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
pub fn descend_into_macros(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
let mut res = smallvec![];
self.descend_into_macros_impl(token.clone(), &mut |t| {
res.push(t.value);
@ -687,7 +687,7 @@ impl<'db> SemanticsImpl<'db> {
res
}
pub fn descend_into_macros_ng_b<T>(
pub fn descend_into_macros_breakable<T>(
&self,
token: SyntaxToken,
mut cb: impl FnMut(InFile<SyntaxToken>) -> ControlFlow<T>,
@ -702,7 +702,7 @@ impl<'db> SemanticsImpl<'db> {
let text = token.text();
let kind = token.kind();
self.descend_into_macros_ng(token.clone(), |InFile { value, file_id: _ }| {
self.descend_into_macros_cb(token.clone(), |InFile { value, file_id: _ }| {
let mapped_kind = value.kind();
let any_ident_match = || kind.is_any_identifier() && value.kind().is_any_identifier();
let matches = (kind == mapped_kind || any_ident_match()) && text == value.text();
@ -722,7 +722,7 @@ impl<'db> SemanticsImpl<'db> {
let text = token.text();
let kind = token.kind();
self.descend_into_macros_ng_b(token.clone(), |InFile { value, file_id: _ }| {
self.descend_into_macros_breakable(token.clone(), |InFile { value, file_id: _ }| {
let mapped_kind = value.kind();
let any_ident_match = || kind.is_any_identifier() && value.kind().is_any_identifier();
let matches = (kind == mapped_kind || any_ident_match()) && text == value.text();

View file

@ -286,7 +286,7 @@ impl DocCommentToken {
let original_start = doc_token.text_range().start();
let relative_comment_offset = offset - original_start - prefix_len;
sema.descend_into_macros_ng_v(doc_token).into_iter().find_map(|t| {
sema.descend_into_macros(doc_token).into_iter().find_map(|t| {
let (node, descended_prefix_len) = match_ast! {
match t {
ast::Comment(comment) => (t.parent()?, TextSize::try_from(comment.prefix().len()).ok()?),

View file

@ -29,7 +29,7 @@ pub(crate) fn goto_declaration(
.find(|it| matches!(it.kind(), IDENT | T![self] | T![super] | T![crate] | T![Self]))?;
let range = original_token.text_range();
let info: Vec<NavigationTarget> = sema
.descend_into_macros_ng_v(original_token)
.descend_into_macros(original_token)
.iter()
.filter_map(|token| {
let parent = token.parent()?;

View file

@ -83,7 +83,7 @@ pub(crate) fn goto_definition(
}
let navs = sema
.descend_into_macros_ng_v(original_token.clone())
.descend_into_macros(original_token.clone())
.into_iter()
.filter_map(|token| {
let parent = token.parent()?;
@ -248,10 +248,7 @@ pub(crate) fn find_fn_or_blocks(
None
};
sema.descend_into_macros_ng_v(token.clone())
.into_iter()
.filter_map(find_ancestors)
.collect_vec()
sema.descend_into_macros(token.clone()).into_iter().filter_map(find_ancestors).collect_vec()
}
fn nav_for_exit_points(
@ -366,7 +363,7 @@ pub(crate) fn find_loops(
None
};
sema.descend_into_macros_ng_v(token.clone())
sema.descend_into_macros(token.clone())
.into_iter()
.filter_map(find_ancestors)
.collect_vec()

View file

@ -69,7 +69,7 @@ pub(crate) fn goto_type_definition(
}
let range = token.text_range();
sema.descend_into_macros_ng_v(token)
sema.descend_into_macros(token)
.into_iter()
.filter_map(|token| {
let ty = sema

View file

@ -181,7 +181,7 @@ fn hover_simple(
// prefer descending the same token kind in attribute expansions, in normal macros text
// equivalency is more important
let mut descended = vec![];
sema.descend_into_macros_ng(original_token.clone(), |token| {
sema.descend_into_macros_cb(original_token.clone(), |token| {
descended.push(token.value);
});
let descended = || descended.iter();

View file

@ -409,7 +409,7 @@ fn traverse(
let mut r = 0;
// FIXME: Add an extra API that takes the file id of this. That is a simple way
// to prevent us constantly walking up the tree to fetch the file
sema.descend_into_macros_ng_b(token.clone(), |tok| {
sema.descend_into_macros_breakable(token.clone(), |tok| {
let tok = tok.value;
let tok_kind = tok.kind();