Skip to content

Commit 1383bca

Browse files
committed
internal: Restructure some semantics APIs for virtual macro files
1 parent 1b809b7 commit 1383bca

File tree

12 files changed

+185
-79
lines changed

12 files changed

+185
-79
lines changed

src/tools/rust-analyzer/crates/hir/src/semantics.rs

Lines changed: 152 additions & 67 deletions
Large diffs are not rendered by default.

src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ impl<'db> SourceAnalyzer<'db> {
13031303
false
13041304
}
13051305

1306+
/// Returns the range of the implicit template argument and its resolution at the given `offset`
13061307
pub(crate) fn resolve_offset_in_format_args(
13071308
&self,
13081309
db: &'db dyn HirDatabase,

src/tools/rust-analyzer/crates/ide-db/src/search.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,16 @@ impl<'a> FindUsages<'a> {
961961
// Search for occurrences of the items name
962962
for offset in Self::match_indices(&text, finder, search_range) {
963963
let ret = tree.token_at_offset(offset).any(|token| {
964-
let Some(str_token) = ast::String::cast(token.clone()) else { return false };
965-
if let Some((range, Some(nameres))) =
966-
sema.check_for_format_args_template(token, offset)
964+
if let Some((range, _frange, string_token, Some(nameres))) =
965+
sema.check_for_format_args_template(token.clone(), offset)
967966
{
968-
return self
969-
.found_format_args_ref(file_id, range, str_token, nameres, sink);
967+
return self.found_format_args_ref(
968+
file_id,
969+
range,
970+
string_token,
971+
nameres,
972+
sink,
973+
);
970974
}
971975
false
972976
});

src/tools/rust-analyzer/crates/ide/src/goto_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn goto_definition(
6767
});
6868
}
6969

70-
if let Some((range, resolution)) =
70+
if let Some((range, _, _, resolution)) =
7171
sema.check_for_format_args_template(original_token.clone(), offset)
7272
{
7373
return Some(RangeInfo::new(

src/tools/rust-analyzer/crates/ide/src/goto_type_definition.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ pub(crate) fn goto_type_definition(
5353
}
5454
});
5555
};
56-
if let Some((range, resolution)) = sema.check_for_format_args_template(token.clone(), offset) {
56+
if let Some((range, _, _, resolution)) =
57+
sema.check_for_format_args_template(token.clone(), offset)
58+
{
5759
if let Some(ty) = resolution.and_then(|res| match Definition::from(res) {
5860
Definition::Const(it) => Some(it.ty(db)),
5961
Definition::Static(it) => Some(it.ty(db)),

src/tools/rust-analyzer/crates/ide/src/highlight_related.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn highlight_references(
160160
FilePosition { file_id, offset }: FilePosition,
161161
vfs_file_id: FileId,
162162
) -> Option<Vec<HighlightedRange>> {
163-
let defs = if let Some((range, resolution)) =
163+
let defs = if let Some((range, _, _, resolution)) =
164164
sema.check_for_format_args_template(token.clone(), offset)
165165
{
166166
match resolution.map(Definition::from) {

src/tools/rust-analyzer/crates/ide/src/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn hover_offset(
200200
});
201201
}
202202

203-
if let Some((range, resolution)) =
203+
if let Some((range, _, _, resolution)) =
204204
sema.check_for_format_args_template(original_token.clone(), offset)
205205
{
206206
let res = hover_for_definition(

src/tools/rust-analyzer/crates/ide/src/references.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub(crate) fn find_defs(
200200
)
201201
})?;
202202

203-
if let Some((_, resolution)) = sema.check_for_format_args_template(token.clone(), offset) {
203+
if let Some((.., resolution)) = sema.check_for_format_args_template(token.clone(), offset) {
204204
return resolution.map(Definition::from).map(|it| vec![it]);
205205
}
206206

src/tools/rust-analyzer/crates/ide/src/rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn find_definitions(
203203
) -> RenameResult<impl Iterator<Item = (FileRange, SyntaxKind, Definition)>> {
204204
let token = syntax.token_at_offset(offset).find(|t| matches!(t.kind(), SyntaxKind::STRING));
205205

206-
if let Some((range, Some(resolution))) =
206+
if let Some((range, _, _, Some(resolution))) =
207207
token.and_then(|token| sema.check_for_format_args_template(token, offset))
208208
{
209209
return Ok(vec![(

src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ fn descend_token(
542542

543543
let mut t = None;
544544
let mut r = 0;
545-
sema.descend_into_macros_breakable(token.clone(), |tok, _ctx| {
545+
sema.descend_into_macros_breakable(token.clone().into(), |tok, _ctx| {
546546
// FIXME: Consider checking ctx transparency for being opaque?
547547
let my_rank = ranker.rank_token(&tok.value);
548548

0 commit comments

Comments
 (0)