From 60aa7d360777331753ae4735f8fd4ea96012d4fd Mon Sep 17 00:00:00 2001 From: Chickenkeeper Date: Fri, 30 Sep 2022 23:43:07 +0100 Subject: [PATCH 1/7] WGSL syntax highlighting fix (#3996) --- languages.toml | 2 +- runtime/queries/wgsl/highlights.scm | 62 +++++++++++++++++------------ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/languages.toml b/languages.toml index a7b8f93d..ab204fcc 100644 --- a/languages.toml +++ b/languages.toml @@ -848,7 +848,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "wgsl" -source = { git = "https://github.com/szebniok/tree-sitter-wgsl", rev = "f00ff52251edbd58f4d39c9c3204383253032c11" } +source = { git = "https://github.com/szebniok/tree-sitter-wgsl", rev = "272e89ef2aeac74178edb9db4a83c1ffef80a463" } [[language]] name = "llvm" diff --git a/runtime/queries/wgsl/highlights.scm b/runtime/queries/wgsl/highlights.scm index 7fbc87d8..baf9dd8f 100644 --- a/runtime/queries/wgsl/highlights.scm +++ b/runtime/queries/wgsl/highlights.scm @@ -1,23 +1,41 @@ -(const_literal) @constant.numeric +(int_literal) @constant.numeric.integer +(float_literal) @constant.numeric.float +(bool_literal) @constant.builtin.boolean -(type_declaration) @type +(global_constant_declaration) @variable +(global_variable_declaration) @variable +(compound_statement) @variable +(const_expression) @function + +(variable_identifier_declaration + (identifier) @variable + (type_declaration) @type) (function_declaration - (identifier) @function) + (identifier) @function + (function_return_type_declaration + (type_declaration) @type)) + +(parameter + (variable_identifier_declaration + (identifier) @variable.parameter + (type_declaration) @type)) (struct_declaration (identifier) @type) + +(struct_declaration + (struct_member + (variable_identifier_declaration + (identifier) @variable.other.member + (type_declaration) @type))) (type_constructor_or_function_call_expression (type_declaration) @function) -(parameter - (variable_identifier_declaration (identifier) @variable.parameter)) - [ "struct" "bitcast" - ; "block" "discard" "enable" "fallthrough" @@ -26,36 +44,28 @@ "private" "read" "read_write" - "return" "storage" "type" "uniform" "var" "workgroup" "write" + "override" (texel_format) -] @keyword ; TODO reserved keywords +] @keyword -[ - (true) - (false) -] @constant.builtin.boolean +"fn" @keyword.function -[ "," "." ":" ";" ] @punctuation.delimiter +"return" @keyword.control.return -;; brackets -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket +["," "." ":" ";"] @punctuation.delimiter + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket [ "loop" "for" + "while" "break" "continue" "continuing" @@ -64,7 +74,6 @@ [ "if" "else" - "elseif" "switch" "case" "default" @@ -92,10 +101,13 @@ "*" "~" "^" + "@" + "++" + "--" ] @operator (attribute - (identifier) @variable.other.member) + (identifier) @attribute) (comment) @comment From a27c384dd23bfe97734944843bff2862214bd78e Mon Sep 17 00:00:00 2001 From: s0LA1337 Date: Sat, 1 Oct 2022 00:44:35 +0000 Subject: [PATCH 2/7] Initial implementation of colored indentation guides --- book/src/configuration.md | 10 ++++++---- helix-term/src/ui/editor.rs | 20 +++++++++++++++++--- helix-view/src/editor.rs | 2 ++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index fdabe768..3a5ab4a2 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -218,10 +218,11 @@ tabpad = "·" # Tabs will look like "→···" (depending on tab width) Options for rendering vertical indent guides. -| Key | Description | Default | -| --- | --- | --- | -| `render` | Whether to render indent guides. | `false` | -| `character` | Literal character to use for rendering the indent guide | `│` | +| Key | Description | Default | +| --- | --- | --- | +| `render` | Whether to render indent guides. | `false` | +| `character` | Literal character to use for rendering the indent guide | `│` | +| `rainbow` | Whether or not the indent guides shall have changing colors. | `false` | Example: @@ -229,4 +230,5 @@ Example: [editor.indent-guides] render = true character = "╎" +rainbow = true ``` diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 7cb29c3b..69e565e1 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -421,17 +421,26 @@ impl EditorView { let text_style = theme.get("ui.text"); let whitespace_style = theme.get("ui.virtual.whitespace"); + let indent_rainbow_colors = [ + helix_view::graphics::Color::Red, + helix_view::graphics::Color::Yellow, + helix_view::graphics::Color::Green, + helix_view::graphics::Color::Cyan, + helix_view::graphics::Color::Blue, + helix_view::graphics::Color::Magenta, + ]; + let mut is_in_indent_area = true; - let mut last_line_indent_level = 0; + let mut last_line_indent_level: u16 = 0; // use whitespace style as fallback for indent-guide - let indent_guide_style = text_style.patch( + let mut indent_guide_style = text_style.patch( theme .try_get("ui.virtual.indent-guide") .unwrap_or_else(|| theme.get("ui.virtual.whitespace")), ); - let draw_indent_guides = |indent_level, line, surface: &mut Surface| { + let mut draw_indent_guides = |indent_level, line, surface: &mut Surface| { if !config.indent_guides.render { return; } @@ -441,6 +450,11 @@ impl EditorView { // extra loops if the code is deeply nested. for i in starting_indent..(indent_level / tab_width as u16) { + if config.indent_guides.rainbow { + let color_index: usize = i as usize % indent_rainbow_colors.len(); + indent_guide_style.fg = Some(indent_rainbow_colors[color_index]); + } + surface.set_string( viewport.x + (i * tab_width as u16) - offset.col as u16, viewport.y + line, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 5eff9983..5acbc5b7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -533,6 +533,7 @@ impl Default for WhitespaceCharacters { pub struct IndentGuidesConfig { pub render: bool, pub character: char, + pub rainbow: bool, } impl Default for IndentGuidesConfig { @@ -540,6 +541,7 @@ impl Default for IndentGuidesConfig { Self { render: false, character: '│', + rainbow: false, } } } From 9bbc12d7b67dcb2ea97a6202391004c77bd5f214 Mon Sep 17 00:00:00 2001 From: s0LA1337 Date: Sat, 1 Oct 2022 01:20:04 +0000 Subject: [PATCH 3/7] Remove unnecessary typing --- helix-term/src/ui/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 69e565e1..e28a95d9 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -431,7 +431,7 @@ impl EditorView { ]; let mut is_in_indent_area = true; - let mut last_line_indent_level: u16 = 0; + let mut last_line_indent_level = 0; // use whitespace style as fallback for indent-guide let mut indent_guide_style = text_style.patch( From 1daf0c35c78fddc21b0418eb33dac8ea734c90d5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 11 Jul 2022 19:10:57 -0500 Subject: [PATCH 4/7] Parse rainbow style array in themes This change adds a field to the schema of themes which takes a list of styles. rainbow = ["red", "orange", "yellow", { modifiers = ["reversed"] }] [palette] red = "#ff0000" orange = "#ffa500" yellow = "#fff000" Normal style rules apply for each element in `rainbows`: you can use definitions from the palette and the full fg/bg/modifiers notation. Themes written with `rainbow` keys are not backwards compatible. Parsing errors will be generated for older versions of Helix attempting to use themes with `rainbow` keys. A default rainbow is provided with base16 colors. This change is made with rainbow pair characters (parens, brackets, etc.) in mind but it could also be used for other rainbow cosmetic elements like rainbow indent-guides. --- book/src/themes.md | 11 +++++ helix-view/src/theme.rs | 103 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/book/src/themes.md b/book/src/themes.md index 9908456f..ea516959 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -89,6 +89,17 @@ Less common modifiers might not be supported by your terminal emulator. | `hidden` | | `crossed_out` | +### Rainbow + +The `rainbow` key is used for rainbow highlight for matching brackets. +The key is a list of styles. + +```toml +rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold"] }] +``` + +Colors from the palette and modifiers may be used. + ### Scopes The following is a list of scopes available to use for styling. diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index fa5fa702..8472ec64 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -103,6 +103,7 @@ pub struct Theme { // tree-sitter highlight styles are stored in a Vec to optimize lookups scopes: Vec, highlights: Vec