aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/syntax_highlighting.rs')
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index d9a28d2b5..2158291dc 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,6 +1,6 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement}; 3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5 5
6use crate::{FileId, db::RootDatabase}; 6use crate::{FileId, db::RootDatabase};
@@ -11,6 +11,21 @@ pub struct HighlightedRange {
11 pub tag: &'static str, 11 pub tag: &'static str,
12} 12}
13 13
14fn is_control_keyword(kind: SyntaxKind) -> bool {
15 match kind {
16 T![for]
17 | T![loop]
18 | T![while]
19 | T![continue]
20 | T![break]
21 | T![if]
22 | T![else]
23 | T![match]
24 | T![return] => true,
25 _ => false,
26 }
27}
28
14pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 29pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
15 let source_file = db.parse(file_id); 30 let source_file = db.parse(file_id);
16 31
@@ -29,6 +44,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
29 NAME => "function", 44 NAME => "function",
30 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", 45 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
31 LIFETIME => "parameter", 46 LIFETIME => "parameter",
47 T![unsafe] => "keyword.unsafe",
48 k if is_control_keyword(k) => "keyword.control",
32 k if k.is_keyword() => "keyword", 49 k if k.is_keyword() => "keyword",
33 _ => { 50 _ => {
34 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { 51 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) {
@@ -40,7 +57,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
40 let mut range_end = name_ref.syntax().range().end(); 57 let mut range_end = name_ref.syntax().range().end();
41 for sibling in path.syntax().siblings_with_tokens(Direction::Next) { 58 for sibling in path.syntax().siblings_with_tokens(Direction::Next) {
42 match sibling.kind() { 59 match sibling.kind() {
43 EXCL | IDENT => range_end = sibling.range().end(), 60 T![!] | IDENT => range_end = sibling.range().end(),
44 _ => (), 61 _ => (),
45 } 62 }
46 } 63 }