Skip to content

Commit

Permalink
tweaks to highlighting and colorscheme
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Feb 14, 2025
1 parent 33e34f3 commit f8efea4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
11 changes: 6 additions & 5 deletions data/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ exec = { fg = "#E6D29E", bg = "#Bf616A" }
boolean = { fg = "#DCA561", bold = true }
character = { fg = "#61DCA5", italic = true }
comment = { fg = "#624354", italic = true }
constant = { fg = "#FF9E3B" }
function = { fg = "#957FB8" }
constant = { fg = "#FFA066" }
function = { fg = "#8793B5" }
"function.macro" = { fg = "#FFA066" }
keyword = { fg = "#Bf616A" }
module = { fg = "#2D4F67" }
number = { fg = "#D27E99" }
operator = { fg = "#E6C384" }
operator = { fg = "#DCA561" }
punctuation = { fg = "#9CABCA" }
string = { fg = "#61DCA5" }
type = { fg = "#7E9CD8" }
variable = { fg = "#E6C384" }
type = { fg = "#9AB292" }
variable = { fg = "#E6D29E" }


# Key mappings to programs that must be available on $PATH or commands.
Expand Down
31 changes: 24 additions & 7 deletions data/tree-sitter/queries/rust/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
(shebang) @keyword.directive

(function_item (identifier) @function)
(function_signature_item (identifier) @function)
(macro_invocation
macro: (identifier) @function.macro
"!" @function.macro)

(identifier) @variable

; Assume all-caps names are constants
Expand All @@ -24,12 +18,35 @@
name: (identifier) @module)
(self) @keyword.builtin

(function_item (identifier) @function)
(function_signature_item (identifier) @function)
(macro_invocation
macro: (identifier) @function.macro
"!" @function.macro)

(call_expression
function: (identifier) @function.call)
(call_expression
function: (scoped_identifier
(identifier) @function.call .))
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
(generic_function
function: (identifier) @function.call)
(generic_function
function: (scoped_identifier
name: (identifier) @function.call))
(generic_function
function: (field_expression
field: (field_identifier) @function.call))

[
(line_comment)
(block_comment)
(outer_doc_comment_marker)
(inner_doc_comment_marker)
] @comment @spell
] @comment

(line_comment
(doc_comment)) @comment.documentation
Expand Down
36 changes: 14 additions & 22 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ impl Config {
Err(e) => return Err(format!("Unable to load config file: {e}")),
};

cfg.set_default_bg_for_tokens();
cfg.expand_home_dir_refs(&home);
// Use default colorscheme's background color if none is specified
for style in cfg.colorscheme.syntax.values_mut() {
style.bg = style.bg.or(Some(cfg.colorscheme.bg));
}

// Replace "~/" shorthand notation in paths with the user's $HOME
for s in [
&mut cfg.tree_sitter.parser_dir,
&mut cfg.tree_sitter.syntax_query_dir,
] {
if s.starts_with("~/") {
*s = s.replacen("~", &home, 1);
}
}

Ok(cfg)
}
Expand All @@ -103,26 +115,6 @@ impl Config {

Err("runtime config updates are not currently supported".to_owned())
}

fn set_default_bg_for_tokens(&mut self) {
for style in self.colorscheme.syntax.values_mut() {
// Use default colorscheme's background color if none is specified
if style.bg.is_none() {
style.bg = Some(self.colorscheme.bg);
}
}
}

fn expand_home_dir_refs(&mut self, home: &str) {
for s in [
&mut self.tree_sitter.parser_dir,
&mut self.tree_sitter.syntax_query_dir,
] {
if s.starts_with("~/") {
*s = s.replacen("~", home, 1);
}
}
}
}

/// A colorscheme for rendering the UI.
Expand Down

0 comments on commit f8efea4

Please sign in to comment.