mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Unleash macro 2.0 in hightlight and more
This commit is contained in:
parent
a193666361
commit
4520002b63
12 changed files with 49 additions and 31 deletions
|
@ -109,8 +109,7 @@ fn doc_attributes<'node>(
|
|||
ast::Impl(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::SelfType(def))),
|
||||
ast::RecordField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
|
||||
ast::TupleField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
|
||||
ast::MacroRules(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Macro(def))),
|
||||
// ast::MacroDef(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),
|
||||
ast::Macro(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Macro(def))),
|
||||
// ast::Use(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),
|
||||
_ => return None
|
||||
}
|
||||
|
|
|
@ -4,18 +4,18 @@ use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
|
|||
use crate::{HlRange, HlTag};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct MacroRulesHighlighter {
|
||||
pub(super) struct MacroHighlighter {
|
||||
state: Option<MacroMatcherParseState>,
|
||||
}
|
||||
|
||||
impl MacroRulesHighlighter {
|
||||
impl MacroHighlighter {
|
||||
pub(super) fn init(&mut self) {
|
||||
self.state = Some(MacroMatcherParseState::default());
|
||||
}
|
||||
|
||||
pub(super) fn advance(&mut self, token: &SyntaxToken) {
|
||||
if let Some(state) = self.state.as_mut() {
|
||||
update_macro_rules_state(state, token);
|
||||
update_macro_state(state, token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,9 +74,9 @@ impl RuleState {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_macro_rules_state(state: &mut MacroMatcherParseState, tok: &SyntaxToken) {
|
||||
fn update_macro_state(state: &mut MacroMatcherParseState, tok: &SyntaxToken) {
|
||||
if !state.in_invoc_body {
|
||||
if tok.kind() == T!['{'] {
|
||||
if tok.kind() == T!['{'] || tok.kind() == T!['('] {
|
||||
state.in_invoc_body = true;
|
||||
}
|
||||
return;
|
|
@ -41,7 +41,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
|
||||
<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="function attribute">rustc_builtin_macro</span><span class="attribute attribute">]</span>
|
||||
<span class="keyword">macro</span> <span class="unresolved_reference declaration">Copy</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">macro</span> <span class="macro declaration">Copy</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
|
||||
<span class="comment">// Needed for function consuming vs normal</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration">marker</span> <span class="brace">{</span>
|
||||
|
@ -158,6 +158,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="parenthesis">(</span><span class="punctuation">$</span>type<span class="colon">:</span>ty<span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span><span class="punctuation">$</span>type<span class="parenthesis">)</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">macro</span> <span class="macro declaration">with_args</span><span class="parenthesis">(</span><span class="punctuation">$</span>i<span class="colon">:</span>ident<span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="punctuation">$</span>i
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">macro</span> <span class="macro declaration">without_args</span> <span class="brace">{</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>i<span class="colon">:</span>ident<span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="brace">{</span>
|
||||
<span class="punctuation">$</span>i
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="comment">// comment</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"Hello, {}!"</span><span class="comma">,</span> <span class="numeric_literal">92</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
|
|
|
@ -129,6 +129,16 @@ macro_rules! keyword_frag {
|
|||
($type:ty) => ($type)
|
||||
}
|
||||
|
||||
macro with_args($i:ident) {
|
||||
$i
|
||||
}
|
||||
|
||||
macro without_args {
|
||||
($i:ident) => {
|
||||
$i
|
||||
}
|
||||
}
|
||||
|
||||
// comment
|
||||
fn main() {
|
||||
println!("Hello, {}!", 92);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue