Skip to content

Conversation

@A4-Tacks
Copy link
Member

@A4-Tacks A4-Tacks commented Sep 25, 2025

Close #11400

Example

macro_rules! foo {
    ($($x:$0)*) => ();
}

Completion items:

ba block
ba expr
ba expr_2021
ba ident
ba item
ba lifetime
ba literal
ba meta
ba pat
ba pat_param
ba path
ba stmt
ba tt
ba ty
ba vis

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2025
@A4-Tacks A4-Tacks force-pushed the comp-macro-segment branch 3 times, most recently from 2e8a2f9 to b4eae3b Compare September 25, 2025 12:10
@A4-Tacks A4-Tacks requested a review from Veykril October 27, 2025 07:05
@A4-Tacks
Copy link
Member Author

A4-Tacks commented Nov 3, 2025

r? @Veykril

Example
---
```rust
macro_rules! foo {
    ($($x:$0)*) => ();
}
```

**Completion items**:

```text
ba block
ba expr
ba expr_2021
ba ident
ba item
ba lifetime
ba literal
ba meta
ba pat
ba pat_param
ba path
ba stmt
ba tt
ba ty
ba vis
```
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor question but otherwise looks good to me!

}

pub fn is_in_macro_matcher(token: &SyntaxToken) -> bool {
let Some(macro_def) = token.parent_ancestors().find_map(ast::Macro::cast) else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(might have errors)

Suggested change
let Some(macro_def) = token.parent_ancestors().find_map(ast::Macro::cast) else {
let Some(Either::Right(macro_def)) = token.parent_ancestors().map_while(Either<ast::TokenTree, ast::Macro>::cast).last() else {

Not really too important but this will short circuit a bit faster I think

Comment on lines +513 to +527
} else if p.kind() == SyntaxKind::TOKEN_TREE
&& p.ancestors().any(|it| ast::Macro::can_cast(it.kind()))
{
if let Some([_ident, colon, _name, dollar]) = fake_ident_token
.siblings_with_tokens(Direction::Prev)
.filter(|it| !it.kind().is_trivia())
.take(4)
.collect_array()
&& dollar.kind() == T![$]
&& colon.kind() == T![:]
{
CompletionAnalysis::MacroSegment
} else {
return None;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this re-use the new function in node-ext or is that filtering too aggressively?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an't this re-use the new function in node-ext

New function checks if it is in ($0) => {} instead of () => {$0}

or is that filtering too aggressively?

For $x : ty, filtering whitespaces makes sense

@Veykril Veykril added this pull request to the merge queue Dec 27, 2025
@Veykril Veykril changed the title Add macro segment completion feat: Add macro segment completion Dec 27, 2025
Merged via the queue into rust-lang:master with commit e08a786 Dec 27, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2025
@A4-Tacks A4-Tacks deleted the comp-macro-segment branch December 27, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add macro fragment completions

3 participants