From 9ade271a67a9fae0d89f8138970679c9730e9fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 21 May 2019 14:04:54 +0300 Subject: Use ThemeColor and add support for light themes --- crates/ra_ide_api/src/syntax_highlighting.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index a03b13839..ab69a4374 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashSet; -use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; +use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T}; use ra_db::SourceDatabase; use crate::{FileId, db::RootDatabase}; @@ -11,6 +11,14 @@ pub struct HighlightedRange { pub tag: &'static str, } +fn is_control_keyword(kind: SyntaxKind) -> bool { + match kind { + FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW + | RETURN_KW => true, + _ => false, + } +} + pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec { let source_file = db.parse(file_id); @@ -29,6 +37,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "function", INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", LIFETIME => "parameter", + UNSAFE_KW => "unsafe", + k if is_control_keyword(k) => "control", k if k.is_keyword() => "keyword", _ => { if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { -- cgit v1.2.3 From b08362f6d2973336764c52ebc7cc5e9f34f0d80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 21 May 2019 16:28:10 +0300 Subject: Address feedback --- crates/ra_ide_api/src/syntax_highlighting.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index ab69a4374..2158291dc 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -13,8 +13,15 @@ pub struct HighlightedRange { fn is_control_keyword(kind: SyntaxKind) -> bool { match kind { - FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW - | RETURN_KW => true, + T![for] + | T![loop] + | T![while] + | T![continue] + | T![break] + | T![if] + | T![else] + | T![match] + | T![return] => true, _ => false, } } @@ -37,8 +44,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "function", INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", LIFETIME => "parameter", - UNSAFE_KW => "unsafe", - k if is_control_keyword(k) => "control", + T![unsafe] => "keyword.unsafe", + k if is_control_keyword(k) => "keyword.control", k if k.is_keyword() => "keyword", _ => { if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { -- cgit v1.2.3