aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-10-14 21:21:58 +0100
committerLukas Wirth <[email protected]>2020-10-14 21:50:26 +0100
commitbab29e65eb87f4765fb22d58bff723780980eeb6 (patch)
treede74eb9ddc59fd542c6aa5c14e778e1f3560cccf
parent8c6dc5f28a5550acffbbb063335833304dac266d (diff)
Default::default the highlighters
-rw-r--r--crates/ide/src/syntax_highlighting.rs6
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/macro_rules.rs15
3 files changed, 7 insertions, 18 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 8ecaff204..527888306 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -74,7 +74,7 @@ pub(crate) fn highlight(
74 74
75 let mut current_macro_call: Option<ast::MacroCall> = None; 75 let mut current_macro_call: Option<ast::MacroCall> = None;
76 let mut format_string_highlighter = FormatStringHighlighter::default(); 76 let mut format_string_highlighter = FormatStringHighlighter::default();
77 let mut macro_rules_highlighter = MacroRulesHighlighter::new(); 77 let mut macro_rules_highlighter = MacroRulesHighlighter::default();
78 78
79 // Walk all nodes, keeping track of whether we are inside a macro or not. 79 // Walk all nodes, keeping track of whether we are inside a macro or not.
80 // If in macro, expand it first and highlight the expanded code. 80 // If in macro, expand it first and highlight the expanded code.
@@ -125,8 +125,8 @@ pub(crate) fn highlight(
125 WalkEvent::Leave(Some(mc)) => { 125 WalkEvent::Leave(Some(mc)) => {
126 assert!(current_macro_call == Some(mc)); 126 assert!(current_macro_call == Some(mc));
127 current_macro_call = None; 127 current_macro_call = None;
128 format_string_highlighter.reset(); 128 format_string_highlighter = FormatStringHighlighter::default();
129 macro_rules_highlighter.reset(); 129 macro_rules_highlighter = MacroRulesHighlighter::default();
130 } 130 }
131 _ => (), 131 _ => (),
132 } 132 }
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index 3ab01295a..71bde24f0 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -12,10 +12,6 @@ pub(super) struct FormatStringHighlighter {
12} 12}
13 13
14impl FormatStringHighlighter { 14impl FormatStringHighlighter {
15 pub(super) fn reset(&mut self) {
16 self.format_string = None;
17 }
18
19 pub(super) fn check_for_format_string(&mut self, parent: &SyntaxNode) { 15 pub(super) fn check_for_format_string(&mut self, parent: &SyntaxNode) {
20 // Check if macro takes a format string and remember it for highlighting later. 16 // Check if macro takes a format string and remember it for highlighting later.
21 // The macros that accept a format string expand to a compiler builtin macros 17 // The macros that accept a format string expand to a compiler builtin macros
diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs
index 0676e0972..4462af47e 100644
--- a/crates/ide/src/syntax_highlighting/macro_rules.rs
+++ b/crates/ide/src/syntax_highlighting/macro_rules.rs
@@ -3,21 +3,14 @@ use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
3 3
4use crate::{HighlightTag, HighlightedRange}; 4use crate::{HighlightTag, HighlightedRange};
5 5
6#[derive(Default)]
6pub(super) struct MacroRulesHighlighter { 7pub(super) struct MacroRulesHighlighter {
7 state: Option<MacroMatcherParseState>, 8 state: Option<MacroMatcherParseState>,
8} 9}
9 10
10impl MacroRulesHighlighter { 11impl MacroRulesHighlighter {
11 pub(super) fn new() -> Self {
12 MacroRulesHighlighter { state: None }
13 }
14
15 pub(super) fn init(&mut self) { 12 pub(super) fn init(&mut self) {
16 self.state = Some(MacroMatcherParseState::new()); 13 self.state = Some(MacroMatcherParseState::default());
17 }
18
19 pub(super) fn reset(&mut self) {
20 self.state = None;
21 } 14 }
22 15
23 pub(super) fn advance(&mut self, token: &SyntaxToken) { 16 pub(super) fn advance(&mut self, token: &SyntaxToken) {
@@ -51,8 +44,8 @@ struct MacroMatcherParseState {
51 in_invoc_body: bool, 44 in_invoc_body: bool,
52} 45}
53 46
54impl MacroMatcherParseState { 47impl Default for MacroMatcherParseState {
55 fn new() -> Self { 48 fn default() -> Self {
56 MacroMatcherParseState { 49 MacroMatcherParseState {
57 paren_ty: None, 50 paren_ty: None,
58 paren_level: 0, 51 paren_level: 0,