From c7aa7bf4baf8e0ac4eca3ebdca065ab2a7bea95c Mon Sep 17 00:00:00 2001 From: Kirawi Date: Wed, 7 Jul 2021 20:51:46 -0400 Subject: VSCode Dark+ Theme (#414) * wip * Add VSCode Dark+ Theme wip wip wip wip wip wip properly detect constants add bool wip * suggestion * add variant for c/c++ * fix hexcode error * removed regex highlight * fixed constant higlighting * wip * add space * add suggestions * update theme * update book * suggestions * fix c/c++ enum * update book--- book/src/themes.md | 1 + 1 file changed, 1 insertion(+) (limited to 'book') diff --git a/book/src/themes.md b/book/src/themes.md index e5c461fd..4d80f99a 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -61,6 +61,7 @@ Possible keys: | `variable.parameter` | | | `type` | | | `type.builtin` | | +| `type.enum.variant` | Enum variants | | `constructor` | | | `function` | | | `function.macro` | | -- cgit v1.2.3-70-g09d2 From 084a8a952292521f1f7b7f4144e6823c29b85507 Mon Sep 17 00:00:00 2001 From: Kirawi Date: Thu, 8 Jul 2021 12:11:20 -0400 Subject: Rewritten Rust `highlights.scm` (#425) * rewrote Rust highlights.scm * wip * wip * wip * wip * fixed type highlighting * wip * rewrite again * moved operators * missing newline * missing newline * update book * fix constructor highlighting * fix constructor highlighting * fix const highlighting * better constructor highlighting * remove dup, bug was my locals.scm file * fixed docs * merge * fixed for highlighting * add yield * remove yield * added yield back * fixed yield highlighting * unecessary--- book/src/themes.md | 1 + helix-core/src/syntax.rs | 4 +- runtime/queries/rust/highlights.scm | 484 ++++++++++++++++++++++-------------- 3 files changed, 306 insertions(+), 183 deletions(-) (limited to 'book') diff --git a/book/src/themes.md b/book/src/themes.md index 4d80f99a..f17195aa 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -51,6 +51,7 @@ Possible keys: | `attribute` | | | `keyword` | | | `keyword.directive` | Preprocessor directives (\#if in C) | +| `keyword.control` | Control flow | | `namespace` | | | `punctuation` | | | `punctuation.delimiter` | | diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 5b45a88f..833ccfb9 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -161,7 +161,7 @@ impl LanguageConfiguration { let injections_query = read_query(&language, "injections.scm"); - let locals_query = ""; + let locals_query = read_query(&language, "locals.scm"); if highlights_query.is_empty() { None @@ -171,7 +171,7 @@ impl LanguageConfiguration { language, &highlights_query, &injections_query, - locals_query, + &locals_query, ) .unwrap(); // TODO: no unwrap config.configure(scopes); diff --git a/runtime/queries/rust/highlights.scm b/runtime/queries/rust/highlights.scm index bb15074b..5e469e67 100644 --- a/runtime/queries/rust/highlights.scm +++ b/runtime/queries/rust/highlights.scm @@ -1,214 +1,336 @@ -; Identifier conventions +; ------- +; Tree-Sitter doesn't allow overrides in regards to captures, +; though it is possible to affect the child node of a captured +; node. Thus, the approach here is to flip the order so that +; overrides are unnecessary. +; ------- -; Assume all-caps names are constants -((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]+$")) -; Assume other uppercase names are enum constructors -(enum_variant) @type.enum.variant -((identifier) @constructor - (#match? @constructor "^[A-Z]")) +; ------- +; Types +; ------- -; Assume that uppercase names in paths are types -(mod_item - name: (identifier) @namespace) -(scoped_identifier - path: (identifier) @namespace) -(scoped_identifier - (scoped_identifier - name: (identifier) @namespace)) -(scoped_type_identifier - path: (identifier) @namespace) -(scoped_type_identifier - (scoped_identifier - name: (identifier) @namespace)) +; --- +; Primitives +; --- -((scoped_identifier - path: (identifier) @type) - (#match? @type "^[A-Z]")) -((scoped_identifier - path: (scoped_identifier - name: (identifier) @type)) - (#match? @type "^[A-Z]")) +(escape_sequence) @escape +(primitive_type) @type.builtin +(boolean_literal) @constant.builtin +[ + (integer_literal) + (float_literal) +] @number +[ + (char_literal) + (string_literal) + (raw_string_literal) +] @string +[ + (line_comment) + (block_comment) +] @comment -; Namespaces +; --- +; Extraneous +; --- -(crate) @namespace -(extern_crate_declaration - (crate) - name: (identifier) @namespace) -(scoped_use_list - path: (identifier) @namespace) -(scoped_use_list - path: (scoped_identifier - (identifier) @namespace)) -(use_list (scoped_identifier (identifier) @namespace . (_))) +(self) @variable.builtin +(enum_variant (identifier) @type.enum.variant) -; Function calls +(field_initializer + (field_identifier) @property) +(shorthand_field_initializer) @variable +(shorthand_field_identifier) @variable -(call_expression - function: (identifier) @function) -(call_expression - function: (field_expression - field: (field_identifier) @function.method)) -(call_expression - function: (scoped_identifier - "::" - name: (identifier) @function)) +(lifetime + "'" @label + (identifier) @label) +(loop_label + (identifier) @type) -(generic_function - function: (identifier) @function) -(generic_function - function: (scoped_identifier - name: (identifier) @function)) -(generic_function - function: (field_expression - field: (field_identifier) @function.method)) +; --- +; Punctuation +; --- -(macro_invocation - macro: (identifier) @function.macro - "!" @function.macro) -(macro_invocation - macro: (scoped_identifier - (identifier) @function.macro .)) +[ + "::" + "." + ";" +] @punctuation.delimiter -; (metavariable) @variable -(metavariable) @function.macro +[ + "(" + ")" + "[" + "]" +] @punctuation.bracket +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) -"$" @function.macro +; --- +; Parameters +; --- -; Function definitions +(parameter + pattern: (identifier) @variable.parameter) +(closure_parameters + (identifier) @variable.parameter) -(function_item (identifier) @function) -(function_signature_item (identifier) @function) -; Other identifiers -(type_identifier) @type -(primitive_type) @type.builtin -(field_identifier) @property +; ------- +; Keywords +; ------- -(line_comment) @comment -(block_comment) @comment +(for_expression + "for" @keyword.control) +((identifier) @keyword.control + (#match? @keyword.control "^yield$")) +[ + "while" + "loop" + "in" + "break" + "continue" -"(" @punctuation.bracket -")" @punctuation.bracket -"[" @punctuation.bracket -"]" @punctuation.bracket + "match" + "if" + "else" + "return" + + "await" +] @keyword.control + +[ + (crate) + (super) + "as" + "use" + "pub" + "mod" + "extern" + + "fn" + "struct" + "enum" + "impl" + "where" + "trait" + "for" + + "type" + "union" + "unsafe" + "default" + "macro_rules!" + + "let" + "ref" + "move" + + "dyn" + "static" + "const" + "async" +] @keyword -(type_arguments - "<" @punctuation.bracket - ">" @punctuation.bracket) -(type_parameters - "<" @punctuation.bracket - ">" @punctuation.bracket) - -"::" @punctuation.delimiter -"." @punctuation.delimiter -";" @punctuation.delimiter - -(parameter (identifier) @variable.parameter) -(closure_parameters (_) @variable.parameter) - -(lifetime (identifier) @label) - -"async" @keyword -"break" @keyword -"const" @keyword -"continue" @keyword -(crate) @keyword -"default" @keyword -"dyn" @keyword -"else" @keyword -"enum" @keyword -"extern" @keyword -"fn" @keyword -"for" @keyword -"if" @keyword -"impl" @keyword -"in" @keyword -"let" @keyword -"let" @keyword -"loop" @keyword -"macro_rules!" @keyword -"match" @keyword -"mod" @keyword -"move" @keyword -"pub" @keyword -"ref" @keyword -"return" @keyword -"static" @keyword -"struct" @keyword -"trait" @keyword -"type" @keyword -"union" @keyword -"unsafe" @keyword -"use" @keyword -"where" @keyword -"while" @keyword (mutable_specifier) @keyword.mut -(use_list (self) @keyword) -(scoped_use_list (self) @keyword) -(scoped_identifier (self) @keyword) -(super) @keyword -"as" @keyword -(self) @variable.builtin -[ -(char_literal) -(string_literal) -(raw_string_literal) -] @string -(boolean_literal) @constant.builtin -(integer_literal) @number -(float_literal) @number +; ------- +; Guess Other Types +; ------- -(escape_sequence) @escape +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]+$")) + +; --- +; PascalCase identifiers in call_expressions (e.g. `Ok()`) +; are assumed to be enum constructors. +; --- + +(call_expression + function: [ + ((identifier) @type.variant + (#match? @type.variant "^[A-Z]")) + (scoped_identifier + name: ((identifier) @type.variant + (#match? @type.variant "^[A-Z]"))) + ]) + +; --- +; Assume that types in match arms are enums and not +; tuple structs. Same for `if let` expressions. +; --- + +(match_pattern + (scoped_identifier + name: (identifier) @constructor)) +(tuple_struct_pattern + type: [ + ((identifier) @constructor) + (scoped_identifier + name: (identifier) @constructor) + ]) +(struct_pattern + type: [ + ((type_identifier) @constructor) + (scoped_type_identifier + name: (type_identifier) @constructor) + ]) +; --- +; Other PascalCase identifiers are assumed to be structs. +; --- + +((identifier) @type + (#match? @type "^[A-Z]")) + + + +; ------- +; Functions +; ------- + +(call_expression + function: [ + ((identifier) @function) + (scoped_identifier + name: (identifier) @function) + (field_expression + field: (field_identifier) @function) + ]) +(generic_function + function: [ + ((identifier) @function) + (scoped_identifier + name: (identifier) @function) + (field_expression + field: (field_identifier) @function.method) + ]) + +(function_item + name: (identifier) @function) + +; --- +; Macros +; --- + +(meta_item + (identifier) @attribute) (attribute_item) @attribute (inner_attribute_item) @attribute +(macro_definition + name: (identifier) @function.macro) +(macro_invocation + macro: [ + ((identifier) @function.macro) + (scoped_identifier + name: (identifier) @function.macro) + ] + "!" @function.macro) + +(metavariable) @variable.parameter +(fragment_specifier) @variable.parameter + + + +; ------- +; Operators +; ------- + [ -"*" -"'" -"->" -"=>" -"<=" -"=" -"==" -"!" -"!=" -"%" -"%=" -"&" -"&=" -"&&" -"|" -"|=" -"||" -"^" -"^=" -"*" -"*=" -"-" -"-=" -"+" -"+=" -"/" -"/=" -">" -"<" -">=" -">>" -"<<" -">>=" -"@" -".." -"..=" -"'" + "*" + "'" + "->" + "=>" + "<=" + "=" + "==" + "!" + "!=" + "%" + "%=" + "&" + "&=" + "&&" + "|" + "|=" + "||" + "^" + "^=" + "*" + "*=" + "-" + "-=" + "+" + "+=" + "/" + "/=" + ">" + "<" + ">=" + ">>" + "<<" + ">>=" + "@" + ".." + "..=" + "'" ] @operator + + +; ------- +; Paths +; ------- + +(use_declaration + argument: (identifier) @namespace) +(use_wildcard + (identifier) @namespace) +(extern_crate_declaration + name: (identifier) @namespace) +(mod_item + name: (identifier) @namespace) +(scoped_use_list + path: (identifier)? @namespace) +(use_list + (identifier) @namespace) +(use_as_clause + path: (identifier)? @namespace + alias: (identifier) @namespace) + +; --- +; Remaining Paths +; --- + +(scoped_identifier + path: (identifier)? @namespace + name: (identifier) @namespace) +(scoped_type_identifier + path: (identifier) @namespace) + + + +; ------- +; Remaining Identifiers +; ------- + "?" @special + +(type_identifier) @type +(identifier) @variable +(field_identifier) @variable -- cgit v1.2.3-70-g09d2 From 722cfedb382abf2a4e48ac45bdfd9b3c5de50a58 Mon Sep 17 00:00:00 2001 From: Cor Peters Date: Fri, 16 Jul 2021 18:12:59 +0200 Subject: Added change_case command (#441) * Added change_case command * Added switch_to_uppercase and switch_to_lowercase Renamed change_case to switch_case. * Updated the Keymap section of the Book * Use flat_map instead of map + flatten * Fix switch_to_uppercase using to_lowercase * Switched 'Alt-`' to uppercase and '`' to lowercase Co-authored-by: Cor --- book/src/keymap.md | 43 +++++++++++++++++++----------------- helix-term/src/commands.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++ helix-term/src/keymap.rs | 4 ++++ 3 files changed, 81 insertions(+), 20 deletions(-) (limited to 'book') diff --git a/book/src/keymap.md b/book/src/keymap.md index c0c455d3..5d6e5795 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -41,26 +41,29 @@ ### Changes -| Key | Description | -| ----- | ----------- | -| `r` | Replace with a character | -| `R` | Replace with yanked text | -| `i` | Insert before selection | -| `a` | Insert after selection (append) | -| `I` | Insert at the start of the line | -| `A` | Insert at the end of the line | -| `o` | Open new line below selection | -| `o` | Open new line above selection | -| `u` | Undo change | -| `U` | Redo change | -| `y` | Yank selection | -| `p` | Paste after selection | -| `P` | Paste before selection | -| `>` | Indent selection | -| `<` | Unindent selection | -| `=` | Format selection | -| `d` | Delete selection | -| `c` | Change selection (delete and enter insert mode) | +| Key | Description | +| ----- | ----------- | +| `r` | Replace with a character | +| `R` | Replace with yanked text | +| `~` | Switch case of the selected text | +| `\`` | Set the selected text to upper case | +| `Alt-\`` | Set the selected text to lower case | +| `i` | Insert before selection | +| `a` | Insert after selection (append) | +| `I` | Insert at the start of the line | +| `A` | Insert at the end of the line | +| `o` | Open new line below selection | +| `o` | Open new line above selection | +| `u` | Undo change | +| `U` | Redo change | +| `y` | Yank selection | +| `p` | Paste after selection | +| `P` | Paste before selection | +| `>` | Indent selection | +| `<` | Unindent selection | +| `=` | Format selection | +| `d` | Delete selection | +| `c` | Change selection (delete and enter insert mode) | ### Selection manipulation diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3b208ca8..7e769f4e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -186,6 +186,9 @@ impl Command { extend_till_prev_char, extend_prev_char, replace, + switch_case, + switch_to_uppercase, + switch_to_lowercase, page_up, page_down, half_page_up, @@ -780,6 +783,57 @@ fn replace(cx: &mut Context) { }) } +fn switch_case(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let transaction = + Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { + let text: Tendril = range + .fragment(doc.text().slice(..)) + .chars() + .flat_map(|ch| { + if ch.is_lowercase() { + ch.to_uppercase().collect() + } else if ch.is_uppercase() { + ch.to_lowercase().collect() + } else { + vec![ch] + } + }) + .collect(); + + (range.from(), range.to() + 1, Some(text)) + }); + + doc.apply(&transaction, view.id); + doc.append_changes_to_history(view.id); +} + +fn switch_to_uppercase(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let transaction = + Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { + let text: Tendril = range.fragment(doc.text().slice(..)).to_uppercase().into(); + + (range.from(), range.to() + 1, Some(text)) + }); + + doc.apply(&transaction, view.id); + doc.append_changes_to_history(view.id); +} + +fn switch_to_lowercase(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let transaction = + Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| { + let text: Tendril = range.fragment(doc.text().slice(..)).to_lowercase().into(); + + (range.from(), range.to() + 1, Some(text)) + }); + + doc.apply(&transaction, view.id); + doc.append_changes_to_history(view.id); +} + fn scroll(cx: &mut Context, offset: usize, direction: Direction) { use Direction::*; let (view, doc) = current!(cx.editor); diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index fe32e49f..32994c37 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -82,6 +82,10 @@ impl Default for Keymaps { key!('r') => Command::replace, key!('R') => Command::replace_with_yanked, + key!('~') => Command::switch_case, + alt!('`') => Command::switch_to_uppercase, + key!('`') => Command::switch_to_lowercase, + key!(Home) => Command::goto_line_start, key!(End) => Command::goto_line_end, -- cgit v1.2.3-70-g09d2