From 31273c69e0be3b2d14f0c76d3f6a735e1d332e63 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 2 May 2024 06:25:15 -0400 Subject: [PATCH 01/29] Add completion/signature bindings to keymap.md (#10654) * Add completion/signature bindings to keymap.md PR #9974 added alt-p/alt-n keybindings to scroll through signatures. This wasn't very discoverable, as it's not in the docs or the command palette. This also removes a broken link for "comment mode" in the table of contents. * Update keymap.md --- book/src/keymap.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 65a223efb08f..55b467a0e691 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -12,8 +12,9 @@ - [Match mode](#match-mode) - [Window mode](#window-mode) - [Space mode](#space-mode) - - [Comment mode](#comment-mode) - [Popup](#popup) + - [Completion Menu](#completion-menu) + - [Signature-help Popup](#signature-help-popup) - [Unimpaired](#unimpaired) - [Insert mode](#insert-mode) - [Select / extend mode](#select--extend-mode) @@ -309,13 +310,31 @@ This layer is a kludge of mappings, mostly pickers. ##### Popup -Displays documentation for item under cursor. +Displays documentation for item under cursor. Remapping currently not supported. | Key | Description | | ---- | ----------- | | `Ctrl-u` | Scroll up | | `Ctrl-d` | Scroll down | +##### Completion Menu + +Displays documentation for the selected completion item. Remapping currently not supported. + +| Key | Description | +| ---- | ----------- | +| `Shift-Tab`, `Ctrl-p`, `Up` | Previous entry | +| `Tab`, `Ctrl-n`, `Down` | Next entry | + +##### Signature-help Popup + +Displays the signature of the selected completion item. Remapping currently not supported. + +| Key | Description | +| ---- | ----------- | +| `Alt-p` | Previous signature | +| `Alt-n` | Next signature | + #### Unimpaired These mappings are in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired). From cfca30887cd4df53af3086c51ab5480cdb3604d5 Mon Sep 17 00:00:00 2001 From: Hichem Date: Fri, 3 May 2024 03:53:07 +0200 Subject: [PATCH 02/29] signature: use the suggested LSP signature when changed (#10655) some LSPs does update the active signature and some not. To make both worlds happy, make the active signature more intelligent. 1. SignatureHelp store now the suggested lsp_signature 2. if the lsp_signature changes then use it 3. otherwise use the last signature from the old popup 4. in case the old signature doesn't exist anymore, show the last signature Signed-off-by: Ben Fekih, Hichem --- helix-term/src/handlers/signature_help.rs | 28 +++++++++++++++++------ helix-term/src/ui/lsp.rs | 7 ++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/helix-term/src/handlers/signature_help.rs b/helix-term/src/handlers/signature_help.rs index 0bb1d3d1694f..4fc00811879d 100644 --- a/helix-term/src/handlers/signature_help.rs +++ b/helix-term/src/handlers/signature_help.rs @@ -238,19 +238,33 @@ pub fn show_signature_help( .collect(); let old_popup = compositor.find_id::>(SignatureHelp::ID); - let mut active_signature = old_popup - .as_ref() - .map(|popup| popup.contents().active_signature()) - .unwrap_or_else(|| response.active_signature.unwrap_or_default() as usize); + let lsp_signature = response.active_signature.map(|s| s as usize); - if active_signature >= signatures.len() { - active_signature = signatures.len() - 1; - } + // take the new suggested lsp signature if changed + // otherwise take the old signature if possible + // otherwise the last one (in case there is less signatures than before) + let active_signature = old_popup + .as_ref() + .map(|popup| { + let old_lsp_sig = popup.contents().lsp_signature(); + let old_sig = popup + .contents() + .active_signature() + .min(signatures.len() - 1); + + if old_lsp_sig != lsp_signature { + lsp_signature.unwrap_or(old_sig) + } else { + old_sig + } + }) + .unwrap_or(lsp_signature.unwrap_or_default()); let contents = SignatureHelp::new( language.to_string(), Arc::clone(&editor.syn_loader), active_signature, + lsp_signature, signatures, ); diff --git a/helix-term/src/ui/lsp.rs b/helix-term/src/ui/lsp.rs index b82f7be294ff..d845be4a7c38 100644 --- a/helix-term/src/ui/lsp.rs +++ b/helix-term/src/ui/lsp.rs @@ -27,6 +27,7 @@ pub struct SignatureHelp { language: String, config_loader: Arc>, active_signature: usize, + lsp_signature: Option, signatures: Vec, } @@ -37,12 +38,14 @@ impl SignatureHelp { language: String, config_loader: Arc>, active_signature: usize, + lsp_signature: Option, signatures: Vec, ) -> Self { Self { language, config_loader, active_signature, + lsp_signature, signatures, } } @@ -51,6 +54,10 @@ impl SignatureHelp { self.active_signature } + pub fn lsp_signature(&self) -> Option { + self.lsp_signature + } + pub fn visible_popup(compositor: &mut Compositor) -> Option<&mut Popup> { compositor.find_id::>(Self::ID) } From 7e13213e7430c95cbad210994cecbfadc52c0714 Mon Sep 17 00:00:00 2001 From: Matthew Pomes Date: Fri, 3 May 2024 05:39:02 -0500 Subject: [PATCH 03/29] Add `is not` and `not in` to python syntax (#10647) --- runtime/queries/python/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 0a082f2fd8c9..9f7d2790ceb4 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -215,9 +215,11 @@ [ "and" "or" + "not in" "in" "not" "del" + "is not" "is" ] @keyword.operator From 61818996c63cb752afb817259a90108f884db1cb Mon Sep 17 00:00:00 2001 From: Ashley Vaughn <59515175+ashl3y-v@users.noreply.github.com> Date: Sun, 5 May 2024 06:48:50 -0700 Subject: [PATCH 04/29] =?UTF-8?q?remove=20'=20and=20add=20=E2=9F=A8?= =?UTF-8?q?=E2=9F=A9=20in=20lean=20autopairs=20(#10688)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- languages.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/languages.toml b/languages.toml index ecf1b49fd040..ec3e36ed67b8 100644 --- a/languages.toml +++ b/languages.toml @@ -1040,6 +1040,13 @@ block-comment-tokens = { start = "/-", end = "-/" } language-servers = [ "lean" ] indent = { tab-width = 2, unit = " " } +[language.auto-pairs] +'(' = ')' +'{' = '}' +'[' = ']' +'"' = '"' +'⟨' = '⟩' + [[grammar]] name = "lean" source = { git = "https://github.com/Julian/tree-sitter-lean", rev = "d98426109258b266e1e92358c5f11716d2e8f638" } From 7d1e5f18a297c126f0c03af90c7ee6131e90fd7c Mon Sep 17 00:00:00 2001 From: Silvan Schmidt Date: Mon, 6 May 2024 17:07:34 +0200 Subject: [PATCH 05/29] fix: update link in adding_languages.md (#10677) Previously, the link would point to the now moved "How to install the default language servers" page. The link now directly points to the up-to-date page. --- book/src/guides/adding_languages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/guides/adding_languages.md b/book/src/guides/adding_languages.md index 0763a3c5c586..1a47b79c673d 100644 --- a/book/src/guides/adding_languages.md +++ b/book/src/guides/adding_languages.md @@ -16,7 +16,7 @@ below. > πŸ’‘ If you are adding a new Language Server configuration, make sure to update > the -> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers) +> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/Language-Server-Configurations) > with the installation instructions. ## Grammar configuration From 50b13d1aeaa1100a65369087b0afbab0b18fe08e Mon Sep 17 00:00:00 2001 From: Guilherme Salustiano Date: Mon, 6 May 2024 17:09:21 +0200 Subject: [PATCH 06/29] docs[install/pre-build binaries]: add runtime setup (#10693) --- book/src/install.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/src/install.md b/book/src/install.md index 07865e698b84..0ba4f05f3149 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -41,9 +41,9 @@ Note that: ## Pre-built binaries -Download pre-built binaries from the -[GitHub Releases page](https://github.com/helix-editor/helix/releases). Add the binary to your system's `$PATH` to use it from the command -line. +Download pre-built binaries from the [GitHub Releases page](https://github.com/helix-editor/helix/releases). +Add the `hx` binary to your system's `$PATH` to use it from the command line, and copy the `runtime` directory into the config directory (for example `~/.config/helix/runtime` on Linux/macOS). +The runtime location can be overriden via the HELIX_RUNTIME environment variable. ## Linux, macOS, Windows and OpenBSD packaging status From 6876f923d5076ac3abe7da3d1459d7cf162eee00 Mon Sep 17 00:00:00 2001 From: Vladyslav Karasov <36513243+cotneit@users.noreply.github.com> Date: Mon, 6 May 2024 18:11:09 +0300 Subject: [PATCH 07/29] lang(json): make field key highlighting consistent with toml and yaml (#10676) --- runtime/queries/json/highlights.scm | 3 ++- runtime/queries/json5/highlights.scm | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/runtime/queries/json/highlights.scm b/runtime/queries/json/highlights.scm index 6df6c9ebcf17..17bb5f75b712 100644 --- a/runtime/queries/json/highlights.scm +++ b/runtime/queries/json/highlights.scm @@ -4,8 +4,9 @@ ] @constant.builtin.boolean (null) @constant.builtin (number) @constant.numeric + (pair - key: (_) @keyword) + key: (_) @variable.other.member) (string) @string (escape_sequence) @constant.character.escape diff --git a/runtime/queries/json5/highlights.scm b/runtime/queries/json5/highlights.scm index 4bf03fe31fc2..3ec4ee296cfa 100644 --- a/runtime/queries/json5/highlights.scm +++ b/runtime/queries/json5/highlights.scm @@ -1,11 +1,20 @@ -(string) @string - -(identifier) @constant - -(number) @constant.numeric - +[ + (true) + (false) +] @constant.builtin.boolean (null) @constant.builtin +(number) @constant.numeric -[(true) (false)] @constant.builtin.boolean +(member + name: (_) @variable.other.member) +(string) @string (comment) @comment + +"," @punctuation.delimiter +[ + "[" + "]" + "{" + "}" +] @punctuation.bracket From f86f350d5d3d30c49224ef696bac1d624930d184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Mon, 6 May 2024 17:37:04 +0200 Subject: [PATCH 08/29] Debugger template: allow missing or empty completion list (#10332) It can be convenient to define project specific debugger templates, some of which might not necessitate prompting the user to define completion. This commit makes completion optional for debugger templates and starts the dap immediately if undefined or empty. --- helix-core/src/syntax.rs | 1 + helix-term/src/commands/dap.rs | 60 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 3cf818f60d6f..bbea9bbe7ab8 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -510,6 +510,7 @@ pub enum DebugArgumentValue { pub struct DebugTemplate { pub name: String, pub request: String, + #[serde(default)] pub completion: Vec, pub args: HashMap, } diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index eda94c44fc38..0e50377ac1a3 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -172,9 +172,9 @@ pub fn dap_start_impl( let mut args: HashMap<&str, Value> = HashMap::new(); - if let Some(params) = params { - for (k, t) in &template.args { - let mut value = t.clone(); + for (k, t) in &template.args { + let mut value = t.clone(); + if let Some(ref params) = params { for (i, x) in params.iter().enumerate() { let mut param = x.to_string(); if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) { @@ -198,22 +198,22 @@ pub fn dap_start_impl( DebugArgumentValue::Boolean(_) => value, }; } + } - match value { - DebugArgumentValue::String(string) => { - if let Ok(integer) = string.parse::() { - args.insert(k, to_value(integer).unwrap()); - } else { - args.insert(k, to_value(string).unwrap()); - } - } - DebugArgumentValue::Array(arr) => { - args.insert(k, to_value(arr).unwrap()); - } - DebugArgumentValue::Boolean(bool) => { - args.insert(k, to_value(bool).unwrap()); + match value { + DebugArgumentValue::String(string) => { + if let Ok(integer) = string.parse::() { + args.insert(k, to_value(integer).unwrap()); + } else { + args.insert(k, to_value(string).unwrap()); } } + DebugArgumentValue::Array(arr) => { + args.insert(k, to_value(arr).unwrap()); + } + DebugArgumentValue::Boolean(bool) => { + args.insert(k, to_value(bool).unwrap()); + } } } @@ -272,17 +272,23 @@ pub fn dap_launch(cx: &mut Context) { templates, (), |cx, template, _action| { - let completions = template.completion.clone(); - let name = template.name.clone(); - let callback = Box::pin(async move { - let call: Callback = - Callback::EditorCompositor(Box::new(move |_editor, compositor| { - let prompt = debug_parameter_prompt(completions, name, Vec::new()); - compositor.push(Box::new(prompt)); - })); - Ok(call) - }); - cx.jobs.callback(callback); + if template.completion.is_empty() { + if let Err(err) = dap_start_impl(cx, Some(&template.name), None, None) { + cx.editor.set_error(err.to_string()); + } + } else { + let completions = template.completion.clone(); + let name = template.name.clone(); + let callback = Box::pin(async move { + let call: Callback = + Callback::EditorCompositor(Box::new(move |_editor, compositor| { + let prompt = debug_parameter_prompt(completions, name, Vec::new()); + compositor.push(Box::new(prompt)); + })); + Ok(call) + }); + cx.jobs.callback(callback); + } }, )))); } From a959c0ef9be59e63617c8e95d1ac59889d45a8b5 Mon Sep 17 00:00:00 2001 From: David Else <12832280+David-Else@users.noreply.github.com> Date: Mon, 6 May 2024 16:39:06 +0100 Subject: [PATCH 09/29] Improve the structure of the documentation (#10619) --- book/src/SUMMARY.md | 7 + book/src/building-from-source.md | 158 +++++++++++++ book/src/configuration.md | 369 ----------------------------- book/src/editor.md | 386 +++++++++++++++++++++++++++++++ book/src/install.md | 314 +------------------------ book/src/keymap.md | 2 +- book/src/package-managers.md | 150 ++++++++++++ book/src/registers.md | 54 +++++ book/src/surround.md | 24 ++ book/src/syntax-aware-motions.md | 68 ++++++ book/src/textobjects.md | 47 ++++ book/src/usage.md | 199 ---------------- 12 files changed, 896 insertions(+), 882 deletions(-) create mode 100644 book/src/building-from-source.md create mode 100644 book/src/editor.md create mode 100644 book/src/package-managers.md create mode 100644 book/src/registers.md create mode 100644 book/src/surround.md create mode 100644 book/src/syntax-aware-motions.md create mode 100644 book/src/textobjects.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index ba330cf77237..027b885a8e84 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -3,12 +3,19 @@ [Helix](./title-page.md) - [Installation](./install.md) + - [Package Managers](./package-managers.md) + - [Building from source](./building-from-source.md) - [Usage](./usage.md) + - [Registers](./registers.md) + - [Surround](./surround.md) + - [Textobjects](./textobjects.md) + - [Syntax aware motions](./syntax-aware-motions.md) - [Keymap](./keymap.md) - [Commands](./commands.md) - [Language support](./lang-support.md) - [Migrating from Vim](./from-vim.md) - [Configuration](./configuration.md) + - [Editor](./editor.md) - [Themes](./themes.md) - [Key remapping](./remapping.md) - [Languages](./languages.md) diff --git a/book/src/building-from-source.md b/book/src/building-from-source.md new file mode 100644 index 000000000000..666917ea4524 --- /dev/null +++ b/book/src/building-from-source.md @@ -0,0 +1,158 @@ +## Building from source + +- [Configuring Helix's runtime files](#configuring-helixs-runtime-files) + - [Linux and macOS](#linux-and-macos) + - [Windows](#windows) + - [Multiple runtime directories](#multiple-runtime-directories) + - [Note to packagers](#note-to-packagers) +- [Validating the installation](#validating-the-installation) +- [Configure the desktop shortcut](#configure-the-desktop-shortcut) + +Requirements: + +Clone the Helix GitHub repository into a directory of your choice. The +examples in this documentation assume installation into either `~/src/` on +Linux and macOS, or `%userprofile%\src\` on Windows. + +- The [Rust toolchain](https://www.rust-lang.org/tools/install) +- The [Git version control system](https://git-scm.com/) +- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang + +If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly: + +```sh +RUSTFLAGS="-C target-feature=-crt-static" +``` + +1. Clone the repository: + + ```sh + git clone https://github.com/helix-editor/helix + cd helix + ``` + +2. Compile from source: + + ```sh + cargo install --path helix-term --locked + ``` + + This command will create the `hx` executable and construct the tree-sitter + grammars in the local `runtime` folder. + +> πŸ’‘ If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD` + +> πŸ’‘ Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch +> grammars with `hx --grammar fetch` and compile them with +> `hx --grammar build`. This will install them in +> the `runtime` directory within the user's helix config directory (more +> [details below](#multiple-runtime-directories)). + +### Configuring Helix's runtime files + +#### Linux and macOS + +The **runtime** directory is one below the Helix source, so either export a +`HELIX_RUNTIME` environment variable to point to that directory and add it to +your `~/.bashrc` or equivalent: + +```sh +export HELIX_RUNTIME=~/src/helix/runtime +``` + +Or, create a symbolic link: + +```sh +ln -Ts $PWD/runtime ~/.config/helix/runtime +``` + +If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again. + +#### Windows + +Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for +`Edit environment variables for your account`) or use the `setx` command in +Cmd: + +```sh +setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime" +``` + +> πŸ’‘ `%userprofile%` resolves to your user directory like +> `C:\Users\Your-Name\` for example. + +Or, create a symlink in `%appdata%\helix\` that links to the source code directory: + +| Method | Command | +| ---------- | -------------------------------------------------------------------------------------- | +| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` | +| Cmd | `cd %appdata%\helix`
`mklink /D runtime "%userprofile%\src\helix\runtime"` | + +> πŸ’‘ On Windows, creating a symbolic link may require running PowerShell or +> Cmd as an administrator. + +#### Multiple runtime directories + +When Helix finds multiple runtime directories it will search through them for files in the +following order: + +1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for + developing and testing helix only). +2. `runtime/` subdirectory of OS-dependent helix user config directory. +3. `$HELIX_RUNTIME` +4. Distribution-specific fallback directory (set at compile timeβ€”not run timeβ€” + with the `HELIX_DEFAULT_RUNTIME` environment variable) +5. `runtime/` subdirectory of path to Helix executable. + +This order also sets the priority for selecting which file will be used if multiple runtime +directories have files with the same name. + +#### Note to packagers + +If you are making a package of Helix for end users, to provide a good out of +the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment +variable at build time (before invoking `cargo build`) to a directory which +will store the final runtime files after installation. For example, say you want +to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build +script could follow are: + +1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime` +1. `cargo build --profile opt --locked --path helix-term` +1. `cp -r runtime $BUILD_DIR/usr/lib/helix/` +1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx` + +This way the resulting `hx` binary will always look for its runtime directory in +`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix` +or `HELIX_RUNTIME`. + +### Validating the installation + +To make sure everything is set up as expected you should run the Helix health +check: + +```sh +hx --health +``` + +For more information on the health check results refer to +[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck). + +### Configure the desktop shortcut + +If your desktop environment supports the +[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html) +you can configure Helix to show up in the application menu by copying the +provided `.desktop` and icon files to their correct folders: + +```sh +cp contrib/Helix.desktop ~/.local/share/applications +cp contrib/helix.png ~/.icons # or ~/.local/share/icons +``` + +To use another terminal than the system default, you can modify the `.desktop` +file. For example, to use `kitty`: + +```sh +sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop +sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop +``` diff --git a/book/src/configuration.md b/book/src/configuration.md index 5e22cebf8f66..0cd12568bf94 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -33,372 +33,3 @@ signal to the Helix process on Unix operating systems, such as by using the comm Finally, you can have a `config.toml` local to a project by putting it under a `.helix` directory in your repository. Its settings will be merged with the configuration directory `config.toml` and the built-in configuration. -## Editor - -### `[editor]` Section - -| Key | Description | Default | -|--|--|---------| -| `scrolloff` | Number of lines of padding around the edge of the screen when scrolling | `5` | -| `mouse` | Enable mouse mode | `true` | -| `middle-click-paste` | Middle click paste support | `true` | -| `scroll-lines` | Number of lines to scroll per scroll wheel step | `3` | -| `shell` | Shell to use when running external commands | Unix: `["sh", "-c"]`
Windows: `["cmd", "/C"]` | -| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `absolute` | -| `cursorline` | Highlight all lines with a cursor | `false` | -| `cursorcolumn` | Highlight all columns with a cursor | `false` | -| `gutters` | Gutters to display: Available are `diagnostics` and `diff` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` | -| `auto-completion` | Enable automatic pop up of auto-completion | `true` | -| `auto-format` | Enable automatic formatting on save | `true` | -| `auto-save` | Enable automatic saving on the focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal | `false` | -| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. | `250` | -| `completion-timeout` | Time in milliseconds after typing a word character before completions are shown, set to 5 for instant. | `250` | -| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` | -| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` | -| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` | -| `auto-info` | Whether to display info boxes | `true` | -| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` | -| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | -| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | -| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | -| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | -| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` | -| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` | -| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` | -| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` | -| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` | -| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid` -| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"` - -### `[editor.statusline]` Section - -Allows configuring the statusline at the bottom of the editor. - -The configuration distinguishes between three areas of the status line: - -`[ ... ... LEFT ... ... | ... ... ... CENTER ... ... ... | ... ... RIGHT ... ... ]` - -Statusline elements can be defined as follows: - -```toml -[editor.statusline] -left = ["mode", "spinner"] -center = ["file-name"] -right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"] -separator = "β”‚" -mode.normal = "NORMAL" -mode.insert = "INSERT" -mode.select = "SELECT" -``` -The `[editor.statusline]` key takes the following sub-keys: - -| Key | Description | Default | -| --- | --- | --- | -| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` | -| `center` | A list of elements aligned to the middle of the statusline | `[]` | -| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` | -| `separator` | The character used to separate elements in the statusline | `"β”‚"` | -| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` | -| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` | -| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` | - -The following statusline elements can be configured: - -| Key | Description | -| ------ | ----------- | -| `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 | -| `file-line-ending` | The file line endings (CRLF or LF) | -| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written | -| `total-line-numbers` | The total line numbers of the opened file | -| `file-type` | The type of the opened file | -| `diagnostics` | The number of warnings and/or errors | -| `workspace-diagnostics` | The number of warnings and/or errors on workspace | -| `selections` | The number of active selections | -| `primary-selection-length` | The number of characters currently in primary selection | -| `position` | The cursor position | -| `position-percentage` | The cursor position as a percentage of the total number of lines | -| `separator` | The string defined in `editor.statusline.separator` (defaults to `"β”‚"`) | -| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) | -| `version-control` | The current branch name or detached commit hash of the opened workspace | -| `register` | The current selected register | - -### `[editor.lsp]` Section - -| Key | Description | Default | -| --- | ----------- | ------- | -| `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` | -| `display-messages` | Display LSP progress messages below statusline[^1] | `false` | -| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` | -| `display-inlay-hints` | Display inlay hints[^2] | `false` | -| `display-signature-help-docs` | Display docs under signature help popup | `true` | -| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` | -| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` | - -[^1]: By default, a progress spinner is shown in the statusline beside the file path. - -[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix. Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances. Please report any bugs you see so we can fix them! - -### `[editor.cursor-shape]` Section - -Defines the shape of cursor in each mode. -Valid values for these options are `block`, `bar`, `underline`, or `hidden`. - -> πŸ’‘ Due to limitations of the terminal environment, only the primary cursor can -> change shape. - -| Key | Description | Default | -| --- | ----------- | ------- | -| `normal` | Cursor shape in [normal mode][normal mode] | `block` | -| `insert` | Cursor shape in [insert mode][insert mode] | `block` | -| `select` | Cursor shape in [select mode][select mode] | `block` | - -[normal mode]: ./keymap.md#normal-mode -[insert mode]: ./keymap.md#insert-mode -[select mode]: ./keymap.md#select--extend-mode - -### `[editor.file-picker]` Section - -Set options for file picker and global search. Ignoring a file means it is -not visible in the Helix file picker and global search. - -All git related options are only enabled in a git repository. - -| Key | Description | Default | -|--|--|---------| -|`hidden` | Enables ignoring hidden files | `true` -|`follow-symlinks` | Follow symlinks instead of ignoring them | `true` -|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | `true` -|`parents` | Enables reading ignore files from parent directories | `true` -|`ignore` | Enables reading `.ignore` files | `true` -|`git-ignore` | Enables reading `.gitignore` files | `true` -|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true` -|`git-exclude` | Enables reading `.git/info/exclude` files | `true` -|`max-depth` | Set with an integer value for maximum depth to recurse | Unset by default - -Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files. - -Additionally, you can use Helix-specific ignore files by creating a local `.helix/ignore` file in the current workspace or a global `ignore` file located in your Helix config directory: -- Linux and Mac: `~/.config/helix/ignore` -- Windows: `%AppData%\helix\ignore` - -Example: - -```ini -# unignore in file picker and global search -!.github/ -!.gitignore -!.gitattributes -``` - -### `[editor.auto-pairs]` Section - -Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a -simple boolean value, or a specific mapping of pairs of single characters. - -To disable auto-pairs altogether, set `auto-pairs` to `false`: - -```toml -[editor] -auto-pairs = false # defaults to `true` -``` - -The default pairs are (){}[]''""``, but these can be customized by -setting `auto-pairs` to a TOML table: - -```toml -[editor.auto-pairs] -'(' = ')' -'{' = '}' -'[' = ']' -'"' = '"' -'`' = '`' -'<' = '>' -``` - -Additionally, this setting can be used in a language config. Unless -the editor setting is `false`, this will override the editor config in -documents with this language. - -Example `languages.toml` that adds `<>` and removes `''` - -```toml -[[language]] -name = "rust" - -[language.auto-pairs] -'(' = ')' -'{' = '}' -'[' = ']' -'"' = '"' -'`' = '`' -'<' = '>' -``` - -### `[editor.search]` Section - -Search specific options. - -| Key | Description | Default | -|--|--|---------| -| `smart-case` | Enable smart case regex searching (case-insensitive unless pattern contains upper case characters) | `true` | -| `wrap-around`| Whether the search should wrap after depleting the matches | `true` | - -### `[editor.whitespace]` Section - -Options for rendering whitespace with visible characters. Use `:set whitespace.render all` to temporarily enable visible whitespace. - -| Key | Description | Default | -|-----|-------------|---------| -| `render` | Whether to render whitespace. May either be `all` or `none`, or a table with sub-keys `space`, `nbsp`, `nnbsp`, `tab`, and `newline` | `none` | -| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `nnbsp`, `newline` or `tabpad` | See example below | - -Example - -```toml -[editor.whitespace] -render = "all" -# or control each character -[editor.whitespace.render] -space = "all" -tab = "all" -nbsp = "none" -nnbsp = "none" -newline = "none" - -[editor.whitespace.characters] -space = "Β·" -nbsp = "⍽" -nnbsp = "␣" -tab = "β†’" -newline = "⏎" -tabpad = "Β·" # Tabs will look like "β†’Β·Β·Β·" (depending on tab width) -``` - -### `[editor.indent-guides]` Section - -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 | `β”‚` | -| `skip-levels` | Number of indent levels to skip | `0` | - -Example: - -```toml -[editor.indent-guides] -render = true -character = "β•Ž" # Some characters that work well: "▏", "┆", "β”Š", "βΈ½" -skip-levels = 1 -``` - -### `[editor.gutters]` Section - -For simplicity, `editor.gutters` accepts an array of gutter types, which will -use default settings for all gutter components. - -```toml -[editor] -gutters = ["diff", "diagnostics", "line-numbers", "spacer"] -``` - -To customize the behavior of gutters, the `[editor.gutters]` section must -be used. This section contains top level settings, as well as settings for -specific gutter components as subsections. - -| Key | Description | Default | -| --- | --- | --- | -| `layout` | A vector of gutters to display | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` | - -Example: - -```toml -[editor.gutters] -layout = ["diff", "diagnostics", "line-numbers", "spacer"] -``` - -#### `[editor.gutters.line-numbers]` Section - -Options for the line number gutter - -| Key | Description | Default | -| --- | --- | --- | -| `min-width` | The minimum number of characters to use | `3` | - -Example: - -```toml -[editor.gutters.line-numbers] -min-width = 1 -``` - -#### `[editor.gutters.diagnostics]` Section - -Currently unused - -#### `[editor.gutters.diff]` Section - -The `diff` gutter option displays colored bars indicating whether a `git` diff represents that a line was added, removed or changed. -These colors are controlled by the theme attributes `diff.plus`, `diff.minus` and `diff.delta`. - -Other diff providers will eventually be supported by a future plugin system. - -There are currently no options for this section. - -#### `[editor.gutters.spacer]` Section - -Currently unused - -### `[editor.soft-wrap]` Section - -Options for soft wrapping lines that exceed the view width: - -| Key | Description | Default | -| --- | --- | --- | -| `enable` | Whether soft wrapping is enabled. | `false` | -| `max-wrap` | Maximum free space left at the end of the line. | `20` | -| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` | -| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `β†ͺ ` | -| `wrap-at-text-width` | Soft wrap at `text-width` instead of using the full viewport size. | `false` | - -Example: - -```toml -[editor.soft-wrap] -enable = true -max-wrap = 25 # increase value to reduce forced mid-word wrapping -max-indent-retain = 0 -wrap-indicator = "" # set wrap-indicator to "" to hide it -``` - -### `[editor.smart-tab]` Section - -Options for navigating and editing using tab key. - -| Key | Description | Default | -|------------|-------------|---------| -| `enable` | If set to true, then when the cursor is in a position with non-whitespace to its left, instead of inserting a tab, it will run `move_parent_node_end`. If there is only whitespace to the left, then it inserts a tab as normal. With the default bindings, to explicitly insert a tab character, press Shift-tab. | `true` | -| `supersede-menu` | Normally, when a menu is on screen, such as when auto complete is triggered, the tab key is bound to cycling through the items. This means when menus are on screen, one cannot use the tab key to trigger the `smart-tab` command. If this option is set to true, the `smart-tab` command always takes precedence, which means one cannot use the tab key to cycle through menu items. One of the other bindings must be used instead, such as arrow keys or `C-n`/`C-p`. | `false` | - - -Due to lack of support for S-tab in some terminals, the default keybindings don't fully embrace smart-tab editing experience. If you enjoy smart-tab navigation and a terminal that supports the [Enhanced Keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol), consider setting extra keybindings: - -``` -[keys.normal] -tab = "move_parent_node_end" -S-tab = "move_parent_node_start" - -[keys.insert] -S-tab = "move_parent_node_start" - -[keys.select] -tab = "extend_parent_node_end" -S-tab = "extend_parent_node_start" -``` diff --git a/book/src/editor.md b/book/src/editor.md new file mode 100644 index 000000000000..88541a7bc0e1 --- /dev/null +++ b/book/src/editor.md @@ -0,0 +1,386 @@ +## Editor + +- [`[editor]` Section](#editor-section) +- [`[editor.statusline]` Section](#editorstatusline-section) +- [`[editor.lsp]` Section](#editorlsp-section) +- [`[editor.cursor-shape]` Section](#editorcursor-shape-section) +- [`[editor.file-picker]` Section](#editorfile-picker-section) +- [`[editor.auto-pairs]` Section](#editorauto-pairs-section) +- [`[editor.search]` Section](#editorsearch-section) +- [`[editor.whitespace]` Section](#editorwhitespace-section) +- [`[editor.indent-guides]` Section](#editorindent-guides-section) +- [`[editor.gutters]` Section](#editorgutters-section) + - [`[editor.gutters.line-numbers]` Section](#editorguttersline-numbers-section) + - [`[editor.gutters.diagnostics]` Section](#editorguttersdiagnostics-section) + - [`[editor.gutters.diff]` Section](#editorguttersdiff-section) + - [`[editor.gutters.spacer]` Section](#editorguttersspacer-section) +- [`[editor.soft-wrap]` Section](#editorsoft-wrap-section) +- [`[editor.smart-tab]` Section](#editorsmart-tab-section) + +### `[editor]` Section + +| Key | Description | Default | +|--|--|---------| +| `scrolloff` | Number of lines of padding around the edge of the screen when scrolling | `5` | +| `mouse` | Enable mouse mode | `true` | +| `middle-click-paste` | Middle click paste support | `true` | +| `scroll-lines` | Number of lines to scroll per scroll wheel step | `3` | +| `shell` | Shell to use when running external commands | Unix: `["sh", "-c"]`
Windows: `["cmd", "/C"]` | +| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `absolute` | +| `cursorline` | Highlight all lines with a cursor | `false` | +| `cursorcolumn` | Highlight all columns with a cursor | `false` | +| `gutters` | Gutters to display: Available are `diagnostics` and `diff` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` | +| `auto-completion` | Enable automatic pop up of auto-completion | `true` | +| `auto-format` | Enable automatic formatting on save | `true` | +| `auto-save` | Enable automatic saving on the focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal | `false` | +| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. | `250` | +| `completion-timeout` | Time in milliseconds after typing a word character before completions are shown, set to 5 for instant. | `250` | +| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` | +| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` | +| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` | +| `auto-info` | Whether to display info boxes | `true` | +| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` | +| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | +| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | +| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | +| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | +| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` | +| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` | +| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` | +| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` | +| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` | +| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid` +| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"` + +### `[editor.statusline]` Section + +Allows configuring the statusline at the bottom of the editor. + +The configuration distinguishes between three areas of the status line: + +`[ ... ... LEFT ... ... | ... ... ... CENTER ... ... ... | ... ... RIGHT ... ... ]` + +Statusline elements can be defined as follows: + +```toml +[editor.statusline] +left = ["mode", "spinner"] +center = ["file-name"] +right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"] +separator = "β”‚" +mode.normal = "NORMAL" +mode.insert = "INSERT" +mode.select = "SELECT" +``` +The `[editor.statusline]` key takes the following sub-keys: + +| Key | Description | Default | +| --- | --- | --- | +| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` | +| `center` | A list of elements aligned to the middle of the statusline | `[]` | +| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` | +| `separator` | The character used to separate elements in the statusline | `"β”‚"` | +| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` | +| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` | +| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` | + +The following statusline elements can be configured: + +| Key | Description | +| ------ | ----------- | +| `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 | +| `file-line-ending` | The file line endings (CRLF or LF) | +| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written | +| `total-line-numbers` | The total line numbers of the opened file | +| `file-type` | The type of the opened file | +| `diagnostics` | The number of warnings and/or errors | +| `workspace-diagnostics` | The number of warnings and/or errors on workspace | +| `selections` | The number of active selections | +| `primary-selection-length` | The number of characters currently in primary selection | +| `position` | The cursor position | +| `position-percentage` | The cursor position as a percentage of the total number of lines | +| `separator` | The string defined in `editor.statusline.separator` (defaults to `"β”‚"`) | +| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) | +| `version-control` | The current branch name or detached commit hash of the opened workspace | +| `register` | The current selected register | + +### `[editor.lsp]` Section + +| Key | Description | Default | +| --- | ----------- | ------- | +| `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` | +| `display-messages` | Display LSP progress messages below statusline[^1] | `false` | +| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` | +| `display-inlay-hints` | Display inlay hints[^2] | `false` | +| `display-signature-help-docs` | Display docs under signature help popup | `true` | +| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` | +| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` | + +[^1]: By default, a progress spinner is shown in the statusline beside the file path. + +[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix. Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances. Please report any bugs you see so we can fix them! + +### `[editor.cursor-shape]` Section + +Defines the shape of cursor in each mode. +Valid values for these options are `block`, `bar`, `underline`, or `hidden`. + +> πŸ’‘ Due to limitations of the terminal environment, only the primary cursor can +> change shape. + +| Key | Description | Default | +| --- | ----------- | ------- | +| `normal` | Cursor shape in [normal mode][normal mode] | `block` | +| `insert` | Cursor shape in [insert mode][insert mode] | `block` | +| `select` | Cursor shape in [select mode][select mode] | `block` | + +[normal mode]: ./keymap.md#normal-mode +[insert mode]: ./keymap.md#insert-mode +[select mode]: ./keymap.md#select--extend-mode + +### `[editor.file-picker]` Section + +Set options for file picker and global search. Ignoring a file means it is +not visible in the Helix file picker and global search. + +All git related options are only enabled in a git repository. + +| Key | Description | Default | +|--|--|---------| +|`hidden` | Enables ignoring hidden files | `true` +|`follow-symlinks` | Follow symlinks instead of ignoring them | `true` +|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | `true` +|`parents` | Enables reading ignore files from parent directories | `true` +|`ignore` | Enables reading `.ignore` files | `true` +|`git-ignore` | Enables reading `.gitignore` files | `true` +|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true` +|`git-exclude` | Enables reading `.git/info/exclude` files | `true` +|`max-depth` | Set with an integer value for maximum depth to recurse | Unset by default + +Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files. + +Additionally, you can use Helix-specific ignore files by creating a local `.helix/ignore` file in the current workspace or a global `ignore` file located in your Helix config directory: +- Linux and Mac: `~/.config/helix/ignore` +- Windows: `%AppData%\helix\ignore` + +Example: + +```ini +# unignore in file picker and global search +!.github/ +!.gitignore +!.gitattributes +``` + +### `[editor.auto-pairs]` Section + +Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a +simple boolean value, or a specific mapping of pairs of single characters. + +To disable auto-pairs altogether, set `auto-pairs` to `false`: + +```toml +[editor] +auto-pairs = false # defaults to `true` +``` + +The default pairs are (){}[]''""``, but these can be customized by +setting `auto-pairs` to a TOML table: + +```toml +[editor.auto-pairs] +'(' = ')' +'{' = '}' +'[' = ']' +'"' = '"' +'`' = '`' +'<' = '>' +``` + +Additionally, this setting can be used in a language config. Unless +the editor setting is `false`, this will override the editor config in +documents with this language. + +Example `languages.toml` that adds `<>` and removes `''` + +```toml +[[language]] +name = "rust" + +[language.auto-pairs] +'(' = ')' +'{' = '}' +'[' = ']' +'"' = '"' +'`' = '`' +'<' = '>' +``` + +### `[editor.search]` Section + +Search specific options. + +| Key | Description | Default | +|--|--|---------| +| `smart-case` | Enable smart case regex searching (case-insensitive unless pattern contains upper case characters) | `true` | +| `wrap-around`| Whether the search should wrap after depleting the matches | `true` | + +### `[editor.whitespace]` Section + +Options for rendering whitespace with visible characters. Use `:set whitespace.render all` to temporarily enable visible whitespace. + +| Key | Description | Default | +|-----|-------------|---------| +| `render` | Whether to render whitespace. May either be `all` or `none`, or a table with sub-keys `space`, `nbsp`, `nnbsp`, `tab`, and `newline` | `none` | +| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `nnbsp`, `newline` or `tabpad` | See example below | + +Example + +```toml +[editor.whitespace] +render = "all" +# or control each character +[editor.whitespace.render] +space = "all" +tab = "all" +nbsp = "none" +nnbsp = "none" +newline = "none" + +[editor.whitespace.characters] +space = "Β·" +nbsp = "⍽" +nnbsp = "␣" +tab = "β†’" +newline = "⏎" +tabpad = "Β·" # Tabs will look like "β†’Β·Β·Β·" (depending on tab width) +``` + +### `[editor.indent-guides]` Section + +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 | `β”‚` | +| `skip-levels` | Number of indent levels to skip | `0` | + +Example: + +```toml +[editor.indent-guides] +render = true +character = "β•Ž" # Some characters that work well: "▏", "┆", "β”Š", "βΈ½" +skip-levels = 1 +``` + +### `[editor.gutters]` Section + +For simplicity, `editor.gutters` accepts an array of gutter types, which will +use default settings for all gutter components. + +```toml +[editor] +gutters = ["diff", "diagnostics", "line-numbers", "spacer"] +``` + +To customize the behavior of gutters, the `[editor.gutters]` section must +be used. This section contains top level settings, as well as settings for +specific gutter components as subsections. + +| Key | Description | Default | +| --- | --- | --- | +| `layout` | A vector of gutters to display | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` | + +Example: + +```toml +[editor.gutters] +layout = ["diff", "diagnostics", "line-numbers", "spacer"] +``` + +#### `[editor.gutters.line-numbers]` Section + +Options for the line number gutter + +| Key | Description | Default | +| --- | --- | --- | +| `min-width` | The minimum number of characters to use | `3` | + +Example: + +```toml +[editor.gutters.line-numbers] +min-width = 1 +``` + +#### `[editor.gutters.diagnostics]` Section + +Currently unused + +#### `[editor.gutters.diff]` Section + +The `diff` gutter option displays colored bars indicating whether a `git` diff represents that a line was added, removed or changed. +These colors are controlled by the theme attributes `diff.plus`, `diff.minus` and `diff.delta`. + +Other diff providers will eventually be supported by a future plugin system. + +There are currently no options for this section. + +#### `[editor.gutters.spacer]` Section + +Currently unused + +### `[editor.soft-wrap]` Section + +Options for soft wrapping lines that exceed the view width: + +| Key | Description | Default | +| --- | --- | --- | +| `enable` | Whether soft wrapping is enabled. | `false` | +| `max-wrap` | Maximum free space left at the end of the line. | `20` | +| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` | +| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `β†ͺ ` | +| `wrap-at-text-width` | Soft wrap at `text-width` instead of using the full viewport size. | `false` | + +Example: + +```toml +[editor.soft-wrap] +enable = true +max-wrap = 25 # increase value to reduce forced mid-word wrapping +max-indent-retain = 0 +wrap-indicator = "" # set wrap-indicator to "" to hide it +``` + +### `[editor.smart-tab]` Section + +Options for navigating and editing using tab key. + +| Key | Description | Default | +|------------|-------------|---------| +| `enable` | If set to true, then when the cursor is in a position with non-whitespace to its left, instead of inserting a tab, it will run `move_parent_node_end`. If there is only whitespace to the left, then it inserts a tab as normal. With the default bindings, to explicitly insert a tab character, press Shift-tab. | `true` | +| `supersede-menu` | Normally, when a menu is on screen, such as when auto complete is triggered, the tab key is bound to cycling through the items. This means when menus are on screen, one cannot use the tab key to trigger the `smart-tab` command. If this option is set to true, the `smart-tab` command always takes precedence, which means one cannot use the tab key to cycle through menu items. One of the other bindings must be used instead, such as arrow keys or `C-n`/`C-p`. | `false` | + + +Due to lack of support for S-tab in some terminals, the default keybindings don't fully embrace smart-tab editing experience. If you enjoy smart-tab navigation and a terminal that supports the [Enhanced Keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol), consider setting extra keybindings: + +``` +[keys.normal] +tab = "move_parent_node_end" +S-tab = "move_parent_node_start" + +[keys.insert] +S-tab = "move_parent_node_start" + +[keys.select] +tab = "extend_parent_node_end" +S-tab = "extend_parent_node_start" +``` diff --git a/book/src/install.md b/book/src/install.md index 0ba4f05f3149..debc82b0180d 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -1,38 +1,10 @@ # Installing Helix - -- [Pre-built binaries](#pre-built-binaries) -- [Linux, macOS, Windows and OpenBSD packaging status](#linux-macos-windows-and-openbsd-packaging-status) -- [Linux](#linux) - - [Ubuntu](#ubuntu) - - [Fedora/RHEL](#fedorarhel) - - [Arch Linux extra](#arch-linux-extra) - - [NixOS](#nixos) - - [Flatpak](#flatpak) - - [Snap](#snap) - - [AppImage](#appimage) -- [macOS](#macos) - - [Homebrew Core](#homebrew-core) - - [MacPorts](#macports) -- [Windows](#windows) - - [Winget](#winget) - - [Scoop](#scoop) - - [Chocolatey](#chocolatey) - - [MSYS2](#msys2) -- [Building from source](#building-from-source) - - [Configuring Helix's runtime files](#configuring-helixs-runtime-files) - - [Linux and macOS](#linux-and-macos) - - [Windows](#windows) - - [Multiple runtime directories](#multiple-runtime-directories) - - [Validating the installation](#validating-the-installation) - - [Configure the desktop shortcut](#configure-the-desktop-shortcut) - - To install Helix, follow the instructions specific to your operating system. Note that: - To get the latest nightly version of Helix, you need to - [build from source](#building-from-source). + [build from source](./building-from-source.md). - To take full advantage of Helix, install the language servers for your preferred programming languages. See the @@ -45,287 +17,3 @@ Download pre-built binaries from the [GitHub Releases page](https://github.com/h Add the `hx` binary to your system's `$PATH` to use it from the command line, and copy the `runtime` directory into the config directory (for example `~/.config/helix/runtime` on Linux/macOS). The runtime location can be overriden via the HELIX_RUNTIME environment variable. -## Linux, macOS, Windows and OpenBSD packaging status - -[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions) - -## Linux - -The following third party repositories are available: - -### Ubuntu - -Add the `PPA` for Helix: - -```sh -sudo add-apt-repository ppa:maveonair/helix-editor -sudo apt update -sudo apt install helix -``` - -### Fedora/RHEL - -```sh -sudo dnf install helix -``` - -### Arch Linux extra - -Releases are available in the `extra` repository: - -```sh -sudo pacman -S helix -``` - -> πŸ’‘ When installed from the `extra` repository, run Helix with `helix` instead of `hx`. -> -> For example: -> ```sh -> helix --health -> ``` -> to check health - -Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available -in the AUR, which builds the master branch. - -### NixOS - -Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute, -the unstable channel usually carries the latest release. - -Helix is also available as a [flake](https://nixos.wiki/wiki/Flakes) in the project -root. Use `nix develop` to spin up a reproducible development shell. Outputs are -cached for each push to master using [Cachix](https://www.cachix.org/). The -flake is configured to automatically make use of this cache assuming the user -accepts the new settings on first use. - -If you are using a version of Nix without flakes enabled, -[install Cachix CLI](https://docs.cachix.org/installation) and use -`cachix use helix` to configure Nix to use cached outputs when possible. - -### Flatpak - -Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix): - -```sh -flatpak install flathub com.helix_editor.Helix -flatpak run com.helix_editor.Helix -``` - -### Snap - -Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with: - -```sh -snap install --classic helix -``` - -This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`. - -### AppImage - -Install Helix using the Linux [AppImage](https://appimage.org/) format. -Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page. - -```sh -chmod +x helix-*.AppImage # change permission for executable mode -./helix-*.AppImage # run helix -``` - -## macOS - -### Homebrew Core - -```sh -brew install helix -``` - -### MacPorts - -```sh -port install helix -``` - -## Windows - -Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/) -or [MSYS2](https://msys2.org/). - -### Winget -Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer. -You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version. - -```sh -winget install Helix.Helix -``` - -### Scoop - -```sh -scoop install helix -``` - -### Chocolatey - -```sh -choco install helix -``` - -### MSYS2 - -For 64-bit Windows 8.1 or above: - -```sh -pacman -S mingw-w64-ucrt-x86_64-helix -``` - -## Building from source - -Requirements: - -Clone the Helix GitHub repository into a directory of your choice. The -examples in this documentation assume installation into either `~/src/` on -Linux and macOS, or `%userprofile%\src\` on Windows. - -- The [Rust toolchain](https://www.rust-lang.org/tools/install) -- The [Git version control system](https://git-scm.com/) -- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang - -If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly: - -```sh -RUSTFLAGS="-C target-feature=-crt-static" -``` - -1. Clone the repository: - - ```sh - git clone https://github.com/helix-editor/helix - cd helix - ``` - -2. Compile from source: - - ```sh - cargo install --path helix-term --locked - ``` - - This command will create the `hx` executable and construct the tree-sitter - grammars in the local `runtime` folder. - -> πŸ’‘ If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD` - -> πŸ’‘ Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch -> grammars with `hx --grammar fetch` and compile them with -> `hx --grammar build`. This will install them in -> the `runtime` directory within the user's helix config directory (more -> [details below](#multiple-runtime-directories)). - -### Configuring Helix's runtime files - -#### Linux and macOS - -The **runtime** directory is one below the Helix source, so either export a -`HELIX_RUNTIME` environment variable to point to that directory and add it to -your `~/.bashrc` or equivalent: - -```sh -export HELIX_RUNTIME=~/src/helix/runtime -``` - -Or, create a symbolic link: - -```sh -ln -Ts $PWD/runtime ~/.config/helix/runtime -``` - -If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again. - -#### Windows - -Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for -`Edit environment variables for your account`) or use the `setx` command in -Cmd: - -```sh -setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime" -``` - -> πŸ’‘ `%userprofile%` resolves to your user directory like -> `C:\Users\Your-Name\` for example. - -Or, create a symlink in `%appdata%\helix\` that links to the source code directory: - -| Method | Command | -| ---------- | -------------------------------------------------------------------------------------- | -| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` | -| Cmd | `cd %appdata%\helix`
`mklink /D runtime "%userprofile%\src\helix\runtime"` | - -> πŸ’‘ On Windows, creating a symbolic link may require running PowerShell or -> Cmd as an administrator. - -#### Multiple runtime directories - -When Helix finds multiple runtime directories it will search through them for files in the -following order: - -1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for - developing and testing helix only). -2. `runtime/` subdirectory of OS-dependent helix user config directory. -3. `$HELIX_RUNTIME` -4. Distribution-specific fallback directory (set at compile timeβ€”not run timeβ€” - with the `HELIX_DEFAULT_RUNTIME` environment variable) -5. `runtime/` subdirectory of path to Helix executable. - -This order also sets the priority for selecting which file will be used if multiple runtime -directories have files with the same name. - -#### Note to packagers - -If you are making a package of Helix for end users, to provide a good out of -the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment -variable at build time (before invoking `cargo build`) to a directory which -will store the final runtime files after installation. For example, say you want -to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build -script could follow are: - -1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime` -1. `cargo build --profile opt --locked --path helix-term` -1. `cp -r runtime $BUILD_DIR/usr/lib/helix/` -1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx` - -This way the resulting `hx` binary will always look for its runtime directory in -`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix` -or `HELIX_RUNTIME`. - -### Validating the installation - -To make sure everything is set up as expected you should run the Helix health -check: - -```sh -hx --health -``` - -For more information on the health check results refer to -[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck). - -### Configure the desktop shortcut - -If your desktop environment supports the -[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html) -you can configure Helix to show up in the application menu by copying the -provided `.desktop` and icon files to their correct folders: - -```sh -cp contrib/Helix.desktop ~/.local/share/applications -cp contrib/helix.png ~/.icons # or ~/.local/share/icons -``` - -To use another terminal than the system default, you can modify the `.desktop` -file. For example, to use `kitty`: - -```sh -sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop -sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop -``` diff --git a/book/src/keymap.md b/book/src/keymap.md index 55b467a0e691..9a6fecbabc5a 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -1,4 +1,4 @@ -# Keymap +## Keymap - [Normal mode](#normal-mode) - [Movement](#movement) diff --git a/book/src/package-managers.md b/book/src/package-managers.md new file mode 100644 index 000000000000..99d2a35007eb --- /dev/null +++ b/book/src/package-managers.md @@ -0,0 +1,150 @@ +## Package managers + +- [Linux](#linux) + - [Ubuntu](#ubuntu) + - [Fedora/RHEL](#fedorarhel) + - [Arch Linux extra](#arch-linux-extra) + - [NixOS](#nixos) + - [Flatpak](#flatpak) + - [Snap](#snap) + - [AppImage](#appimage) +- [macOS](#macos) + - [Homebrew Core](#homebrew-core) + - [MacPorts](#macports) +- [Windows](#windows) + - [Winget](#winget) + - [Scoop](#scoop) + - [Chocolatey](#chocolatey) + - [MSYS2](#msys2) + +[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions) + +## Linux + +The following third party repositories are available: + +### Ubuntu + +Add the `PPA` for Helix: + +```sh +sudo add-apt-repository ppa:maveonair/helix-editor +sudo apt update +sudo apt install helix +``` + +### Fedora/RHEL + +```sh +sudo dnf install helix +``` + +### Arch Linux extra + +Releases are available in the `extra` repository: + +```sh +sudo pacman -S helix +``` + +> πŸ’‘ When installed from the `extra` repository, run Helix with `helix` instead of `hx`. +> +> For example: +> ```sh +> helix --health +> ``` +> to check health + +Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available +in the AUR, which builds the master branch. + +### NixOS + +Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute, +the unstable channel usually carries the latest release. + +Helix is also available as a [flake](https://nixos.wiki/wiki/Flakes) in the project +root. Use `nix develop` to spin up a reproducible development shell. Outputs are +cached for each push to master using [Cachix](https://www.cachix.org/). The +flake is configured to automatically make use of this cache assuming the user +accepts the new settings on first use. + +If you are using a version of Nix without flakes enabled, +[install Cachix CLI](https://docs.cachix.org/installation) and use +`cachix use helix` to configure Nix to use cached outputs when possible. + +### Flatpak + +Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix): + +```sh +flatpak install flathub com.helix_editor.Helix +flatpak run com.helix_editor.Helix +``` + +### Snap + +Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with: + +```sh +snap install --classic helix +``` + +This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`. + +### AppImage + +Install Helix using the Linux [AppImage](https://appimage.org/) format. +Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page. + +```sh +chmod +x helix-*.AppImage # change permission for executable mode +./helix-*.AppImage # run helix +``` + +## macOS + +### Homebrew Core + +```sh +brew install helix +``` + +### MacPorts + +```sh +port install helix +``` + +## Windows + +Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/) +or [MSYS2](https://msys2.org/). + +### Winget +Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer. +You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version. + +```sh +winget install Helix.Helix +``` + +### Scoop + +```sh +scoop install helix +``` + +### Chocolatey + +```sh +choco install helix +``` + +### MSYS2 + +For 64-bit Windows 8.1 or above: + +```sh +pacman -S mingw-w64-ucrt-x86_64-helix +``` diff --git a/book/src/registers.md b/book/src/registers.md new file mode 100644 index 000000000000..2edf7e27a271 --- /dev/null +++ b/book/src/registers.md @@ -0,0 +1,54 @@ +## Registers + +- [User-defined registers](#user-defined-registers) +- [Default registers](#default-registers) +- [Special registers](#special-registers) + +In Helix, registers are storage locations for text and other data, such as the +result of a search. Registers can be used to cut, copy, and paste text, similar +to the clipboard in other text editors. Usage is similar to Vim, with `"` being +used to select a register. + +### User-defined registers + +Helix allows you to create your own named registers for storing text, for +example: + +- `"ay` - Yank the current selection to register `a`. +- `"op` - Paste the text in register `o` after the selection. + +If a register is selected before invoking a change or delete command, the selection will be stored in the register and the action will be carried out: + +- `"hc` - Store the selection in register `h` and then change it (delete and enter insert mode). +- `"md` - Store the selection in register `m` and delete it. + +### Default registers + +Commands that use registers, like yank (`y`), use a default register if none is specified. +These registers are used as defaults: + +| Register character | Contains | +| --- | --- | +| `/` | Last search | +| `:` | Last executed command | +| `"` | Last yanked text | +| `@` | Last recorded macro | + +### Special registers + +Some registers have special behavior when read from and written to. + +| Register character | When read | When written | +| --- | --- | --- | +| `_` | No values are returned | All values are discarded | +| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable | +| `.` | Contents of the current selections | This register is not writable | +| `%` | Name of the current file | This register is not writable | +| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard | +| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard | + +When yanking multiple selections to the clipboard registers, the selections +are joined with newlines. Pasting from these registers will paste multiple +selections if the clipboard was last yanked to by the Helix session. Otherwise +the clipboard contents are pasted as one selection. + diff --git a/book/src/surround.md b/book/src/surround.md new file mode 100644 index 000000000000..187d2876a4c3 --- /dev/null +++ b/book/src/surround.md @@ -0,0 +1,24 @@ +## Surround + +Helix includes built-in functionality similar to [vim-surround](https://github.com/tpope/vim-surround). +The keymappings have been inspired from [vim-sandwich](https://github.com/machakann/vim-sandwich): + +![Surround demo](https://user-images.githubusercontent.com/23398472/122865801-97073180-d344-11eb-8142-8f43809982c6.gif) + +| Key Sequence | Action | +| --------------------------------- | --------------------------------------- | +| `ms` (after selecting text) | Add surround characters to selection | +| `mr` | Replace the closest surround characters | +| `md` | Delete the closest surround characters | + +You can use counts to act on outer pairs. + +Surround can also act on multiple selections. For example, to change every occurrence of `(use)` to `[use]`: + +1. `%` to select the whole file +2. `s` to split the selections on a search term +3. Input `use` and hit Enter +4. `mr([` to replace the parentheses with square brackets + +Multiple characters are currently not supported, but planned for future release. + diff --git a/book/src/syntax-aware-motions.md b/book/src/syntax-aware-motions.md new file mode 100644 index 000000000000..aab52b1b4a86 --- /dev/null +++ b/book/src/syntax-aware-motions.md @@ -0,0 +1,68 @@ +## Moving the selection with syntax-aware motions + +`Alt-p`, `Alt-o`, `Alt-i`, and `Alt-n` (or `Alt` and arrow keys) allow you to move the +selection according to its location in the syntax tree. For example, many languages have the +following syntax for function calls: + +```js +func(arg1, arg2, arg3); +``` + +A function call might be parsed by tree-sitter into a tree like the following. + +```tsq +(call + function: (identifier) ; func + arguments: + (arguments ; (arg1, arg2, arg3) + (identifier) ; arg1 + (identifier) ; arg2 + (identifier))) ; arg3 +``` + +Use `:tree-sitter-subtree` to view the syntax tree of the primary selection. In +a more intuitive tree format: + +``` + β”Œβ”€β”€β”€β”€β” + β”‚callβ”‚ + β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β” + β”‚ β”‚ +β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” +β”‚identifierβ”‚ β”‚argumentsβ”‚ +β”‚ "func" β”‚ β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β” +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ + β”‚ β”‚ β”‚ + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚identifierβ”‚ β”‚identifierβ”‚ β”‚identifierβ”‚ + β”‚ "arg1" β”‚ β”‚ "arg2" β”‚ β”‚ "arg3" β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +If you have a selection that wraps `arg1` (see the tree above), and you use +`Alt-n`, it will select the next sibling in the syntax tree: `arg2`. + +```js +// before +func([arg1], arg2, arg3) +// after +func(arg1, [arg2], arg3); +``` + +Similarly, `Alt-o` will expand the selection to the parent node, in this case, the +arguments node. + +```js +func[(arg1, arg2, arg3)]; +``` + +There is also some nuanced behavior that prevents you from getting stuck on a +node with no sibling. When using `Alt-p` with a selection on `arg1`, the previous +child node will be selected. In the event that `arg1` does not have a previous +sibling, the selection will move up the syntax tree and select the previous +element. As a result, using `Alt-p` with a selection on `arg1` will move the +selection to the "func" `identifier`. + +[lang-support]: ./lang-support.md +[unimpaired-keybinds]: ./keymap.md#unimpaired +[tree-sitter-nav-demo]: https://user-images.githubusercontent.com/23398472/152332550-7dfff043-36a2-4aec-b8f2-77c13eb56d6f.gif diff --git a/book/src/textobjects.md b/book/src/textobjects.md new file mode 100644 index 000000000000..92ca5645bc6e --- /dev/null +++ b/book/src/textobjects.md @@ -0,0 +1,47 @@ +## Selecting and manipulating text with textobjects + +In Helix, textobjects are a way to select, manipulate and operate on a piece of +text in a structured way. They allow you to refer to blocks of text based on +their structure or purpose, such as a word, sentence, paragraph, or even a +function or block of code. + +![Textobject demo](https://user-images.githubusercontent.com/23398472/124231131-81a4bb00-db2d-11eb-9d10-8e577ca7b177.gif) +![Textobject tree-sitter demo](https://user-images.githubusercontent.com/23398472/132537398-2a2e0a54-582b-44ab-a77f-eb818942203d.gif) + +- `ma` - Select around the object (`va` in Vim, `` in Kakoune) +- `mi` - Select inside the object (`vi` in Vim, `` in Kakoune) + +| Key after `mi` or `ma` | Textobject selected | +| --- | --- | +| `w` | Word | +| `W` | WORD | +| `p` | Paragraph | +| `(`, `[`, `'`, etc. | Specified surround pairs | +| `m` | The closest surround pair | +| `f` | Function | +| `t` | Type (or Class) | +| `a` | Argument/parameter | +| `c` | Comment | +| `T` | Test | +| `g` | Change | + +> πŸ’‘ `f`, `t`, etc. need a tree-sitter grammar active for the current +document and a special tree-sitter query file to work properly. [Only +some grammars][lang-support] currently have the query file implemented. +Contributions are welcome! + +## Navigating using tree-sitter textobjects + +Navigating between functions, classes, parameters, and other elements is +possible using tree-sitter and textobject queries. For +example to move to the next function use `]f`, to move to previous +type use `[t`, and so on. + +![Tree-sitter-nav-demo][tree-sitter-nav-demo] + +For the full reference see the [unimpaired][unimpaired-keybinds] section of the key bind +documentation. + +> πŸ’‘ This feature relies on tree-sitter textobjects +> and requires the corresponding query file to work properly. + diff --git a/book/src/usage.md b/book/src/usage.md index e01482193193..859cb670959d 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -1,15 +1,5 @@ # Using Helix - -- [Registers](#registers) - - [User-defined registers](#user-defined-registers) - - [Special registers](#special-registers) -- [Surround](#surround) -- [Selecting and manipulating text with textobjects](#selecting-and-manipulating-text-with-textobjects) -- [Navigating using tree-sitter textobjects](#navigating-using-tree-sitter-textobjects) -- [Moving the selection with syntax-aware motions](#moving-the-selection-with-syntax-aware-motions) - - For a full interactive introduction to Helix, refer to the [tutor](https://github.com/helix-editor/helix/blob/master/runtime/tutor) which can be accessed via the command `hx --tutor` or `:tutor`. @@ -17,192 +7,3 @@ can be accessed via the command `hx --tutor` or `:tutor`. > πŸ’‘ Currently, not all functionality is fully documented, please refer to the > [key mappings](./keymap.md) list. -## Registers - -In Helix, registers are storage locations for text and other data, such as the -result of a search. Registers can be used to cut, copy, and paste text, similar -to the clipboard in other text editors. Usage is similar to Vim, with `"` being -used to select a register. - -### User-defined registers - -Helix allows you to create your own named registers for storing text, for -example: - -- `"ay` - Yank the current selection to register `a`. -- `"op` - Paste the text in register `o` after the selection. - -If a register is selected before invoking a change or delete command, the selection will be stored in the register and the action will be carried out: - -- `"hc` - Store the selection in register `h` and then change it (delete and enter insert mode). -- `"md` - Store the selection in register `m` and delete it. - -### Default registers - -Commands that use registers, like yank (`y`), use a default register if none is specified. -These registers are used as defaults: - -| Register character | Contains | -| --- | --- | -| `/` | Last search | -| `:` | Last executed command | -| `"` | Last yanked text | -| `@` | Last recorded macro | - -### Special registers - -Some registers have special behavior when read from and written to. - -| Register character | When read | When written | -| --- | --- | --- | -| `_` | No values are returned | All values are discarded | -| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable | -| `.` | Contents of the current selections | This register is not writable | -| `%` | Name of the current file | This register is not writable | -| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard | -| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard | - -When yanking multiple selections to the clipboard registers, the selections -are joined with newlines. Pasting from these registers will paste multiple -selections if the clipboard was last yanked to by the Helix session. Otherwise -the clipboard contents are pasted as one selection. - -## Surround - -Helix includes built-in functionality similar to [vim-surround](https://github.com/tpope/vim-surround). -The keymappings have been inspired from [vim-sandwich](https://github.com/machakann/vim-sandwich): - -![Surround demo](https://user-images.githubusercontent.com/23398472/122865801-97073180-d344-11eb-8142-8f43809982c6.gif) - -| Key Sequence | Action | -| --------------------------------- | --------------------------------------- | -| `ms` (after selecting text) | Add surround characters to selection | -| `mr` | Replace the closest surround characters | -| `md` | Delete the closest surround characters | - -You can use counts to act on outer pairs. - -Surround can also act on multiple selections. For example, to change every occurrence of `(use)` to `[use]`: - -1. `%` to select the whole file -2. `s` to split the selections on a search term -3. Input `use` and hit Enter -4. `mr([` to replace the parentheses with square brackets - -Multiple characters are currently not supported, but planned for future release. - -## Selecting and manipulating text with textobjects - -In Helix, textobjects are a way to select, manipulate and operate on a piece of -text in a structured way. They allow you to refer to blocks of text based on -their structure or purpose, such as a word, sentence, paragraph, or even a -function or block of code. - -![Textobject demo](https://user-images.githubusercontent.com/23398472/124231131-81a4bb00-db2d-11eb-9d10-8e577ca7b177.gif) -![Textobject tree-sitter demo](https://user-images.githubusercontent.com/23398472/132537398-2a2e0a54-582b-44ab-a77f-eb818942203d.gif) - -- `ma` - Select around the object (`va` in Vim, `` in Kakoune) -- `mi` - Select inside the object (`vi` in Vim, `` in Kakoune) - -| Key after `mi` or `ma` | Textobject selected | -| --- | --- | -| `w` | Word | -| `W` | WORD | -| `p` | Paragraph | -| `(`, `[`, `'`, etc. | Specified surround pairs | -| `m` | The closest surround pair | -| `f` | Function | -| `t` | Type (or Class) | -| `a` | Argument/parameter | -| `c` | Comment | -| `T` | Test | -| `g` | Change | - -> πŸ’‘ `f`, `t`, etc. need a tree-sitter grammar active for the current -document and a special tree-sitter query file to work properly. [Only -some grammars][lang-support] currently have the query file implemented. -Contributions are welcome! - -## Navigating using tree-sitter textobjects - -Navigating between functions, classes, parameters, and other elements is -possible using tree-sitter and textobject queries. For -example to move to the next function use `]f`, to move to previous -type use `[t`, and so on. - -![Tree-sitter-nav-demo][tree-sitter-nav-demo] - -For the full reference see the [unimpaired][unimpaired-keybinds] section of the key bind -documentation. - -> πŸ’‘ This feature relies on tree-sitter textobjects -> and requires the corresponding query file to work properly. - -## Moving the selection with syntax-aware motions - -`Alt-p`, `Alt-o`, `Alt-i`, and `Alt-n` (or `Alt` and arrow keys) allow you to move the -selection according to its location in the syntax tree. For example, many languages have the -following syntax for function calls: - -```js -func(arg1, arg2, arg3); -``` - -A function call might be parsed by tree-sitter into a tree like the following. - -```tsq -(call - function: (identifier) ; func - arguments: - (arguments ; (arg1, arg2, arg3) - (identifier) ; arg1 - (identifier) ; arg2 - (identifier))) ; arg3 -``` - -Use `:tree-sitter-subtree` to view the syntax tree of the primary selection. In -a more intuitive tree format: - -``` - β”Œβ”€β”€β”€β”€β” - β”‚callβ”‚ - β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β” - β”‚ β”‚ -β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” -β”‚identifierβ”‚ β”‚argumentsβ”‚ -β”‚ "func" β”‚ β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β” -β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ - β”‚ β”‚ β”‚ - β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” - β”‚identifierβ”‚ β”‚identifierβ”‚ β”‚identifierβ”‚ - β”‚ "arg1" β”‚ β”‚ "arg2" β”‚ β”‚ "arg3" β”‚ - β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ -``` - -If you have a selection that wraps `arg1` (see the tree above), and you use -`Alt-n`, it will select the next sibling in the syntax tree: `arg2`. - -```js -// before -func([arg1], arg2, arg3) -// after -func(arg1, [arg2], arg3); -``` - -Similarly, `Alt-o` will expand the selection to the parent node, in this case, the -arguments node. - -```js -func[(arg1, arg2, arg3)]; -``` - -There is also some nuanced behavior that prevents you from getting stuck on a -node with no sibling. When using `Alt-p` with a selection on `arg1`, the previous -child node will be selected. In the event that `arg1` does not have a previous -sibling, the selection will move up the syntax tree and select the previous -element. As a result, using `Alt-p` with a selection on `arg1` will move the -selection to the "func" `identifier`. - -[lang-support]: ./lang-support.md -[unimpaired-keybinds]: ./keymap.md#unimpaired -[tree-sitter-nav-demo]: https://user-images.githubusercontent.com/23398472/152332550-7dfff043-36a2-4aec-b8f2-77c13eb56d6f.gif From 295a9a95ceb65352fc6c706a38193d25a50223fd Mon Sep 17 00:00:00 2001 From: Arthur D <110528300+c0rydoras@users.noreply.github.com> Date: Mon, 6 May 2024 18:04:08 +0200 Subject: [PATCH 10/29] feat: add support for gjs and gts (#9940) --- book/src/generated/lang-support.md | 2 + languages.toml | 70 +++++++++++++++++++++++++++++ runtime/queries/_gjs/highlights.scm | 5 +++ runtime/queries/_gjs/injections.scm | 20 +++++++++ runtime/queries/gjs/highlights.scm | 1 + runtime/queries/gjs/indents.scm | 1 + runtime/queries/gjs/injections.scm | 1 + runtime/queries/gjs/locals.scm | 1 + runtime/queries/gjs/tags.scm | 1 + runtime/queries/gjs/textobjects.scm | 1 + runtime/queries/gts/highlights.scm | 1 + runtime/queries/gts/indents.scm | 1 + runtime/queries/gts/injections.scm | 1 + runtime/queries/gts/locals.scm | 1 + runtime/queries/gts/tags.scm | 1 + runtime/queries/gts/textobjects.scm | 1 + 16 files changed, 109 insertions(+) create mode 100644 runtime/queries/_gjs/highlights.scm create mode 100644 runtime/queries/_gjs/injections.scm create mode 100644 runtime/queries/gjs/highlights.scm create mode 100644 runtime/queries/gjs/indents.scm create mode 100644 runtime/queries/gjs/injections.scm create mode 100644 runtime/queries/gjs/locals.scm create mode 100644 runtime/queries/gjs/tags.scm create mode 100644 runtime/queries/gjs/textobjects.scm create mode 100644 runtime/queries/gts/highlights.scm create mode 100644 runtime/queries/gts/indents.scm create mode 100644 runtime/queries/gts/injections.scm create mode 100644 runtime/queries/gts/locals.scm create mode 100644 runtime/queries/gts/tags.scm create mode 100644 runtime/queries/gts/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 8418138c8def..f9d3dab201c1 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -62,6 +62,7 @@ | git-config | βœ“ | | | | | git-ignore | βœ“ | | | | | git-rebase | βœ“ | | | | +| gjs | βœ“ | βœ“ | βœ“ | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` | | gleam | βœ“ | βœ“ | | `gleam` | | glimmer | βœ“ | | | `ember-language-server` | | glsl | βœ“ | βœ“ | βœ“ | | @@ -73,6 +74,7 @@ | gowork | βœ“ | | | `gopls` | | graphql | βœ“ | βœ“ | | `graphql-lsp` | | groovy | βœ“ | | | | +| gts | βœ“ | βœ“ | βœ“ | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` | | hare | βœ“ | | | | | haskell | βœ“ | βœ“ | | `haskell-language-server-wrapper` | | haskell-persistent | βœ“ | | | | diff --git a/languages.toml b/languages.toml index ec3e36ed67b8..ace01e968bb6 100644 --- a/languages.toml +++ b/languages.toml @@ -197,6 +197,28 @@ inlayHints.functionLikeReturnTypes.enabled = true inlayHints.enumMemberValues.enabled = true inlayHints.parameterNames.enabled = "all" +[language-server.vscode-eslint-language-server] +command = "vscode-eslint-language-server" +args = ["--stdio"] + +[language-server.vscode-eslint-language-server.config] +validate = "on" +experimental = { useFlatConfig = false } +rulesCustomizations = [] +run = "onType" +problems = { shortenToSingleLine = false } +nodePath = "" + +[language-server.vscode-eslint-language-server.config.codeAction.disableRuleComment] +enable = true +location = "separateLine" + +[language-server.vscode-eslint-language-server.config.codeAction.showDocumentation] +enable = true + +[language-server.vscode-eslint-language-server.config.workingDirectory] +mode = "location" + [[language]] name = "rust" scope = "source.rust" @@ -3586,3 +3608,51 @@ language-servers = ["pest-language-server"] [[grammar]] name = "pest" source = { git = "https://github.com/pest-parser/tree-sitter-pest", rev = "a8a98a824452b1ec4da7f508386a187a2f234b85" } + +[[language]] +name = "gjs" +scope = "source.gjs" +file-types = ["gjs"] +roots = ["package.json", "ember-cli-build.js"] +comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } +language-servers = [ + { except-features = [ + "format", "diagnostics", + ], name = "typescript-language-server" }, + "vscode-eslint-language-server", + "ember-language-server", +] +indent = { tab-width = 2, unit = " " } +grammar = "javascript" + +[language.auto-pairs] +'<' = '>' +"'" = "'" +"{" = "}" +"(" = ")" +'"' = '"' + +[[language]] +name = "gts" +scope = "source.gts" +file-types = ["gts"] +roots = ["package.json", "ember-cli-build.js"] +comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } +language-servers = [ + { except-features = [ + "format", "diagnostics", + ], name = "typescript-language-server" }, + "vscode-eslint-language-server", + "ember-language-server", +] +indent = { tab-width = 2, unit = " " } +grammar = "typescript" + +[language.auto-pairs] +'<' = '>' +"'" = "'" +"{" = "}" +"(" = ")" +'"' = '"' diff --git a/runtime/queries/_gjs/highlights.scm b/runtime/queries/_gjs/highlights.scm new file mode 100644 index 000000000000..f410a10705d9 --- /dev/null +++ b/runtime/queries/_gjs/highlights.scm @@ -0,0 +1,5 @@ +[ + (glimmer_opening_tag) + (glimmer_closing_tag) +] @constant.builtin + diff --git a/runtime/queries/_gjs/injections.scm b/runtime/queries/_gjs/injections.scm new file mode 100644 index 000000000000..830463168b6a --- /dev/null +++ b/runtime/queries/_gjs/injections.scm @@ -0,0 +1,20 @@ +; PARSE GLIMMER TEMPLATES +(call_expression + function: [ + (identifier) @injection.language + (member_expression + property: (property_identifier) @injection.language) + ] + arguments: (template_string) @injection.content) + +; e.g.: +((glimmer_template) @injection.content + (#set! injection.language "hbs")) + +; Parse Ember/Glimmer/Handlebars/HTMLBars/etc. template literals +; e.g.: await render(hbs``) +(call_expression + function: ((identifier) @_name + (#eq? @_name "hbs")) + arguments: ((template_string) @glimmer + (#offset! @glimmer 0 1 0 -1))) diff --git a/runtime/queries/gjs/highlights.scm b/runtime/queries/gjs/highlights.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/highlights.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gjs/indents.scm b/runtime/queries/gjs/indents.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/indents.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gjs/injections.scm b/runtime/queries/gjs/injections.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/injections.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gjs/locals.scm b/runtime/queries/gjs/locals.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/locals.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gjs/tags.scm b/runtime/queries/gjs/tags.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/tags.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gjs/textobjects.scm b/runtime/queries/gjs/textobjects.scm new file mode 100644 index 000000000000..519838521e3f --- /dev/null +++ b/runtime/queries/gjs/textobjects.scm @@ -0,0 +1 @@ +; inherits: _gjs,_javascript,ecma diff --git a/runtime/queries/gts/highlights.scm b/runtime/queries/gts/highlights.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/highlights.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma diff --git a/runtime/queries/gts/indents.scm b/runtime/queries/gts/indents.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/indents.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma diff --git a/runtime/queries/gts/injections.scm b/runtime/queries/gts/injections.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/injections.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma diff --git a/runtime/queries/gts/locals.scm b/runtime/queries/gts/locals.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/locals.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma diff --git a/runtime/queries/gts/tags.scm b/runtime/queries/gts/tags.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/tags.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma diff --git a/runtime/queries/gts/textobjects.scm b/runtime/queries/gts/textobjects.scm new file mode 100644 index 000000000000..5ad3ee1bb8b2 --- /dev/null +++ b/runtime/queries/gts/textobjects.scm @@ -0,0 +1 @@ +; inherits: _gjs,_typescript,ecma From b437b8b0eed868078ea97737d919a95eca4b7cb0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 6 May 2024 18:04:32 +0200 Subject: [PATCH 11/29] Add support for Inko (#10656) This adds formatting and Tree-sitter support for Inko (https://inko-lang.org/). --- book/src/generated/lang-support.md | 1 + languages.toml | 15 +++ runtime/queries/inko/highlights.scm | 193 +++++++++++++++++++++++++++ runtime/queries/inko/indents.scm | 36 +++++ runtime/queries/inko/injections.scm | 2 + runtime/queries/inko/locals.scm | 10 ++ runtime/queries/inko/textobjects.scm | 38 ++++++ 7 files changed, 295 insertions(+) create mode 100644 runtime/queries/inko/highlights.scm create mode 100644 runtime/queries/inko/indents.scm create mode 100644 runtime/queries/inko/injections.scm create mode 100644 runtime/queries/inko/locals.scm create mode 100644 runtime/queries/inko/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index f9d3dab201c1..27fd583c230b 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -90,6 +90,7 @@ | idris | | | | `idris2-lsp` | | iex | βœ“ | | | | | ini | βœ“ | | | | +| inko | βœ“ | βœ“ | βœ“ | | | janet | βœ“ | | | | | java | βœ“ | βœ“ | βœ“ | `jdtls` | | javascript | βœ“ | βœ“ | βœ“ | `typescript-language-server` | diff --git a/languages.toml b/languages.toml index ace01e968bb6..498e9c717c06 100644 --- a/languages.toml +++ b/languages.toml @@ -2691,6 +2691,21 @@ indent = { tab-width = 4, unit = "\t" } name = "ini" source = { git = "https://github.com/justinmk/tree-sitter-ini", rev = "4d247fb876b4ae6b347687de4a179511bf67fcbc" } +[[language]] +name = "inko" +auto-format = true +scope = "source.inko" +injection-regex = "inko" +file-types = ["inko"] +roots = ["inko.pkg"] +comment-token = "#" +indent = { tab-width = 2, unit = " " } +formatter = { command = "inko", args = ["fmt", "-"] } + +[[grammar]] +name = "inko" +source = { git = "https://github.com/inko-lang/tree-sitter-inko", rev = "6983354c13a14bc621d7a3619f1790149e901187" } + [[language]] name = "bicep" scope = "source.bicep" diff --git a/runtime/queries/inko/highlights.scm b/runtime/queries/inko/highlights.scm new file mode 100644 index 000000000000..2f1cdc1276fa --- /dev/null +++ b/runtime/queries/inko/highlights.scm @@ -0,0 +1,193 @@ +; Brackets and operators +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "," + "." + ":" +] @punctuation.delimiter + +[ + "!=" + "%" + "%=" + "&" + "&=" + "*" + "**" + "**=" + "*=" + "+" + "+=" + "-" + "-=" + "/" + "/=" + "<" + "<<" + "<<=" + "<=" + "<=" + "==" + ">" + ">=" + ">=" + ">>" + ">>=" + ">>>" + ">>>=" + "^" + "^=" + "|" + "|=" +] @operator + +; Keywords +[ + "as" + "for" + "impl" + "let" + "mut" + "ref" + "uni" + "move" + "recover" +] @keyword + +"fn" @keyword.function + +"import" @keyword.control.import + +[ + "and" + "or" +] @keyword.operator + +[ + "class" + "trait" +] @keyword.storage.type + +[ + "extern" + (modifier) + (visibility) +] @keyword.storage.modifier + +[ + "loop" + "while" + (break) + (next) +] @keyword.control.repeat + +"return" @keyword.control.return + +[ + "throw" + "try" +] @keyword.control.exception + +[ + "case" + "else" + "if" + "match" +] @keyword.control.conditional + +; Comments +(line_comment) @comment.line + +; Literals +(self) @variable.builtin + +(nil) @constant.builtin + +[ + (true) + (false) +] @constant.builtin.boolean + +(integer) @constant.numeric.integer + +(float) @constant.numeric.float + +(string) @string + +(escape_sequence) @constant.character.escape + +(interpolation + "${" @punctuation.special + "}" @punctuation.special) + +(constant) @constant + +; Patterns +(integer_pattern) @constant.numeric.integer + +(string_pattern) @string + +(constant_pattern) @constant + +; Types +(generic_type + name: _ @type) + +(type) @type + +; Imports +(extern_import + path: _ @string) + +; Classes +(class + name: _ @type) + +(define_field + name: _ @variable.other.member) + +; Traits +(trait + name: _ @type) + +; Implementations +(implement_trait + class: _ @type) + +(reopen_class + name: _ @type) + +(bound + name: _ @type) + +; Methods +(method + name: _ @function) + +(external_function + name: _ @function) + +(argument + name: _ @variable.parameter) + +(named_argument + name: _ @variable.parameter) + +(call + name: _ @function) + +(field) @variable.other.member + +; Identifiers/variable references +((identifier) @function + (#is-not? local)) + +(identifier) @variable diff --git a/runtime/queries/inko/indents.scm b/runtime/queries/inko/indents.scm new file mode 100644 index 000000000000..973e212692e0 --- /dev/null +++ b/runtime/queries/inko/indents.scm @@ -0,0 +1,36 @@ +[ + (arguments) + (array) + (assign_field) + (assign_local) + (assign_receiver_field) + (binary) + (block) + (bounds) + (cast) + (class) + (class_pattern) + (compound_assign_field) + (compound_assign_local) + (compound_assign_receiver_field) + (define_constant) + (define_variable) + (grouped_expression) + (implement_trait) + (match) + (or_pattern) + (reopen_class) + (replace_field) + (replace_local) + (symbols) + (trait) + (tuple) + (tuple_pattern) + (type_arguments) +] @indent + +[ + ")" + "]" + "}" +] @outdent diff --git a/runtime/queries/inko/injections.scm b/runtime/queries/inko/injections.scm new file mode 100644 index 000000000000..36849c87341c --- /dev/null +++ b/runtime/queries/inko/injections.scm @@ -0,0 +1,2 @@ +((line_comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/inko/locals.scm b/runtime/queries/inko/locals.scm new file mode 100644 index 000000000000..3266bcae0316 --- /dev/null +++ b/runtime/queries/inko/locals.scm @@ -0,0 +1,10 @@ +[ + (method) + (block) +] @local.scope + +(argument name: _ @local.definition) +(define_variable name: _ @local.definition) +(named_argument name: _ @local.definition) + +(identifier) @local.reference diff --git a/runtime/queries/inko/textobjects.scm b/runtime/queries/inko/textobjects.scm new file mode 100644 index 000000000000..304333808f07 --- /dev/null +++ b/runtime/queries/inko/textobjects.scm @@ -0,0 +1,38 @@ +(class + body: (_) @class.inside) @class.around + +(trait + body: (_) @class.inside) @class.around + +(method + body: (_) @function.inside) @function.around + +(reopen_class + body: (_) @class.inside) @class.around + +(implement_trait + body: (_) @class.inside) @class.around + +(external_function + body: (_) @function.inside) @function.around + +(closure + body: (_) @function.inside) @function.around + +(arguments + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(type_arguments + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(line_comment) @comment.inside + +(line_comment)+ @comment.around + +(array (_) @entry.around) + +(tuple (_) @entry.around) + +(tuple_pattern (_) @entry.around) + +(define_field (_) @entry.inside) @entry.around From e16a4f8a2cc37f07c274c70c1bdcf03c70e61eec Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Mon, 6 May 2024 10:33:59 -0600 Subject: [PATCH 12/29] Expose all flake outputs through flake-compat (#10673) --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 50e7e6819716..d2c51ec3a33c 100644 --- a/default.nix +++ b/default.nix @@ -5,4 +5,4 @@ let sha256 = "sha256:1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7"; }; in - (import compat {src = ./.;}).defaultNix.default + (import compat {src = ./.;}).defaultNix From beb5afcbef9f102c209de7aa32f126ded9dda515 Mon Sep 17 00:00:00 2001 From: Szabin Date: Mon, 6 May 2024 18:51:20 +0200 Subject: [PATCH 13/29] Revert "Refactor statusline elements to build `Spans` (#9122)" (#10642) --- helix-term/src/ui/statusline.rs | 412 +++++++++++++++++++------------- 1 file changed, 242 insertions(+), 170 deletions(-) diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 8a87242f99e8..7437cbd074e5 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -4,6 +4,7 @@ use helix_view::document::DEFAULT_LANGUAGE_NAME; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, graphics::Rect, + theme::Style, Document, Editor, View, }; @@ -19,6 +20,7 @@ pub struct RenderContext<'a> { pub view: &'a View, pub focused: bool, pub spinners: &'a ProgressSpinners, + pub parts: RenderBuffer<'a>, } impl<'a> RenderContext<'a> { @@ -35,10 +37,18 @@ impl<'a> RenderContext<'a> { view, focused, spinners, + parts: RenderBuffer::default(), } } } +#[derive(Default)] +pub struct RenderBuffer<'a> { + pub left: Spans<'a>, + pub center: Spans<'a>, + pub right: Spans<'a>, +} + pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface) { let base_style = if context.focused { context.editor.theme.get("ui.statusline") @@ -48,87 +58,85 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface surface.set_style(viewport.with_height(1), base_style); - let statusline = render_statusline(context, viewport.width as usize); + let write_left = |context: &mut RenderContext, text, style| { + append(&mut context.parts.left, text, &base_style, style) + }; + let write_center = |context: &mut RenderContext, text, style| { + append(&mut context.parts.center, text, &base_style, style) + }; + let write_right = |context: &mut RenderContext, text, style| { + append(&mut context.parts.right, text, &base_style, style) + }; + + // Left side of the status line. + + let config = context.editor.config(); + + let element_ids = &config.statusline.left; + element_ids + .iter() + .map(|element_id| get_render_function(*element_id)) + .for_each(|render| render(context, write_left)); surface.set_spans( viewport.x, viewport.y, - &statusline, - statusline.width() as u16, + &context.parts.left, + context.parts.left.width() as u16, ); -} -pub fn render_statusline<'a>(context: &mut RenderContext, width: usize) -> Spans<'a> { - let config = context.editor.config(); + // Right side of the status line. - let element_ids = &config.statusline.left; - let mut left = element_ids + let element_ids = &config.statusline.right; + element_ids .iter() .map(|element_id| get_render_function(*element_id)) - .flat_map(|render| render(context).0) - .collect::>(); + .for_each(|render| render(context, write_right)); + + surface.set_spans( + viewport.x + + viewport + .width + .saturating_sub(context.parts.right.width() as u16), + viewport.y, + &context.parts.right, + context.parts.right.width() as u16, + ); + + // Center of the status line. let element_ids = &config.statusline.center; - let mut center = element_ids + element_ids .iter() .map(|element_id| get_render_function(*element_id)) - .flat_map(|render| render(context).0) - .collect::>(); + .for_each(|render| render(context, write_center)); - let element_ids = &config.statusline.right; - let mut right = element_ids - .iter() - .map(|element_id| get_render_function(*element_id)) - .flat_map(|render| render(context).0) - .collect::>(); - - let left_area_width: usize = left.iter().map(|s| s.width()).sum(); - let center_area_width: usize = center.iter().map(|s| s.width()).sum(); - let right_area_width: usize = right.iter().map(|s| s.width()).sum(); - - let min_spacing_between_areas = 1usize; - let sides_space_required = left_area_width + right_area_width + min_spacing_between_areas; - let total_space_required = sides_space_required + center_area_width + min_spacing_between_areas; - - let mut statusline: Vec = vec![]; - - if center_area_width > 0 && total_space_required <= width { - // SAFETY: this subtraction cannot underflow because `left_area_width + center_area_width + right_area_width` - // is smaller than `total_space_required`, which is smaller than `width` in this branch. - let total_spacers = width - (left_area_width + center_area_width + right_area_width); - // This is how much padding space it would take on either side to align the center area to the middle. - let center_margin = (width - center_area_width) / 2; - let left_spacers = if left_area_width < center_margin && right_area_width < center_margin { - // Align the center area to the middle if there is enough space on both sides. - center_margin - left_area_width - } else { - // Otherwise split the available space evenly and use it as margin. - // The center element won't be aligned to the middle but it will be evenly - // spaced between the left and right areas. - total_spacers / 2 - }; - let right_spacers = total_spacers - left_spacers; - - statusline.append(&mut left); - statusline.push(" ".repeat(left_spacers).into()); - statusline.append(&mut center); - statusline.push(" ".repeat(right_spacers).into()); - statusline.append(&mut right); - } else if right_area_width > 0 && sides_space_required <= width { - let side_areas_width = left_area_width + right_area_width; - statusline.append(&mut left); - statusline.push(" ".repeat(width - side_areas_width).into()); - statusline.append(&mut right); - } else if left_area_width <= width { - statusline.append(&mut left); - } + // Width of the empty space between the left and center area and between the center and right area. + let spacing = 1u16; - statusline.into() + let edge_width = context.parts.left.width().max(context.parts.right.width()) as u16; + let center_max_width = viewport.width.saturating_sub(2 * edge_width + 2 * spacing); + let center_width = center_max_width.min(context.parts.center.width() as u16); + + surface.set_spans( + viewport.x + viewport.width / 2 - center_width / 2, + viewport.y, + &context.parts.center, + center_width, + ); +} + +fn append(buffer: &mut Spans, text: String, base_style: &Style, style: Option