Skip to content
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

Use ThemeColor and add support for light themes #1299

Merged
merged 2 commits into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion 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};
Expand All @@ -11,6 +11,21 @@ pub struct HighlightedRange {
pub tag: &'static str,
}

fn is_control_keyword(kind: SyntaxKind) -> bool {
match kind {
T![for]
| T![loop]
| T![while]
| T![continue]
| T![break]
| T![if]
| T![else]
| T![match]
| T![return] => true,
_ => false,
}
}

pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
let source_file = db.parse(file_id);

Expand All @@ -29,6 +44,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
NAME => "function",
INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
LIFETIME => "parameter",
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) {
Expand Down
110 changes: 110 additions & 0 deletions editors/code/package.json
Expand Up @@ -268,6 +268,116 @@
},
"pattern": "$rustc"
}
],
"colors": [
{
"id": "ralsp.comment",
"description": "Color for comments",
"defaults": {
"dark": "#6A9955",
"light": "#008000",
"highContrast": "#7CA668"
}
},
{
"id": "ralsp.string",
"description": "Color for strings",
"defaults": {
"dark": "#CE9178",
"light": "#A31515",
"highContrast": "#CE9178"
}
},
{
"id": "ralsp.keyword",
"description": "Color for keywords",
"defaults": {
"dark": "#569cd6",
"light": "#0000FF",
"highContrast": "#569CD6"
}
},
{
"id": "ralsp.keyword.control",
"description": "Color for control keywords",
"defaults": {
"dark": "#C586C0",
"light": "#AF00DB",
"highContrast": "#C586C0"
}
},
{
"id": "ralsp.keyword.unsafe",
"description": "Color for unsafe",
"defaults": {
"dark": "#FF3030",
"light": "#FF1010",
"highContrast": "#FF1010"
}
},
{
"id": "ralsp.function",
"description": "Color for functions",
"defaults": {
"dark": "#DCDCAA",
"light": "#795E26",
"highContrast": "#DCDCAA"
}
},
{
"id": "ralsp.parameter",
"description": "Color for parameters",
"defaults": {
"dark": "#9CDCFE",
"light": "#001080",
"highContrast": "#9CDCFE"
}
},
{
"id": "ralsp.builtin",
"description": "Color for builtins",
"defaults": {
"dark": "#DD6718",
"light": "#DD6718",
"highContrast": "#DD6718"
}
},
{
"id": "ralsp.text",
"description": "Color for text",
"defaults": {
"dark": "#D4D4D4",
"light": "#000000",
"highContrast": "#FFFFFF"
}
},
{
"id": "ralsp.attribute",
"description": "Color for attributes",
"defaults": {
"dark": "#9FE9BF",
"light": "#1F4B1F",
"highContrast": "#108010"
}
},
{
"id": "ralsp.literal",
"description": "Color for literals",
"defaults": {
"dark": "#BECEA8",
"light": "#09885A",
"highContrast": "#B5CEA8"
}
},
{
"id": "ralsp.macro",
"description": "Color for DFAF8F",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be it Color for macros?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, fixed in #1305.

"defaults": {
"dark": "#BFEBBF",
"light": "#DD6718",
"highContrast": "#ED7718"
}
}
]
}
}
34 changes: 21 additions & 13 deletions editors/code/src/highlighting.ts
Expand Up @@ -13,23 +13,31 @@ export class Highlighter {
string,
vscode.TextEditorDecorationType
> {
const decor = (color: string) =>
vscode.window.createTextEditorDecorationType({ color });
const colorContrib = (
tag: string
): [string, vscode.TextEditorDecorationType] => {
const color = new vscode.ThemeColor('ralsp.' + tag);
const decor = vscode.window.createTextEditorDecorationType({
color
});
return [tag, decor];
};

const decorations: Iterable<
[string, vscode.TextEditorDecorationType]
> = [
['background', decor('#3F3F3F')],
['comment', decor('#7F9F7F')],
['string', decor('#CC9393')],
['keyword', decor('#F0DFAF')],
['function', decor('#93E0E3')],
['parameter', decor('#94BFF3')],
['builtin', decor('#DD6718')],
['text', decor('#DCDCCC')],
['attribute', decor('#BFEBBF')],
['literal', decor('#DFAF8F')],
['macro', decor('#DFAF8F')]
colorContrib('comment'),
colorContrib('string'),
colorContrib('keyword'),
colorContrib('keyword.control'),
colorContrib('keyword.unsafe'),
colorContrib('function'),
colorContrib('parameter'),
colorContrib('builtin'),
colorContrib('text'),
colorContrib('attribute'),
colorContrib('literal'),
colorContrib('macro')
];

return new Map<string, vscode.TextEditorDecorationType>(decorations);
Expand Down