-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Add macro segment completion #20741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2e8a2f9 to
b4eae3b
Compare
|
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
```
b4eae3b to
d2cc89f
Compare
Veykril
left a comment
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(might have errors)
| 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
| } 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; | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Close #11400
Example
Completion items: