From 9282f1b8e546583d9e461cd78bed7d2f21dd1770 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 15 Mar 2024 19:52:57 -0400 Subject: [PATCH 001/101] Handle starting and continuing the count separately (#9887) --- helix-term/src/ui/editor.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f3bba5d1c7552..c1e36bbddc4e3 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -916,13 +916,15 @@ impl EditorView { fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEvent) { match (event, cxt.editor.count) { - // count handling - (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) - if !self.keymaps.contains_key(mode, event) => - { + // If the count is already started and the input is a number, always continue the count. + (key!(i @ '0'..='9'), Some(count)) => { + let i = i.to_digit(10).unwrap() as usize; + cxt.editor.count = NonZeroUsize::new(count.get() * 10 + i); + } + // A non-zero digit will start the count if that number isn't used by a keymap. + (key!(i @ '1'..='9'), None) if !self.keymaps.contains_key(mode, event) => { let i = i.to_digit(10).unwrap() as usize; - cxt.editor.count = - std::num::NonZeroUsize::new(cxt.editor.count.map_or(i, |c| c.get() * 10 + i)); + cxt.editor.count = NonZeroUsize::new(i); } // special handling for repeat operator (key!('.'), _) if self.keymaps.pending().is_empty() => { From 6fea7876a47df8627a4b40361a6fc0f692c6601f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 16 Mar 2024 18:20:47 +0530 Subject: [PATCH 002/101] Fix comment key bind behaviour in OCaml (#9894) --- languages.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/languages.toml b/languages.toml index bf726e349721e..8fbb98e883d17 100644 --- a/languages.toml +++ b/languages.toml @@ -1083,7 +1083,6 @@ injection-regex = "ocaml" file-types = ["ml"] shebangs = ["ocaml", "ocamlrun", "ocamlscript"] block-comment-tokens = { start = "(*", end = "*)" } -comment-token = "(**)" language-servers = [ "ocamllsp" ] indent = { tab-width = 2, unit = " " } From 761df60077bf33cb1077eb4cb019885ea3dd6ae7 Mon Sep 17 00:00:00 2001 From: Emi <95967983+EmiOnGit@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:06:24 +0100 Subject: [PATCH 003/101] Keybind for Extend/shrink selection up and down (#9080) * implement another selection modifying command * Selection feels more ergonomic in case of swapping the direction. This also fixes a problem when starting at an empty line. * rename select_line_up/down to select_line_above/below * apply clippy suggestion of using cmp instead of if-chain * revert `Extent` implementing `Clone/Copy` * move select_line functions below extend_line implementations * implement help add function, which saturates at the number of text lines --------- Co-authored-by: Emi --- helix-term/src/commands.rs | 57 +++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4ac2496ebd48d..133f2d5408a8c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -57,6 +57,7 @@ use crate::{ use crate::job::{self, Jobs}; use std::{ + cmp::Ordering, collections::{HashMap, HashSet}, fmt, future::Future, @@ -300,6 +301,8 @@ impl MappableCommand { extend_line, "Select current line, if already selected, extend to another line based on the anchor", extend_line_below, "Select current line, if already selected, extend to next line", extend_line_above, "Select current line, if already selected, extend to previous line", + select_line_above, "Select current line, if already selected, extend or shrink line above based on the anchor", + select_line_below, "Select current line, if already selected, extend or shrink line below based on the anchor", extend_to_line_bounds, "Extend selection to line bounds", shrink_to_line_bounds, "Shrink selection to line bounds", delete_selection, "Delete selection", @@ -2435,7 +2438,6 @@ fn extend_line_below(cx: &mut Context) { fn extend_line_above(cx: &mut Context) { extend_line_impl(cx, Extend::Above); } - fn extend_line_impl(cx: &mut Context, extend: Extend) { let count = cx.count(); let (view, doc) = current!(cx.editor); @@ -2474,6 +2476,59 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { doc.set_selection(view.id, selection); } +fn select_line_below(cx: &mut Context) { + select_line_impl(cx, Extend::Below); +} +fn select_line_above(cx: &mut Context) { + select_line_impl(cx, Extend::Above); +} +fn select_line_impl(cx: &mut Context, extend: Extend) { + let mut count = cx.count(); + let (view, doc) = current!(cx.editor); + let text = doc.text(); + let saturating_add = |a: usize, b: usize| (a + b).min(text.len_lines()); + let selection = doc.selection(view.id).clone().transform(|range| { + let (start_line, end_line) = range.line_range(text.slice(..)); + let start = text.line_to_char(start_line); + let end = text.line_to_char(saturating_add(end_line, 1)); + let direction = range.direction(); + + // Extending to line bounds is counted as one step + if range.from() != start || range.to() != end { + count = count.saturating_sub(1) + } + let (anchor_line, head_line) = match (&extend, direction) { + (Extend::Above, Direction::Forward) => (start_line, end_line.saturating_sub(count)), + (Extend::Above, Direction::Backward) => (end_line, start_line.saturating_sub(count)), + (Extend::Below, Direction::Forward) => (start_line, saturating_add(end_line, count)), + (Extend::Below, Direction::Backward) => (end_line, saturating_add(start_line, count)), + }; + let (anchor, head) = match anchor_line.cmp(&head_line) { + Ordering::Less => ( + text.line_to_char(anchor_line), + text.line_to_char(saturating_add(head_line, 1)), + ), + Ordering::Equal => match extend { + Extend::Above => ( + text.line_to_char(saturating_add(anchor_line, 1)), + text.line_to_char(head_line), + ), + Extend::Below => ( + text.line_to_char(head_line), + text.line_to_char(saturating_add(anchor_line, 1)), + ), + }, + + Ordering::Greater => ( + text.line_to_char(saturating_add(anchor_line, 1)), + text.line_to_char(head_line), + ), + }; + Range::new(anchor, head) + }); + + doc.set_selection(view.id, selection); +} fn extend_to_line_bounds(cx: &mut Context) { let (view, doc) = current!(cx.editor); From 61f7d9ce2f2d20f4b0bd2f21036eac1f11cb2c5c Mon Sep 17 00:00:00 2001 From: Arthur Deierlein <110528300+c0rydoras@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:36:54 +0100 Subject: [PATCH 004/101] fix typo "braket" in jsx highlights (#9910) --- runtime/queries/_jsx/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/_jsx/highlights.scm b/runtime/queries/_jsx/highlights.scm index 853254e5be4ee..2a696641ca19b 100644 --- a/runtime/queries/_jsx/highlights.scm +++ b/runtime/queries/_jsx/highlights.scm @@ -40,4 +40,4 @@ (jsx_closing_element [""] @punctuation.bracket) ; -(jsx_self_closing_element ["<" "/>"] @punctuation.braket) +(jsx_self_closing_element ["<" "/>"] @punctuation.bracket) From 9ec0271873ed484f96342489b4117391e88abcd3 Mon Sep 17 00:00:00 2001 From: Arthur Deierlein <110528300+c0rydoras@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:53:30 +0100 Subject: [PATCH 005/101] Add support for hyprland config (#9899) * feat: add hyprland config language * adjust indents to helix * adjust highlights to helix --- book/src/generated/lang-support.md | 1 + languages.toml | 12 +++++ runtime/queries/hyprlang/highlights.scm | 58 +++++++++++++++++++++++++ runtime/queries/hyprlang/indents.scm | 6 +++ runtime/queries/hyprlang/injections.scm | 3 ++ 5 files changed, 80 insertions(+) create mode 100644 runtime/queries/hyprlang/highlights.scm create mode 100644 runtime/queries/hyprlang/indents.scm create mode 100644 runtime/queries/hyprlang/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 7792bf5941819..2cb1e926ce31e 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -77,6 +77,7 @@ | hosts | ✓ | | | | | html | ✓ | | | `vscode-html-language-server` | | hurl | ✓ | | ✓ | | +| hyprlang | ✓ | | ✓ | | | idris | | | | `idris2-lsp` | | iex | ✓ | | | | | ini | ✓ | | | | diff --git a/languages.toml b/languages.toml index 8fbb98e883d17..b01da144d52f2 100644 --- a/languages.toml +++ b/languages.toml @@ -3284,3 +3284,15 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ld" source = { git = "https://github.com/mtoohey31/tree-sitter-ld", rev = "81978cde3844bfc199851e39c80a20ec6444d35e" } + +[[language]] +name = "hyprlang" +scope = "source.hyprlang" +roots = ["hyprland.conf"] +file-types = [ { glob = "hyprland.conf"} ] +comment-token = "#" +grammar = "hyprlang" + +[[grammar]] +name = "hyprlang" +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-hyprlang", rev = "27af9b74acf89fa6bed4fb8cb8631994fcb2e6f3"} diff --git a/runtime/queries/hyprlang/highlights.scm b/runtime/queries/hyprlang/highlights.scm new file mode 100644 index 0000000000000..bf898c9cdd224 --- /dev/null +++ b/runtime/queries/hyprlang/highlights.scm @@ -0,0 +1,58 @@ +(comment) @comment + +[ + "source" + "exec" + "exec-once" +] @function.builtin + +(keyword + (name) @keyword) + +(assignment + (name) @variable.other.member) + +(section + (name) @namespace) + +(section + device: (device_name) @type) + +(variable) @variable + +"$" @punctuation.special + +(boolean) @constant.builtin.boolean + +(string) @string + +(mod) @constant + +[ + "rgb" + "rgba" +] @function.builtin + +[ + (number) + (legacy_hex) + (angle) + (hex) +] @constant.numeric + +"deg" @type + +"," @punctuation.delimiter + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "-" + "+" +] @operator diff --git a/runtime/queries/hyprlang/indents.scm b/runtime/queries/hyprlang/indents.scm new file mode 100644 index 0000000000000..88bfe7434276e --- /dev/null +++ b/runtime/queries/hyprlang/indents.scm @@ -0,0 +1,6 @@ +(section) @indent + +(section + "}" @outdent) + +"}" @extend diff --git a/runtime/queries/hyprlang/injections.scm b/runtime/queries/hyprlang/injections.scm new file mode 100644 index 0000000000000..1f0199ed807dd --- /dev/null +++ b/runtime/queries/hyprlang/injections.scm @@ -0,0 +1,3 @@ +(exec + (string) @injection.content + (#set! injection.language "bash")) From e36774c2c8f967c16ce2e10f2ba074838b324ec6 Mon Sep 17 00:00:00 2001 From: "George \"Riye\" Hollister" Date: Sun, 17 Mar 2024 22:54:05 +0000 Subject: [PATCH 006/101] Add Support for JSONC (#9906) * Added `jsonc` language with support for comments The `vscode-json-language-server` accepts `jsonc` as a language id. Allowing the use of comments within JSON files. * fix: Update `injdection-rejex` to be unique * fix: use includes to remove redundant queries * ci: Generate language-support docs --- book/src/generated/lang-support.md | 1 + languages.toml | 10 +++++++++- runtime/queries/jsonc/highlights.scm | 2 ++ runtime/queries/jsonc/indents.scm | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/jsonc/highlights.scm create mode 100644 runtime/queries/jsonc/indents.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 2cb1e926ce31e..40029657f55f4 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -88,6 +88,7 @@ | jsdoc | ✓ | | | | | json | ✓ | | ✓ | `vscode-json-language-server` | | json5 | ✓ | | | | +| jsonc | ✓ | | ✓ | `vscode-json-language-server` | | jsonnet | ✓ | | | `jsonnet-language-server` | | jsx | ✓ | ✓ | ✓ | `typescript-language-server` | | julia | ✓ | ✓ | ✓ | `julia` | diff --git a/languages.toml b/languages.toml index b01da144d52f2..4018fbe0e3299 100644 --- a/languages.toml +++ b/languages.toml @@ -367,7 +367,6 @@ scope = "source.json" injection-regex = "json" file-types = [ "json", - "jsonc", "arb", "ipynb", "geojson", @@ -396,6 +395,15 @@ indent = { tab-width = 2, unit = " " } name = "json" source = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "73076754005a460947cafe8e03a8cf5fa4fa2938" } +[[language]] +name = "jsonc" +scope = "source.json" +injection-regex = "jsonc" +file-types = ["jsonc"] +grammar = "json" +language-servers = [ "vscode-json-language-server" ] +auto-format = true +indent = { tab-width = 2, unit = " " } [[language]] name = "json5" diff --git a/runtime/queries/jsonc/highlights.scm b/runtime/queries/jsonc/highlights.scm new file mode 100644 index 0000000000000..0164321b60d57 --- /dev/null +++ b/runtime/queries/jsonc/highlights.scm @@ -0,0 +1,2 @@ +; inherits: json +(comment) @comment diff --git a/runtime/queries/jsonc/indents.scm b/runtime/queries/jsonc/indents.scm new file mode 100644 index 0000000000000..41269219efd8f --- /dev/null +++ b/runtime/queries/jsonc/indents.scm @@ -0,0 +1 @@ +; inherits: json From 3890376a23e84d5bcdac31cb9d0f6913abe0fc7f Mon Sep 17 00:00:00 2001 From: Dan Cardamore Date: Sun, 17 Mar 2024 18:55:49 -0400 Subject: [PATCH 007/101] add 'file-absolute-path' to statusline (#4535) * feat: add 'file-abs-path' to statusline (#4434) * cleanup implementation * rename to be non-abbreviated names --------- Co-authored-by: Michael Davis --- book/src/configuration.md | 1 + helix-term/src/ui/statusline.rs | 17 +++++++++++++++++ helix-view/src/editor.rs | 3 +++ 3 files changed, 21 insertions(+) diff --git a/book/src/configuration.md b/book/src/configuration.md index d8793645793c7..8857af82a98e2 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -108,6 +108,7 @@ The following statusline elements can be configured: | `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) | | `spinner` | A progress spinner indicating LSP activity | | `file-name` | The path/name of the opened file | +| `file-absolute-path` | The absolute path/name of the opened file | | `file-base-name` | The basename of the opened file | | `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) | | `file-encoding` | The encoding of the opened file if it differs from UTF-8 | diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 9871828ee3d05..c3464067f06c3 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -142,6 +142,7 @@ where helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner, helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name, helix_view::editor::StatusLineElement::FileName => render_file_name, + helix_view::editor::StatusLineElement::FileAbsolutePath => render_file_absolute_path, helix_view::editor::StatusLineElement::FileModificationIndicator => { render_file_modification_indicator } @@ -430,6 +431,22 @@ where write(context, title, None); } +fn render_file_absolute_path(context: &mut RenderContext, write: F) +where + F: Fn(&mut RenderContext, String, Option