Compare commits

...

228 Commits

Author SHA1 Message Date
dependabot[bot]
5b0563419e build(deps): bump the rust-dependencies group with 4 updates (#14550)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-07 10:15:38 -05:00
junglerobba
c599e4e7ee commands: make goto next/prev add to the jumplist (#14467) 2025-10-06 09:05:29 -05:00
RoloEdits
e4c538831f perf(transport): switch to sonic_rs for parsing (#13690) 2025-10-06 09:04:49 -05:00
Ross Smyth
35aab18b96 nix: Update flake lock 2025-10-06 10:00:08 -04:00
Ross Smyth
93a5ff7268 nix: systems -> flakeExposed for risc-v flake exposure 2025-10-06 10:00:08 -04:00
Paul Mattern
7081150db7 add rainbow brackets to nord theme (#14546) 2025-10-06 08:56:14 -05:00
Ricardo Fernández Serrata
a270846551 feat(langs): recognize .sh_history (#14541) 2025-10-06 08:49:46 -05:00
evie
6fffaf6a7d add highlighting for nearley (#14482) 2025-10-04 15:22:28 -04:00
Lingxuan Ye
81b4a2c9d8 style: unify verbs in help message to base form (#14501) 2025-10-04 15:22:13 -04:00
alschena
e50e8a3638 feat(languages): add support for the eiffel programming language (#14470)
Co-authored-by: Alessandro Schena <alessandro.schena@constructor.org>
2025-10-04 15:12:09 -04:00
may
0a2972980f queries(scheme): properly highlight define-values (#14504) 2025-10-04 15:01:45 -04:00
Maksymilian Wrzesień
a8ac3c5010 feat: enable comment highlights in jsonnet (#14527) 2025-10-04 14:59:28 -04:00
Remo Senekowitsch
5c3e4b67d9 Add injections for mise config (#14525) 2025-10-04 14:55:40 -04:00
Will Faught
cb3c450125 Add .itermcolors to xml file types (#14531) 2025-10-04 14:55:00 -04:00
Will Faught
f327307faa Add .terminal to xml file types (#14532) 2025-10-04 14:49:43 -04:00
Remo Senekowitsch
abe82e7474 Add injections for inline scripts in jj config (#14530) 2025-10-04 14:48:54 -04:00
dependabot[bot]
bfcbef10c5 build(deps): bump the rust-dependencies group with 8 updates (#14518)
Bumps the rust-dependencies group with 8 updates:

| Package | From | To |
| --- | --- | --- |
| [thiserror](https://github.com/dtolnay/thiserror) | `2.0.16` | `2.0.17` |
| [tempfile](https://github.com/Stebalien/tempfile) | `3.22.0` | `3.23.0` |
| [regex](https://github.com/rust-lang/regex) | `1.11.2` | `1.11.3` |
| [serde](https://github.com/serde-rs/serde) | `1.0.226` | `1.0.228` |
| [libc](https://github.com/rust-lang/libc) | `0.2.175` | `0.2.176` |
| [cc](https://github.com/rust-lang/cc-rs) | `1.2.38` | `1.2.39` |
| [regex-automata](https://github.com/rust-lang/regex) | `0.4.10` | `0.4.11` |
| [windows-sys](https://github.com/microsoft/windows-rs) | `0.61.0` | `0.61.1` |


Updates `thiserror` from 2.0.16 to 2.0.17
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/2.0.16...2.0.17)

Updates `tempfile` from 3.22.0 to 3.23.0
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Stebalien/tempfile/compare/v3.22.0...v3.23.0)

Updates `regex` from 1.11.2 to 1.11.3
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.11.2...1.11.3)

Updates `serde` from 1.0.226 to 1.0.228
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.226...v1.0.228)

Updates `libc` from 0.2.175 to 0.2.176
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.176/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.175...0.2.176)

Updates `cc` from 1.2.38 to 1.2.39
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.38...cc-v1.2.39)

Updates `regex-automata` from 0.4.10 to 0.4.11
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/commits)

Updates `windows-sys` from 0.61.0 to 0.61.1
- [Release notes](https://github.com/microsoft/windows-rs/releases)
- [Commits](https://github.com/microsoft/windows-rs/commits)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-version: 2.0.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: tempfile
  dependency-version: 3.23.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: rust-dependencies
- dependency-name: regex
  dependency-version: 1.11.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: serde
  dependency-version: 1.0.228
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: libc
  dependency-version: 0.2.176
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: cc
  dependency-version: 1.2.39
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: regex-automata
  dependency-version: 0.4.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
- dependency-name: windows-sys
  dependency-version: 0.61.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: rust-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-29 23:13:15 -04:00
Jesús González
109c812233 Add rainbow brackets support to Darcula themes (#14506) 2025-09-25 15:47:01 -05:00
Norman Paniagua
50c1a676f1 Update doom-one theme (#14384) 2025-09-25 22:16:30 +02:00
Jakob Jordan
ed08fbd410 Update zenburn theme (#14459) 2025-09-24 08:55:53 -05:00
Michael Davis
ce351f4b11 Avoid cloning language server names in Document::save
`language_servers` is a `HashMap<String, Arc<Client>>` so the clients
are cheap to clone but not the language server names. The names are
unused in the save future so we can avoid the unnecessary clones by
looking only at the `HashMap::values`.
2025-09-23 10:22:50 -04:00
Sofus
a5d0a0e1c2 Support textDocument/diagnostic specification (Pull diagnostics) (#11315)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2025-09-23 09:10:58 -05:00
Alexander Shirokov
ba506a51cb Use the default terminal size when runtime detection fails
This commit adds a fallback terminal size to use when runtime detection
fails. Since calling `size` from `Terminal` will never fail now, it also
changes the function’s signature.

If the client code wants to know whether the call succeeded or failed,
it’s still possible to call `size` via `Backend`.
2025-09-23 09:33:25 -04:00
dependabot[bot]
0ebe450991 build(deps): bump the rust-dependencies group with 6 updates (#14483)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-23 08:29:37 -05:00
RoloEdits
37fe42d05d fix(lints): clippy 1.89-1.90 (#14223) 2025-09-22 08:44:17 -05:00
Sylvain Terrien
55167c21df feat: flatten single-child dirs in file explorer (#14173) 2025-09-22 08:32:27 -05:00
Karem Abdul-Samad
8acfc55280 feat: add file explorer options (#13888) 2025-09-21 14:56:44 -04:00
Daniel Fichtinger
1426e1feb5 update source for mail grammar (#14479)
Co-authored-by: Daniel Fichtinger <daniel@ficd.sh>
2025-09-21 14:42:03 -04:00
Axlefublr
1bf9879778 update nushell parser and queries (#14377) 2025-09-21 11:16:53 -05:00
Michael Davis
23a647aee8 Support mode 2031 dark/light mode detection (#14356) 2025-09-21 10:41:04 -05:00
Michael Davis
c2b582aa45 tui: Use Crossterm on Windows (#14454) 2025-09-21 09:35:08 -05:00
Ian Hobson
0ae37dc52b Add rainbows for Koto (#14469) 2025-09-18 09:12:32 -05:00
Michael Davis
dbb472d4c4 tui: Patch cell content style instead of overwriting
This is a follow-up to #13776 to patch cell contents rather than
overwrite the contents. `ui.text.focus` might only set a modifier like
bold or italic. This should not become the only style in the cell: it
should be layered on top so that the cell has the directory and text
colors from the contents.
2025-09-16 10:51:35 -04:00
Sri Senthil Balaji J
46e3617f6b fix(queries/svelte): inherit html for injections and set svelte_raw_text to typescript (#14460) 2025-09-16 09:35:34 -04:00
dependabot[bot]
c0921202a0 build(deps): bump the rust-dependencies group with 6 updates (#14458)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-15 20:35:59 -04:00
Piotr Ginał
ffe513d6aa statusline: dynamic padding for unfocused mode (#14440) 2025-09-15 17:50:05 -04:00
Sri Senthil Balaji J
d015eff4aa fix(helix-view/clipboard): use serde generated name for Win32Yank (#14455) 2025-09-15 10:18:49 -05:00
CalebLarsen
a4d780483b fix: Make Table Cells set the style of their text (#13776) 2025-09-15 09:01:21 -05:00
Ash Joseph
ea2541f424 Added Ashokai theme family (#14446) 2025-09-15 08:45:35 -05:00
Sri Senthil Balaji J
69713975c6 Switch svelte treesitter and update queries (#14343) 2025-09-15 08:44:20 -05:00
Xavier R. Guérin
2dddace12e Add support for the SlightLisp language (#14236) 2025-09-15 08:35:50 -05:00
CalebLarsen
66737c6a4f Close prompts when switching windows (#13620) 2025-09-15 08:32:43 -05:00
Matt
fbf6407ab3 Extend DebugArgumentValue to support toml tables, ref #14282 (#14283) 2025-09-15 05:56:59 -03:00
Kristoffer Plagborg Bak Sørensen
1f020b1d72 feat(languages): add latexmkrc to perl file-types (#14450) 2025-09-14 19:11:17 -04:00
Antti Eskelinen
9acfa51209 Add .tmux.conf glob to bash file-types (#14449) 2025-09-14 09:11:06 -04:00
Lukáš Lalinský
2d7436fc20 Add support for matching function call arguments in Zig (#14436) 2025-09-13 20:13:21 -04:00
Igor Támara
1388166570 feat: add support for grammar wikitext the mediawiki dialect (#14432) 2025-09-13 20:02:01 -04:00
Steffen
342f2a982d Update fortran tree sitter files (#14448) 2025-09-13 19:28:20 -04:00
Steffen
5bfc7bfc07 feat: add uppercase file extensions for Fortran (#14447) 2025-09-13 19:25:32 -04:00
Kristoffer Plagborg Bak Sørensen
5609e3b3c2 feat: add .kube/kuberc to list of yaml file-types (#14444) 2025-09-13 19:13:51 -04:00
Kristoffer Plagborg Bak Sørensen
c614467be8 feat(languages): add podman *.conf files to toml file-types (#14443) 2025-09-13 19:13:10 -04:00
Michael Davis
c531b7a4fa Add debug logging of reset-cursor escape sequence
This can be used to debug the escape sequence used to reset the cursor
when quitting Helix. The cursor should reset to whatever is configured
in the terminal but this usually needs information from terminfo.
2025-09-12 10:42:44 -04:00
Valentin Cocaud
92b0a2f414 feat(helix-tui): add configuration to manually enable/disable KKP (#14398) 2025-09-12 09:32:22 -05:00
Michael Davis
378b27cad9 Bump termina to v0.1.1
This fixes the build for Illumos as termina now skips compiling
macOS-specific polling functions when not building for macOS.
2025-09-12 10:12:55 -04:00
fl0
209558645a Add new theme: Nvim-dark (#14403) 2025-09-10 09:09:30 -05:00
dependabot[bot]
987b04bd26 build(deps): bump the rust-dependencies group with 6 updates (#14410)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-10 09:08:49 -05:00
Grégoire Locqueville
322bb1c189 Fix Lean LSP module imports (#14381)
Co-authored-by: Grégoire Locqueville <gregoire.locqueville@cnrs.fr>
2025-09-10 09:07:59 -05:00
quantonganh
34e0f7e82f Add a simple language server for HDL (nand2tetris) (#14415) 2025-09-10 08:45:50 -05:00
Kristoffer Plagborg Bak Sørensen
97293c9f36 feat(languages): add gitlab-ci language specialized from yaml (#14396) 2025-09-10 08:41:04 -05:00
Kristoffer Plagborg Bak Sørensen
71038266e8 feat(highlights): add support for syntax features in hurl version 6.0.0 (#12725) 2025-09-10 08:39:34 -05:00
Charles Hall
05a99c2cca fix white/bright white base16 color mixup (#14409) 2025-09-10 08:38:45 -05:00
Axlefublr
14030d0b63 kdl queries: basic tag.scm and niri injections (#14401) 2025-09-10 08:28:31 -05:00
Abderrahmane TAHRI JOUTI
ff376b0d1a move cyan_light to jetbrains_cyan_light (#14412) 2025-09-10 08:27:25 -05:00
Kristoffer Plagborg Bak Sørensen
d25726f573 feat: add fods and fodt extensions to xml filetype (#14416) 2025-09-10 08:26:52 -05:00
may
8f2af68b30 scheme: add block comment token, textobjects.scm (#14408)
* lang(scheme): add block comment token

* queries(scheme): add comment text objects

* chore: run cargo xtask docgen
2025-09-10 08:26:27 -05:00
Kristoffer Plagborg Bak Sørensen
fe8e21a07f feat(bash): add init scripts for xinit and startx to bash file-types (#14397) 2025-09-10 08:22:10 -05:00
may
d0218f7e78 queries(scheme): mark the variables of do as @variable 2025-09-05 10:36:13 -04:00
may
e2333f60ae queries(scheme): convert a #match? to a #any-of? 2025-09-05 10:36:13 -04:00
may
70187c430c queries(scheme): more consistently indent with two spaces
... and also remove a trailing space
2025-09-05 10:36:13 -04:00
kpbaks
8058fefef0 feat: add docker-language-server
Official language server for Dockerfiles, Compose files, and Bake files.
https://github.com/docker/docker-language-server/
2025-09-05 10:35:26 -04:00
kpbaks
0928e5ea1c feat: add docker-bake language
Docker bake files are primarily written in `hcl`, but you can also write
it in `json` and `yaml`. The official material and documentation for the
feature uses `hcl`, which is why this commit makes the choice of
associating the `docker-bake` language with `docker-bake.hcl` files.
The primary motivation of this specialization is to inject the
`dockerfile` language into the `dockerfile-inline` attribute.
2025-09-05 10:35:26 -04:00
Ariel Chenet
b391185716 Add Expert LSP support for Elixir and Heex languages (#14395)
Co-authored-by: Ariel Chenet <arielchenet@pm.me>
2025-09-05 09:31:37 -05:00
may
f59dc9e48f mark arguments of case-lambda as variable, mark case-lambda as keyword (#14386) 2025-09-04 09:08:20 -05:00
Kristoffer Plagborg Bak Sørensen
d63c2d2fea feat: add runhaskell and stack as haskell shebangs (#14385) 2025-09-04 09:06:27 -05:00
Kristoffer Plagborg Bak Sørensen
0a4207be32 feat: detect .wslconfig as ini filetype (#14383) 2025-09-04 09:06:01 -05:00
Kristoffer Plagborg Bak Sørensen
3adc021c06 feat(ruby): detect .irbrc file as ruby (#14382) 2025-09-04 09:05:34 -05:00
Axlefublr
d1750a7502 fish injection query for nu, on nu -c (#14376) 2025-09-03 10:17:07 -05:00
dependabot[bot]
c5f0a4bc22 build(deps): bump the rust-dependencies group with 2 updates (#14373)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-03 08:16:33 -05:00
Kristoffer Plagborg Bak Sørensen
4967229e85 feat(ruby): inject bash into builtin ways of running system commands (#14372) 2025-09-02 17:51:42 -05:00
Nora Breitmoser-Widdecke
68f11f9324 language support for strictdoc (#14314) 2025-09-02 08:56:15 -05:00
Kristoffer Plagborg Bak Sørensen
af74a61ad4 feat(languages): detect more vim file-types (#14365) 2025-09-02 08:39:21 -05:00
Andrey R.
cfb5158cd1 fix(theme): correct goto_word and comments background in flatwhite.toml (#14348) 2025-09-01 10:23:26 -04:00
Dang
e3fafb6bad use constant.builtin.boolean scope for ecma boolean (#14357) 2025-08-31 17:24:50 -04:00
Michael Davis
6e9939a2d1 Improve "written" message for small (<1024B) files
Using a float when the file size is in bytes is confusing. Instead we
should show "123B" for <1024B and use floats only for KiB and above.
2025-08-31 12:44:55 -04:00
Michael Davis
b08aba8e8e Remove Backend::get_cursor
It is unused and cannot be used on some terminal hosts like `conhost`
that do not respond to VT queries. This doesn't have any affect on
behavior - I'm removing it so that we don't rely on it in the future.
2025-08-31 12:25:01 -04:00
Michael Davis
83abbe56df Replace Crossterm with Termina
This change switches out the terminal manipulation library to one I've
been working on: Termina. It's somewhat similar to Crossterm API-wise
but is a bit lower-level. It's also influenced a lot by TermWiz - the
terminal manipulation library in WezTerm which we've considered
switching to a few times.

Termina is more verbose than Crossterm as it has a lower level interface
that exposes escape sequences and pushes handling to the application.
API-wise the important piece is that the equivalents of Crossterm's
`poll_internal` / `read_internal` are exposed. This is used for reading
the cursor position in both Crossterm and Termina, for example, but also
now can be used to detect features like the Kitty keyboard protocol and
synchronized output sequences simultaneously.
2025-08-31 12:25:01 -04:00
Michael Davis
9cc912a63e tui: Refactor Config type handling in backends
The `Config` can be passed when creating the backend (for example
`CrosstermBackend::new`) and is already updated in the
`Backend::reconfigure` callback. Recreating the tui `Config` during
`claim` and `restore` is unnecessary and causes a clone of the editor's
Config which is a fairly large type. This change drops the `Config`
parameter from those callbacks and updates the callers. Instead it is
passed to `CrosstermBackend` which then owns it.

I've also moved the override from the `editor.undercurl` key onto the
tui `Config` type - I believe it was just an oversight that this was not
done originally. And I've updated the `From<EditorConfig> for Config`
to take a reference to the editor's `Config` to avoid the unnecessary
clone during `CrosstermBackend::new` and `Backend::reconfigure`.
2025-08-31 10:50:02 -04:00
Nik Revenco
fe1393cec8 queries(rust): Highlight type infer in more places (#14351) 2025-08-31 09:01:45 -04:00
Nik Revenco
392e444ff9 queries(rust): properly highlight Dioxus' rsx! macro (#14354) 2025-08-31 09:01:05 -04:00
Nik Revenco
0ea5d87985 queries(rust): Highlight tacit functions when we are 100% sure they are (#14350) 2025-08-31 08:58:46 -04:00
Kristoffer Plagborg Bak Sørensen
6b73c3c550 feat: add shellcheckrc language (#14202) 2025-08-31 08:53:42 -04:00
Michael Davis
b309d72688 Fix bugs in Editor::focus (#14262) 2025-08-31 08:52:40 -04:00
Kalpaj Chaudhari
d546a799e5 Add tag queries for java, kotlin, protobuf and bash (#14349) 2025-08-31 08:47:58 -04:00
Arthur
7c37e8acea support cython (#14128) 2025-08-31 08:35:33 -04:00
Michael Davis
d4c91daa5e queries: Inject regex into regular Rust string literals
Previously regex was injected only into raw string literals.

    Regex::new(r"[a-z]") // was highlighted
    Regex::new("[a-z]") // is now also highlighted
2025-08-31 08:23:08 -04:00
Robin Kraft
dc7c2acc08 add a link to release packe on debian installation docs (#14346) 2025-08-31 07:43:57 -04:00
Kristoffer Plagborg Bak Sørensen
99cea8c284 feat(bash): inject bash into builtins expecting bash code as input (#14268) 2025-08-30 13:46:08 -04:00
Tijs-B
077c901be9 fix(htmldjango): add roots to htmldjango language (#14305) 2025-08-30 13:42:23 -04:00
Bryce Berger
a5bf7c0d5e queries: update highlights/injections for jjconfig (#14308) 2025-08-30 13:38:26 -04:00
Michael Davis
8ab20720da Update tree-sitter-gleam
The latest changes in the grammar add support for `echo ... as`
expressions.
2025-08-30 13:30:33 -04:00
dependabot[bot]
feeaec097a build(deps): bump the rust-dependencies group with 8 updates (#14317)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-30 13:27:26 -04:00
Georgios Tsoulis
4f5eaa4186 docs: fix possible error when building the optimized version from source (#14330) 2025-08-30 13:25:53 -04:00
Jonas Köhnen
7a5b618fe5 Fix shell pipe command lines not using expansions (#14191) 2025-08-30 13:16:22 -04:00
RoloEdits
77ff51caa4 feat(grammar): update zig tree-sitter (#14336) 2025-08-29 10:16:45 -04:00
Erik
7e4e556f84 feat(languages): Add buck2 PACKAGE files as starlark file type (#14324) 2025-08-27 09:46:17 -05:00
zoey
96c60198ec update: nyxvamp-theme (#14319) 2025-08-26 17:20:07 -04:00
Ross Smyth
3dadd82c89 nix: Remove debug ls -al (#14320) 2025-08-26 17:19:41 -04:00
Jaakko Paju
5a8fb732f2 add AWS config and kube config file support (#14316) 2025-08-26 10:44:01 -05:00
Kristoffer Plagborg Bak Sørensen
8671882ee2 feat(languages): specialize toml file-type for git-cliff config file (#14301) 2025-08-25 08:50:38 -05:00
Sylvain Terrien
1d3e65fdbc theme: add color-modes support to molokai (#14250) 2025-08-25 08:49:46 -05:00
Uładzisłaŭ Hińko
f81b59fc15 Add NvChad's solarized dark theme (#14280) 2025-08-25 08:49:09 -05:00
Vítor Galvão
cc8e890906 languages.toml: Add GPX extension to XML (#14300)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2025-08-25 08:38:04 -05:00
Michael Davis
aa14cd38fc queries: Fix precedence of Rust for-loop keyword highlight
The `for` literal node is marked as a `keyword` since it can also show
up outside of for loops, like in `for<'a> fn(&'a T)`. The for loop
highlight which tags `keyword.control.repeat` needs to move lower in the
file than the `keyword` one to take precedence.
2025-08-25 09:31:12 -04:00
Michael Davis
22a3b10dd8 themes: Fix other modus vivendi licenses
This is the same as 95c378a764 but for the other variants.
2025-08-22 09:35:34 -04:00
ishanray
535e6ee77b Make buffer picker default to last file (#14176) 2025-08-22 08:30:31 -05:00
Aidan Gauland
4b40b45527 Add Flatbuffers language and grammar (#14275) 2025-08-22 08:05:54 -05:00
Michael Davis
95c378a764 themes: Fix modus vivendi license
The GFDL-1.3-only text must've been copied from the modus vivendi website
<https://protesilaos.com/emacs/modus-themes#h:b14c3fcb-13dd-4144-9d92-2c58b3ed16d3>.
The actual license is a GPL-3.0-or-later:
<https://github.com/protesilaos/modus-themes/blob/main/COPYING>.
2025-08-22 08:59:54 -04:00
Kristoffer Plagborg Bak Sørensen
74bb02ffe7 feat(languages): specilize toml file-type for cross-rs config file (#14274) 2025-08-19 18:19:44 -04:00
Matej Almáši
b81ee02db4 fix adwaita-light ui.virtual color (#14238) 2025-08-19 18:09:34 -04:00
dependabot[bot]
9ec07cf1f6 build(deps): bump the rust-dependencies group with 3 updates (#14270)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-19 10:57:21 -05:00
evie
9f34f8b5ff don't remove highlights for selections in modus_* themes (#14232) 2025-08-18 08:25:03 -05:00
Kristoffer Plagborg Bak Sørensen
3fb1443162 feat(python): add regex injection to functions in the std re module (#14254) 2025-08-18 08:24:38 -05:00
Kristoffer Plagborg Bak Sørensen
207c0e3899 feat: inject jq into jq "..." string literals in common shells (#14253) 2025-08-18 08:23:53 -05:00
Erasin Wang
f9f5fe6b12 Add rainbows for Lua (#14256) 2025-08-18 08:22:50 -05:00
Erasin Wang
e5e7fe43ce Add queries for Wgsl (#14257) 2025-08-18 08:22:15 -05:00
Erasin Wang
da4ede9535 Add rainbows for ron (#14258) 2025-08-18 08:21:48 -05:00
Ricardo Fernández Serrata
6f26a257d5 Recognize .git/info/exclude as .gitignore (#14264) 2025-08-18 08:20:44 -05:00
Michael Davis
b1eb9c09f4 queries: Fix highlight of ':' in TypeScript ternary expressions
The ':' node is set to punctuation.delimiter in typescript and this
comes after the ternary_expression pattern in the ecma highlights. So we
need to copy that pattern after the punctuation.delimiter pattern.
2025-08-18 09:16:41 -04:00
Gabor Pihaj
b6ccbddc77 fix: add runtimeDir as propagated build input (#14247) 2025-08-16 10:51:17 -04:00
Gareth Widlansky
a4a2b50a50 Add support for KConfig (#14205) 2025-08-15 09:52:58 -05:00
Francesco Urbani
e5d1f6c517 feat: add a tree-sitter grammar for systemverilog (#14174) 2025-08-15 09:06:10 -05:00
Erik
050e1d9b47 feat: add a tree-sitter grammar for Doxyfile (#14235) 2025-08-15 09:01:42 -05:00
Nick Pupko
2b9cc20d23 Improve error messages for goto LSP commands (#14171) 2025-08-15 08:33:57 -05:00
Artyom Vasich
9e3b510dc7 fix(go): enable markdown injections in function doc comments (#14230) 2025-08-15 08:30:42 -05:00
Gareth Widlansky
6b93c77033 add rainbows.scm for tsq (#14216) 2025-08-15 08:30:23 -05:00
Erasin Wang
fdaec3f972 Add rainbows.scm for PHP (#14228) 2025-08-15 08:27:15 -05:00
rusty-snake
8a898c88bc book: Add Helix mode in Lite XL and Lapce (#14210) 2025-08-15 08:26:46 -05:00
Fabian Mettler
e0544d01f1 Remove the Ubuntu PPA installation method from the docs (#14237) 2025-08-15 08:25:00 -05:00
dependabot[bot]
001efa801e build(deps): bump actions/download-artifact from 4 to 5 (#14219)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2025-08-12 14:12:22 -05:00
dependabot[bot]
00dbca93c4 build(deps): bump the rust-dependencies group with 5 updates (#14222)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-12 07:53:31 -05:00
dependabot[bot]
6726c1f41c build(deps): bump actions/checkout from 4 to 5 (#14220)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-12 07:52:43 -05:00
evie
7747d3b93e adjust cyan in modus_vivendi rainbow (and yellow in _tritanopia) (#14218) 2025-08-12 07:51:46 -05:00
Peter Rice
4d0466d30c Add rainbows.scm queries for Janet (#14203) 2025-08-10 16:52:32 -04:00
Mike Boutin
ed2807ae07 Improve onedarker theme by adding highlight scopes (#14194) 2025-08-10 09:41:04 -04:00
Kristoffer Plagborg Bak Sørensen
327f3852f4 feat: add pip-requirements language (#14161) 2025-08-09 20:17:42 -04:00
Friedrich Stoltzfus
155fde5178 feat: add tree-sitter rainbow query for Swift (#14165) 2025-08-09 20:16:05 -04:00
Nik Revenco
f5a399c7f9 fix: 2 bugs in the Alt-) and Alt-( commands (#13985) 2025-08-09 20:13:37 -04:00
Trevor Gross
cb7188d5cc jj: Set the indent to four spaces for descriptions (#14199) 2025-08-09 20:07:03 -04:00
Poliorcetics
a44695e4e8 just: bump grammar support to fix alias name bug and add tag queries (#14169) 2025-08-09 19:57:16 -04:00
Jonas Köhnen
ef3a49d03c Support features of :open in :vsplit & :hsplit (#13461) 2025-08-09 19:50:49 -04:00
Kristoffer Plagborg Bak Sørensen
56fa9bf7c1 feat: inject css into standard browser API methods that expect css selector as argument (#14181) 2025-08-09 19:42:27 -04:00
Álan Crístoffer
b5a9c34e14 languages(matlab): bump grammar version (#14195) 2025-08-09 19:39:39 -04:00
infastin
e8e36a6a8e feat: update go grammar and queries (#14167) 2025-08-09 18:45:23 -04:00
infastin
18572973e6 feat: update css grammar and highlights.scm (#14147)
* feat: update css grammar and highlights.scm

* chore: replace any-of with match

* fix: replace match with eq

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2025-08-08 09:34:09 +09:00
Isaac Corbrey
4a25f63169 languages: Add doc comment token for C# (#14164) 2025-08-08 09:33:27 +09:00
dependabot[bot]
0345400c41 build(deps): bump the rust-dependencies group with 4 updates (#14163)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-05 08:26:46 -05:00
quantonganh
43990ed0c8 feat: add a tree-sitter grammar for hdl (#14140) 2025-08-03 17:38:22 -04:00
Kristoffer Plagborg Bak Sørensen
178c55708a feat: add robots.txt language (#14089) 2025-08-03 17:19:09 -04:00
Kristoffer Plagborg Bak Sørensen
6c0d598183 Update go-format-string grammar and queries (#14106) 2025-08-03 17:18:09 -04:00
evie
5b5f6daab3 fix parentheses in popup description for html tag matching (#14157) 2025-08-03 17:17:44 -04:00
zoey
601c904e50 chore: visual fixes to nyxvamp radiance base variant theme (#14130) 2025-08-03 17:11:51 -04:00
chtenb
93cf3b1baf Update koka grammar and queries to support koka v3 (#14135) 2025-08-03 17:04:49 -04:00
Kristoffer Plagborg Bak Sørensen
fdfc6df122 Add --no-format flag to :update command (#14136) 2025-08-03 16:56:33 -04:00
Rich
d2595930fa docs: add encodings for < and > literals in remapping (#14144)
Currently docs do not include the remappings for literal < or >, which can be important characters for macros relating to markup languages.
2025-08-02 11:27:27 -04:00
evie
758f80a4fc give modus-vivendi rainbows (#14131) 2025-07-31 09:01:53 -05:00
Trevor Gross
e58b08d22a docker: Update the default indentation to match other editors (#14108) 2025-07-30 08:50:20 -05:00
Alex Pearwin
62f3cd3f5a docs: Correct expansion argument formatting (#14123) 2025-07-30 08:47:50 -05:00
Mo Bitar
39cccc23e5 book: Update inline diagnostics defaults (#14124) 2025-07-30 08:45:14 -05:00
dependabot[bot]
f0be627dcb build(deps): bump the rust-dependencies group with 7 updates (#14109)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-29 09:40:56 -05:00
wcampbell
1bdd8ae784 Update rst to v0.2.0 (#14111) 2025-07-29 09:40:00 -05:00
Remo Senekowitsch
2d5a19f081 editorconfig: allow empty alternates (#14107) 2025-07-28 18:02:42 -05:00
David Else
d9fe4798fa Add rainbow brackets for dark_plus (#14103) 2025-07-28 09:45:03 -05:00
Matthew Toohey
39eec87284 Remove lean server memory limit (#14075) 2025-07-27 23:13:08 -04:00
Emran
285a7440a3 Update tree-sitter-blade and queries (#14097)
Co-authored-by: Emran <Emran@MacBook.local>
2025-07-27 19:29:17 -04:00
Knoqx
2f7cc9d0ae Reduce weight of 1 space indents in indent detection (#14088) 2025-07-27 18:36:18 -04:00
Michael Davis
ca4f638dfd Run 'cargo xtask docgen' 2025-07-27 15:18:36 -04:00
George Hollister
4480da752c feat(theme): Sync catppuccin themes to include rainbow array (#14094) 2025-07-27 15:18:00 -04:00
Michael Davis
1f7b593857 Add rainbows.scm queries for rust-format-args-macro
This fixes rainbow brackets within format macros like `println!`.
2025-07-27 15:09:59 -04:00
alice pellerin
6807e32ec1 Preserve file creation time on macOS and Windows (#13561) 2025-07-26 20:29:37 -04:00
Michael Davis
54e748b0ce Run 'cargo xtask docgen' 2025-07-26 18:37:15 -04:00
jyn
c8224bcf4e add insert_character_interactive command (#11411) 2025-07-26 18:32:41 -04:00
Michael Davis
1941f0b639 Rainbow tree-sitter matches 🌈 (#13530) 2025-07-26 18:02:29 -04:00
Kristoffer Plagborg Bak Sørensen
e17b80a5a2 feat: add grammar for lua pattern language (#14082) 2025-07-26 17:25:46 -04:00
Michael Davis
6dc4722665 Enable inline diagnostics by default (#13970) 2025-07-26 17:23:15 -04:00
Muhammad Fathir Irhas
6ea3677b9f Current working directory status (#10998)
Co-authored-by: mfirhas <mfathirirhas@gmail.com>
2025-07-26 17:12:07 -04:00
rathewolf
fe2291a59b add aura 'n aurara themes (#11791) 2025-07-26 17:08:59 -04:00
Daniel Rotter
a789ec7f4b Use separate color for primary selection in jetbrains_dark (#12606)
Co-authored-by: Yannic Nuwenhof <ynuwenhof@pm.me>
2025-07-26 16:42:17 -04:00
CalebLarsen
6b511964bb docs: Add jumplist documentation to the book (#13849) 2025-07-26 16:41:40 -04:00
Michael Davis
ddbac29d14 docs: Add architecture notes for stdx and event crates
Co-authored-by: kirawi <67773714+kirawi@users.noreply.github.com>E
2025-07-26 16:38:58 -04:00
Md Atiquz Zaman
f4557d0bff Enhance Sidra theme color palette and JS support (#14033) 2025-07-26 16:05:30 -04:00
RoloEdits
6479f74a57 feat(lsp): sort diagnostic picker by severity (#13806) 2025-07-26 15:58:04 -04:00
Axlefublr
27c90b7fff add more quote types to markdown autopairs (#13693) 2025-07-26 15:54:31 -04:00
Chuyang Chen
9ea190b729 Improve the keymap doc in the book (#13655) 2025-07-26 15:39:41 -04:00
Sylvain Terrien
c2782568f1 feat: add language filtering to hx --health (#13484) 2025-07-26 15:38:25 -04:00
Daniel Fichtinger
8dbc664a30 feat: add yamlfmt as default yaml formatter (#13310) 2025-07-26 15:22:19 -04:00
Nik Revenco
f72b6f758b feat: add workspace_directory and current_working_directory variable expansions (#13068)
Co-authored-by: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com>
2025-07-26 14:58:32 -04:00
Daniel Fichtinger
4fd4588482 feat: Add vimscript language support (#13062) 2025-07-26 14:51:15 -04:00
Hendrik
94c96cfe0e fix(queries): typst function highlight (#14068) 2025-07-26 12:16:48 -04:00
Carter Watson
44b5413716 fix: gruvbox theme collision (#14063) 2025-07-26 12:16:21 -04:00
Alexander
e15134beac prompt: fix crash on unwrap graphemes (#14050)
Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2025-07-26 12:14:55 -04:00
Kristoffer Plagborg Bak Sørensen
22e60d6a71 feat: highlight go string interpolation that use stdlib fmt package (#14069) 2025-07-26 11:51:10 -04:00
RoloEdits
8297d60ca0 ci(release): update runner os for windows and macos (#14073) 2025-07-26 11:48:45 -04:00
Valtteri Koskivuori
4281228da3 fix(queries): Fix filesystem permissions for snakemake (#14061) 2025-07-24 13:09:40 -04:00
kiara
395a71bf53 languages: nix formatter (#14046) 2025-07-23 12:51:17 -04:00
Ian Hobson
1e4bf6704a Update Koto grammar and queries, add formatter (#14049) 2025-07-23 12:47:47 -04:00
Alexander Meinhardt Scheurer-Volkmann
b01fbb4a22 Fix symlink directories in file explorer (#14028) 2025-07-21 14:10:06 -04:00
MrWheatley
f75a26cb9b added janet indents (#14020) 2025-07-21 14:07:11 -04:00
MrWheatley
21ae1c98fb fix janet highlights (#14017) 2025-07-21 14:00:21 -04:00
Fea
7b8a4b7a51 feat: Add kotlin-lsp to languages.toml (#14021) 2025-07-21 14:00:08 -04:00
Yorick Peterse
715d4ae2d5 tree-sitter: update Inko grammar and queries (#14022) 2025-07-21 13:51:50 -04:00
Ivan Shymkiv
22b184b570 Fixed theme location (#14016) 2025-07-19 17:33:47 -05:00
Ivan Shymkiv
665ee4da22 feat(theme): add Gruvbox Material Dark theme variants (#14005) 2025-07-19 15:45:15 -05:00
Ivan Shymkiv
ecd18e3eb2 feat(themes): add Gruvbox Material Light theme (#14007) 2025-07-19 15:44:42 -05:00
Poliorcetics
e7f95ca6b2 just: bump grammar support to handle module path in aliases and recipes dependencies (#14009) 2025-07-19 15:18:18 -04:00
Michael Davis
4418e338e8 Use syntax symbol pickers for Erlang
Neither language server robustly supports workspace symbol search.
`erlang-ls`'s symbol picker takes a long time to open successfully on
boot. `elp`'s is faster but not faster than the tags query.
2025-07-18 11:17:10 -04:00
Michael Davis
6c71fc00b2 Document tags.scm queries, commands and language support 2025-07-18 11:17:10 -04:00
Michael Davis
727758e068 Add syntax symbol pickers based on tags.scm queries 2025-07-18 11:16:42 -04:00
Michael Davis
63eb1b870c Add initial tags.scm queries
Co-authored-by: cgahr <26804763+cgahr@users.noreply.github.com>
Co-authored-by: eh <correia.eh@gmail.com>
2025-07-18 11:12:41 -04:00
Michael Davis
2d5826d194 Complete words from open buffers (#13206) 2025-07-18 09:51:00 -05:00
Michael Davis
9f4ef2fc3d Add release notes for 25.07.1
(cherry picked from commit a05c151bb6)
2025-07-18 10:39:27 -04:00
RoloEdits
fd8aacc1a4 build: lower ubuntu version from 24.04 to 22.04 (#13983) 2025-07-18 09:16:21 -05:00
Björn Ganslandt
2ee11a0a9d Add textobjects for XML, HTML and JSX (#11158) 2025-07-16 09:02:52 -05:00
Poliorcetics
9512cb9472 contrib(completions/nushell): switch from deprecated filter to where (#13848) 2025-07-16 08:43:33 -05:00
Bryce Berger
3658e97c2b Add tree-sitter injections for jj config files (#13926) 2025-07-16 08:36:54 -05:00
dependabot[bot]
ab668c2dfc build(deps): bump toml from 0.8.23 to 0.9.2 in the rust-dependencies group (#13955)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2025-07-16 08:18:17 -05:00
Anton Romanov
ef2ebc5f24 [theme] Fix zenburn doc comment color (#13962) 2025-07-16 08:10:57 -05:00
Michael Davis
5cda70e866 Add changelog notes for 25.07 (#13939) 2025-07-15 13:26:52 -05:00
Meiram Shunshalin
c67c3faa78 feat(themes): add soft-wrap style for nightfox (#13957) 2025-07-15 08:42:41 -05:00
373 changed files with 17359 additions and 2866 deletions

View File

@@ -20,7 +20,7 @@ jobs:
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install MSRV toolchain - name: Install MSRV toolchain
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master
@@ -51,7 +51,7 @@ jobs:
HELIX_LOG_LEVEL: info HELIX_LOG_LEVEL: info
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install MSRV toolchain - name: Install MSRV toolchain
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master
@@ -85,7 +85,7 @@ jobs:
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install MSRV toolchain - name: Install MSRV toolchain
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master
@@ -121,7 +121,7 @@ jobs:
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install MSRV toolchain - name: Install MSRV toolchain
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install nix - name: Install nix
uses: cachix/install-nix-action@v31 uses: cachix/install-nix-action@v31

View File

@@ -11,7 +11,7 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
- name: Setup mdBook - name: Setup mdBook
uses: peaceiris/actions-mdbook@v2 uses: peaceiris/actions-mdbook@v2

View File

@@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Install stable toolchain - name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
@@ -58,23 +58,21 @@ jobs:
strategy: strategy:
fail-fast: false # don't fail other jobs if one fails fail-fast: false # don't fail other jobs if one fails
matrix: matrix:
build: [x86_64-linux, aarch64-linux, x86_64-macos, x86_64-windows] #, x86_64-win-gnu, win32-msvc build: [x86_64-linux, aarch64-linux, x86_64-macos, x86_64-windows, aarch64-macos] #, x86_64-win-gnu, win32-msvc
include: include:
- build: x86_64-linux - build: x86_64-linux
os: ubuntu-24.04 # WARN: When changing this to a newer version, make sure that the GLIBC isnt too new, as this can cause issues
# with portablity on older systems that dont follow ubuntus more rapid release cadence.
os: ubuntu-22.04
rust: stable rust: stable
target: x86_64-unknown-linux-gnu target: x86_64-unknown-linux-gnu
cross: false cross: false
- build: aarch64-linux - build: aarch64-linux
os: ubuntu-24.04-arm # Version should be kept in lockstep with the x86_64 version
os: ubuntu-22.04-arm
rust: stable rust: stable
target: aarch64-unknown-linux-gnu target: aarch64-unknown-linux-gnu
cross: false cross: false
# - build: riscv64-linux
# os: ubuntu-22.04
# rust: stable
# target: riscv64gc-unknown-linux-gnu
# cross: true
- build: x86_64-macos - build: x86_64-macos
os: macos-latest os: macos-latest
rust: stable rust: stable
@@ -85,13 +83,16 @@ jobs:
rust: stable rust: stable
target: x86_64-pc-windows-msvc target: x86_64-pc-windows-msvc
cross: false cross: false
# 23.03: build issues
- build: aarch64-macos - build: aarch64-macos
os: macos-latest os: macos-latest
rust: stable rust: stable
target: aarch64-apple-darwin target: aarch64-apple-darwin
cross: false cross: false
skip_tests: true # x86_64 host can't run aarch64 code # - build: riscv64-linux
# os: ubuntu-22.04
# rust: stable
# target: riscv64gc-unknown-linux-gnu
# cross: true
# - build: x86_64-win-gnu # - build: x86_64-win-gnu
# os: windows-2019 # os: windows-2019
# rust: stable-x86_64-gnu # rust: stable-x86_64-gnu
@@ -103,16 +104,16 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Download grammars - name: Download grammars
uses: actions/download-artifact@v4 uses: actions/download-artifact@v5
- name: Move grammars under runtime - name: Move grammars under runtime
if: "!startsWith(matrix.os, 'windows')" if: "!startsWith(matrix.os, 'windows')"
run: | run: |
mkdir -p runtime/grammars/sources mkdir -p runtime/grammars/sources
tar xJf grammars/grammars.tar.xz -C runtime/grammars/sources tar xJf grammars.tar.xz -C runtime/grammars/sources
# The rust-toolchain action ignores rust-toolchain.toml files. # The rust-toolchain action ignores rust-toolchain.toml files.
# Removing this before building with cargo ensures that the rust-toolchain # Removing this before building with cargo ensures that the rust-toolchain
@@ -213,7 +214,7 @@ jobs:
shell: bash shell: bash
run: | run: |
mkdir -p dist mkdir -p dist
if [ "${{ matrix.os }}" = "windows-2019" ]; then if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/opt/hx.exe" "dist/" cp "target/${{ matrix.target }}/opt/hx.exe" "dist/"
else else
cp "target/${{ matrix.target }}/opt/hx" "dist/" cp "target/${{ matrix.target }}/opt/hx" "dist/"
@@ -234,9 +235,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v5
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v5
- name: Build archive - name: Build archive
shell: bash shell: bash
@@ -291,7 +292,7 @@ jobs:
file_glob: true file_glob: true
tag: ${{ github.ref_name }} tag: ${{ github.ref_name }}
overwrite: true overwrite: true
- name: Upload binaries as artifact - name: Upload binaries as artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
if: env.preview == 'true' if: env.preview == 'true'

View File

@@ -20,6 +20,306 @@ Updated languages and queries:
Packaging: Packaging:
--> -->
# 25.07.1 (2025-07-18)
This is a patch release which lowers the GLIBC requirements of the release artifacts published to GitHub ([#13983](https://github.com/helix-editor/helix/pull/13983))
# 25.07 (2025-07-15)
As always, a big thank you to all of the contributors! This release saw changes from 195 contributors.
Breaking changes:
* The parsing of the command line has been rewritten and now supports flags and expansions ([#12527](https://github.com/helix-editor/helix/pull/12527), [#13018](https://github.com/helix-editor/helix/pull/13018), [9574e55](https://github.com/helix-editor/helix/commit/9574e55), [2d4c2a1](https://github.com/helix-editor/helix/commit/2d4c2a1), [#13192](https://github.com/helix-editor/helix/pull/13192), [67f1fe2](https://github.com/helix-editor/helix/commit/67f1fe2), [#13466](https://github.com/helix-editor/helix/pull/13466), [#13467](https://github.com/helix-editor/helix/pull/13467), [#13840](https://github.com/helix-editor/helix/pull/13840))
* Quoting and spaces are now handled differently. This can break existing keymaps which use typable commands, in particular `:sh`, `:set-option` or `:toggle-option`.
* The `:rsort` command has been removed. Use the reverse flag instead: `:sort --reverse`
Features:
* Add a picker which explores directories ([#11285](https://github.com/helix-editor/helix/pull/11285), [d4aed40](https://github.com/helix-editor/helix/commit/d4aed40))
* Allow cycling through multiple LSP Hover responses with `A-n`/`A-p` ([#10122](https://github.com/helix-editor/helix/pull/10122), [2367b20](https://github.com/helix-editor/helix/commit/2367b20))
* Add support for incomplete LSP completions ([5c1f3f8](https://github.com/helix-editor/helix/commit/5c1f3f8))
* Add support for EditorConfig ([#13056](https://github.com/helix-editor/helix/pull/13056), [#13443](https://github.com/helix-editor/helix/pull/13443))
* Add support for LSP document colors ([#12308](https://github.com/helix-editor/helix/pull/12308), [d43de14](https://github.com/helix-editor/helix/commit/d43de14), [47cdd23](https://github.com/helix-editor/helix/commit/47cdd23), [ba54b6a](https://github.com/helix-editor/helix/commit/ba54b6a), [#13188](https://github.com/helix-editor/helix/pull/13188))
* Support expansions in external formatter arguments ([#13429](https://github.com/helix-editor/helix/pull/13429))
* Switch out the highlighter for the `tree-house` crate ([#12972](https://github.com/helix-editor/helix/pull/12972), [09bc67a](https://github.com/helix-editor/helix/commit/09bc67a), [a7c3a43](https://github.com/helix-editor/helix/commit/a7c3a43), [3ceae88](https://github.com/helix-editor/helix/commit/3ceae88), [05ae617](https://github.com/helix-editor/helix/commit/05ae617), [5a1dcc2](https://github.com/helix-editor/helix/commit/5a1dcc2), [ebf96bd](https://github.com/helix-editor/helix/commit/ebf96bd), [#13644](https://github.com/helix-editor/helix/pull/13644), [b1f4717](https://github.com/helix-editor/helix/commit/b1f4717), [7410fe3](https://github.com/helix-editor/helix/commit/7410fe3), [633c5fb](https://github.com/helix-editor/helix/commit/633c5fb), [362e97e](https://github.com/helix-editor/helix/commit/362e97e), [#13828](https://github.com/helix-editor/helix/pull/13828), [6fd1efd](https://github.com/helix-editor/helix/commit/6fd1efd))
* This fixes a number of highlighter bugs.
* Locals like parameter highlights are now highlighted even when the definition is not in view.
* Markdown is now injected into rust doc comments (`///` and `//!`).
* Add support for the DAP `startDebugging` reverse request ([#13403](https://github.com/helix-editor/helix/pull/13403))
Commands:
* Add `copy_between_registers` for interactive copying between two registers ([066e938](https://github.com/helix-editor/helix/commit/066e938))
* Add `extend_to_file_{start,end}`, select-mode variants of `goto_file_{start,end}` ([#11767](https://github.com/helix-editor/helix/pull/11767))
* Add `:!` alias for `:sh` and `:|` for `:pipe` ([#13263](https://github.com/helix-editor/helix/pull/13263))
* Add `goto_column` and `extend_to_column` ([#13440](https://github.com/helix-editor/helix/pull/13440))
* Add an `--insensitive`/`-i` flag to the `:sort` command ([#13560](https://github.com/helix-editor/helix/pull/13560))
* Add `rotate_selections_first` and `rotate_selections_last` ([#13615](https://github.com/helix-editor/helix/pull/13615))
* Add a `--no-format` flag for all `:write` commands ([2f56091](https://github.com/helix-editor/helix/commit/2f56091))
* Add a `--skip-visible` flag for `:buffer-close-others` and `:buffer-close-others!` ([#5393](https://github.com/helix-editor/helix/pull/5393))
Usability improvements:
* Replace current file using `A-ret` in pickers rather than loading it in the background ([#12605](https://github.com/helix-editor/helix/pull/12605))
* Set multiple selections when passing a file with multiple locations to `hx` ([#12192](https://github.com/helix-editor/helix/pull/12192))
* Add path completion for multiple cursors ([#12550](https://github.com/helix-editor/helix/pull/12550), [c9dc940](https://github.com/helix-editor/helix/commit/c9dc940))
* Truncate long prompt lines with "…" ([#12036](https://github.com/helix-editor/helix/pull/12036), [9d6ea77](https://github.com/helix-editor/helix/commit/9d6ea77), [0b9701e](https://github.com/helix-editor/helix/commit/0b9701e), [d3fb8fc](https://github.com/helix-editor/helix/commit/d3fb8fc))
* Allow specifying languages in `:lsp-stop` and `:lsp-restart` ([#12578](https://github.com/helix-editor/helix/pull/12578), [3d7e273](https://github.com/helix-editor/helix/commit/3d7e273))
* Add `m` (nearest matching pair) to infobox popups for `md` and `mr` ([#12650](https://github.com/helix-editor/helix/pull/12650))
* Add a hint message in the statusline when using `:sort` on a single selection ([#12585](https://github.com/helix-editor/helix/pull/12585))
* Avoid wrapping around in `goto_{next,prev}_diag` ([#12704](https://github.com/helix-editor/helix/pull/12704))
* Support responses from multiple language servers for LSP goto-definition (and declaration, type definition and implementation) and goto-references ([f7394d5](https://github.com/helix-editor/helix/commit/f7394d5), [1a821ac](https://github.com/helix-editor/helix/commit/1a821ac), [d285a8a](https://github.com/helix-editor/helix/commit/d285a8a))
* Show formatter errors in `:format` ([47f84d0](https://github.com/helix-editor/helix/commit/47f84d0))
* Show typable command docs in keybinding infobox popups when the command takes no arguments ([e9c16b7](https://github.com/helix-editor/helix/commit/e9c16b7))
* Add per-command titles to register selection infobox popups for `select_register`, `insert_register` and `copy_between_registers` ([e0da129](https://github.com/helix-editor/helix/commit/e0da129))
* Add container name column to the LSP symbol picker ([#12930](https://github.com/helix-editor/helix/pull/12930))
* Add a theme key for highlighting directories in completions and picker items ([#12855](https://github.com/helix-editor/helix/pull/12855), [7bebe0a](https://github.com/helix-editor/helix/commit/7bebe0a))
* Add `editor.trim-final-newlines` and `editor.trim-trailing-whitespace` config options ([aa20eb8](https://github.com/helix-editor/helix/commit/aa20eb8))
* Warn when the configured theme is unusable because true-color is not available ([#13058](https://github.com/helix-editor/helix/pull/13058))
* Allow configuring `[workspace-]diagnostic` statusline element severities ([#13288](https://github.com/helix-editor/helix/pull/13288), [b0528bb](https://github.com/helix-editor/helix/commit/b0528bb))
* Improve completion for shell commands ([#12883](https://github.com/helix-editor/helix/pull/12883), [532f241](https://github.com/helix-editor/helix/commit/532f241))
* Show the primary selection index in the `selections` statusline element when there are multiple selections ([#12326](https://github.com/helix-editor/helix/pull/12326))
* Use configured language server names when possible in `--health` output ([#13573](https://github.com/helix-editor/helix/pull/13573))
* Add a statusline element for indentation style ([#13632](https://github.com/helix-editor/helix/pull/13632))
* Set the working directory of language server commands to the workspace root ([#13691](https://github.com/helix-editor/helix/pull/13691))
* Avoid jumpiness in the picker preview for languages with non-default tab widths ([#13761](https://github.com/helix-editor/helix/pull/13761))
* Add a config option for limiting LSP inlay hint length ([#13742](https://github.com/helix-editor/helix/pull/13742))
* Improve heuristics used in the diff gutter ([#13722](https://github.com/helix-editor/helix/pull/13722))
* Allow moving a file with `:move` when its old path does not exist ([#13748](https://github.com/helix-editor/helix/pull/13748))
* Allow moving a file into a directory with `:move` ([#13922](https://github.com/helix-editor/helix/pull/13922))
* Show human-readable file sizes in the statusline message for file writes ([#13627](https://github.com/helix-editor/helix/pull/13627))
* Add diagnostic source to the diagnosics pickers ([#13758](https://github.com/helix-editor/helix/pull/13758))
* Show all active scopes under the cursor in `:tree-sitter-highlight-name` ([4a85171](https://github.com/helix-editor/helix/commit/4a85171))
* Auto-close the LSP code-actions popup ([#13832](https://github.com/helix-editor/helix/pull/13832))
* Add a configuration option for controlling atomic writes to disk ([#13656](https://github.com/helix-editor/helix/pull/13656))
Fixes:
* Fix panic from using `search_selection_detect_word_boundaries` (`*`) at the end of the file ([#12611](https://github.com/helix-editor/helix/pull/12611))
* Discard placeholder text for zero tabstop `${0:placeholder}` ([#12647](https://github.com/helix-editor/helix/pull/12647))
* Fix panic in `goto_file` (`gf`) on file names with non-ASCII characters ([#12673](https://github.com/helix-editor/helix/pull/12673))
* Only accept unmodified characters in `goto_word` (`gw`) ([f5f9f49](https://github.com/helix-editor/helix/commit/f5f9f49), [0364521](https://github.com/helix-editor/helix/commit/0364521))
* Skip recording keys pressed by macros while recording a macro ([#12733](https://github.com/helix-editor/helix/pull/12733))
* Deny unknown fields in `editor.smart-tab` config ([28047fe](https://github.com/helix-editor/helix/commit/28047fe))
* Fix soft-wrap word boundary detection for Unicode combining accent characters ([#12483](https://github.com/helix-editor/helix/pull/12483))
* Fix clearing of infobox popups in `select_register` and `insert_register` commands ([e882a75](https://github.com/helix-editor/helix/commit/e882a75))
* Fix handling of `stderr` of DAP child processes ([d0d1693](https://github.com/helix-editor/helix/commit/d0d1693))
* Cancel all pending requests when a DAP session terminates ([26db541](https://github.com/helix-editor/helix/commit/26db541))
* Properly discard out-of-date diagnostics ([313a647](https://github.com/helix-editor/helix/commit/313a647))
* Fix display of multiple language servers in `hx --health` ([#12841](https://github.com/helix-editor/helix/pull/12841))
* Respect `editor.default-yank-register` in `:yank-joined` ([#12890](https://github.com/helix-editor/helix/pull/12890))
* Escape percent character when pasting the history register into the picker ([#12886](https://github.com/helix-editor/helix/pull/12886))
* Render rulers before the cursor ([2d3b75a](https://github.com/helix-editor/helix/commit/2d3b75a))
* Avoid inserting final newlines in empty files ([67879a1](https://github.com/helix-editor/helix/commit/67879a1))
* Gracefully handle partial failure in multi-language-server requests ([#13156](https://github.com/helix-editor/helix/pull/13156), [14cab4b](https://github.com/helix-editor/helix/commit/14cab4b))
* Improve LSP progress message display in the statusline ([#13180](https://github.com/helix-editor/helix/pull/13180))
* Fix behavior of `<esc>` removing added indentation in documents with CRLF line endings ([702a961](https://github.com/helix-editor/helix/commit/702a961))
* Append changes to document history before pushing jumplist jumps ([#13619](https://github.com/helix-editor/helix/pull/13619))
* Fix overflow in the display of large chunks of text in the signature-help component ([#13566](https://github.com/helix-editor/helix/pull/13566))
* Fix panic from clearing whitespace when changing multiple selections on one line ([#13673](https://github.com/helix-editor/helix/pull/13673))
* Include formatting options in LSP range formatting request ([#13734](https://github.com/helix-editor/helix/pull/13734))
* Consistently set statusline errors when LSP features are not available ([#12577](https://github.com/helix-editor/helix/pull/12577))
* Fix `goto_file` on Windows ([#13770](https://github.com/helix-editor/helix/pull/13770))
* Fix crash in `goto_word` (`gw`) when `editor.jump-label-alphabet` is configured to be empty ([#13863](https://github.com/helix-editor/helix/pull/13863))
* Fix `open_above` / `open_below` (`o` / `O`) when using a count on a document with CRLF line-endings ([#13905](https://github.com/helix-editor/helix/pull/13905))
Themes:
* Update `modus` themes ([#12670](https://github.com/helix-editor/helix/pull/12670))
* Update `snazzy` ([#11089](https://github.com/helix-editor/helix/pull/11089))
* Update `gruber-darker` ([#12797](https://github.com/helix-editor/helix/pull/12797))
* Update `cyan_light` ([#12864](https://github.com/helix-editor/helix/pull/12864), [#12891](https://github.com/helix-editor/helix/pull/12891))
* Update `onedarker` ([#12833](https://github.com/helix-editor/helix/pull/12833))
* Update `github_light` ([#12907](https://github.com/helix-editor/helix/pull/12907))
* Update `kanagawa` ([#12895](https://github.com/helix-editor/helix/pull/12895))
* Add `beans` ([#12963](https://github.com/helix-editor/helix/pull/12963))
* Update `base16_transparent` ([#13080](https://github.com/helix-editor/helix/pull/13080))
* Update `sunset` ([#13086](https://github.com/helix-editor/helix/pull/13086))
* Add `carbon` ([#13067](https://github.com/helix-editor/helix/pull/13067))
* Update `soralized` ([#13121](https://github.com/helix-editor/helix/pull/13121))
* Add `focus_nova` ([#13144](https://github.com/helix-editor/helix/pull/13144))
* Update `onedark` ([#13166](https://github.com/helix-editor/helix/pull/13166))
* Update `adwaita-light` ([#13174](https://github.com/helix-editor/helix/pull/13174))
* Add `earl_grey` ([#13203](https://github.com/helix-editor/helix/pull/13203))
* Update `spacebones` ([#13213](https://github.com/helix-editor/helix/pull/13213))
* Add `peachpuff` ([#13225](https://github.com/helix-editor/helix/pull/13225))
* Update catppuccin themes ([#13262](https://github.com/helix-editor/helix/pull/13262))
* Update gruvbox themes ([#13315](https://github.com/helix-editor/helix/pull/13315))
* Update serika themes ([#13341](https://github.com/helix-editor/helix/pull/13341))
* Add `gruvbox-material` ([#13311](https://github.com/helix-editor/helix/pull/13311))
* Add `ashen` ([#13366](https://github.com/helix-editor/helix/pull/13366))
* Update Zed themes ([#13370](https://github.com/helix-editor/helix/pull/13370))
* Update Tokyonight themes ([#13375](https://github.com/helix-editor/helix/pull/13375))
* Update `onelight` ([#13413](https://github.com/helix-editor/helix/pull/13413))
* Add `ataraxia` ([#13390](https://github.com/helix-editor/helix/pull/13390))
* Add `vesper` ([#13394](https://github.com/helix-editor/helix/pull/13394))
* Add `kinda_nvim` and `kinda_nvim_light` ([#13406](https://github.com/helix-editor/helix/pull/13406))
* Update `sonokai` ([#13410](https://github.com/helix-editor/helix/pull/13410))
* Add `nyxvamp` themes ([#12185](https://github.com/helix-editor/helix/pull/12185))
* Update nord themes ([#13574](https://github.com/helix-editor/helix/pull/13574))
* Add `lapis_aquamarine` ([#13726](https://github.com/helix-editor/helix/pull/13726))
* Add `sidra` ([#13575](https://github.com/helix-editor/helix/pull/13575))
* Add `dark-synthwave` ([#13857](https://github.com/helix-editor/helix/pull/13857))
* Update `rose_pine` ([#13908](https://github.com/helix-editor/helix/pull/13908))
* Add `doom-one` ([#13933](https://github.com/helix-editor/helix/pull/13933))
* Update `nightfox` ([#13957](https://github.com/helix-editor/helix/pull/13957))
New languages:
* Ghostty config ([#12703](https://github.com/helix-editor/helix/pull/12703))
* Tera ([#12756](https://github.com/helix-editor/helix/pull/12756))
* FGA ([#12763](https://github.com/helix-editor/helix/pull/12763))
* CSV ([#11973](https://github.com/helix-editor/helix/pull/11973))
* Yara ([#12753](https://github.com/helix-editor/helix/pull/12753))
* Djot ([#12562](https://github.com/helix-editor/helix/pull/12562))
* Ink ([#12773](https://github.com/helix-editor/helix/pull/12773))
* Mail ([#12945](https://github.com/helix-editor/helix/pull/12945))
* SourcePawn ([#13028](https://github.com/helix-editor/helix/pull/13028))
* TLA+ ([#13081](https://github.com/helix-editor/helix/pull/13081))
* Werk ([#13136](https://github.com/helix-editor/helix/pull/13136))
* Debian control file ([#13245](https://github.com/helix-editor/helix/pull/13245))
* WESL ([#13267](https://github.com/helix-editor/helix/pull/13267))
* Fennel ([#13260](https://github.com/helix-editor/helix/pull/13260), [6081a5d](https://github.com/helix-editor/helix/commit/6081a5d))
* Quarto ([#13339](https://github.com/helix-editor/helix/pull/13339))
* Pug ([#13435](https://github.com/helix-editor/helix/pull/13435))
* Slang ([#13449](https://github.com/helix-editor/helix/pull/13449))
* Dunst config ([#13458](https://github.com/helix-editor/helix/pull/13458))
* Luau ([#13702](https://github.com/helix-editor/helix/pull/13702))
* Caddyfile ([#13859](https://github.com/helix-editor/helix/pull/13859))
* Java properties ([#13874](https://github.com/helix-editor/helix/pull/13874))
* Git notes ([#13885](https://github.com/helix-editor/helix/pull/13885))
* systemd (split from INI) ([#13907](https://github.com/helix-editor/helix/pull/13907))
* JSON-LD (split from JSON) ([#13925](https://github.com/helix-editor/helix/pull/13925))
* Django HTML ([#13935](https://github.com/helix-editor/helix/pull/13935))
Updated languages and queries:
* Add `ruby-lsp` for Ruby ([#12511](https://github.com/helix-editor/helix/pull/12511))
* Add `wat_server` for Wat ([#12581](https://github.com/helix-editor/helix/pull/12581))
* Recognize `bun.lock` as JSONC ([fcf981b](https://github.com/helix-editor/helix/commit/fcf981b))
* Update tree-sitter-rust ([#12607](https://github.com/helix-editor/helix/pull/12607), [1afa63d](https://github.com/helix-editor/helix/commit/1afa63d))
* Fix configuration of `cs-lsp` ([#12615](https://github.com/helix-editor/helix/pull/12615))
* Add `beancount-language-server` for Beancount ([#12610](https://github.com/helix-editor/helix/pull/12610))
* Update tree-sitter-fish ([#12456](https://github.com/helix-editor/helix/pull/12456))
* Add `fish-lsp` for Fish ([#12456](https://github.com/helix-editor/helix/pull/12456))
* Update tree-sitter-ini ([#12456](https://github.com/helix-editor/helix/pull/12456), [#13088](https://github.com/helix-editor/helix/pull/13088))
* Recognize `hgrc` as INI ([#12456](https://github.com/helix-editor/helix/pull/12456))
* Restrict tagged template injection languages for ECMA languages ([#12217](https://github.com/helix-editor/helix/pull/12217))
* Update tree-sitter-zig ([#11980](https://github.com/helix-editor/helix/pull/11980), [#12708](https://github.com/helix-editor/helix/pull/12708))
* Update tree-sitter-elixir ([8bf9adf](https://github.com/helix-editor/helix/commit/8bf9adf))
* Add `asm-lsp` for Assembly dialects ([#12684](https://github.com/helix-editor/helix/pull/12684))
* Update tree-sitter-just ([#12692](https://github.com/helix-editor/helix/pull/12692), #)
* Update tree-sitter-cairo ([#12712](https://github.com/helix-editor/helix/pull/12712))
* Configure a comment token for Svelte ([#12743](https://github.com/helix-editor/helix/pull/12743))
* Recognize `.sublime-*` files ([#12750](https://github.com/helix-editor/helix/pull/12750))
* Highlight `$` tagged templates as shell commands in ECMA languages ([#12751](https://github.com/helix-editor/helix/pull/12751))
* Add `#'` comment token for R ([#12748](https://github.com/helix-editor/helix/pull/12748))
* Fix module/namespace highlight in Unison ([93fa990](https://github.com/helix-editor/helix/commit/93fa990))
* Add missing `#not-eq?` and `#not-match?` highlights in TSQ ([3824010](https://github.com/helix-editor/helix/commit/3824010))
* Reverse the precedence order of highlight queries ([#9458](https://github.com/helix-editor/helix/pull/9458), [#12777](https://github.com/helix-editor/helix/pull/12777), [#12795](https://github.com/helix-editor/helix/pull/12795), [144a4f4](https://github.com/helix-editor/helix/commit/144a4f4), [e1c26eb](https://github.com/helix-editor/helix/commit/e1c26eb), [e1060a2](https://github.com/helix-editor/helix/commit/e1060a2), [7f41670](https://github.com/helix-editor/helix/commit/7f41670), [#13293](https://github.com/helix-editor/helix/pull/13293))
* Update Rust highlights ([b8bfc44](https://github.com/helix-editor/helix/commit/b8bfc44), [#12871](https://github.com/helix-editor/helix/pull/12871), [#13664](https://github.com/helix-editor/helix/pull/13664))
* Add block comment configuration for PHP ([0ab403d](https://github.com/helix-editor/helix/commit/0ab403d))
* Update Gren highlights ([#12769](https://github.com/helix-editor/helix/pull/12769))
* Remove `ERROR` node highlighting from all highlight queries ([16ff063](https://github.com/helix-editor/helix/commit/16ff063))
* Update tree-sitter-erlang and highlights ([18b9eb9](https://github.com/helix-editor/helix/commit/18b9eb9), [9f3b193](https://github.com/helix-editor/helix/commit/9f3b193), [12139a4](https://github.com/helix-editor/helix/commit/12139a4))
* Update Nix injections ([#12776](https://github.com/helix-editor/helix/pull/12776), [#12774](https://github.com/helix-editor/helix/pull/12774), [#13851](https://github.com/helix-editor/helix/pull/13851))
* Add indent queries for Nix ([#12829](https://github.com/helix-editor/helix/pull/12829))
* Update Markdown highlights ([#12696](https://github.com/helix-editor/helix/pull/12696))
* Recognize `xsl` as XML ([#12834](https://github.com/helix-editor/helix/pull/12834))
* Remove deprecated `typst-lsp` config ([5a66270](https://github.com/helix-editor/helix/commit/5a66270))
* Replace `pkgbuild-language-server` with `termux-language-server` ([c3c9a0d](https://github.com/helix-editor/helix/commit/c3c9a0d))
* Update SQL highlights ([#12837](https://github.com/helix-editor/helix/pull/12837))
* Recognize `mpd` and `smil` as XML ([#12916](https://github.com/helix-editor/helix/pull/12916))
* Add indents and textojbects for Kotlin ([#12925](https://github.com/helix-editor/helix/pull/12925))
* Fix module highlights in Koto ([7e87a36](https://github.com/helix-editor/helix/commit/7e87a36))
* Update language servers for Protobuf ([#12936](https://github.com/helix-editor/helix/pull/12936))
* Add `astro-ls` for Astro ([#12939](https://github.com/helix-editor/helix/pull/12939))
* Fix recognition of "scons*" files as Python ([#12943](https://github.com/helix-editor/helix/pull/12943))
* Update C# queries ([#12948](https://github.com/helix-editor/helix/pull/12948))
* Add comment textojbect to TOML ([#12952](https://github.com/helix-editor/helix/pull/12952))
* Add `starpls` as Starlark language server ([#12958](https://github.com/helix-editor/helix/pull/12958))
* Add `pkl-lsp` for PKL ([#12962](https://github.com/helix-editor/helix/pull/12962))
* Add `kdlfmt` formatter for KDL ([#12967](https://github.com/helix-editor/helix/pull/12967))
* Update CSS highlights ([#12497](https://github.com/helix-editor/helix/pull/12497), [fed3edc](https://github.com/helix-editor/helix/commit/fed3edc))
* Add `harper-ls` ([#13029](https://github.com/helix-editor/helix/pull/13029))
* Change `wgsl_analyzer` to `wgsl-analyzer` ([#13063](https://github.com/helix-editor/helix/pull/13063))
* Update tree-sitter-vhdl ([#13091](https://github.com/helix-editor/helix/pull/13091))
* Update tree-sitter-openscad ([#13033](https://github.com/helix-editor/helix/pull/13033))
* Update Rust injections ([694b615](https://github.com/helix-editor/helix/commit/694b615), [1bd7a39](https://github.com/helix-editor/helix/commit/1bd7a39))
* Update Ruby highlights ([#13055](https://github.com/helix-editor/helix/pull/13055))
* Recognize `gitconfig` as an extension ([#13115](https://github.com/helix-editor/helix/pull/13115))
* Add `///` comment token for Amber ([#13122](https://github.com/helix-editor/helix/pull/13122))
* Add indent queries for Starlark ([#13126](https://github.com/helix-editor/helix/pull/13126))
* Recognize more systemd file types as INI ([#13139](https://github.com/helix-editor/helix/pull/13139))
* Update scheme queries ([#13143](https://github.com/helix-editor/helix/pull/13143))
* Recognize `tmTheme` as XML ([#13202](https://github.com/helix-editor/helix/pull/13202))
* Update `golangci-lint` command for v2 ([#13204](https://github.com/helix-editor/helix/pull/13204))
* Add `just-lsp` for Just ([#13276](https://github.com/helix-editor/helix/pull/13276))
* Add a tree-sitter-prolog grammar ([#11611](https://github.com/helix-editor/helix/pull/11611))
* Fix typos in Ada queries ([#13251](https://github.com/helix-editor/helix/pull/13251))
* Update mint language server args ([#13248](https://github.com/helix-editor/helix/pull/13248))
* Update typescript highlights ([#13250](https://github.com/helix-editor/helix/pull/13250))
* Update tree-sitter-jjdescription ([#13329](https://github.com/helix-editor/helix/pull/13329))
* Add injection queries for Quint ([#13322](https://github.com/helix-editor/helix/pull/13322))
* Update tree-sitter-scss and highlights ([#13414](https://github.com/helix-editor/helix/pull/13414))
* Update tree-sitter-go-mod ([#13395](https://github.com/helix-editor/helix/pull/13395))
* Update tree-sitter-svelte ([#13423](https://github.com/helix-editor/helix/pull/13423))
* Update Lua highlights ([#13401](https://github.com/helix-editor/helix/pull/13401))
* Update Go highlights ([#13425](https://github.com/helix-editor/helix/pull/13425), [25b299a](https://github.com/helix-editor/helix/commit/25b299a), [#13825](https://github.com/helix-editor/helix/pull/13825))
* Recognize `.git-blame-ignore-revs` as gitignore ([#13460](https://github.com/helix-editor/helix/pull/13460))
* Update Verilog highlights ([#13473](https://github.com/helix-editor/helix/pull/13473), [#13493](https://github.com/helix-editor/helix/pull/13493))
* Update tree-sitter-v ([#13469](https://github.com/helix-editor/helix/pull/13469))
* Update WGSL highlights ([#13479](https://github.com/helix-editor/helix/pull/13479))
* Update Bash highlights ([#13477](https://github.com/helix-editor/helix/pull/13477))
* Update tree-sitter-cpp ([#13504](https://github.com/helix-editor/helix/pull/13504))
* Update rust-analyzer config to use server-side file watching ([#13432](https://github.com/helix-editor/helix/pull/13432))
* Update Vue injections ([#13511](https://github.com/helix-editor/helix/pull/13511))
* Recognize `sld` as Scheme ([#13528](https://github.com/helix-editor/helix/pull/13528))
* Recognize more files as git-attributes ([#13540](https://github.com/helix-editor/helix/pull/13540))
* Update tree-sitter-haskell and queries ([#13475](https://github.com/helix-editor/helix/pull/13475))
* Align INI highlights with TOML ([#13589](https://github.com/helix-editor/helix/pull/13589))
* Add tree-sitter-rust-format-args for `format_args!` injections in Rust ([#13533](https://github.com/helix-editor/helix/pull/13533), [#13657](https://github.com/helix-editor/helix/pull/13657), [4dd4ba7](https://github.com/helix-editor/helix/commit/4dd4ba7), [86f10ae](https://github.com/helix-editor/helix/commit/86f10ae))
* Update Ungrammar highlights ([8d58f6c](https://github.com/helix-editor/helix/commit/8d58f6c))
* Add `ty` language server for Python ([#13643](https://github.com/helix-editor/helix/pull/13643))
* Add `clarinet` language server for Clarity ([#13647](https://github.com/helix-editor/helix/pull/13647))
* Update prisma config to avoid a crash in the language server ([f6878f6](https://github.com/helix-editor/helix/commit/f6878f6))
* Add `pyrefly` for Python ([#13713](https://github.com/helix-editor/helix/pull/13713))
* Update Python highlights ([#13715](https://github.com/helix-editor/helix/pull/13715))
* Update Mojo language server and formatter to `pixi` ([#13648](https://github.com/helix-editor/helix/pull/13648))
* Add `tombi` for TOML ([#13723](https://github.com/helix-editor/helix/pull/13723))
* Add `neocmakelsp` for CMake ([#13740](https://github.com/helix-editor/helix/pull/13740))
* Update C and C++ highlights ([#13747](https://github.com/helix-editor/helix/pull/13747), [#13772](https://github.com/helix-editor/helix/pull/13772))
* Highlight escape sequences in ECMA languages ([#13762](https://github.com/helix-editor/helix/pull/13762))
* Add an external formatter config for Crystal ([#13759](https://github.com/helix-editor/helix/pull/13759))
* Add `amber-lsp` for Amber ([#13763](https://github.com/helix-editor/helix/pull/13763))
* Update HTML highlights ([#13753](https://github.com/helix-editor/helix/pull/13753))
* Update tree-sitter-purescript and highlights ([#13782](https://github.com/helix-editor/helix/pull/13782))
* Update tree-sitter-gleam and highlights ([#13793](https://github.com/helix-editor/helix/pull/13793), [#13807](https://github.com/helix-editor/helix/pull/13807), [#13813](https://github.com/helix-editor/helix/pull/13813))
* Recognize Buck files as Starlark ([#13810](https://github.com/helix-editor/helix/pull/13810))
* Use tree-sitter-crystal instead of tree-sitter-ruby for Crystal and add custom queries ([#13805](https://github.com/helix-editor/helix/pull/13805))
* Update tree-sitter-twig ([#13689](https://github.com/helix-editor/helix/pull/13689))
* Recognize `jsconfig.json` as JSONC, use as JavaScript and JSX roots ([#13822](https://github.com/helix-editor/helix/pull/13822))
* Recognize `.gem/credentials` as YAML ([#13843](https://github.com/helix-editor/helix/pull/13843))
* Update Dockerfile injections ([#13845](https://github.com/helix-editor/helix/pull/13845), 13852)
* Change tree-sitter parser for Git commit message files ([44293df](https://github.com/helix-editor/helix/commit/44293df))
* Recognize `mimeapps.list` as INI ([#13850](https://github.com/helix-editor/helix/pull/13850))
* Update tree-sitter-odin, highlights and indents ([#13877](https://github.com/helix-editor/helix/pull/13877), [#13917](https://github.com/helix-editor/helix/pull/13917))
* Add locals queries for C, improve parameter highlighting ([#13876](https://github.com/helix-editor/helix/pull/13876))
* Add textobjects for QML ([#13855](https://github.com/helix-editor/helix/pull/13855))
* Add comment tokens for DTD ([#13904](https://github.com/helix-editor/helix/pull/13904))
* Add `dts-lsp` for DeviceTree ([#13907](https://github.com/helix-editor/helix/pull/13907))
* Update gomod highlights ([#13913](https://github.com/helix-editor/helix/pull/13913))
* Recognize `compose.yaml` and `compose.yml` as Docker Compose ([#13930](https://github.com/helix-editor/helix/pull/13930))
Packaging:
* Fix handling of spaces in Bash completion ([#12828](https://github.com/helix-editor/helix/pull/12828))
* Refactor Nix flake ([#12831](https://github.com/helix-editor/helix/pull/12831), [#13024](https://github.com/helix-editor/helix/pull/13024), [cb1ecc9](https://github.com/helix-editor/helix/commit/cb1ecc9), [#13305](https://github.com/helix-editor/helix/pull/13305))
* Add `ConsoleOnly` to `Helix.desktop` categories ([#13236](https://github.com/helix-editor/helix/pull/13236))
* Drop Nix flake dependency on flake-utils ([60a03a3](https://github.com/helix-editor/helix/commit/60a03a3))
* Increase the MSRV to 1.82 ([#13275](https://github.com/helix-editor/helix/pull/13275))
# 25.01.1 (2025-01-19) # 25.01.1 (2025-01-19)
25.01.1 is a patch release focusing on fixing bugs and panics from changes in 25.01. 25.01.1 is a patch release focusing on fixing bugs and panics from changes in 25.01.

833
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -41,18 +41,21 @@ tree-house = { version = "0.3.0", default-features = false }
nucleo = "0.5.0" nucleo = "0.5.0"
slotmap = "1.0.7" slotmap = "1.0.7"
thiserror = "2.0" thiserror = "2.0"
tempfile = "3.20.0" tempfile = "3.23.0"
bitflags = "2.9" bitflags = "2.9"
unicode-segmentation = "1.2" unicode-segmentation = "1.2"
ropey = { version = "1.6.1", default-features = false, features = ["simd"] } ropey = { version = "1.6.1", default-features = false, features = ["simd"] }
foldhash = "0.1" foldhash = "0.2"
parking_lot = "0.12" parking_lot = "0.12"
futures-executor = "0.3" futures-executor = "0.3"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
tokio-stream = "0.1.17" tokio-stream = "0.1.17"
toml = "0.9"
termina = "0.1"
sonic-rs = "0.5"
[workspace.package] [workspace.package]
version = "25.1.1" version = "25.7.1"
edition = "2021" edition = "2021"
authors = ["Blaž Hrastnik <blaz@mxxn.io>"] authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
categories = ["editor"] categories = ["editor"]

View File

@@ -11,6 +11,7 @@
- [Textobjects](./textobjects.md) - [Textobjects](./textobjects.md)
- [Syntax aware motions](./syntax-aware-motions.md) - [Syntax aware motions](./syntax-aware-motions.md)
- [Pickers](./pickers.md) - [Pickers](./pickers.md)
- [Jumplist](./jumplist.md)
- [Keymap](./keymap.md) - [Keymap](./keymap.md)
- [Command line](./command-line.md) - [Command line](./command-line.md)
- [Commands](./commands.md) - [Commands](./commands.md)
@@ -28,3 +29,5 @@
- [Adding textobject queries](./guides/textobject.md) - [Adding textobject queries](./guides/textobject.md)
- [Adding indent queries](./guides/indent.md) - [Adding indent queries](./guides/indent.md)
- [Adding injection queries](./guides/injection.md) - [Adding injection queries](./guides/injection.md)
- [Adding tags queries](./guides/tags.md)
- [Adding rainbow bracket queries](./guides/rainbow_bracket_queries.md)

View File

@@ -42,7 +42,7 @@ RUSTFLAGS="-C target-feature=-crt-static"
# Optimized # Optimized
cargo install \ cargo install \
--profile opt \ --profile opt \
--config 'build.rustflags="-C target-cpu=native"' \ --config 'build.rustflags=["-C", "target-cpu=native"]' \
--path helix-term \ --path helix-term \
--locked --locked
``` ```

View File

@@ -47,6 +47,8 @@ The following variables are supported:
| `cursor_column` | The column number of the primary cursor in the currently focused document, starting at 1. This is counted as the number of grapheme clusters from the start of the line rather than bytes or codepoints. | | `cursor_column` | The column number of the primary cursor in the currently focused document, starting at 1. This is counted as the number of grapheme clusters from the start of the line rather than bytes or codepoints. |
| `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. | | `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. |
| `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. | | `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. |
| `current_working_directory` | Current working directory |
| `workspace_directory` | Nearest ancestor directory of the current working directory that contains `.git`, `.svn`, `jj` or `.helix` |
| `language` | A string containing the language name of the currently focused document.| | `language` | A string containing the language name of the currently focused document.|
| `selection` | A string containing the contents of the primary selection of the currently focused document. | | `selection` | A string containing the contents of the primary selection of the currently focused document. |
| `selection_line_start` | The line number of the start of the primary selection in the currently focused document, starting at 1. | | `selection_line_start` | The line number of the start of the primary selection in the currently focused document, starting at 1. |

View File

@@ -19,6 +19,7 @@
- [`[editor.soft-wrap]` Section](#editorsoft-wrap-section) - [`[editor.soft-wrap]` Section](#editorsoft-wrap-section)
- [`[editor.smart-tab]` Section](#editorsmart-tab-section) - [`[editor.smart-tab]` Section](#editorsmart-tab-section)
- [`[editor.inline-diagnostics]` Section](#editorinline-diagnostics-section) - [`[editor.inline-diagnostics]` Section](#editorinline-diagnostics-section)
- [`[editor.word-completion]` Section](#editorword-completion-section)
### `[editor]` Section ### `[editor]` Section
@@ -59,9 +60,11 @@
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` | | `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` | `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"` | `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"`
| `end-of-line-diagnostics` | Minimum severity of diagnostics to render at the end of the line. Set to `disable` to disable entirely. Refer to the setting about `inline-diagnostics` for more details | "disable" | `end-of-line-diagnostics` | Minimum severity of diagnostics to render at the end of the line. Set to `disable` to disable entirely. Refer to the setting about `inline-diagnostics` for more details | `"hint"`
| `clipboard-provider` | Which API to use for clipboard interaction. One of `pasteboard` (MacOS), `wayland`, `x-clip`, `x-sel`, `win-32-yank`, `termux`, `tmux`, `windows`, `termcode`, `none`, or a custom command set. | Platform and environment specific. | | `clipboard-provider` | Which API to use for clipboard interaction. One of `pasteboard` (MacOS), `wayland`, `x-clip`, `x-sel`, `win32-yank`, `termux`, `tmux`, `windows`, `termcode`, `none`, or a custom command set. | Platform and environment specific. |
| `editor-config` | Whether to read settings from [EditorConfig](https://editorconfig.org) files | `true` | | `editor-config` | Whether to read settings from [EditorConfig](https://editorconfig.org) files | `true` |
| `rainbow-brackets` | Whether to render rainbow colors for matching brackets. Requires tree-sitter `rainbows.scm` queries for the language. | `false` |
| `kitty-keyboard-protocol` | Whether to enable Kitty Keyboard Protocol. Can be `enabled`, `disabled` or `auto` | `auto` |
### `[editor.clipboard-provider]` Section ### `[editor.clipboard-provider]` Section
@@ -131,6 +134,7 @@ The following statusline elements can be configured:
| `file-name` | The path/name of the opened file | | `file-name` | The path/name of the opened file |
| `file-absolute-path` | The absolute 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-base-name` | The basename of the opened file |
| `current-working-directory` | The current working directory |
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) | | `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-encoding` | The encoding of the opened file if it differs from UTF-8 |
| `file-line-ending` | The file line endings (CRLF or LF) | | `file-line-ending` | The file line endings (CRLF or LF) |
@@ -220,6 +224,25 @@ Example:
!.gitattributes !.gitattributes
``` ```
### `[editor.file-explorer]` Section
In addition to the options for the file picker and global search, a similar set of options is presented to configure the file explorer separately. However, unlike the file picker, the defaults are set to avoid ignoring most files.
Note that the ignore files consulted by the file explorer when `ignore` is set to true are the same ones used by the file picker, including the aforementioned Helix-specific ignore files.
| Key | Description | Default |
|--|--|---------|
|`hidden` | Enables ignoring hidden files | `false`
|`follow-symlinks` | Follow symlinks instead of ignoring them | `false`
|`parents` | Enables reading ignore files from parent directories | `false`
|`ignore` | Enables reading `.ignore` files | `false`
|`git-ignore` | Enables reading `.gitignore` files | `false`
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `false`
|`git-exclude` | Enables reading `.git/info/exclude` files | `false`
|`flatten-dirs` | Enables flattening single child directories | `true`
### `[editor.auto-pairs]` Section ### `[editor.auto-pairs]` Section
Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a
@@ -450,7 +473,7 @@ fn main() {
| Key | Description | Default | | Key | Description | Default |
|------------|-------------|---------| |------------|-------------|---------|
| `cursor-line` | The minimum severity that a diagnostic must have to be shown inline on the line that contains the primary cursor. Set to `disable` to not show any diagnostics inline. This option does not have any effect when in insert-mode and will only take effect 350ms after moving the cursor to a different line. | `"disable"` | | `cursor-line` | The minimum severity that a diagnostic must have to be shown inline on the line that contains the primary cursor. Set to `disable` to not show any diagnostics inline. This option does not have any effect when in insert-mode and will only take effect 350ms after moving the cursor to a different line. | `"warning"` |
| `other-lines` | The minimum severity that a diagnostic must have to be shown inline on a line that does not contain the cursor-line. Set to `disable` to not show any diagnostics inline. | `"disable"` | | `other-lines` | The minimum severity that a diagnostic must have to be shown inline on a line that does not contain the cursor-line. Set to `disable` to not show any diagnostics inline. | `"disable"` |
| `prefix-len` | How many horizontal bars `─` are rendered before the diagnostic text. | `1` | | `prefix-len` | How many horizontal bars `─` are rendered before the diagnostic text. | `1` |
| `max-wrap` | Equivalent of the `editor.soft-wrap.max-wrap` option for diagnostics. | `20` | | `max-wrap` | Equivalent of the `editor.soft-wrap.max-wrap` option for diagnostics. | `20` |
@@ -468,12 +491,20 @@ fn main() {
} }
``` ```
### `[editor.word-completion]` Section
The new diagnostic rendering is not yet enabled by default. As soon as end of line or inline diagnostics are enabled the old diagnostics rendering is automatically disabled. The recommended default setting are: Options for controlling completion of words from open buffers.
| Key | Description | Default |
| --- | --- | --- |
| `enable` | Whether word completion is enabled | `true` |
| `trigger-length` | Number of word characters to type before triggering completion | `7` |
Example:
```toml ```toml
[editor] [editor.word-completion]
end-of-line-diagnostics = "hint" enable = true
[editor.inline-diagnostics] # Set the trigger length lower so that words are completed more often
cursor-line = "warning" # show warnings and errors on the cursorline inline trigger-length = 4
``` ```

View File

@@ -1,279 +1,304 @@
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default language servers | | Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Code Navigation Tags | Rainbow Brackets | Default language servers |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- | --- | --- |
| ada | ✓ | ✓ | | `ada_language_server` | | ada | ✓ | ✓ | | | | `ada_language_server` |
| adl | ✓ | ✓ | ✓ | | | adl | ✓ | ✓ | ✓ | | | |
| agda | ✓ | | | | | agda | ✓ | | | | | |
| alloy | ✓ | | | | | alloy | ✓ | | | | | |
| amber | ✓ | | | `amber-lsp` | | amber | ✓ | | | | | `amber-lsp` |
| astro | ✓ | | | `astro-ls` | | astro | ✓ | | | | | `astro-ls` |
| awk | ✓ | ✓ | | `awk-language-server` | | awk | ✓ | ✓ | | | | `awk-language-server` |
| bash | ✓ | ✓ | ✓ | `bash-language-server` | | bash | ✓ | ✓ | ✓ | ✓ | ✓ | `bash-language-server` |
| bass | ✓ | | | `bass` | | bass | ✓ | | | | | `bass` |
| beancount | ✓ | | | `beancount-language-server` | | beancount | ✓ | | | | | `beancount-language-server` |
| bibtex | ✓ | | | `texlab` | | bibtex | ✓ | | | | | `texlab` |
| bicep | ✓ | | | `bicep-langserver` | | bicep | ✓ | | | | | `bicep-langserver` |
| bitbake | ✓ | | | `bitbake-language-server` | | bitbake | ✓ | | | | | `bitbake-language-server` |
| blade | ✓ | | | | | blade | ✓ | | | | ✓ | |
| blueprint | ✓ | | | `blueprint-compiler` | | blueprint | ✓ | | | | | `blueprint-compiler` |
| c | ✓ | ✓ | ✓ | `clangd` | | c | ✓ | ✓ | ✓ | ✓ | ✓ | `clangd` |
| c-sharp | ✓ | ✓ | | `OmniSharp` | | c-sharp | ✓ | ✓ | | ✓ | | `OmniSharp` |
| cabal | | | | `haskell-language-server-wrapper` | | cabal | | | | | | `haskell-language-server-wrapper` |
| caddyfile | ✓ | ✓ | ✓ | | | caddyfile | ✓ | ✓ | ✓ | | | |
| cairo | ✓ | ✓ | ✓ | `cairo-language-server` | | cairo | ✓ | ✓ | ✓ | | | `cairo-language-server` |
| capnp | ✓ | | ✓ | | | capnp | ✓ | | ✓ | | | |
| cel | ✓ | | | | | cel | ✓ | | | | | |
| circom | ✓ | | | `circom-lsp` | | circom | ✓ | | | | | `circom-lsp` |
| clarity | ✓ | | | `clarinet` | | clarity | ✓ | | | | | `clarinet` |
| clojure | ✓ | | | `clojure-lsp` | | clojure | ✓ | | | | ✓ | `clojure-lsp` |
| cmake | ✓ | ✓ | ✓ | `neocmakelsp`, `cmake-language-server` | | cmake | ✓ | ✓ | ✓ | | | `neocmakelsp`, `cmake-language-server` |
| codeql | ✓ | ✓ | | `codeql` | | codeql | ✓ | ✓ | | | | `codeql` |
| comment | ✓ | | | | | comment | ✓ | | | | | |
| common-lisp | ✓ | | ✓ | `cl-lsp` | | common-lisp | ✓ | | ✓ | | ✓ | `cl-lsp` |
| cpon | ✓ | | ✓ | | | cpon | ✓ | | ✓ | | | |
| cpp | ✓ | ✓ | ✓ | `clangd` | | cpp | ✓ | ✓ | ✓ | ✓ | ✓ | `clangd` |
| crystal | ✓ | ✓ | ✓ | `crystalline`, `ameba-ls` | | cross-config | ✓ | ✓ | | | ✓ | `taplo`, `tombi` |
| css | ✓ | | ✓ | `vscode-css-language-server` | | crystal | ✓ | ✓ | | ✓ | | `crystalline`, `ameba-ls` |
| csv | ✓ | | | | | css | ✓ | | ✓ | | | `vscode-css-language-server` |
| cue | ✓ | | | `cuelsp` | | csv | ✓ | | | | | |
| cylc | ✓ | | | | | cue | ✓ | | | | | `cuelsp` |
| d | ✓ | ✓ | ✓ | `serve-d` | | cylc | ✓ | ✓ | ✓ | | | |
| dart | ✓ | ✓ | ✓ | `dart` | | cython | ✓ | | ✓ | ✓ | | |
| dbml | ✓ | | | | | d | ✓ | ✓ | ✓ | | | `serve-d` |
| debian | ✓ | | | | | dart | ✓ | ✓ | | | | `dart` |
| devicetree | ✓ | | | `dts-lsp` | | dbml | ✓ | | | | | |
| dhall | ✓ | ✓ | | `dhall-lsp-server` | | debian | ✓ | | | | | |
| diff | ✓ | | | | | devicetree | ✓ | | | | | `dts-lsp` |
| djot | ✓ | | | | | dhall | ✓ | ✓ | | | | `dhall-lsp-server` |
| docker-compose | ✓ | | | `docker-compose-langserver`, `yaml-language-server` | | diff | ✓ | | | | | |
| dockerfile | ✓ | | | `docker-langserver` | | djot | ✓ | | | | | |
| dot | ✓ | | | `dot-language-server` | | docker-bake | ✓ | ✓ | ✓ | ✓ | ✓ | `docker-language-server` |
| dtd | ✓ | | | | | docker-compose | ✓ | ✓ | ✓ | | | `docker-compose-langserver`, `yaml-language-server`, `docker-language-server` |
| dune | ✓ | | | | | dockerfile | ✓ | ✓ | | | | `docker-langserver`, `docker-language-server` |
| dunstrc | ✓ | | | | | dot | ✓ | | | | | `dot-language-server` |
| earthfile | ✓ | ✓ | ✓ | `earthlyls` | | doxyfile | ✓ | ✓ | ✓ | ✓ | | |
| edoc | ✓ | | | | | dtd | ✓ | | | | | |
| eex | ✓ | | | | | dune | ✓ | | | | | |
| ejs | ✓ | | | | | dunstrc | ✓ | | | | | |
| elisp | ✓ | | | | | earthfile | ✓ | ✓ | ✓ | | | `earthlyls` |
| elixir | ✓ | | | `elixir-ls` | | edoc | ✓ | | | | | |
| elm | ✓ | ✓ | | `elm-language-server` | | eex | ✓ | | | | | |
| elvish | ✓ | | | `elvish` | | eiffel | ✓ | ✓ | ✓ | | | `eiffel-language-server` |
| env | ✓ | | | | | ejs | ✓ | | | | | |
| erb | ✓ | | | | | elisp | ✓ | | | ✓ | | |
| erlang | ✓ | ✓ | | `erlang_ls`, `elp` | | elixir | ✓ | ✓ | ✓ | ✓ | ✓ | `elixir-ls`, `expert` |
| esdl | ✓ | | | | | elm | ✓ | ✓ | | | | `elm-language-server` |
| fennel | ✓ | | | `fennel-ls` | | elvish | ✓ | | | | | `elvish` |
| fga | ✓ | ✓ | | | | env | ✓ | ✓ | | | | |
| fidl | ✓ | | | | | erb | ✓ | | | | | |
| fish | ✓ | ✓ | ✓ | `fish-lsp` | | erlang | ✓ | ✓ | | ✓ | ✓ | `erlang_ls`, `elp` |
| forth | ✓ | | | `forth-lsp` | | esdl | ✓ | | | | | |
| fortran | ✓ | | ✓ | `fortls` | | fennel | ✓ | | | | | `fennel-ls` |
| fsharp | ✓ | | | `fsautocomplete` | | fga | ✓ | ✓ | ✓ | | | |
| gas | ✓ | ✓ | | `asm-lsp` | | fidl | ✓ | | | | | |
| gdscript | ✓ | ✓ | ✓ | | | fish | ✓ | ✓ | ✓ | | | `fish-lsp` |
| gemini | ✓ | | | | | flatbuffers | ✓ | | | | | |
| gherkin | ✓ | | | | | forth | ✓ | | | | | `forth-lsp` |
| ghostty | ✓ | | | | | fortran | ✓ | | ✓ | | | `fortls` |
| git-attributes | ✓ | | | | | fsharp | ✓ | | | | | `fsautocomplete` |
| git-commit | ✓ | ✓ | | | | gas | ✓ | ✓ | | | | `asm-lsp` |
| git-config | ✓ | ✓ | | | | gdscript | ✓ | ✓ | ✓ | ✓ | | |
| git-ignore | ✓ | | | | | gemini | ✓ | | | | | |
| git-notes | ✓ | | | | | gherkin | ✓ | | | | | |
| git-rebase | ✓ | | | | | ghostty | ✓ | | | | | |
| gjs | ✓ | | | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` | | git-attributes | ✓ | | | | | |
| gleam | ✓ | ✓ | | `gleam` | | git-cliff-config | ✓ | ✓ | | | ✓ | `taplo`, `tombi` |
| glimmer | ✓ | | | `ember-language-server` | | git-commit | ✓ | ✓ | | | | |
| glsl | ✓ | ✓ | ✓ | `glsl_analyzer` | | git-config | ✓ | ✓ | | | | |
| gn | ✓ | | | | | git-ignore | ✓ | | | | | |
| go | ✓ | | | `gopls`, `golangci-lint-langserver` | | git-notes | ✓ | | | | | |
| godot-resource | ✓ | | | | | git-rebase | ✓ | | | | | |
| gomod | ✓ | | | `gopls` | | gitlab-ci | ✓ | | ✓ | ✓ | ✓ | `yaml-language-server`, `gitlab-ci-ls` |
| gotmpl | ✓ | | | `gopls` | | gjs | ✓ | ✓ | ✓ | ✓ | | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` |
| gowork | ✓ | | | `gopls` | | gleam | ✓ | ✓ | | | ✓ | `gleam` |
| gpr | ✓ | | | `ada_language_server` | | glimmer | ✓ | | | | | `ember-language-server` |
| graphql | ✓ | ✓ | | `graphql-lsp` | | glsl | ✓ | ✓ | ✓ | | | `glsl_analyzer` |
| gren | ✓ | | | | | gn | ✓ | | | | | |
| groovy | ✓ | | | | | go | ✓ | | ✓ | ✓ | ✓ | `gopls`, `golangci-lint-langserver` |
| gts | ✓ | | | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` | | go-format-string | ✓ | | | | ✓ | |
| hare | ✓ | | | | | godot-resource | ✓ | ✓ | | | | |
| haskell | ✓ | | | `haskell-language-server-wrapper` | | gomod | ✓ | | | | | `gopls` |
| haskell-persistent | ✓ | | | | | gotmpl | ✓ | | | | | `gopls` |
| hcl | ✓ | ✓ | ✓ | `terraform-ls` | | gowork | ✓ | | | | | `gopls` |
| heex | ✓ | | | `elixir-ls` | | gpr | ✓ | | | | | `ada_language_server` |
| helm | ✓ | | | `helm_ls` | | graphql | ✓ | ✓ | | | | `graphql-lsp` |
| hocon | ✓ | ✓ | | | | gren | ✓ | ✓ | | | | |
| hoon | ✓ | | | | | groovy | ✓ | | | | | |
| hosts | ✓ | | | | | gts | ✓ | | | ✓ | | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` |
| html | ✓ | | | `vscode-html-language-server`, `superhtml` | | hare | ✓ | | | | | |
| htmldjango | ✓ | | | `djlsp`, `vscode-html-language-server`, `superhtml` | | haskell | ✓ | ✓ | | | | `haskell-language-server-wrapper` |
| hurl | ✓ | ✓ | ✓ | | | haskell-persistent | ✓ | | | | | |
| hyprlang | ✓ | | ✓ | `hyprls` | | hcl | ✓ | | ✓ | | | `terraform-ls` |
| idris | | | | `idris2-lsp` | | hdl | ✓ | | | | | `hdls` |
| iex | ✓ | | | | | heex | ✓ | ✓ | | | | `elixir-ls`, `expert` |
| ini | ✓ | | | | | helm | ✓ | | | | | `helm_ls` |
| ink | ✓ | | | | | hocon | ✓ | ✓ | ✓ | | | |
| inko | ✓ | | | | | hoon | ✓ | | | | | |
| janet | ✓ | | | | | hosts | ✓ | | | | | |
| java | ✓ | ✓ | ✓ | `jdtls` | | html | ✓ | ✓ | | | ✓ | `vscode-html-language-server`, `superhtml` |
| javascript | ✓ | | ✓ | `typescript-language-server` | | htmldjango | ✓ | | | | | `djlsp`, `vscode-html-language-server`, `superhtml` |
| jinja | ✓ | | | | | hurl | ✓ | ✓ | ✓ | | | |
| jjdescription | ✓ | | | | | hyprlang | ✓ | | | | | `hyprls` |
| jq | | | | `jq-lsp` | | idris | | | | | | `idris2-lsp` |
| jsdoc | ✓ | | | | | iex | ✓ | | | | | |
| json | ✓ | | | `vscode-json-language-server` | | ini | ✓ | | | | | |
| json-ld | ✓ | | | `vscode-json-language-server` | | ink | ✓ | | | | | |
| json5 | ✓ | | | | | inko | ✓ | ✓ | ✓ | ✓ | | |
| jsonc | ✓ | | ✓ | `vscode-json-language-server` | | janet | ✓ | | ✓ | | ✓ | |
| jsonnet | ✓ | | | `jsonnet-language-server` | | java | ✓ | | ✓ | ✓ | ✓ | `jdtls` |
| jsx | ✓ | ✓ | ✓ | `typescript-language-server` | | javascript | ✓ | ✓ | ✓ | ✓ | ✓ | `typescript-language-server` |
| julia | ✓ | | | `julia` | | jinja | ✓ | | | | | |
| just | ✓ | ✓ | ✓ | `just-lsp` | | jjconfig | ✓ | ✓ | ✓ | | | `taplo`, `tombi` |
| kdl | ✓ | | | | | jjdescription | ✓ | | | | | |
| koka | ✓ | | ✓ | `koka` | | jjrevset | ✓ | | | | | |
| kotlin | ✓ | | | `kotlin-language-server` | | jjtemplate | ✓ | | | | | |
| koto | ✓ | ✓ | | `koto-ls` | | jq | ✓ | ✓ | | | | `jq-lsp` |
| latex | ✓ | ✓ | | `texlab` | | jsdoc | ✓ | | | | | |
| ld | ✓ | | ✓ | | | json | ✓ | ✓ | ✓ | | ✓ | `vscode-json-language-server` |
| ldif | ✓ | | | | | json-ld | ✓ | ✓ | ✓ | | | `vscode-json-language-server` |
| lean | ✓ | | | `lean` | | json5 | ✓ | | | | | |
| ledger | ✓ | | | | | jsonc | ✓ | | ✓ | | | `vscode-json-language-server` |
| llvm | ✓ | | | | | jsonnet | ✓ | | | | | `jsonnet-language-server` |
| llvm-mir | ✓ | ✓ | ✓ | | | jsx | ✓ | ✓ | ✓ | ✓ | ✓ | `typescript-language-server` |
| llvm-mir-yaml | ✓ | | ✓ | | | julia | ✓ | | ✓ | | | `julia` |
| log | ✓ | | | | | just | ✓ | | | ✓ | | `just-lsp` |
| lpf | ✓ | | | | | kconfig | ✓ | | ✓ | | | |
| lua | ✓ | ✓ | ✓ | `lua-language-server` | | kdl | ✓ | ✓ | ✓ | ✓ | | |
| luau | ✓ | ✓ | | `luau-lsp` | | koka | ✓ | | ✓ | | | `koka` |
| mail | ✓ | ✓ | | | | kotlin | ✓ | ✓ | ✓ | ✓ | | `kotlin-language-server` |
| make | ✓ | | ✓ | | | koto | ✓ | ✓ | ✓ | | ✓ | `koto-ls` |
| markdoc | ✓ | | | `markdoc-ls` | | latex | ✓ | ✓ | | | | `texlab` |
| markdown | ✓ | | | `marksman`, `markdown-oxide` | | ld | ✓ | | ✓ | | | |
| markdown-rustdoc | ✓ | | | | | ldif | ✓ | | | | | |
| markdown.inline | ✓ | | | | | lean | ✓ | | | | | `lake` |
| matlab | ✓ | | | | | ledger | ✓ | | | | | |
| mermaid | ✓ | | | | | llvm | ✓ | ✓ | ✓ | | | |
| meson | ✓ | | ✓ | `mesonlsp` | | llvm-mir | ✓ | | ✓ | | | |
| mint | | | | `mint` | | llvm-mir-yaml | ✓ | | | | | |
| mojo | ✓ | | | `pixi` | | log | ✓ | | | | | |
| move | ✓ | | | | | lpf | ✓ | | | | | |
| msbuild | ✓ | | ✓ | | | lua | ✓ | | ✓ | | ✓ | `lua-language-server` |
| nasm | ✓ | | | `asm-lsp` | | luap | ✓ | | | | | |
| nestedtext | ✓ | ✓ | ✓ | | | luau | ✓ | ✓ | ✓ | | | `luau-lsp` |
| nginx | ✓ | | | | | mail | ✓ | ✓ | | | | |
| nickel | ✓ | | ✓ | `nls` | | make | ✓ | | ✓ | | | |
| nim | ✓ | ✓ | ✓ | `nimlangserver` | | markdoc | ✓ | | | | | `markdoc-ls` |
| nix | ✓ | ✓ | | `nil`, `nixd` | | markdown | ✓ | | | ✓ | | `marksman`, `markdown-oxide` |
| nu | ✓ | | | `nu` | | markdown-rustdoc | ✓ | | | | | |
| nunjucks | ✓ | | | | | markdown.inline | ✓ | | | | | |
| ocaml | ✓ | | ✓ | `ocamllsp` | | matlab | ✓ | | ✓ | | | |
| ocaml-interface | ✓ | | | `ocamllsp` | | mermaid | ✓ | | | | | |
| odin | ✓ | ✓ | | `ols` | | meson | ✓ | | ✓ | | | `mesonlsp` |
| ohm | ✓ | | | | | mint | | | | | | `mint` |
| opencl | ✓ | ✓ | ✓ | `clangd` | | miseconfig | ✓ | ✓ | ✓ | | | `taplo`, `tombi` |
| openscad | ✓ | | | `openscad-lsp` | | mojo | ✓ | ✓ | ✓ | | | `pixi` |
| org | ✓ | | | | | move | ✓ | | | | | |
| pascal | ✓ | ✓ | | `pasls` | | msbuild | ✓ | | ✓ | | | |
| passwd | ✓ | | | | | nasm | ✓ | ✓ | | | | `asm-lsp` |
| pem | ✓ | | | | | nearley | ✓ | | | | ✓ | |
| perl | ✓ | ✓ | ✓ | `perlnavigator` | | nestedtext | ✓ | ✓ | ✓ | | | |
| pest | ✓ | | | `pest-language-server` | | nginx | ✓ | | | | | |
| php | ✓ | ✓ | ✓ | `intelephense` | | nickel | ✓ | | ✓ | | | `nls` |
| php-only | ✓ | | | | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` |
| pkgbuild | ✓ | ✓ | ✓ | `termux-language-server`, `bash-language-server` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` |
| pkl | ✓ | | ✓ | `pkl-lsp` | | nu | ✓ | | ✓ | | | `nu` |
| po | ✓ | | | | | nunjucks | ✓ | | | | | |
| pod | ✓ | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` |
| ponylang | ✓ | | | | | ocaml-interface | ✓ | | | | | `ocamllsp` |
| powershell | ✓ | | | | | odin | ✓ | ✓ | ✓ | | | `ols` |
| prisma | ✓ | ✓ | | `prisma-language-server` | | ohm | ✓ | ✓ | | | | |
| prolog | ✓ | | ✓ | `swipl` | | opencl | ✓ | | ✓ | | | `clangd` |
| properties | ✓ | | | | | openscad | ✓ | | | | | `openscad-lsp` |
| protobuf | ✓ | | | `buf`, `pb`, `protols` | | org | ✓ | | | | | |
| prql | ✓ | | | | | pascal | ✓ | ✓ | | | | `pasls` |
| pug | ✓ | | | | | passwd | ✓ | | | | | |
| purescript | ✓ | ✓ | | `purescript-language-server` | | pem | ✓ | | | | | |
| python | ✓ | ✓ | ✓ | `ty`, `ruff`, `jedi-language-server`, `pylsp` | | perl | ✓ | ✓ | ✓ | | | `perlnavigator` |
| qml | ✓ | ✓ | ✓ | `qmlls` | | pest | ✓ | ✓ | ✓ | | | `pest-language-server` |
| quarto | ✓ | | ✓ | | | php | ✓ | ✓ | | ✓ | ✓ | `intelephense` |
| quint | ✓ | | | `quint-language-server` | | php-only | ✓ | | | ✓ | | |
| r | ✓ | | | `R` | | pip-requirements | ✓ | | | | | |
| racket | ✓ | | | `racket` | | pkgbuild | ✓ | ✓ | ✓ | | | `termux-language-server`, `bash-language-server` |
| regex | ✓ | | | | | pkl | ✓ | | ✓ | | | `pkl-lsp` |
| rego | ✓ | | | `regols` | | po | ✓ | ✓ | | | | |
| rescript | ✓ | ✓ | | `rescript-language-server` | | pod | ✓ | | | | | |
| rmarkdown | ✓ | | ✓ | `R` | | ponylang | ✓ | | ✓ | | | |
| robot | ✓ | | | `robotframework_ls` | | powershell | ✓ | | | | | |
| ron | ✓ | | ✓ | | | prisma | ✓ | ✓ | | | | `prisma-language-server` |
| rst | ✓ | | | | | prolog | ✓ | | ✓ | | | `swipl` |
| ruby | ✓ | ✓ | | `ruby-lsp`, `solargraph` | | properties | ✓ | ✓ | | | | |
| rust | ✓ | ✓ | ✓ | `rust-analyzer` | | protobuf | ✓ | ✓ | ✓ | ✓ | | `buf`, `pb`, `protols` |
| rust-format-args | ✓ | | | | | prql | ✓ | | | | | |
| rust-format-args-macro | ✓ | | | | | pug | ✓ | | | | | |
| sage | ✓ | ✓ | | | | purescript | ✓ | ✓ | | | | `purescript-language-server` |
| scala | ✓ | ✓ | ✓ | `metals` | | python | ✓ | ✓ | ✓ | ✓ | ✓ | `ty`, `ruff`, `jedi-language-server`, `pylsp` |
| scheme | ✓ | | ✓ | | | qml | ✓ | ✓ | ✓ | | | `qmlls` |
| scss | ✓ | | | `vscode-css-language-server` | | quarto | ✓ | | ✓ | | | |
| slang | ✓ | | ✓ | `slangd` | | quint | ✓ | | | | | `quint-language-server` |
| slint | ✓ | | ✓ | `slint-lsp` | | r | ✓ | | | | | `R` |
| smali | ✓ | | ✓ | | | racket | ✓ | | ✓ | | ✓ | `racket` |
| smithy | ✓ | | | `cs` | | regex | ✓ | | | | ✓ | |
| sml | ✓ | | | | | rego | ✓ | | | | | `regols` |
| snakemake | ✓ | | | `pylsp` | | rescript | ✓ | ✓ | | | | `rescript-language-server` |
| solidity | ✓ | ✓ | | `solc` | | rmarkdown | ✓ | | ✓ | | | `R` |
| sourcepawn | ✓ | | | `sourcepawn-studio` | | robot | ✓ | | | | | `robotframework_ls` |
| spade | ✓ | | ✓ | `spade-language-server` | | robots.txt | ✓ | ✓ | | ✓ | | |
| spicedb | ✓ | | | | | ron | ✓ | | ✓ | ✓ | | |
| sql | ✓ | | | | | rst | ✓ | | | | | |
| sshclientconfig | ✓ | | | | | ruby | ✓ | ✓ | ✓ | ✓ | ✓ | `ruby-lsp`, `solargraph` |
| starlark | ✓ | ✓ | ✓ | `starpls` | | rust | ✓ | ✓ | ✓ | ✓ | ✓ | `rust-analyzer` |
| strace | ✓ | | | | | rust-format-args | ✓ | | | | | |
| supercollider | ✓ | | | | | rust-format-args-macro | ✓ | | ✓ | | ✓ | |
| svelte | ✓ | | | `svelteserver` | | sage | ✓ | | | | | |
| sway | ✓ | ✓ | ✓ | `forc` | | scala | ✓ | ✓ | ✓ | | | `metals` |
| swift | ✓ | ✓ | | `sourcekit-lsp` | | scheme | ✓ | ✓ | | | ✓ | |
| systemd | ✓ | | | `systemd-lsp` | | scss | ✓ | | | | ✓ | `vscode-css-language-server` |
| t32 | ✓ | | | | | shellcheckrc | ✓ | ✓ | | | | |
| tablegen | ✓ | ✓ | ✓ | | | slang | ✓ | ✓ | ✓ | | | `slangd` |
| tact | ✓ | ✓ | ✓ | | | slint | ✓ | ✓ | ✓ | | | `slint-lsp` |
| task | ✓ | | | | | slisp | ✓ | | | ✓ | | |
| tcl | ✓ | | ✓ | | | smali | ✓ | | ✓ | | | |
| teal | ✓ | | | `teal-language-server` | | smithy | ✓ | | | | | `cs` |
| templ | ✓ | | | `templ` | | sml | ✓ | | | | | |
| tera | ✓ | | | | | snakemake | ✓ | | ✓ | | | `pylsp` |
| textproto | ✓ | ✓ | | | | solidity | ✓ | ✓ | | | | `solc` |
| tfvars | ✓ | | | `terraform-ls` | | sourcepawn | ✓ | ✓ | | | | `sourcepawn-studio` |
| thrift | ✓ | | | | | spade | ✓ | | | | | `spade-language-server` |
| tlaplus | ✓ | | | | | spicedb | ✓ | | | ✓ | | |
| todotxt | ✓ | | | | | sql | ✓ | ✓ | | | | |
| toml | ✓ | ✓ | | `taplo`, `tombi` | | sshclientconfig | ✓ | | | | | |
| tsq | ✓ | | | `ts_query_ls` | | starlark | ✓ | ✓ | ✓ | | ✓ | `starpls` |
| tsx | ✓ | | | `typescript-language-server` | | strace | ✓ | | | | | |
| twig | ✓ | | | | | strictdoc | ✓ | | | ✓ | | |
| typescript | ✓ | | | `typescript-language-server` | | supercollider | ✓ | | | | | |
| typespec | ✓ | ✓ | | `tsp-server` | | svelte | ✓ | | ✓ | | | `svelteserver` |
| typst | ✓ | | | `tinymist` | | sway | ✓ | ✓ | ✓ | | | `forc` |
| ungrammar | ✓ | | | | | swift | ✓ | ✓ | | | ✓ | `sourcekit-lsp` |
| unison | ✓ | ✓ | | | | systemd | ✓ | | | | | `systemd-lsp` |
| uxntal | ✓ | | | | | systemverilog | ✓ | | | | | |
| v | ✓ | | | `v-analyzer` | | t32 | ✓ | | | | | |
| vala | ✓ | ✓ | | `vala-language-server` | | tablegen | ✓ | ✓ | ✓ | | | |
| vento | ✓ | | | | | tact | ✓ | ✓ | ✓ | | | |
| verilog | ✓ | ✓ | | `svlangserver` | | task | ✓ | | | | | |
| vhdl | ✓ | | | `vhdl_ls` | | tcl | ✓ | | ✓ | | | |
| vhs | ✓ | | | | | teal | ✓ | | | | | `teal-language-server` |
| vue | ✓ | | | `vue-language-server` | | templ | ✓ | | | | | `templ` |
| wast | ✓ | | | | | tera | ✓ | | | | | |
| wat | ✓ | | | `wat_server` | | textproto | ✓ | ✓ | ✓ | | | |
| webc | ✓ | | | | | tfvars | ✓ | | ✓ | | | `terraform-ls` |
| werk | ✓ | | | | | thrift | ✓ | | | | | |
| wesl | ✓ | | | | | tlaplus | ✓ | | | | | |
| wgsl | ✓ | | | `wgsl-analyzer` | | todotxt | ✓ | | | | | |
| wit | ✓ | | ✓ | | | toml | ✓ | ✓ | | | ✓ | `taplo`, `tombi` |
| wren | ✓ | | ✓ | | | tsq | ✓ | | | | ✓ | `ts_query_ls` |
| xit | ✓ | | | | | tsx | ✓ | ✓ | | | ✓ | `typescript-language-server` |
| xml | ✓ | | | | | twig | ✓ | | | | | |
| xtc | ✓ | | | | | typescript | ✓ | | | ✓ | ✓ | `typescript-language-server` |
| yaml | ✓ | ✓ | ✓ | `yaml-language-server`, `ansible-language-server` | | typespec | ✓ | ✓ | ✓ | | | `tsp-server` |
| yara | ✓ | | | `yls` | | typst | ✓ | | | ✓ | | `tinymist` |
| yuck | ✓ | | | | | ungrammar | ✓ | | | | | |
| zig | ✓ | ✓ | ✓ | `zls` | | unison | ✓ | ✓ | ✓ | | | |
| uxntal | ✓ | | | | | |
| v | ✓ | ✓ | ✓ | | | `v-analyzer` |
| vala | ✓ | ✓ | | | | `vala-language-server` |
| vento | ✓ | | | | | |
| verilog | ✓ | ✓ | | | | `svlangserver` |
| vhdl | ✓ | | | | | `vhdl_ls` |
| vhs | ✓ | | | | | |
| vim | ✓ | | | | | |
| vue | ✓ | | | | | `vue-language-server` |
| wast | ✓ | | | | | |
| wat | ✓ | | | | | `wat_server` |
| webc | ✓ | | | | | |
| werk | ✓ | | | | | |
| wesl | ✓ | ✓ | | | | |
| wgsl | ✓ | ✓ | ✓ | ✓ | ✓ | `wgsl-analyzer` |
| wikitext | ✓ | | | | | `wikitext-lsp` |
| wit | ✓ | | ✓ | | | |
| wren | ✓ | ✓ | ✓ | | | |
| xit | ✓ | | | | | |
| xml | ✓ | ✓ | ✓ | | ✓ | |
| xtc | ✓ | | | | | |
| yaml | ✓ | ✓ | ✓ | | ✓ | `yaml-language-server`, `ansible-language-server` |
| yara | ✓ | | | | | `yls` |
| yuck | ✓ | | | | | |
| zig | ✓ | ✓ | ✓ | | | `zls` |

View File

@@ -106,10 +106,14 @@
| `code_action` | Perform code action | normal: `` <space>a ``, select: `` <space>a `` | | `code_action` | Perform code action | normal: `` <space>a ``, select: `` <space>a `` |
| `buffer_picker` | Open buffer picker | normal: `` <space>b ``, select: `` <space>b `` | | `buffer_picker` | Open buffer picker | normal: `` <space>b ``, select: `` <space>b `` |
| `jumplist_picker` | Open jumplist picker | normal: `` <space>j ``, select: `` <space>j `` | | `jumplist_picker` | Open jumplist picker | normal: `` <space>j ``, select: `` <space>j `` |
| `symbol_picker` | Open symbol picker | normal: `` <space>s ``, select: `` <space>s `` | | `symbol_picker` | Open symbol picker | |
| `syntax_symbol_picker` | Open symbol picker from syntax information | |
| `lsp_or_syntax_symbol_picker` | Open symbol picker from LSP or syntax information | normal: `` <space>s ``, select: `` <space>s `` |
| `changed_file_picker` | Open changed file picker | normal: `` <space>g ``, select: `` <space>g `` | | `changed_file_picker` | Open changed file picker | normal: `` <space>g ``, select: `` <space>g `` |
| `select_references_to_symbol_under_cursor` | Select symbol references | normal: `` <space>h ``, select: `` <space>h `` | | `select_references_to_symbol_under_cursor` | Select symbol references | normal: `` <space>h ``, select: `` <space>h `` |
| `workspace_symbol_picker` | Open workspace symbol picker | normal: `` <space>S ``, select: `` <space>S `` | | `workspace_symbol_picker` | Open workspace symbol picker | |
| `syntax_workspace_symbol_picker` | Open workspace symbol picker from syntax information | |
| `lsp_or_syntax_workspace_symbol_picker` | Open workspace symbol picker from LSP or syntax information | normal: `` <space>S ``, select: `` <space>S `` |
| `diagnostics_picker` | Open diagnostic picker | normal: `` <space>d ``, select: `` <space>d `` | | `diagnostics_picker` | Open diagnostic picker | normal: `` <space>d ``, select: `` <space>d `` |
| `workspace_diagnostics_picker` | Open workspace diagnostic picker | normal: `` <space>D ``, select: `` <space>D `` | | `workspace_diagnostics_picker` | Open workspace diagnostic picker | normal: `` <space>D ``, select: `` <space>D `` |
| `last_picker` | Open last picker | normal: `` <space>' ``, select: `` <space>' `` | | `last_picker` | Open last picker | normal: `` <space>' ``, select: `` <space>' `` |
@@ -168,6 +172,8 @@
| `smart_tab` | Insert tab if all cursors have all whitespace to their left; otherwise, run a separate command. | insert: `` <tab> `` | | `smart_tab` | Insert tab if all cursors have all whitespace to their left; otherwise, run a separate command. | insert: `` <tab> `` |
| `insert_tab` | Insert tab char | insert: `` <S-tab> `` | | `insert_tab` | Insert tab char | insert: `` <S-tab> `` |
| `insert_newline` | Insert newline char | insert: `` <C-j> ``, `` <ret> `` | | `insert_newline` | Insert newline char | insert: `` <C-j> ``, `` <ret> `` |
| `insert_char_interactive` | Insert an interactively-chosen char | |
| `append_char_interactive` | Append an interactively-chosen char | |
| `delete_char_backward` | Delete previous char | insert: `` <C-h> ``, `` <backspace> ``, `` <S-backspace> `` | | `delete_char_backward` | Delete previous char | insert: `` <C-h> ``, `` <backspace> ``, `` <S-backspace> `` |
| `delete_char_forward` | Delete next char | insert: `` <C-d> ``, `` <del> `` | | `delete_char_forward` | Delete next char | insert: `` <C-d> ``, `` <del> `` |
| `delete_word_backward` | Delete previous word | insert: `` <C-w> ``, `` <A-backspace> `` | | `delete_word_backward` | Delete previous word | insert: `` <C-w> ``, `` <A-backspace> `` |
@@ -267,6 +273,8 @@
| `goto_prev_comment` | Goto previous comment | normal: `` [c ``, select: `` [c `` | | `goto_prev_comment` | Goto previous comment | normal: `` [c ``, select: `` [c `` |
| `goto_next_test` | Goto next test | normal: `` ]T ``, select: `` ]T `` | | `goto_next_test` | Goto next test | normal: `` ]T ``, select: `` ]T `` |
| `goto_prev_test` | Goto previous test | normal: `` [T ``, select: `` [T `` | | `goto_prev_test` | Goto previous test | normal: `` [T ``, select: `` [T `` |
| `goto_next_xml_element` | Goto next (X)HTML element | normal: `` ]x ``, select: `` ]x `` |
| `goto_prev_xml_element` | Goto previous (X)HTML element | normal: `` [x ``, select: `` [x `` |
| `goto_next_entry` | Goto next pairing | normal: `` ]e ``, select: `` ]e `` | | `goto_next_entry` | Goto next pairing | normal: `` ]e ``, select: `` ]e `` |
| `goto_prev_entry` | Goto previous pairing | normal: `` [e ``, select: `` [e `` | | `goto_prev_entry` | Goto previous pairing | normal: `` [e ``, select: `` [e `` |
| `goto_next_paragraph` | Goto next paragraph | normal: `` ]p ``, select: `` ]p `` | | `goto_next_paragraph` | Goto next paragraph | normal: `` ]p ``, select: `` ]p `` |

View File

@@ -1,4 +1,4 @@
# Guides # Guides
This section contains guides for adding new language server configurations, This section contains guides for adding new language server configurations,
tree-sitter grammars, textobject queries, and other similar items. tree-sitter grammars, textobject and rainbow bracket queries, and other similar items.

View File

@@ -0,0 +1,132 @@
# Adding Rainbow Bracket Queries
Helix uses `rainbows.scm` tree-sitter query files to provide rainbow bracket
functionality.
Tree-sitter queries are documented in the tree-sitter online documentation.
If you're writing queries for the first time, be sure to check out the section
on [syntax highlighting queries] and on [query syntax].
Rainbow queries have two captures: `@rainbow.scope` and `@rainbow.bracket`.
`@rainbow.scope` should capture any node that increases the nesting level
while `@rainbow.bracket` should capture any bracket nodes. Put another way:
`@rainbow.scope` switches to the next rainbow color for all nodes in the tree
under it while `@rainbow.bracket` paints captured nodes with the current
rainbow color.
For an example, let's add rainbow queries for the tree-sitter query (TSQ)
language itself. These queries will go into a
`runtime/queries/tsq/rainbows.scm` file in the repository root.
First we'll add the `@rainbow.bracket` captures. TSQ only has parentheses and
square brackets:
```tsq
["(" ")" "[" "]"] @rainbow.bracket
```
The ordering of the nodes within the alternation (square brackets) is not
taken into consideration.
> Note: Why are these nodes quoted? Most syntax highlights capture text
> surrounded by parentheses. These are _named nodes_ and correspond to the
> names of rules in the grammar. Brackets are usually written in tree-sitter
> grammars as literal strings, for example:
>
> ```js
> {
> // ...
> arguments: seq("(", repeat($.argument), ")"),
> // ...
> }
> ```
>
> Nodes written as literal strings in tree-sitter grammars may be captured
> in queries with those same literal strings.
Then we'll add `@rainbow.scope` captures. The easiest way to do this is to
view the `grammar.js` file in the tree-sitter grammar's repository. For TSQ,
that file is [here][tsq grammar.js]. As we scroll down the `grammar.js`, we
see that the `(alternation)`, (L36) `(group)` (L57), `(named_node)` (L59),
`(predicate)` (L87) and `(wildcard_node)` (L97) nodes all contain literal
parentheses or square brackets in their definitions. These nodes are all
direct parents of brackets and happen to also be the nodes we want to change
to the next rainbow color, so we capture them as `@rainbow.scope`.
```tsq
[
(group)
(named_node)
(wildcard_node)
(predicate)
(alternation)
] @rainbow.scope
```
This strategy works as a rule of thumb for most programming and configuration
languages. Markup languages can be trickier and may take additional
experimentation to find the correct nodes to use for scopes and brackets.
The `:tree-sitter-subtree` command shows the syntax tree under the primary
selection in S-expression format and can be a useful tool for determining how
to write a query.
### Properties
The `rainbow.include-children` property may be applied to `@rainbow.scope`
captures. By default, all `@rainbow.bracket` captures must be direct descendant
of a node captured with `@rainbow.scope` in a syntax tree in order to be
highlighted. The `rainbow.include-children` property disables that check and
allows `@rainbow.bracket` captures to be highlighted if they are direct or
indirect descendants of some node captured with `@rainbow.scope`.
For example, this property is used in the HTML rainbow queries.
For a document like `<a>link</a>`, the syntax tree is:
```tsq
(element ; <a>link</a>
(start_tag ; <a>
(tag_name)) ; a
(text) ; link
(end_tag ; </a>
(tag_name))) ; a
```
If we want to highlight the `<`, `>` and `</` nodes with rainbow colors, we
capture them as `@rainbow.bracket`:
```tsq
["<" ">" "</"] @rainbow.bracket
```
And we capture `(element)` as `@rainbow.scope` because `(element)` nodes nest
within each other: they increment the nesting level and switch to the next
color in the rainbow.
```tsq
(element) @rainbow.scope
```
But this combination of `@rainbow.scope` and `@rainbow.bracket` will not
highlight any nodes. `<`, `>` and `</` are children of the `(start_tag)` and
`(end_tag)` nodes. We can't capture `(start_tag)` and `(end_tag)` as
`@rainbow.scope` because they don't nest other elements. We can fix this case
by removing the requirement that `<`, `>` and `</` are direct descendants of
`(element)` using the `rainbow.include-children` property.
```tsq
((element) @rainbow.scope
(#set! rainbow.include-children))
```
With this property set, `<`, `>`, and `</` will highlight with rainbow colors
even though they aren't direct descendents of the `(element)` node.
`rainbow.include-children` is not necessary for the vast majority of programming
languages. It is only necessary when the node that increments the nesting level
(changes rainbow color) is not the direct parent of the bracket node.
[syntax highlighting queries]: https://tree-sitter.github.io/tree-sitter/syntax-highlighting#highlights
[query syntax]: https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries
[tsq grammar.js]: https://github.com/the-mikedavis/tree-sitter-tsq/blob/48b5e9f82ae0a4727201626f33a17f69f8e0ff86/grammar.js

34
book/src/guides/tags.md Normal file
View File

@@ -0,0 +1,34 @@
## Adding tags queries
See tree-sitter's documentation on [Code Navigation Systems] for more
background on tags queries.
Helix provides LSP-like features such as document and workspace symbol pickers
out-of-the-box for languages with `tags.scm` queries based on syntax trees. To
be analyzed a language must have a tree-sitter grammar and a `tags.scm` query
file which pattern matches interesting nodes from syntax trees.
Query files should be placed in `runtime/queries/{language}/tags.scm`
when contributing to Helix. You may place these under your local runtime
directory (`~/.config/helix/runtime` in Linux for example) for the sake of
testing.
The following [captures][tree-sitter-captures] are recognized:
| Capture name |
|--- |
| `definition.class` |
| `definition.constant` |
| `definition.function` |
| `definition.interface` |
| `definition.macro` |
| `definition.module` |
| `definition.struct` |
| `definition.type` |
[Example query files][example-queries] can be found in the Helix GitHub
repository.
[Code Navigation Systems]: https://tree-sitter.github.io/tree-sitter/4-code-navigation.html
[tree-sitter-captures]: https://tree-sitter.github.io/tree-sitter/using-parsers/queries/index.html
[example-queries]: https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+path%3A%2A%2A/tags.scm&type=Code

View File

@@ -28,6 +28,8 @@ The following [captures][tree-sitter-captures] are recognized:
| `comment.around` | | `comment.around` |
| `entry.inside` | | `entry.inside` |
| `entry.around` | | `entry.around` |
| `xml-element.inside` |
| `xml-element.around` |
[Example query files][textobject-examples] can be found in the helix GitHub repository. [Example query files][textobject-examples] can be found in the helix GitHub repository.

36
book/src/jumplist.md Normal file
View File

@@ -0,0 +1,36 @@
## Using the jumplist
To help with quick navigation, Helix maintains a list of "jumps" called the jumplist.
Whenever you make a significant movement (see next section), Helix stores your selections from before the move as a jump.
A jump serves as a kind of checkpoint, allowing you to jump to a separate location, make edits, and return to where you were with your previous selections.
This way, the jumplist tracks both your previous location and your selections.
You can manually save a jump by using `Ctrl-s`.
To jump backward in the jumplist, use `Ctrl-o`; to go forward, use `Ctrl-i`. To view and select from the full jumplist, use `Space-j` to open the jumplist picker.
### What makes a jump
The following is a non-exhaustive list of which actions add a jump to the jumplist:
- Switching buffers
- Using the buffer picker, going to the next/previous buffer
- Going to the last accessed/modified file
- Making a new file (`:new FILE`)
- Opening a file (`:open FILE`)
- Includes `:log-open`, `:config-open`, `:config-open-workspace`, `:tutor`
- Navigating by pickers, global search, or the file explorer
- `goto_file` (`gf`)
- Big in-file movements
- `select_regex` (`s`)
- `split_regex` (`S`)
- `search` (`/`)
- `keep_selections` and `remove_selections` (`K` and `<A-K>`)
- `goto_file_start` (`gg`)
- `goto_file_end`
- `goto_last_line` (`ge`)
- `:goto 123` / `:123` / `123G`
- `goto_definition` (`gd`)
- `goto_declaration` (`gD`)
- `goto_type_definition` (`gy`)
- `goto_reference` (`gr`)
- Other
- `Ctrl-s` manually creates a jump
- Trying to close a modified buffer can switch you to that buffer and create a jump
- The debugger can create jumps as you jump stack frames

View File

@@ -35,6 +35,8 @@ Normal mode is the default mode when you launch helix. You can return to it from
> NOTE: Unlike Vim, `f`, `F`, `t` and `T` are not confined to the current line. > NOTE: Unlike Vim, `f`, `F`, `t` and `T` are not confined to the current line.
> Hereafter, `<n>` represents an integer by typing a sequence of digits.
| Key | Description | Command | | Key | Description | Command |
| ----- | ----------- | ------- | | ----- | ----------- | ------- |
| `h`, `Left` | Move left | `move_char_left` | | `h`, `Left` | Move left | `move_char_left` |
@@ -51,7 +53,7 @@ Normal mode is the default mode when you launch helix. You can return to it from
| `f` | Find next char | `find_next_char` | | `f` | Find next char | `find_next_char` |
| `T` | Find till previous char | `till_prev_char` | | `T` | Find till previous char | `till_prev_char` |
| `F` | Find previous char | `find_prev_char` | | `F` | Find previous char | `find_prev_char` |
| `G` | Go to line number `<n>` | `goto_line` | | `<n>G`, `<n>gg` | Go to line number `<n>` | `goto_line` |
| `Alt-.` | Repeat last motion (`f`, `t`, `m`, `[` or `]`) | `repeat_last_motion` | | `Alt-.` | Repeat last motion (`f`, `t`, `m`, `[` or `]`) | `repeat_last_motion` |
| `Home` | Move to the start of the line | `goto_line_start` | | `Home` | Move to the start of the line | `goto_line_start` |
| `End` | Move to the end of the line | `goto_line_end` | | `End` | Move to the end of the line | `goto_line_end` |
@@ -212,8 +214,10 @@ Jumps to various locations.
| Key | Description | Command | | Key | Description | Command |
| ----- | ----------- | ------- | | ----- | ----------- | ------- |
| `g` | Go to line number `<n>` else start of file | `goto_file_start` | | `<n>g`| Go to line number `<n>` | `goto_file_start` |
| <code>&#124;</code> | Go to column number `<n>` else start of line | `goto_column` | | `g` | Go to the start of the file | `goto_file_start` |
| <code>&lt;n&gt;&#124;</code> | Go to column number `<n>` | `goto_column` |
| <code>&#124;</code> | Go to the start of line | `goto_column` |
| `e` | Go to the end of the file | `goto_last_line` | | `e` | Go to the end of the file | `goto_last_line` |
| `f` | Go to files in the selections | `goto_file` | | `f` | Go to files in the selections | `goto_file` |
| `h` | Go to the start of the line | `goto_line_start` | | `h` | Go to the start of the line | `goto_line_start` |
@@ -348,30 +352,32 @@ Displays the signature of the selected completion item. Remapping currently not
These mappings are in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired). These mappings are in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired).
| Key | Description | Command | | Key | Description | Command |
| ----- | ----------- | ------- | | ----- | ----------- | ------- |
| `]d` | Go to next diagnostic (**LSP**) | `goto_next_diag` | | `]d` | Go to next diagnostic (**LSP**) | `goto_next_diag` |
| `[d` | Go to previous diagnostic (**LSP**) | `goto_prev_diag` | | `[d` | Go to previous diagnostic (**LSP**) | `goto_prev_diag` |
| `]D` | Go to last diagnostic in document (**LSP**) | `goto_last_diag` | | `]D` | Go to last diagnostic in document (**LSP**) | `goto_last_diag` |
| `[D` | Go to first diagnostic in document (**LSP**) | `goto_first_diag` | | `[D` | Go to first diagnostic in document (**LSP**) | `goto_first_diag` |
| `]f` | Go to next function (**TS**) | `goto_next_function` | | `]f` | Go to next function (**TS**) | `goto_next_function` |
| `[f` | Go to previous function (**TS**) | `goto_prev_function` | | `[f` | Go to previous function (**TS**) | `goto_prev_function` |
| `]t` | Go to next type definition (**TS**) | `goto_next_class` | | `]t` | Go to next type definition (**TS**) | `goto_next_class` |
| `[t` | Go to previous type definition (**TS**) | `goto_prev_class` | | `[t` | Go to previous type definition (**TS**) | `goto_prev_class` |
| `]a` | Go to next argument/parameter (**TS**) | `goto_next_parameter` | | `]a` | Go to next argument/parameter (**TS**) | `goto_next_parameter` |
| `[a` | Go to previous argument/parameter (**TS**) | `goto_prev_parameter` | | `[a` | Go to previous argument/parameter (**TS**) | `goto_prev_parameter` |
| `]c` | Go to next comment (**TS**) | `goto_next_comment` | | `]c` | Go to next comment (**TS**) | `goto_next_comment` |
| `[c` | Go to previous comment (**TS**) | `goto_prev_comment` | | `[c` | Go to previous comment (**TS**) | `goto_prev_comment` |
| `]T` | Go to next test (**TS**) | `goto_next_test` | | `]T` | Go to next test (**TS**) | `goto_next_test` |
| `[T` | Go to previous test (**TS**) | `goto_prev_test` | | `[T` | Go to previous test (**TS**) | `goto_prev_test` |
| `]p` | Go to next paragraph | `goto_next_paragraph` | | `]p` | Go to next paragraph | `goto_next_paragraph` |
| `[p` | Go to previous paragraph | `goto_prev_paragraph` | | `[p` | Go to previous paragraph | `goto_prev_paragraph` |
| `]g` | Go to next change | `goto_next_change` | | `]g` | Go to next change | `goto_next_change` |
| `[g` | Go to previous change | `goto_prev_change` | | `[g` | Go to previous change | `goto_prev_change` |
| `]G` | Go to last change | `goto_last_change` | | `]G` | Go to last change | `goto_last_change` |
| `[G` | Go to first change | `goto_first_change` | | `[G` | Go to first change | `goto_first_change` |
| `]Space` | Add newline below | `add_newline_below` | | `[x` | Go to next (X)HTML element | `goto_next_xml_element` |
| `[Space` | Add newline above | `add_newline_above` | | `]x` | Go to previous (X)HTML element | `goto_prev_xml_element` |
| `]Space` | Add newline below | `add_newline_below` |
| `[Space` | Add newline above | `add_newline_above` |
## Insert mode ## Insert mode

View File

@@ -71,8 +71,10 @@ These configuration keys are available:
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set, defaults to `editor.text-width` | | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set, defaults to `editor.text-width` |
| `rulers` | Overrides the `editor.rulers` config key for the language. | | `rulers` | Overrides the `editor.rulers` config key for the language. |
| `path-completion` | Overrides the `editor.path-completion` config key for the language. | | `path-completion` | Overrides the `editor.path-completion` config key for the language. |
| `word-completion` | Overrides the [`editor.word-completion`](./editor.md#editorword-completion-section) configuration for the language. |
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml`. Overwrites the setting of the same name in `config.toml` if set. | | `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml`. Overwrites the setting of the same name in `config.toml` if set. |
| `persistent-diagnostic-sources` | An array of LSP diagnostic sources assumed unchanged when the language server resends the same set of diagnostics. Helix can track the position for these diagnostics internally instead. Useful for diagnostics that are recomputed on save. | `persistent-diagnostic-sources` | An array of LSP diagnostic sources assumed unchanged when the language server resends the same set of diagnostics. Helix can track the position for these diagnostics internally instead. Useful for diagnostics that are recomputed on save.
| `rainbow-brackets` | Overrides the `editor.rainbow-brackets` config key for the language |
### File-type detection and the `file-types` key ### File-type detection and the `file-types` key
@@ -109,7 +111,7 @@ of the formatter command. In particular, the `%{buffer_name}` variable can be pa
argument to the formatter: argument to the formatter:
```toml ```toml
formatter = { command = "mylang-formatter" , args = ["--stdin", "--stdin-filename %{buffer_name}"] } formatter = { command = "mylang-formatter" , args = ["--stdin", "--stdin-filename", "%{buffer_name}"] }
``` ```
## Language Server configuration ## Language Server configuration

View File

@@ -15,6 +15,8 @@ Helix' keymap and interaction model ([Using Helix](#usage.md)) is easier to adop
| [Visual Studio Code](https://code.visualstudio.com/) | [Helix for VS Code](https://marketplace.visualstudio.com/items?itemName=jasew.vscode-helix-emulation) extension| | [Visual Studio Code](https://code.visualstudio.com/) | [Helix for VS Code](https://marketplace.visualstudio.com/items?itemName=jasew.vscode-helix-emulation) extension|
| [Zed](https://zed.dev/) | native via keybindings ([Bug](https://github.com/zed-industries/zed/issues/4642)) | | [Zed](https://zed.dev/) | native via keybindings ([Bug](https://github.com/zed-industries/zed/issues/4642)) |
| [CodeMirror](https://codemirror.net/) | [codemirror-helix](https://gitlab.com/_rvidal/codemirror-helix) | | [CodeMirror](https://codemirror.net/) | [codemirror-helix](https://gitlab.com/_rvidal/codemirror-helix) |
| [Lite XL](https://lite-xl.com/) | [lite-modal-hx](https://codeberg.org/Mandarancio/lite-modal-hx) |
| [Lapce](https://lap.dev/lapce/) | | Requested: https://github.com/lapce/lapce/issues/281 |
## Shells ## Shells

View File

@@ -2,7 +2,6 @@
- [Linux](#linux) - [Linux](#linux)
- [Ubuntu/Debian](#ubuntudebian) - [Ubuntu/Debian](#ubuntudebian)
- [Ubuntu (PPA)](#ubuntu-ppa)
- [Fedora/RHEL](#fedorarhel) - [Fedora/RHEL](#fedorarhel)
- [Arch Linux extra](#arch-linux-extra) - [Arch Linux extra](#arch-linux-extra)
- [NixOS](#nixos) - [NixOS](#nixos)
@@ -26,21 +25,11 @@ The following third party repositories are available:
### Ubuntu/Debian ### Ubuntu/Debian
Install the Debian package from the release page. Install the Debian package [from the release page](https://github.com/helix-editor/helix/releases/latest).
If you are running a system older than Ubuntu 22.04, Mint 21, or Debian 12, you can build the `.deb` file locally If you are running a system older than Ubuntu 22.04, Mint 21, or Debian 12, you can build the `.deb` file locally
[from source](./building-from-source.md#building-the-debian-package). [from source](./building-from-source.md#building-the-debian-package).
### Ubuntu (PPA)
Add the `PPA` for Helix:
```sh
sudo add-apt-repository ppa:maveonair/helix-editor
sudo apt update
sudo apt install helix
```
### Fedora/RHEL ### Fedora/RHEL
```sh ```sh

View File

@@ -89,24 +89,26 @@ Cmd-s = ":write" # Cmd or Win or Meta and 's' to write
Special keys are encoded as follows: Special keys are encoded as follows:
| Key name | Representation | | Key name | Representation |
| --- | --- | | --- | --- |
| Backspace | `"backspace"` | | Backspace | `"backspace"` |
| Space | `"space"` | | Space | `"space"` |
| Return/Enter | `"ret"` | | Return/Enter | `"ret"` |
| Left | `"left"` | | Left | `"left"` |
| Right | `"right"` | | Right | `"right"` |
| Up | `"up"` | | Up | `"up"` |
| Down | `"down"` | | Down | `"down"` |
| Home | `"home"` | | Home | `"home"` |
| End | `"end"` | | End | `"end"` |
| Page Up | `"pageup"` | | Page Up | `"pageup"` |
| Page Down | `"pagedown"` | | Page Down | `"pagedown"` |
| Tab | `"tab"` | | Tab | `"tab"` |
| Delete | `"del"` | | Delete | `"del"` |
| Insert | `"ins"` | | Insert | `"ins"` |
| Null | `"null"` | | Null | `"null"` |
| Escape | `"esc"` | | Escape | `"esc"` |
| Less Than (<) | `"lt"` |
| Greater Than (>) | `"gt"` |
Keys can be disabled by binding them to the `no_op` command. Keys can be disabled by binding them to the `no_op` command.

View File

@@ -24,6 +24,7 @@ function or block of code.
| `c` | Comment | | `c` | Comment |
| `T` | Test | | `T` | Test |
| `g` | Change | | `g` | Change |
| `x` | (X)HTML element |
> 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current > 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current
document and a special tree-sitter query file to work properly. [Only document and a special tree-sitter query file to work properly. [Only

View File

@@ -2,6 +2,17 @@
To use a theme add `theme = "<name>"` to the top of your [`config.toml`](./configuration.md) file, or select it during runtime using `:theme <name>`. To use a theme add `theme = "<name>"` to the top of your [`config.toml`](./configuration.md) file, or select it during runtime using `:theme <name>`.
Separate themes can be configured for light and dark modes. On terminals supporting [mode 2031 dark/light detection](https://github.com/contour-terminal/contour/blob/master/docs/vt-extensions/color-palette-update-notifications.md), the theme mode is detected from the terminal.
```toml
[theme]
dark = "catppuccin_frappe"
light = "catppuccin_latte"
## Optional. Used if the terminal doesn't declare a preference.
## Defaults to the theme set for `dark` if not specified.
# fallback = "catppuccin_frappe"
```
## Creating a theme ## Creating a theme
Create a file with the name of your theme as the file name (i.e `mytheme.toml`) and place it in your `themes` directory (i.e `~/.config/helix/themes` or `%AppData%\helix\themes` on Windows). The directory might have to be created beforehand. Create a file with the name of your theme as the file name (i.e `mytheme.toml`) and place it in your `themes` directory (i.e `~/.config/helix/themes` or `%AppData%\helix\themes` on Windows). The directory might have to be created beforehand.
@@ -130,6 +141,17 @@ inherits = "boo_berry"
berry = "#2A2A4D" berry = "#2A2A4D"
``` ```
### Rainbow
The `rainbow` key is used for rainbow highlight for matching brackets.
The key is a list of styles.
```toml
rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold"] }]
```
Colors from the palette and modifiers may be used.
### Scopes ### Scopes
The following is a list of scopes available to use for styling: The following is a list of scopes available to use for styling:

View File

@@ -47,6 +47,12 @@
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="25.07.1" date="2025-07-18">
<url>https://github.com/helix-editor/helix/releases/tag/25.07.1</url>
</release>
<release version="25.07" date="2025-07-15">
<url>https://helix-editor.com/news/release-25-07-highlights/</url>
</release>
<release version="25.01.1" date="2025-01-19"> <release version="25.01.1" date="2025-01-19">
<url>https://github.com/helix-editor/helix/releases/tag/25.01.1</url> <url>https://github.com/helix-editor/helix/releases/tag/25.01.1</url>
</release> </release>

View File

@@ -13,8 +13,8 @@ _hx() {
return 0 return 0
;; ;;
--health) --health)
languages=$(hx --health | tail -n '+7' | awk '{print $1}' | sed 's/\x1b\[[0-9;]*m//g') languages=$(hx --health all-languages | tail -n '+2' | awk '{print $1}' | sed 's/\x1b\[[0-9;]*m//g')
mapfile -t COMPREPLY < <(compgen -W """$languages""" -- "$cur") mapfile -t COMPREPLY < <(compgen -W """clipboard languages all-languages all $languages""" -- "$cur")
return 0 return 0
;; ;;
esac esac

View File

@@ -4,6 +4,10 @@
complete -c hx -s h -l help -d "Prints help information" complete -c hx -s h -l help -d "Prints help information"
complete -c hx -l tutor -d "Loads the tutorial" complete -c hx -l tutor -d "Loads the tutorial"
complete -c hx -l health -xa "(__hx_langs_ops)" -d "Checks for errors" complete -c hx -l health -xa "(__hx_langs_ops)" -d "Checks for errors"
complete -c hx -l health -xka all -d "Prints all diagnostic informations"
complete -c hx -l health -xka all-languages -d "Lists all languages"
complete -c hx -l health -xka languages -d "Lists user configured languages"
complete -c hx -l health -xka clipboard -d "Prints system clipboard provider"
complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetch or build tree-sitter grammars" complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetch or build tree-sitter grammars"
complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity" complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
complete -c hx -s V -l version -d "Prints version information" complete -c hx -s V -l version -d "Prints version information"
@@ -14,5 +18,5 @@ complete -c hx -l log -r -d "Specifies a file to use for logging"
complete -c hx -s w -l working-dir -d "Specify initial working directory" -xa "(__fish_complete_directories)" complete -c hx -s w -l working-dir -d "Specify initial working directory" -xa "(__fish_complete_directories)"
function __hx_langs_ops function __hx_langs_ops
hx --health languages | tail -n '+2' | string replace -fr '^(\S+) .*' '$1' hx --health all-languages | tail -n '+2' | string replace -fr '^(\S+) .*' '$1'
end end

View File

@@ -5,8 +5,8 @@
# The help message won't be overridden though, so it will still be present here # The help message won't be overridden though, so it will still be present here
def health_categories [] { def health_categories [] {
let languages = ^hx --health languages | detect columns | get Language | filter { $in != null } let languages = ^hx --health all-languages | detect columns | get Language | where { $in != null }
let completions = [ "all", "clipboard", "languages" ] | append $languages let completions = [ "all", "clipboard", "languages", "all-languages" ] | append $languages
return $completions return $completions
} }

View File

@@ -25,7 +25,7 @@ _hx() {
case "$state" in case "$state" in
health) health)
local languages=($(hx --health | tail -n '+11' | awk '{print $1}' | sed 's/\x1b\[[0-9;]*m//g;s/[✘✓]//g')) local languages=($(hx --health all-languages | tail -n '+2' | awk '{print $1}' | sed 's/\x1b\[[0-9;]*m//g;s/[✘✓]//g'))
_values 'language' $languages _values 'language' $languages
;; ;;
grammar) grammar)

View File

@@ -46,6 +46,8 @@ in
allowBuiltinFetchGit = true; allowBuiltinFetchGit = true;
}; };
propagatedBuildInputs = [ runtimeDir ];
nativeBuildInputs = [ nativeBuildInputs = [
installShellFiles installShellFiles
git git

View File

@@ -1,10 +1,12 @@
| Crate | Description | | Crate | Description |
| ----------- | ----------- | | ----------- | ----------- |
| helix-stdx | Extensions to the standard library (similar to [`rust-analyzer`'s](https://github.com/rust-lang/rust-analyzer/blob/ea413f67a8f730b4211c09e103f8207c62e7dbc3/crates/stdx/Cargo.toml#L5)) |
| helix-core | Core editing primitives, functional. | | helix-core | Core editing primitives, functional. |
| helix-lsp | Language server client | | helix-lsp | Language server client |
| helix-lsp-types | Language Server Protocol type definitions | | helix-lsp-types | Language Server Protocol type definitions |
| helix-dap | Debug Adapter Protocol (DAP) client | | helix-dap | Debug Adapter Protocol (DAP) client |
| helix-event | Primitives for defining and handling events within the editor |
| helix-loader | Functions for building, fetching, and loading external resources | | helix-loader | Functions for building, fetching, and loading external resources |
| helix-view | UI abstractions for use in backends, imperative shell. | | helix-view | UI abstractions for use in backends, imperative shell. |
| helix-term | Terminal UI | | helix-term | Terminal UI |
@@ -110,3 +112,17 @@ The `main` function sets up a new `Application` that runs the event loop.
## TUI / Term ## TUI / Term
TODO: document Component and rendering related stuff TODO: document Component and rendering related stuff
## Event
The `helix-event` crate defines primitives for defining and acting on events
within the editor. "Events" cover things like opening, changing and closing of
documents, starting and stopping of language servers and more.
`helix-event` has tools for defining events and registering _hooks_ which run
any time an event is emitted. `helix-event` also provides `AsyncHook` - a tool
for running cancellable tasks which run after events with _debouncing_.
See the `AsyncHook` type for more information. Events can be created within the
`events!` macro. Synchronous hooks can be created with `register_hook!`. And
editor-wide events can be sent to hooks with `helix_event::dispatch`.

12
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1740560979, "lastModified": 1759381078,
"narHash": "sha256-Vr3Qi346M+8CjedtbyUevIGDZW8LcA1fTG0ugPY/Hic=", "narHash": "sha256-gTrEEp5gEspIcCOx9PD8kMaF1iEmfBcTbO0Jag2QhQs=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5135c59491985879812717f4c9fea69604e7f26f", "rev": "7df7ff7d8e00218376575f0acdcc5d66741351ee",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -29,11 +29,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1740623427, "lastModified": 1759631821,
"narHash": "sha256-3SdPQrZoa4odlScFDUHd4CUPQ/R1gtH4Mq9u8CBiK8M=", "narHash": "sha256-V8A1L0FaU/aSXZ1QNJScxC12uP4hANeRBgI4YdhHeRM=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "d342e8b5fd88421ff982f383c853f0fc78a847ab", "rev": "1d7cbdaad90f8a5255a89a6eddd8af24dc89cafe",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -16,13 +16,7 @@
... ...
}: let }: let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
systems = [ eachSystem = lib.genAttrs lib.systems.flakeExposed;
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
eachSystem = lib.genAttrs systems;
pkgsFor = eachSystem (system: pkgsFor = eachSystem (system:
import nixpkgs { import nixpkgs {
localSystem.system = system; localSystem.system = system;

View File

@@ -87,8 +87,6 @@
$CC -c src/parser.c -o parser.o $FLAGS $CC -c src/parser.c -o parser.o $FLAGS
$CXX -shared -o $NAME.so *.o $CXX -shared -o $NAME.so *.o
ls -al
runHook postBuild runHook postBuild
''; '';

View File

@@ -30,7 +30,7 @@ unicode-segmentation.workspace = true
# For now lets lock the version to avoid rendering glitches # For now lets lock the version to avoid rendering glitches
# when installing without `--locked` # when installing without `--locked`
unicode-width = "=0.1.12" unicode-width = "=0.1.12"
unicode-general-category = "1.0" unicode-general-category = "1.1"
slotmap.workspace = true slotmap.workspace = true
tree-house.workspace = true tree-house.workspace = true
once_cell = "1.21" once_cell = "1.21"
@@ -44,7 +44,7 @@ log = "0.4"
anyhow = "1.0" anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
toml = "0.8" toml.workspace = true
imara-diff = "0.2.0" imara-diff = "0.2.0"
encoding_rs = "0.8" encoding_rs = "0.8"

View File

@@ -16,6 +16,7 @@ pub struct CompletionItem {
pub enum CompletionProvider { pub enum CompletionProvider {
Lsp(LanguageServerId), Lsp(LanguageServerId),
Path, Path,
Word,
} }
impl From<LanguageServerId> for CompletionProvider { impl From<LanguageServerId> for CompletionProvider {

View File

@@ -228,6 +228,7 @@ impl FromStr for Ini {
let glob = GlobBuilder::new(&glob_str) let glob = GlobBuilder::new(&glob_str)
.literal_separator(true) .literal_separator(true)
.backslash_escape(true) .backslash_escape(true)
.empty_alternates(true)
.build()?; .build()?;
ini.sections.push(Section { ini.sections.push(Section {
glob: glob.compile_matcher(), glob: glob.compile_matcher(),

View File

@@ -1,4 +1,4 @@
use std::{borrow::Cow, collections::HashMap, iter}; use std::{borrow::Cow, collections::HashMap};
use helix_stdx::rope::RopeSliceExt; use helix_stdx::rope::RopeSliceExt;
use tree_house::TREE_SITTER_MATCH_LIMIT; use tree_house::TREE_SITTER_MATCH_LIMIT;
@@ -153,6 +153,12 @@ pub fn auto_detect_indent_style(document_text: &Rope) -> Option<IndentStyle> {
// Give more weight to tabs, because their presence is a very // Give more weight to tabs, because their presence is a very
// strong indicator. // strong indicator.
histogram[0] *= 2; histogram[0] *= 2;
// Gives less weight to single indent, as single spaces are
// often used in certain languages' comment systems and rarely
// used as the actual document indentation.
if histogram[1] > 1 {
histogram[1] /= 2;
}
histogram histogram
}; };
@@ -208,7 +214,10 @@ fn whitespace_with_same_width(text: RopeSlice) -> String {
if grapheme == "\t" { if grapheme == "\t" {
s.push('\t'); s.push('\t');
} else { } else {
s.extend(std::iter::repeat(' ').take(grapheme_width(&Cow::from(grapheme)))); s.extend(std::iter::repeat_n(
' ',
grapheme_width(&Cow::from(grapheme)),
));
} }
} }
s s
@@ -237,10 +246,10 @@ pub fn normalize_indentation(
original_len += 1; original_len += 1;
} }
if indent_style == IndentStyle::Tabs { if indent_style == IndentStyle::Tabs {
dst.extend(iter::repeat('\t').take(len / tab_width)); dst.extend(std::iter::repeat_n('\t', len / tab_width));
len %= tab_width; len %= tab_width;
} }
dst.extend(iter::repeat(' ').take(len)); dst.extend(std::iter::repeat_n(' ', len));
original_len original_len
} }

View File

@@ -361,7 +361,7 @@ impl Transform {
} }
} }
FormatItem::Conditional(i, ref if_, ref else_) => { FormatItem::Conditional(i, ref if_, ref else_) => {
if cap.get_group(i).map_or(true, |mat| mat.is_empty()) { if cap.get_group(i).is_none_or(|mat| mat.is_empty()) {
buf.push_str(else_) buf.push_str(else_)
} else { } else {
buf.push_str(if_) buf.push_str(if_)

View File

@@ -13,6 +13,7 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use arc_swap::{ArcSwap, Guard}; use arc_swap::{ArcSwap, Guard};
use config::{Configuration, FileType, LanguageConfiguration, LanguageServerConfiguration}; use config::{Configuration, FileType, LanguageConfiguration, LanguageServerConfiguration};
use foldhash::HashSet;
use helix_loader::grammar::get_language; use helix_loader::grammar::get_language;
use helix_stdx::rope::RopeSliceExt as _; use helix_stdx::rope::RopeSliceExt as _;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
@@ -20,7 +21,10 @@ use ropey::RopeSlice;
use tree_house::{ use tree_house::{
highlighter, highlighter,
query_iter::QueryIter, query_iter::QueryIter,
tree_sitter::{Grammar, InactiveQueryCursor, InputEdit, Node, Query, RopeInput, Tree}, tree_sitter::{
query::{InvalidPredicateError, UserPredicate},
Capture, Grammar, InactiveQueryCursor, InputEdit, Node, Pattern, Query, RopeInput, Tree,
},
Error, InjectionLanguageMarker, LanguageConfig as SyntaxConfig, Layer, Error, InjectionLanguageMarker, LanguageConfig as SyntaxConfig, Layer,
}; };
@@ -28,6 +32,7 @@ use crate::{indent::IndentQuery, tree_sitter, ChangeSet, Language};
pub use tree_house::{ pub use tree_house::{
highlighter::{Highlight, HighlightEvent}, highlighter::{Highlight, HighlightEvent},
query_iter::QueryIterEvent,
Error as HighlighterError, LanguageLoader, TreeCursor, TREE_SITTER_MATCH_LIMIT, Error as HighlighterError, LanguageLoader, TreeCursor, TREE_SITTER_MATCH_LIMIT,
}; };
@@ -37,6 +42,8 @@ pub struct LanguageData {
syntax: OnceCell<Option<SyntaxConfig>>, syntax: OnceCell<Option<SyntaxConfig>>,
indent_query: OnceCell<Option<IndentQuery>>, indent_query: OnceCell<Option<IndentQuery>>,
textobject_query: OnceCell<Option<TextObjectQuery>>, textobject_query: OnceCell<Option<TextObjectQuery>>,
tag_query: OnceCell<Option<TagQuery>>,
rainbow_query: OnceCell<Option<RainbowQuery>>,
} }
impl LanguageData { impl LanguageData {
@@ -46,6 +53,8 @@ impl LanguageData {
syntax: OnceCell::new(), syntax: OnceCell::new(),
indent_query: OnceCell::new(), indent_query: OnceCell::new(),
textobject_query: OnceCell::new(), textobject_query: OnceCell::new(),
tag_query: OnceCell::new(),
rainbow_query: OnceCell::new(),
} }
} }
@@ -154,6 +163,74 @@ impl LanguageData {
.as_ref() .as_ref()
} }
/// Compiles the tags.scm query for a language.
/// This function should only be used by this module or the xtask crate.
pub fn compile_tag_query(
grammar: Grammar,
config: &LanguageConfiguration,
) -> Result<Option<TagQuery>> {
let name = &config.language_id;
let text = read_query(name, "tags.scm");
if text.is_empty() {
return Ok(None);
}
let query = Query::new(grammar, &text, |_pattern, predicate| match predicate {
// TODO: these predicates are allowed in tags.scm queries but not yet used.
UserPredicate::IsPropertySet { key: "local", .. } => Ok(()),
UserPredicate::Other(pred) => match pred.name() {
"strip!" | "select-adjacent!" => Ok(()),
_ => Err(InvalidPredicateError::unknown(predicate)),
},
_ => Err(InvalidPredicateError::unknown(predicate)),
})
.with_context(|| format!("Failed to compile tags.scm query for '{name}'"))?;
Ok(Some(TagQuery { query }))
}
fn tag_query(&self, loader: &Loader) -> Option<&TagQuery> {
self.tag_query
.get_or_init(|| {
let grammar = self.syntax_config(loader)?.grammar;
Self::compile_tag_query(grammar, &self.config)
.map_err(|err| {
log::error!("{err}");
})
.ok()
.flatten()
})
.as_ref()
}
/// Compiles the rainbows.scm query for a language.
/// This function should only be used by this module or the xtask crate.
pub fn compile_rainbow_query(
grammar: Grammar,
config: &LanguageConfiguration,
) -> Result<Option<RainbowQuery>> {
let name = &config.language_id;
let text = read_query(name, "rainbows.scm");
if text.is_empty() {
return Ok(None);
}
let rainbow_query = RainbowQuery::new(grammar, &text)
.with_context(|| format!("Failed to compile rainbows.scm query for '{name}'"))?;
Ok(Some(rainbow_query))
}
fn rainbow_query(&self, loader: &Loader) -> Option<&RainbowQuery> {
self.rainbow_query
.get_or_init(|| {
let grammar = self.syntax_config(loader)?.grammar;
Self::compile_rainbow_query(grammar, &self.config)
.map_err(|err| {
log::error!("{err}");
})
.ok()
.flatten()
})
.as_ref()
}
fn reconfigure(&self, scopes: &[String]) { fn reconfigure(&self, scopes: &[String]) {
if let Some(Some(config)) = self.syntax.get() { if let Some(Some(config)) = self.syntax.get() {
reconfigure_highlights(config, scopes); reconfigure_highlights(config, scopes);
@@ -339,6 +416,14 @@ impl Loader {
self.language(lang).textobject_query(self) self.language(lang).textobject_query(self)
} }
pub fn tag_query(&self, lang: Language) -> Option<&TagQuery> {
self.language(lang).tag_query(self)
}
fn rainbow_query(&self, lang: Language) -> Option<&RainbowQuery> {
self.language(lang).rainbow_query(self)
}
pub fn language_server_configs(&self) -> &HashMap<String, LanguageServerConfiguration> { pub fn language_server_configs(&self) -> &HashMap<String, LanguageServerConfiguration> {
&self.language_server_configs &self.language_server_configs
} }
@@ -477,15 +562,15 @@ impl Syntax {
self.inner.tree_for_byte_range(start, end) self.inner.tree_for_byte_range(start, end)
} }
pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node> { pub fn named_descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node<'_>> {
self.inner.named_descendant_for_byte_range(start, end) self.inner.named_descendant_for_byte_range(start, end)
} }
pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node> { pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Node<'_>> {
self.inner.descendant_for_byte_range(start, end) self.inner.descendant_for_byte_range(start, end)
} }
pub fn walk(&self) -> TreeCursor { pub fn walk(&self) -> TreeCursor<'_> {
self.inner.walk() self.inner.walk()
} }
@@ -511,6 +596,92 @@ impl Syntax {
{ {
QueryIter::new(&self.inner, source, loader, range) QueryIter::new(&self.inner, source, loader, range)
} }
pub fn tags<'a>(
&'a self,
source: RopeSlice<'a>,
loader: &'a Loader,
range: impl RangeBounds<u32>,
) -> QueryIter<'a, 'a, impl FnMut(Language) -> Option<&'a Query> + 'a, ()> {
self.query_iter(
source,
|lang| loader.tag_query(lang).map(|q| &q.query),
range,
)
}
pub fn rainbow_highlights(
&self,
source: RopeSlice,
rainbow_length: usize,
loader: &Loader,
range: impl RangeBounds<u32>,
) -> OverlayHighlights {
struct RainbowScope<'tree> {
end: u32,
node: Option<Node<'tree>>,
highlight: Highlight,
}
let mut scope_stack = Vec::<RainbowScope>::new();
let mut highlights = Vec::new();
let mut query_iter = self.query_iter::<_, (), _>(
source,
|lang| loader.rainbow_query(lang).map(|q| &q.query),
range,
);
while let Some(event) = query_iter.next() {
let QueryIterEvent::Match(mat) = event else {
continue;
};
let rainbow_query = loader
.rainbow_query(query_iter.current_language())
.expect("language must have a rainbow query to emit matches");
let byte_range = mat.node.byte_range();
// Pop any scopes that end before this capture begins.
while scope_stack
.last()
.is_some_and(|scope| byte_range.start >= scope.end)
{
scope_stack.pop();
}
let capture = Some(mat.capture);
if capture == rainbow_query.scope_capture {
scope_stack.push(RainbowScope {
end: byte_range.end,
node: if rainbow_query
.include_children_patterns
.contains(&mat.pattern)
{
None
} else {
Some(mat.node.clone())
},
highlight: Highlight::new((scope_stack.len() % rainbow_length) as u32),
});
} else if capture == rainbow_query.bracket_capture {
if let Some(scope) = scope_stack.last() {
if !scope
.node
.as_ref()
.is_some_and(|node| mat.node.parent().as_ref() != Some(node))
{
let start = source
.byte_to_char(source.floor_char_boundary(byte_range.start as usize));
let end =
source.byte_to_char(source.ceil_char_boundary(byte_range.end as usize));
highlights.push((scope.highlight, start..end));
}
}
}
}
OverlayHighlights::Heterogenous { highlights }
}
} }
pub type Highlighter<'a> = highlighter::Highlighter<'a, 'a, Loader>; pub type Highlighter<'a> = highlighter::Highlighter<'a, 'a, Loader>;
@@ -881,6 +1052,11 @@ impl TextObjectQuery {
} }
} }
#[derive(Debug)]
pub struct TagQuery {
pub query: Query,
}
pub fn pretty_print_tree<W: fmt::Write>(fmt: &mut W, node: Node) -> fmt::Result { pub fn pretty_print_tree<W: fmt::Write>(fmt: &mut W, node: Node) -> fmt::Result {
if node.child_count() == 0 { if node.child_count() == 0 {
if node_is_visible(&node) { if node_is_visible(&node) {
@@ -897,7 +1073,7 @@ fn node_is_visible(node: &Node) -> bool {
node.is_missing() || (node.is_named() && node.grammar().node_kind_is_visible(node.kind_id())) node.is_missing() || (node.is_named() && node.grammar().node_kind_is_visible(node.kind_id()))
} }
fn format_anonymous_node_kind(kind: &str) -> Cow<str> { fn format_anonymous_node_kind(kind: &str) -> Cow<'_, str> {
if kind.contains('"') { if kind.contains('"') {
Cow::Owned(kind.replace('"', "\\\"")) Cow::Owned(kind.replace('"', "\\\""))
} else { } else {
@@ -953,6 +1129,56 @@ fn pretty_print_tree_impl<W: fmt::Write>(
Ok(()) Ok(())
} }
/// Finds the child of `node` which contains the given byte range.
pub fn child_for_byte_range<'a>(node: &Node<'a>, range: ops::Range<u32>) -> Option<Node<'a>> {
for child in node.children() {
let child_range = child.byte_range();
if range.start >= child_range.start && range.end <= child_range.end {
return Some(child);
}
}
None
}
#[derive(Debug)]
pub struct RainbowQuery {
query: Query,
include_children_patterns: HashSet<Pattern>,
scope_capture: Option<Capture>,
bracket_capture: Option<Capture>,
}
impl RainbowQuery {
fn new(grammar: Grammar, source: &str) -> Result<Self, tree_sitter::query::ParseError> {
let mut include_children_patterns = HashSet::default();
let query = Query::new(grammar, source, |pattern, predicate| match predicate {
UserPredicate::SetProperty {
key: "rainbow.include-children",
val,
} => {
if val.is_some() {
return Err(
"property 'rainbow.include-children' does not take an argument".into(),
);
}
include_children_patterns.insert(pattern);
Ok(())
}
_ => Err(InvalidPredicateError::unknown(predicate)),
})?;
Ok(Self {
include_children_patterns,
scope_capture: query.get_capture("rainbow.scope"),
bracket_capture: query.get_capture("rainbow.bracket"),
query,
})
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use once_cell::sync::Lazy; use once_cell::sync::Lazy;

View File

@@ -7,6 +7,7 @@ use serde::{ser::SerializeSeq as _, Deserialize, Serialize};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
fmt::{self, Display}, fmt::{self, Display},
num::NonZeroU8,
path::PathBuf, path::PathBuf,
str::FromStr, str::FromStr,
}; };
@@ -60,6 +61,8 @@ pub struct LanguageConfiguration {
/// If set, overrides `editor.path-completion`. /// If set, overrides `editor.path-completion`.
pub path_completion: Option<bool>, pub path_completion: Option<bool>,
/// If set, overrides `editor.word-completion`.
pub word_completion: Option<WordCompletion>,
#[serde(default)] #[serde(default)]
pub diagnostic_severity: Severity, pub diagnostic_severity: Severity,
@@ -98,6 +101,8 @@ pub struct LanguageConfiguration {
pub workspace_lsp_roots: Option<Vec<PathBuf>>, pub workspace_lsp_roots: Option<Vec<PathBuf>>,
#[serde(default)] #[serde(default)]
pub persistent_diagnostic_sources: Vec<String>, pub persistent_diagnostic_sources: Vec<String>,
/// Overrides the `editor.rainbow-brackets` config key for the language.
pub rainbow_brackets: Option<bool>,
} }
impl LanguageConfiguration { impl LanguageConfiguration {
@@ -265,6 +270,7 @@ pub enum LanguageServerFeature {
WorkspaceSymbols, WorkspaceSymbols,
// Symbols, use bitflags, see above? // Symbols, use bitflags, see above?
Diagnostics, Diagnostics,
PullDiagnostics,
RenameSymbol, RenameSymbol,
InlayHints, InlayHints,
DocumentColors, DocumentColors,
@@ -289,6 +295,7 @@ impl Display for LanguageServerFeature {
DocumentSymbols => "document-symbols", DocumentSymbols => "document-symbols",
WorkspaceSymbols => "workspace-symbols", WorkspaceSymbols => "workspace-symbols",
Diagnostics => "diagnostics", Diagnostics => "diagnostics",
PullDiagnostics => "pull-diagnostics",
RenameSymbol => "rename-symbol", RenameSymbol => "rename-symbol",
InlayHints => "inlay-hints", InlayHints => "inlay-hints",
DocumentColors => "document-colors", DocumentColors => "document-colors",
@@ -441,6 +448,7 @@ pub enum DebugArgumentValue {
String(String), String(String),
Array(Vec<String>), Array(Vec<String>),
Boolean(bool), Boolean(bool),
Table(HashMap<String, String>),
} }
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
@@ -572,6 +580,13 @@ pub struct SoftWrap {
pub wrap_at_text_width: Option<bool>, pub wrap_at_text_width: Option<bool>,
} }
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct WordCompletion {
pub enable: Option<bool>,
pub trigger_length: Option<NonZeroU8>,
}
fn deserialize_regex<'de, D>(deserializer: D) -> Result<Option<rope::Regex>, D::Error> fn deserialize_regex<'de, D>(deserializer: D) -> Result<Option<rope::Regex>, D::Error>
where where
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,

View File

@@ -19,6 +19,16 @@ pub enum Operation {
Insert(Tendril), Insert(Tendril),
} }
impl Operation {
/// The number of characters affected by the operation.
pub fn len_chars(&self) -> usize {
match self {
Self::Retain(n) | Self::Delete(n) => *n,
Self::Insert(s) => s.chars().count(),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Assoc { pub enum Assoc {
Before, Before,
@@ -510,7 +520,7 @@ impl ChangeSet {
pos pos
} }
pub fn changes_iter(&self) -> ChangeIterator { pub fn changes_iter(&self) -> ChangeIterator<'_> {
ChangeIterator::new(self) ChangeIterator::new(self)
} }
} }
@@ -743,7 +753,7 @@ impl Transaction {
}) })
} }
pub fn changes_iter(&self) -> ChangeIterator { pub fn changes_iter(&self) -> ChangeIterator<'_> {
self.changes.changes_iter() self.changes.changes_iter()
} }
} }

View File

@@ -26,7 +26,7 @@ slotmap.workspace = true
futures-executor.workspace = true futures-executor.workspace = true
futures-util.workspace = true futures-util.workspace = true
tokio-stream.workspace = true tokio-stream.workspace = true
sonic-rs.workspace = true
[dev-dependencies] [dev-dependencies]
fern = "0.7" fern = "0.7"

View File

@@ -13,7 +13,7 @@ use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
#[error("failed to parse: {0}")] #[error("failed to parse: {0}")]
Parse(#[from] serde_json::Error), Parse(Box<dyn std::error::Error + Send + Sync>),
#[error("IO Error: {0}")] #[error("IO Error: {0}")]
IO(#[from] std::io::Error), IO(#[from] std::io::Error),
#[error("request {0} timed out")] #[error("request {0} timed out")]
@@ -29,6 +29,18 @@ pub enum Error {
} }
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = core::result::Result<T, Error>;
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Self::Parse(Box::new(value))
}
}
impl From<sonic_rs::Error> for Error {
fn from(value: sonic_rs::Error) -> Self {
Self::Parse(Box::new(value))
}
}
#[derive(Debug)] #[derive(Debug)]
pub enum Request { pub enum Request {
RunInTerminal(<requests::RunInTerminal as types::Request>::Arguments), RunInTerminal(<requests::RunInTerminal as types::Request>::Arguments),

View File

@@ -125,12 +125,14 @@ impl Transport {
info!("[{}] <- DAP {}", id, msg); info!("[{}] <- DAP {}", id, msg);
// try parsing as output (server response) or call (server request) // NOTE: We avoid using `?` here, since it would return early on error
let output: serde_json::Result<Payload> = serde_json::from_str(msg); // and skip clearing `content`. By returning the result directly instead,
// we ensure `content.clear()` is always called.
let output = sonic_rs::from_slice(content).map_err(Into::into);
content.clear(); content.clear();
Ok(output?) output
} }
async fn recv_server_error( async fn recv_server_error(

View File

@@ -13,7 +13,7 @@ homepage.workspace = true
[dependencies] [dependencies]
foldhash.workspace = true foldhash.workspace = true
hashbrown = "0.15" hashbrown = "0.16"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] }
# the event registry is essentially read only but must be an rwlock so we can # the event registry is essentially read only but must be an rwlock so we can
# setup new events on initialization, hardware-lock-elision hugely benefits this case # setup new events on initialization, hardware-lock-elision hugely benefits this case

View File

@@ -19,7 +19,7 @@ helix-stdx = { path = "../helix-stdx" }
anyhow = "1" anyhow = "1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
toml = "0.8" toml.workspace = true
etcetera = "0.10" etcetera = "0.10"
once_cell = "1.21" once_cell = "1.21"
log = "0.4" log = "0.4"

View File

@@ -213,6 +213,27 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
Ok(grammars) Ok(grammars)
} }
pub fn get_grammar_names() -> Result<Option<HashSet<String>>> {
let config: Configuration = crate::config::user_lang_config()
.context("Could not parse languages.toml")?
.try_into()?;
let grammars = match config.grammar_selection {
Some(GrammarSelection::Only { only: selections }) => Some(selections),
Some(GrammarSelection::Except { except: rejections }) => Some(
config
.grammar
.into_iter()
.map(|grammar| grammar.grammar_id)
.filter(|id| !rejections.contains(id))
.collect(),
),
None => None,
};
Ok(grammars)
}
fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)> fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)>
where where
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone, F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,

View File

@@ -244,7 +244,12 @@ pub fn merge_toml_values(left: toml::Value, right: toml::Value, merge_depth: usi
/// Otherwise (workspace, false) is returned /// Otherwise (workspace, false) is returned
pub fn find_workspace() -> (PathBuf, bool) { pub fn find_workspace() -> (PathBuf, bool) {
let current_dir = current_working_dir(); let current_dir = current_working_dir();
for ancestor in current_dir.ancestors() { find_workspace_in(current_dir)
}
pub fn find_workspace_in(dir: impl AsRef<Path>) -> (PathBuf, bool) {
let dir = dir.as_ref();
for ancestor in dir.ancestors() {
if ancestor.join(".git").exists() if ancestor.join(".git").exists()
|| ancestor.join(".svn").exists() || ancestor.join(".svn").exists()
|| ancestor.join(".jj").exists() || ancestor.join(".jj").exists()
@@ -254,7 +259,7 @@ pub fn find_workspace() -> (PathBuf, bool) {
} }
} }
(current_dir, true) (dir.to_owned(), true)
} }
fn default_config_file() -> PathBuf { fn default_config_file() -> PathBuf {

View File

@@ -22,8 +22,8 @@ license = "MIT"
[dependencies] [dependencies]
bitflags.workspace = true bitflags.workspace = true
serde = { version = "1.0.219", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.140" serde_json = "1.0.145"
url = {version = "2.5.4", features = ["serde"]} url = {version = "2.5.4", features = ["serde"]}
[features] [features]

View File

@@ -129,6 +129,7 @@ pub struct CodeActionParams {
/// response for CodeActionRequest /// response for CodeActionRequest
pub type CodeActionResponse = Vec<CodeActionOrCommand>; pub type CodeActionResponse = Vec<CodeActionOrCommand>;
#[allow(clippy::large_enum_variant)] // TODO: In a separate PR attempt the `Box<CodeAction>` pattern.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum CodeActionOrCommand { pub enum CodeActionOrCommand {

View File

@@ -40,14 +40,6 @@ pub struct WorkDoneProgressCancelParams {
pub token: ProgressToken, pub token: ProgressToken,
} }
/// Options to signal work done progress support in server capabilities.
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub work_done_progress: Option<bool>,
}
/// An optional token that a server can use to report work done progress /// An optional token that a server can use to report work done progress
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)] #[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]

View File

@@ -25,9 +25,10 @@ globset = "0.4.16"
log = "0.4" log = "0.4"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
tokio = { version = "1.46", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] } tokio = { version = "1.47", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
tokio-stream.workspace = true tokio-stream.workspace = true
parking_lot.workspace = true parking_lot.workspace = true
arc-swap = "1" arc-swap = "1"
slotmap.workspace = true slotmap.workspace = true
thiserror.workspace = true thiserror.workspace = true
sonic-rs.workspace = true

View File

@@ -372,6 +372,7 @@ impl Client {
Some(OneOf::Left(true) | OneOf::Right(_)) Some(OneOf::Left(true) | OneOf::Right(_))
), ),
LanguageServerFeature::Diagnostics => true, // there's no extra server capability LanguageServerFeature::Diagnostics => true, // there's no extra server capability
LanguageServerFeature::PullDiagnostics => capabilities.diagnostic_provider.is_some(),
LanguageServerFeature::RenameSymbol => matches!( LanguageServerFeature::RenameSymbol => matches!(
capabilities.rename_provider, capabilities.rename_provider,
Some(OneOf::Left(true)) | Some(OneOf::Right(_)) Some(OneOf::Left(true)) | Some(OneOf::Right(_))
@@ -602,6 +603,9 @@ impl Client {
did_rename: Some(true), did_rename: Some(true),
..Default::default() ..Default::default()
}), }),
diagnostic: Some(lsp::DiagnosticWorkspaceClientCapabilities {
refresh_support: Some(true),
}),
..Default::default() ..Default::default()
}), }),
text_document: Some(lsp::TextDocumentClientCapabilities { text_document: Some(lsp::TextDocumentClientCapabilities {
@@ -679,6 +683,10 @@ impl Client {
}), }),
..Default::default() ..Default::default()
}), }),
diagnostic: Some(lsp::DiagnosticClientCapabilities {
dynamic_registration: Some(false),
related_document_support: Some(true),
}),
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities { publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
version_support: Some(true), version_support: Some(true),
tag_support: Some(lsp::TagSupport { tag_support: Some(lsp::TagSupport {
@@ -1229,6 +1237,32 @@ impl Client {
Some(self.call::<lsp::request::RangeFormatting>(params)) Some(self.call::<lsp::request::RangeFormatting>(params))
} }
pub fn text_document_diagnostic(
&self,
text_document: lsp::TextDocumentIdentifier,
previous_result_id: Option<String>,
) -> Option<impl Future<Output = Result<lsp::DocumentDiagnosticReportResult>>> {
let capabilities = self.capabilities();
// Return early if the server does not support pull diagnostic.
let identifier = match capabilities.diagnostic_provider.as_ref()? {
lsp::DiagnosticServerCapabilities::Options(cap) => cap.identifier.clone(),
lsp::DiagnosticServerCapabilities::RegistrationOptions(cap) => {
cap.diagnostic_options.identifier.clone()
}
};
let params = lsp::DocumentDiagnosticParams {
text_document,
identifier,
previous_result_id,
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
partial_result_params: lsp::PartialResultParams::default(),
};
Some(self.call::<lsp::request::DocumentDiagnosticRequest>(params))
}
pub fn text_document_document_highlight( pub fn text_document_document_highlight(
&self, &self,
text_document: lsp::TextDocumentIdentifier, text_document: lsp::TextDocumentIdentifier,

View File

@@ -37,7 +37,7 @@ pub enum Error {
#[error("protocol error: {0}")] #[error("protocol error: {0}")]
Rpc(#[from] jsonrpc::Error), Rpc(#[from] jsonrpc::Error),
#[error("failed to parse: {0}")] #[error("failed to parse: {0}")]
Parse(#[from] serde_json::Error), Parse(Box<dyn std::error::Error + Send + Sync>),
#[error("IO Error: {0}")] #[error("IO Error: {0}")]
IO(#[from] std::io::Error), IO(#[from] std::io::Error),
#[error("request {0} timed out")] #[error("request {0} timed out")]
@@ -52,6 +52,18 @@ pub enum Error {
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
} }
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Self::Parse(Box::new(value))
}
}
impl From<sonic_rs::Error> for Error {
fn from(value: sonic_rs::Error) -> Self {
Self::Parse(Box::new(value))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum OffsetEncoding { pub enum OffsetEncoding {
/// UTF-8 code units aka bytes /// UTF-8 code units aka bytes
@@ -463,6 +475,7 @@ pub enum MethodCall {
RegisterCapability(lsp::RegistrationParams), RegisterCapability(lsp::RegistrationParams),
UnregisterCapability(lsp::UnregistrationParams), UnregisterCapability(lsp::UnregistrationParams),
ShowDocument(lsp::ShowDocumentParams), ShowDocument(lsp::ShowDocumentParams),
WorkspaceDiagnosticRefresh,
} }
impl MethodCall { impl MethodCall {
@@ -494,6 +507,7 @@ impl MethodCall {
let params: lsp::ShowDocumentParams = params.parse()?; let params: lsp::ShowDocumentParams = params.parse()?;
Self::ShowDocument(params) Self::ShowDocument(params)
} }
lsp::request::WorkspaceDiagnosticRefresh::METHOD => Self::WorkspaceDiagnosticRefresh,
_ => { _ => {
return Err(Error::Unhandled); return Err(Error::Unhandled);
} }

View File

@@ -98,7 +98,7 @@ impl Transport {
buffer.clear(); buffer.clear();
if reader.read_line(buffer).await? == 0 { if reader.read_line(buffer).await? == 0 {
return Err(Error::StreamClosed); return Err(Error::StreamClosed);
}; }
// debug!("<- header {:?}", buffer); // debug!("<- header {:?}", buffer);
@@ -133,12 +133,14 @@ impl Transport {
info!("{language_server_name} <- {msg}"); info!("{language_server_name} <- {msg}");
// try parsing as output (server response) or call (server request) // NOTE: We avoid using `?` here, since it would return early on error
let output: serde_json::Result<ServerMessage> = serde_json::from_str(msg); // and skip clearing `content`. By returning the result directly instead,
// we ensure `content.clear()` is always called.
let output = sonic_rs::from_slice(content).map_err(Into::into);
content.clear(); content.clear();
Ok(output?) output
} }
async fn recv_server_error( async fn recv_server_error(

View File

@@ -19,14 +19,14 @@ which = "8.0"
regex-cursor = "0.1.5" regex-cursor = "0.1.5"
bitflags.workspace = true bitflags.workspace = true
once_cell = "1.21" once_cell = "1.21"
regex-automata = "0.4.9" regex-automata = "0.4.10"
unicode-segmentation.workspace = true unicode-segmentation.workspace = true
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.60", features = ["Win32_Foundation", "Win32_Security", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Threading"] } windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Security", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Threading"] }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
rustix = { version = "1.0", features = ["fs"] } rustix = { version = "1.1", features = ["fs"] }
[dev-dependencies] [dev-dependencies]
tempfile.workspace = true tempfile.workspace = true

View File

@@ -85,7 +85,7 @@ fn find_brace_end(src: &[u8]) -> Option<usize> {
None None
} }
fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>) -> Cow<OsStr> { fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>) -> Cow<'_, OsStr> {
use regex_automata::meta::Regex; use regex_automata::meta::Regex;
static REGEX: Lazy<Regex> = Lazy::new(|| { static REGEX: Lazy<Regex> = Lazy::new(|| {
@@ -157,7 +157,7 @@ fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>)
/// * `${<var>:-<default>}`, `${<var>-<default>}` /// * `${<var>:-<default>}`, `${<var>-<default>}`
/// * `${<var>:=<default>}`, `${<var>=default}` /// * `${<var>:=<default>}`, `${<var>=default}`
/// ///
pub fn expand<S: AsRef<OsStr> + ?Sized>(src: &S) -> Cow<OsStr> { pub fn expand<S: AsRef<OsStr> + ?Sized>(src: &S) -> Cow<'_, OsStr> {
expand_impl(src.as_ref(), |var| std::env::var_os(var)) expand_impl(src.as_ref(), |var| std::env::var_os(var))
} }

View File

@@ -71,6 +71,16 @@ mod imp {
perms.set_mode(new_perms); perms.set_mode(new_perms);
} }
#[cfg(target_os = "macos")]
{
use std::fs::{File, FileTimes};
use std::os::macos::fs::FileTimesExt;
let to_file = File::options().write(true).open(to)?;
let times = FileTimes::new().set_created(from_meta.created()?);
to_file.set_times(times)?;
}
std::fs::set_permissions(to, perms)?; std::fs::set_permissions(to, perms)?;
Ok(()) Ok(())
@@ -109,7 +119,13 @@ mod imp {
use std::ffi::c_void; use std::ffi::c_void;
use std::os::windows::{ffi::OsStrExt, fs::OpenOptionsExt, io::AsRawHandle}; use std::os::windows::{
ffi::OsStrExt,
fs::{FileTimesExt, OpenOptionsExt},
io::AsRawHandle,
};
use std::fs::{File, FileTimes};
struct SecurityDescriptor { struct SecurityDescriptor {
sd: PSECURITY_DESCRIPTOR, sd: PSECURITY_DESCRIPTOR,
@@ -413,6 +429,10 @@ mod imp {
let meta = std::fs::metadata(from)?; let meta = std::fs::metadata(from)?;
let perms = meta.permissions(); let perms = meta.permissions();
let to_file = File::options().write(true).open(to)?;
let times = FileTimes::new().set_created(meta.created()?);
to_file.set_times(times)?;
std::fs::set_permissions(to, perms)?; std::fs::set_permissions(to, perms)?;
Ok(()) Ok(())

View File

@@ -54,14 +54,14 @@ anyhow = "1"
once_cell = "1.21" once_cell = "1.21"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] }
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] } tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["termina", "crossterm"] }
crossterm = { version = "0.28", features = ["event-stream"] } termina = { workspace = true, features = ["event-stream"] }
signal-hook = "0.3" signal-hook = "0.3"
tokio-stream = "0.1" tokio-stream = "0.1"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
arc-swap = { version = "1.7.1" } arc-swap = { version = "1.7.1" }
termini = "1" termini = "1"
indexmap = "2.10" indexmap = "2.11"
# Logging # Logging
fern = "0.7" fern = "0.7"
@@ -82,7 +82,7 @@ open = "5.3.2"
url = "2.5.4" url = "2.5.4"
# config # config
toml = "0.8" toml.workspace = true
serde_json = "1.0" serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
@@ -91,12 +91,14 @@ serde = { version = "1.0", features = ["derive"] }
grep-regex = "0.1.13" grep-regex = "0.1.13"
grep-searcher = "0.1.14" grep-searcher = "0.1.14"
dashmap = "6.0"
[target.'cfg(windows)'.dependencies]
crossterm = { version = "0.28", features = ["event-stream"] }
[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 [target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
libc = "0.2.174" libc = "0.2.176"
[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { version = "0.28", features = ["event-stream", "use-dev-tty", "libc"] }
[build-dependencies] [build-dependencies]
helix-loader = { path = "../helix-loader" } helix-loader = { path = "../helix-loader" }

View File

@@ -30,32 +30,41 @@ use crate::{
}; };
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
#[cfg(not(feature = "integration"))] use std::{
use std::io::stdout; io::{stdin, IsTerminal},
use std::{io::stdin, path::Path, sync::Arc}; path::Path,
sync::Arc,
};
#[cfg(not(windows))] #[cfg_attr(windows, allow(unused_imports))]
use anyhow::Context; use anyhow::{Context, Error};
use anyhow::Error;
use crossterm::{event::Event as CrosstermEvent, tty::IsTty};
#[cfg(not(windows))] #[cfg(not(windows))]
use {signal_hook::consts::signal, signal_hook_tokio::Signals}; use {signal_hook::consts::signal, signal_hook_tokio::Signals};
#[cfg(windows)] #[cfg(windows)]
type Signals = futures_util::stream::Empty<()>; type Signals = futures_util::stream::Empty<()>;
#[cfg(not(feature = "integration"))] #[cfg(all(not(windows), not(feature = "integration")))]
use tui::backend::TerminaBackend;
#[cfg(all(windows, not(feature = "integration")))]
use tui::backend::CrosstermBackend; use tui::backend::CrosstermBackend;
#[cfg(feature = "integration")] #[cfg(feature = "integration")]
use tui::backend::TestBackend; use tui::backend::TestBackend;
#[cfg(not(feature = "integration"))] #[cfg(all(not(windows), not(feature = "integration")))]
type TerminalBackend = TerminaBackend;
#[cfg(all(windows, not(feature = "integration")))]
type TerminalBackend = CrosstermBackend<std::io::Stdout>; type TerminalBackend = CrosstermBackend<std::io::Stdout>;
#[cfg(feature = "integration")] #[cfg(feature = "integration")]
type TerminalBackend = TestBackend; type TerminalBackend = TestBackend;
#[cfg(not(windows))]
type TerminalEvent = termina::Event;
#[cfg(windows)]
type TerminalEvent = crossterm::event::Event;
type Terminal = tui::terminal::Terminal<TerminalBackend>; type Terminal = tui::terminal::Terminal<TerminalBackend>;
pub struct Application { pub struct Application {
@@ -68,6 +77,8 @@ pub struct Application {
signals: Signals, signals: Signals,
jobs: Jobs, jobs: Jobs,
lsp_progress: LspProgressMap, lsp_progress: LspProgressMap,
theme_mode: Option<theme::Mode>,
} }
#[cfg(feature = "integration")] #[cfg(feature = "integration")]
@@ -103,14 +114,18 @@ impl Application {
theme_parent_dirs.extend(helix_loader::runtime_dirs().iter().cloned()); theme_parent_dirs.extend(helix_loader::runtime_dirs().iter().cloned());
let theme_loader = theme::Loader::new(&theme_parent_dirs); let theme_loader = theme::Loader::new(&theme_parent_dirs);
#[cfg(not(feature = "integration"))] #[cfg(all(not(windows), not(feature = "integration")))]
let backend = CrosstermBackend::new(stdout(), &config.editor); let backend = TerminaBackend::new((&config.editor).into())
.context("failed to create terminal backend")?;
#[cfg(all(windows, not(feature = "integration")))]
let backend = CrosstermBackend::new(std::io::stdout(), (&config.editor).into());
#[cfg(feature = "integration")] #[cfg(feature = "integration")]
let backend = TestBackend::new(120, 150); let backend = TestBackend::new(120, 150);
let theme_mode = backend.get_theme_mode();
let terminal = Terminal::new(backend)?; let terminal = Terminal::new(backend)?;
let area = terminal.size().expect("couldn't get terminal size"); let area = terminal.size();
let mut compositor = Compositor::new(area); let mut compositor = Compositor::new(area);
let config = Arc::new(ArcSwap::from_pointee(config)); let config = Arc::new(ArcSwap::from_pointee(config));
let handlers = handlers::setup(config.clone()); let handlers = handlers::setup(config.clone());
@@ -123,7 +138,12 @@ impl Application {
})), })),
handlers, handlers,
); );
Self::load_configured_theme(&mut editor, &config.load()); Self::load_configured_theme(
&mut editor,
&config.load(),
terminal.backend().supports_true_color(),
theme_mode,
);
let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| { let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
&config.keys &config.keys
@@ -214,7 +234,7 @@ impl Application {
} else { } else {
editor.new_file(Action::VerticalSplit); editor.new_file(Action::VerticalSplit);
} }
} else if stdin().is_tty() || cfg!(feature = "integration") { } else if stdin().is_terminal() || cfg!(feature = "integration") {
editor.new_file(Action::VerticalSplit); editor.new_file(Action::VerticalSplit);
} else { } else {
editor editor
@@ -242,6 +262,7 @@ impl Application {
signals, signals,
jobs: Jobs::new(), jobs: Jobs::new(),
lsp_progress: LspProgressMap::new(), lsp_progress: LspProgressMap::new(),
theme_mode,
}; };
Ok(app) Ok(app)
@@ -282,7 +303,7 @@ impl Application {
pub async fn event_loop<S>(&mut self, input_stream: &mut S) pub async fn event_loop<S>(&mut self, input_stream: &mut S)
where where
S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin, S: Stream<Item = std::io::Result<TerminalEvent>> + Unpin,
{ {
self.render().await; self.render().await;
@@ -295,7 +316,7 @@ impl Application {
pub async fn event_loop_until_idle<S>(&mut self, input_stream: &mut S) -> bool pub async fn event_loop_until_idle<S>(&mut self, input_stream: &mut S) -> bool
where where
S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin, S: Stream<Item = std::io::Result<TerminalEvent>> + Unpin,
{ {
loop { loop {
if self.editor.should_close() { if self.editor.should_close() {
@@ -367,7 +388,7 @@ impl Application {
ConfigEvent::Update(editor_config) => { ConfigEvent::Update(editor_config) => {
let mut app_config = (*self.config.load().clone()).clone(); let mut app_config = (*self.config.load().clone()).clone();
app_config.editor = *editor_config; app_config.editor = *editor_config;
if let Err(err) = self.terminal.reconfigure(app_config.editor.clone().into()) { if let Err(err) = self.terminal.reconfigure((&app_config.editor).into()) {
self.editor.set_error(err.to_string()); self.editor.set_error(err.to_string());
}; };
self.config.store(Arc::new(app_config)); self.config.store(Arc::new(app_config));
@@ -396,7 +417,12 @@ impl Application {
// the sake of locals highlighting. // the sake of locals highlighting.
let lang_loader = helix_core::config::user_lang_loader()?; let lang_loader = helix_core::config::user_lang_loader()?;
self.editor.syn_loader.store(Arc::new(lang_loader)); self.editor.syn_loader.store(Arc::new(lang_loader));
Self::load_configured_theme(&mut self.editor, &default_config); Self::load_configured_theme(
&mut self.editor,
&default_config,
self.terminal.backend().supports_true_color(),
self.theme_mode,
);
// Re-parse any open documents with the new language config. // Re-parse any open documents with the new language config.
let lang_loader = self.editor.syn_loader.load(); let lang_loader = self.editor.syn_loader.load();
@@ -412,8 +438,7 @@ impl Application {
document.replace_diagnostics(diagnostics, &[], None); document.replace_diagnostics(diagnostics, &[], None);
} }
self.terminal self.terminal.reconfigure((&default_config.editor).into())?;
.reconfigure(default_config.editor.clone().into())?;
// Store new config // Store new config
self.config.store(Arc::new(default_config)); self.config.store(Arc::new(default_config));
Ok(()) Ok(())
@@ -430,12 +455,18 @@ impl Application {
} }
/// Load the theme set in configuration /// Load the theme set in configuration
fn load_configured_theme(editor: &mut Editor, config: &Config) { fn load_configured_theme(
let true_color = config.editor.true_color || crate::true_color(); editor: &mut Editor,
config: &Config,
terminal_true_color: bool,
mode: Option<theme::Mode>,
) {
let true_color = terminal_true_color || config.editor.true_color || crate::true_color();
let theme = config let theme = config
.theme .theme
.as_ref() .as_ref()
.and_then(|theme| { .and_then(|theme_config| {
let theme = theme_config.choose(mode);
editor editor
.theme_loader .theme_loader
.load(theme) .load(theme)
@@ -503,7 +534,7 @@ impl Application {
// https://github.com/neovim/neovim/issues/12322 // https://github.com/neovim/neovim/issues/12322
// https://github.com/neovim/neovim/pull/13084 // https://github.com/neovim/neovim/pull/13084
for retries in 1..=10 { for retries in 1..=10 {
match self.claim_term().await { match self.terminal.claim() {
Ok(()) => break, Ok(()) => break,
Err(err) if retries == 10 => panic!("Failed to claim terminal: {}", err), Err(err) if retries == 10 => panic!("Failed to claim terminal: {}", err),
Err(_) => continue, Err(_) => continue,
@@ -511,7 +542,7 @@ impl Application {
} }
// redraw the terminal // redraw the terminal
let area = self.terminal.size().expect("couldn't get terminal size"); let area = self.terminal.size();
self.compositor.resize(area); self.compositor.resize(area);
self.terminal.clear().expect("couldn't clear terminal"); self.terminal.clear().expect("couldn't clear terminal");
@@ -573,24 +604,41 @@ impl Application {
doc.set_last_saved_revision(doc_save_event.revision, doc_save_event.save_time); doc.set_last_saved_revision(doc_save_event.revision, doc_save_event.save_time);
let lines = doc_save_event.text.len_lines(); let lines = doc_save_event.text.len_lines();
let mut sz = doc_save_event.text.len_bytes() as f32; let size = doc_save_event.text.len_bytes();
const SUFFIX: [&str; 4] = ["B", "KiB", "MiB", "GiB"]; enum Size {
let mut i = 0; Bytes(u16),
while i < SUFFIX.len() - 1 && sz >= 1024.0 { HumanReadable(f32, &'static str),
sz /= 1024.0;
i += 1;
} }
impl std::fmt::Display for Size {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bytes(bytes) => write!(f, "{bytes}B"),
Self::HumanReadable(size, suffix) => write!(f, "{size:.1}{suffix}"),
}
}
}
let size = if size < 1024 {
Size::Bytes(size as u16)
} else {
const SUFFIX: [&str; 4] = ["B", "KiB", "MiB", "GiB"];
let mut size = size as f32;
let mut i = 0;
while i < SUFFIX.len() - 1 && size >= 1024.0 {
size /= 1024.0;
i += 1;
}
Size::HumanReadable(size, SUFFIX[i])
};
self.editor self.editor
.set_doc_path(doc_save_event.doc_id, &doc_save_event.path); .set_doc_path(doc_save_event.doc_id, &doc_save_event.path);
// TODO: fix being overwritten by lsp // TODO: fix being overwritten by lsp
self.editor.set_status(format!( self.editor.set_status(format!(
"'{}' written, {}L {:.1}{}", "'{}' written, {lines}L {size}",
get_relative_path(&doc_save_event.path).to_string_lossy(), get_relative_path(&doc_save_event.path).to_string_lossy(),
lines,
sz,
SUFFIX[i],
)); ));
} }
@@ -635,7 +683,10 @@ impl Application {
false false
} }
pub async fn handle_terminal_events(&mut self, event: std::io::Result<CrosstermEvent>) { pub async fn handle_terminal_events(&mut self, event: std::io::Result<TerminalEvent>) {
#[cfg(not(windows))]
use termina::escape::csi;
let mut cx = crate::compositor::Context { let mut cx = crate::compositor::Context {
editor: &mut self.editor, editor: &mut self.editor,
jobs: &mut self.jobs, jobs: &mut self.jobs,
@@ -643,20 +694,51 @@ impl Application {
}; };
// Handle key events // Handle key events
let should_redraw = match event.unwrap() { let should_redraw = match event.unwrap() {
CrosstermEvent::Resize(width, height) => { #[cfg(not(windows))]
termina::Event::WindowResized(termina::WindowSize { rows, cols, .. }) => {
self.terminal
.resize(Rect::new(0, 0, cols, rows))
.expect("Unable to resize terminal");
let area = self.terminal.size();
self.compositor.resize(area);
self.compositor
.handle_event(&Event::Resize(cols, rows), &mut cx)
}
#[cfg(not(windows))]
// Ignore keyboard release events.
termina::Event::Key(termina::event::KeyEvent {
kind: termina::event::KeyEventKind::Release,
..
}) => false,
#[cfg(not(windows))]
termina::Event::Csi(csi::Csi::Mode(csi::Mode::ReportTheme(mode))) => {
Self::load_configured_theme(
&mut self.editor,
&self.config.load(),
self.terminal.backend().supports_true_color(),
Some(mode.into()),
);
true
}
#[cfg(windows)]
TerminalEvent::Resize(width, height) => {
self.terminal self.terminal
.resize(Rect::new(0, 0, width, height)) .resize(Rect::new(0, 0, width, height))
.expect("Unable to resize terminal"); .expect("Unable to resize terminal");
let area = self.terminal.size().expect("couldn't get terminal size"); let area = self.terminal.size();
self.compositor.resize(area); self.compositor.resize(area);
self.compositor self.compositor
.handle_event(&Event::Resize(width, height), &mut cx) .handle_event(&Event::Resize(width, height), &mut cx)
} }
#[cfg(windows)]
// Ignore keyboard release events. // Ignore keyboard release events.
CrosstermEvent::Key(crossterm::event::KeyEvent { crossterm::event::Event::Key(crossterm::event::KeyEvent {
kind: crossterm::event::KeyEventKind::Release, kind: crossterm::event::KeyEventKind::Release,
.. ..
}) => false, }) => false,
@@ -1021,6 +1103,26 @@ impl Application {
let result = self.handle_show_document(params, offset_encoding); let result = self.handle_show_document(params, offset_encoding);
Ok(json!(result)) Ok(json!(result))
} }
Ok(MethodCall::WorkspaceDiagnosticRefresh) => {
let language_server = language_server!().id();
let documents: Vec<_> = self
.editor
.documents
.values()
.filter(|x| x.supports_language_server(language_server))
.map(|x| x.id())
.collect();
for document in documents {
handlers::diagnostics::request_document_diagnostics(
&mut self.editor,
document,
);
}
Ok(serde_json::Value::Null)
}
}; };
let language_server = language_server!(); let language_server = language_server!();
@@ -1099,36 +1201,60 @@ impl Application {
lsp::ShowDocumentResult { success: true } lsp::ShowDocumentResult { success: true }
} }
async fn claim_term(&mut self) -> std::io::Result<()> {
let terminal_config = self.config.load().editor.clone().into();
self.terminal.claim(terminal_config)
}
fn restore_term(&mut self) -> std::io::Result<()> { fn restore_term(&mut self) -> std::io::Result<()> {
let terminal_config = self.config.load().editor.clone().into();
use helix_view::graphics::CursorKind; use helix_view::graphics::CursorKind;
self.terminal self.terminal
.backend_mut() .backend_mut()
.show_cursor(CursorKind::Block) .show_cursor(CursorKind::Block)
.ok(); .ok();
self.terminal.restore(terminal_config) self.terminal.restore()
}
#[cfg(all(not(feature = "integration"), not(windows)))]
pub fn event_stream(&self) -> impl Stream<Item = std::io::Result<TerminalEvent>> + Unpin {
use termina::{escape::csi, Terminal as _};
let reader = self.terminal.backend().terminal().event_reader();
termina::EventStream::new(reader, |event| {
// Accept either non-escape sequences or theme mode updates.
!event.is_escape()
|| matches!(
event,
termina::Event::Csi(csi::Csi::Mode(csi::Mode::ReportTheme(_)))
)
})
}
#[cfg(all(not(feature = "integration"), windows))]
pub fn event_stream(&self) -> impl Stream<Item = std::io::Result<TerminalEvent>> + Unpin {
crossterm::event::EventStream::new()
}
#[cfg(feature = "integration")]
pub fn event_stream(&self) -> impl Stream<Item = std::io::Result<TerminalEvent>> + Unpin {
use std::{
pin::Pin,
task::{Context, Poll},
};
/// A dummy stream that never polls as ready.
pub struct DummyEventStream;
impl Stream for DummyEventStream {
type Item = std::io::Result<TerminalEvent>;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending
}
}
DummyEventStream
} }
pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error> pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error>
where where
S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin, S: Stream<Item = std::io::Result<TerminalEvent>> + Unpin,
{ {
self.claim_term().await?; self.terminal.claim()?;
// Exit the alternate screen and disable raw mode before panicking
let hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
// We can't handle errors properly inside this closure. And it's
// probably not a good idea to `unwrap()` inside a panic handler.
// So we just ignore the `Result`.
let _ = TerminalBackend::force_restore();
hook(info);
}));
self.event_loop(input_stream).await; self.event_loop(input_stream).await;

View File

@@ -1,5 +1,6 @@
pub(crate) mod dap; pub(crate) mod dap;
pub(crate) mod lsp; pub(crate) mod lsp;
pub(crate) mod syntax;
pub(crate) mod typed; pub(crate) mod typed;
pub use dap::*; pub use dap::*;
@@ -11,6 +12,7 @@ use helix_stdx::{
}; };
use helix_vcs::{FileChange, Hunk}; use helix_vcs::{FileChange, Hunk};
pub use lsp::*; pub use lsp::*;
pub use syntax::*;
use tui::{ use tui::{
text::{Span, Spans}, text::{Span, Spans},
widgets::Cell, widgets::Cell,
@@ -20,7 +22,8 @@ pub use typed::*;
use helix_core::{ use helix_core::{
char_idx_at_visual_offset, char_idx_at_visual_offset,
chars::char_is_word, chars::char_is_word,
command_line, comment, command_line::{self, Args},
comment,
doc_formatter::TextFormat, doc_formatter::TextFormat,
encoding, find_workspace, encoding, find_workspace,
graphemes::{self, next_grapheme_boundary}, graphemes::{self, next_grapheme_boundary},
@@ -44,6 +47,7 @@ use helix_core::{
use helix_view::{ use helix_view::{
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME}, document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
editor::Action, editor::Action,
expansion,
info::Info, info::Info,
input::KeyEvent, input::KeyEvent,
keyboard::KeyCode, keyboard::KeyCode,
@@ -405,9 +409,13 @@ impl MappableCommand {
buffer_picker, "Open buffer picker", buffer_picker, "Open buffer picker",
jumplist_picker, "Open jumplist picker", jumplist_picker, "Open jumplist picker",
symbol_picker, "Open symbol picker", symbol_picker, "Open symbol picker",
syntax_symbol_picker, "Open symbol picker from syntax information",
lsp_or_syntax_symbol_picker, "Open symbol picker from LSP or syntax information",
changed_file_picker, "Open changed file picker", changed_file_picker, "Open changed file picker",
select_references_to_symbol_under_cursor, "Select symbol references", select_references_to_symbol_under_cursor, "Select symbol references",
workspace_symbol_picker, "Open workspace symbol picker", workspace_symbol_picker, "Open workspace symbol picker",
syntax_workspace_symbol_picker, "Open workspace symbol picker from syntax information",
lsp_or_syntax_workspace_symbol_picker, "Open workspace symbol picker from LSP or syntax information",
diagnostics_picker, "Open diagnostic picker", diagnostics_picker, "Open diagnostic picker",
workspace_diagnostics_picker, "Open workspace diagnostic picker", workspace_diagnostics_picker, "Open workspace diagnostic picker",
last_picker, "Open last picker", last_picker, "Open last picker",
@@ -466,6 +474,8 @@ impl MappableCommand {
smart_tab, "Insert tab if all cursors have all whitespace to their left; otherwise, run a separate command.", smart_tab, "Insert tab if all cursors have all whitespace to their left; otherwise, run a separate command.",
insert_tab, "Insert tab char", insert_tab, "Insert tab char",
insert_newline, "Insert newline char", insert_newline, "Insert newline char",
insert_char_interactive, "Insert an interactively-chosen char",
append_char_interactive, "Append an interactively-chosen char",
delete_char_backward, "Delete previous char", delete_char_backward, "Delete previous char",
delete_char_forward, "Delete next char", delete_char_forward, "Delete next char",
delete_word_backward, "Delete previous word", delete_word_backward, "Delete previous word",
@@ -565,6 +575,8 @@ impl MappableCommand {
goto_prev_comment, "Goto previous comment", goto_prev_comment, "Goto previous comment",
goto_next_test, "Goto next test", goto_next_test, "Goto next test",
goto_prev_test, "Goto previous test", goto_prev_test, "Goto previous test",
goto_next_xml_element, "Goto next (X)HTML element",
goto_prev_xml_element, "Goto previous (X)HTML element",
goto_next_entry, "Goto next pairing", goto_next_entry, "Goto next pairing",
goto_prev_entry, "Goto previous pairing", goto_prev_entry, "Goto previous pairing",
goto_next_paragraph, "Goto next paragraph", goto_next_paragraph, "Goto next paragraph",
@@ -3189,9 +3201,11 @@ fn buffer_picker(cx: &mut Context) {
.into() .into()
}), }),
]; ];
let initial_cursor = if items.len() <= 1 { 0 } else { 1 };
let picker = Picker::new(columns, 2, items, (), |cx, meta, action| { let picker = Picker::new(columns, 2, items, (), |cx, meta, action| {
cx.editor.switch(meta.id, action); cx.editor.switch(meta.id, action);
}) })
.with_initial_cursor(initial_cursor)
.with_preview(|editor, meta| { .with_preview(|editor, meta| {
let doc = &editor.documents.get(&meta.id)?; let doc = &editor.documents.get(&meta.id)?;
let lines = doc.selections().values().next().map(|selection| { let lines = doc.selections().values().next().map(|selection| {
@@ -3856,6 +3870,7 @@ fn goto_column_impl(cx: &mut Context, movement: Movement) {
let pos = graphemes::nth_next_grapheme_boundary(text, line_start, count - 1).min(line_end); let pos = graphemes::nth_next_grapheme_boundary(text, line_start, count - 1).min(line_end);
range.put_cursor(text, pos, movement == Movement::Extend) range.put_cursor(text, pos, movement == Movement::Extend)
}); });
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
@@ -3877,6 +3892,7 @@ fn goto_last_modification(cx: &mut Context) {
.selection(view.id) .selection(view.id)
.clone() .clone()
.transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select)); .transform(|range| range.put_cursor(text, pos, cx.editor.mode == Mode::Select));
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
} }
@@ -3928,6 +3944,7 @@ fn goto_first_diag(cx: &mut Context) {
Some(diag) => Selection::single(diag.range.start, diag.range.end), Some(diag) => Selection::single(diag.range.start, diag.range.end),
None => return, None => return,
}; };
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
view.diagnostics_handler view.diagnostics_handler
.immediately_show_diagnostic(doc, view.id); .immediately_show_diagnostic(doc, view.id);
@@ -3939,6 +3956,7 @@ fn goto_last_diag(cx: &mut Context) {
Some(diag) => Selection::single(diag.range.start, diag.range.end), Some(diag) => Selection::single(diag.range.start, diag.range.end),
None => return, None => return,
}; };
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
view.diagnostics_handler view.diagnostics_handler
.immediately_show_diagnostic(doc, view.id); .immediately_show_diagnostic(doc, view.id);
@@ -3962,6 +3980,7 @@ fn goto_next_diag(cx: &mut Context) {
Some(diag) => Selection::single(diag.range.start, diag.range.end), Some(diag) => Selection::single(diag.range.start, diag.range.end),
None => return, None => return,
}; };
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
view.diagnostics_handler view.diagnostics_handler
.immediately_show_diagnostic(doc, view.id); .immediately_show_diagnostic(doc, view.id);
@@ -3991,6 +4010,7 @@ fn goto_prev_diag(cx: &mut Context) {
Some(diag) => Selection::single(diag.range.end, diag.range.start), Some(diag) => Selection::single(diag.range.end, diag.range.start),
None => return, None => return,
}; };
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
view.diagnostics_handler view.diagnostics_handler
.immediately_show_diagnostic(doc, view.id); .immediately_show_diagnostic(doc, view.id);
@@ -4021,6 +4041,7 @@ fn goto_first_change_impl(cx: &mut Context, reverse: bool) {
}; };
if hunk != Hunk::NONE { if hunk != Hunk::NONE {
let range = hunk_range(hunk, doc.text().slice(..)); let range = hunk_range(hunk, doc.text().slice(..));
push_jump(view, doc);
doc.set_selection(view.id, Selection::single(range.anchor, range.head)); doc.set_selection(view.id, Selection::single(range.anchor, range.head));
} }
} }
@@ -4076,6 +4097,7 @@ fn goto_next_change_impl(cx: &mut Context, direction: Direction) {
} }
}); });
push_jump(view, doc);
doc.set_selection(view.id, selection) doc.set_selection(view.id, selection)
}; };
cx.editor.apply_motion(motion); cx.editor.apply_motion(motion);
@@ -4096,7 +4118,7 @@ fn hunk_range(hunk: Hunk, text: RopeSlice) -> Range {
} }
pub mod insert { pub mod insert {
use crate::events::PostInsertChar; use crate::{events::PostInsertChar, key};
use super::*; use super::*;
pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>; pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
@@ -4175,11 +4197,15 @@ pub mod insert {
} }
pub fn insert_tab(cx: &mut Context) { pub fn insert_tab(cx: &mut Context) {
insert_tab_impl(cx, 1)
}
fn insert_tab_impl(cx: &mut Context, count: usize) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
// TODO: round out to nearest indentation level (for example a line with 3 spaces should // TODO: round out to nearest indentation level (for example a line with 3 spaces should
// indent by one to reach 4 spaces). // indent by one to reach 4 spaces).
let indent = Tendril::from(doc.indent_style.as_str()); let indent = Tendril::from(doc.indent_style.as_str().repeat(count));
let transaction = Transaction::insert( let transaction = Transaction::insert(
doc.text(), doc.text(),
&doc.selection(view.id).clone().cursors(doc.text().slice(..)), &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
@@ -4188,6 +4214,49 @@ pub mod insert {
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
} }
pub fn append_char_interactive(cx: &mut Context) {
// Save the current mode, so we can restore it later.
let mode = cx.editor.mode;
append_mode(cx);
insert_selection_interactive(cx, mode);
}
pub fn insert_char_interactive(cx: &mut Context) {
let mode = cx.editor.mode;
insert_mode(cx);
insert_selection_interactive(cx, mode);
}
fn insert_selection_interactive(cx: &mut Context, old_mode: Mode) {
let count = cx.count();
// need to wait for next key
cx.on_next_key(move |cx, event| {
match event {
KeyEvent {
code: KeyCode::Char(ch),
..
} => {
for _ in 0..count {
insert::insert_char(cx, ch)
}
}
key!(Enter) => {
if count != 1 {
cx.editor
.set_error("inserting multiple newlines not yet supported");
return;
}
insert_newline(cx)
}
key!(Tab) => insert_tab_impl(cx, count),
_ => (),
};
// Restore the old mode.
cx.editor.mode = old_mode;
});
}
pub fn insert_newline(cx: &mut Context) { pub fn insert_newline(cx: &mut Context) {
let config = cx.editor.config(); let config = cx.editor.config();
let (view, doc) = current_ref!(cx.editor); let (view, doc) = current_ref!(cx.editor);
@@ -5311,6 +5380,7 @@ fn rotate_selections_last(cx: &mut Context) {
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
#[derive(Debug)]
enum ReorderStrategy { enum ReorderStrategy {
RotateForward, RotateForward,
RotateBackward, RotateBackward,
@@ -5323,34 +5393,50 @@ fn reorder_selection_contents(cx: &mut Context, strategy: ReorderStrategy) {
let text = doc.text().slice(..); let text = doc.text().slice(..);
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
let mut fragments: Vec<_> = selection
let mut ranges: Vec<_> = selection
.slices(text) .slices(text)
.map(|fragment| fragment.chunks().collect()) .map(|fragment| fragment.chunks().collect())
.collect(); .collect();
let group = count let rotate_by = count.map_or(1, |count| count.get().min(ranges.len()));
.map(|count| count.get())
.unwrap_or(fragments.len()) // default to rotating everything as one group
.min(fragments.len());
for chunk in fragments.chunks_mut(group) { let primary_index = match strategy {
// TODO: also modify main index ReorderStrategy::RotateForward => {
match strategy { ranges.rotate_right(rotate_by);
ReorderStrategy::RotateForward => chunk.rotate_right(1), // Like `usize::wrapping_add`, but provide a custom range from `0` to `ranges.len()`
ReorderStrategy::RotateBackward => chunk.rotate_left(1), (selection.primary_index() + ranges.len() + rotate_by) % ranges.len()
ReorderStrategy::Reverse => chunk.reverse(), }
}; ReorderStrategy::RotateBackward => {
} ranges.rotate_left(rotate_by);
// Like `usize::wrapping_sub`, but provide a custom range from `0` to `ranges.len()`
(selection.primary_index() + ranges.len() - rotate_by) % ranges.len()
}
ReorderStrategy::Reverse => {
if rotate_by % 2 == 0 {
// nothing changed, if we reverse something an even
// amount of times, the output will be the same
return;
}
ranges.reverse();
// -1 to turn 1-based len into 0-based index
(ranges.len() - 1) - selection.primary_index()
}
};
let transaction = Transaction::change( let transaction = Transaction::change(
doc.text(), doc.text(),
selection selection
.ranges() .ranges()
.iter() .iter()
.zip(fragments) .zip(ranges)
.map(|(range, fragment)| (range.from(), range.to(), Some(fragment))), .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
); );
doc.set_selection(
view.id,
Selection::new(selection.ranges().into(), primary_index),
);
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
} }
@@ -5834,6 +5920,7 @@ fn goto_ts_object_impl(cx: &mut Context, object: &'static str, direction: Direct
} }
}); });
push_jump(view, doc);
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} else { } else {
editor.set_status("Syntax-tree is not available in current buffer"); editor.set_status("Syntax-tree is not available in current buffer");
@@ -5882,6 +5969,14 @@ fn goto_prev_test(cx: &mut Context) {
goto_ts_object_impl(cx, "test", Direction::Backward) goto_ts_object_impl(cx, "test", Direction::Backward)
} }
fn goto_next_xml_element(cx: &mut Context) {
goto_ts_object_impl(cx, "xml-element", Direction::Forward)
}
fn goto_prev_xml_element(cx: &mut Context) {
goto_ts_object_impl(cx, "xml-element", Direction::Backward)
}
fn goto_next_entry(cx: &mut Context) { fn goto_next_entry(cx: &mut Context) {
goto_ts_object_impl(cx, "entry", Direction::Forward) goto_ts_object_impl(cx, "entry", Direction::Forward)
} }
@@ -5949,6 +6044,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
'c' => textobject_treesitter("comment", range), 'c' => textobject_treesitter("comment", range),
'T' => textobject_treesitter("test", range), 'T' => textobject_treesitter("test", range),
'e' => textobject_treesitter("entry", range), 'e' => textobject_treesitter("entry", range),
'x' => textobject_treesitter("xml-element", range),
'p' => textobject::textobject_paragraph(text, range, objtype, count), 'p' => textobject::textobject_paragraph(text, range, objtype, count),
'm' => textobject::textobject_pair_surround_closest( 'm' => textobject::textobject_pair_surround_closest(
doc.syntax(), doc.syntax(),
@@ -5993,6 +6089,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
("e", "Data structure entry (tree-sitter)"), ("e", "Data structure entry (tree-sitter)"),
("m", "Closest surrounding pair (tree-sitter)"), ("m", "Closest surrounding pair (tree-sitter)"),
("g", "Change"), ("g", "Change"),
("x", "(X)HTML element (tree-sitter)"),
(" ", "... or any character acting as a pair"), (" ", "... or any character acting as a pair"),
]; ];
@@ -6170,64 +6267,52 @@ enum ShellBehavior {
} }
fn shell_pipe(cx: &mut Context) { fn shell_pipe(cx: &mut Context) {
shell_prompt(cx, "pipe:".into(), ShellBehavior::Replace); shell_prompt_for_behavior(cx, "pipe:".into(), ShellBehavior::Replace);
} }
fn shell_pipe_to(cx: &mut Context) { fn shell_pipe_to(cx: &mut Context) {
shell_prompt(cx, "pipe-to:".into(), ShellBehavior::Ignore); shell_prompt_for_behavior(cx, "pipe-to:".into(), ShellBehavior::Ignore);
} }
fn shell_insert_output(cx: &mut Context) { fn shell_insert_output(cx: &mut Context) {
shell_prompt(cx, "insert-output:".into(), ShellBehavior::Insert); shell_prompt_for_behavior(cx, "insert-output:".into(), ShellBehavior::Insert);
} }
fn shell_append_output(cx: &mut Context) { fn shell_append_output(cx: &mut Context) {
shell_prompt(cx, "append-output:".into(), ShellBehavior::Append); shell_prompt_for_behavior(cx, "append-output:".into(), ShellBehavior::Append);
} }
fn shell_keep_pipe(cx: &mut Context) { fn shell_keep_pipe(cx: &mut Context) {
ui::prompt( shell_prompt(cx, "keep-pipe:".into(), |cx, args| {
cx, let shell = &cx.editor.config().shell;
"keep-pipe:".into(), let (view, doc) = current!(cx.editor);
Some('|'), let selection = doc.selection(view.id);
ui::completers::none,
move |cx, input: &str, event: PromptEvent| {
let shell = &cx.editor.config().shell;
if event != PromptEvent::Validate {
return;
}
if input.is_empty() {
return;
}
let (view, doc) = current!(cx.editor);
let selection = doc.selection(view.id);
let mut ranges = SmallVec::with_capacity(selection.len()); let mut ranges = SmallVec::with_capacity(selection.len());
let old_index = selection.primary_index(); let old_index = selection.primary_index();
let mut index: Option<usize> = None; let mut index: Option<usize> = None;
let text = doc.text().slice(..); let text = doc.text().slice(..);
for (i, range) in selection.ranges().iter().enumerate() { for (i, range) in selection.ranges().iter().enumerate() {
let fragment = range.slice(text); let fragment = range.slice(text);
if let Err(err) = shell_impl(shell, input, Some(fragment.into())) { if let Err(err) = shell_impl(shell, args.join(" ").as_str(), Some(fragment.into())) {
log::debug!("Shell command failed: {}", err); log::debug!("Shell command failed: {}", err);
} else { } else {
ranges.push(*range); ranges.push(*range);
if i >= old_index && index.is_none() { if i >= old_index && index.is_none() {
index = Some(ranges.len() - 1); index = Some(ranges.len() - 1);
}
} }
} }
}
if ranges.is_empty() { if ranges.is_empty() {
cx.editor.set_error("No selections remaining"); cx.editor.set_error("No selections remaining");
return; return;
} }
let index = index.unwrap_or_else(|| ranges.len() - 1); let index = index.unwrap_or_else(|| ranges.len() - 1);
doc.set_selection(view.id, Selection::new(ranges, index)); doc.set_selection(view.id, Selection::new(ranges, index));
}, });
);
} }
fn shell_impl(shell: &[String], cmd: &str, input: Option<Rope>) -> anyhow::Result<Tendril> { fn shell_impl(shell: &[String], cmd: &str, input: Option<Rope>) -> anyhow::Result<Tendril> {
@@ -6382,25 +6467,35 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
view.ensure_cursor_in_view(doc, config.scrolloff); view.ensure_cursor_in_view(doc, config.scrolloff);
} }
fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) { fn shell_prompt<F>(cx: &mut Context, prompt: Cow<'static, str>, mut callback_fn: F)
where
F: FnMut(&mut compositor::Context, Args) + 'static,
{
ui::prompt( ui::prompt(
cx, cx,
prompt, prompt,
Some('|'), Some('|'),
ui::completers::shell, |editor, input| complete_command_args(editor, SHELL_SIGNATURE, &SHELL_COMPLETER, input, 0),
move |cx, input: &str, event: PromptEvent| { move |cx, input, event| {
if event != PromptEvent::Validate { if event != PromptEvent::Validate || input.is_empty() {
return; return;
} }
if input.is_empty() { match Args::parse(input, SHELL_SIGNATURE, true, |token| {
return; expansion::expand(cx.editor, token).map_err(|err| err.into())
}) {
Ok(args) => callback_fn(cx, args),
Err(err) => cx.editor.set_error(err.to_string()),
} }
shell(cx, input, &behavior);
}, },
); );
} }
fn shell_prompt_for_behavior(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
shell_prompt(cx, prompt, move |cx, args| {
shell(cx, args.join(" ").as_str(), &behavior)
})
}
fn suspend(_cx: &mut Context) { fn suspend(_cx: &mut Context) {
#[cfg(not(windows))] #[cfg(not(windows))]
{ {
@@ -6823,3 +6918,34 @@ fn jump_to_word(cx: &mut Context, behaviour: Movement) {
} }
jump_to_label(cx, words, behaviour) jump_to_label(cx, words, behaviour)
} }
fn lsp_or_syntax_symbol_picker(cx: &mut Context) {
let doc = doc!(cx.editor);
if doc
.language_servers_with_feature(LanguageServerFeature::DocumentSymbols)
.next()
.is_some()
{
lsp::symbol_picker(cx);
} else if doc.syntax().is_some() {
syntax_symbol_picker(cx);
} else {
cx.editor
.set_error("No language server supporting document symbols or syntax info available");
}
}
fn lsp_or_syntax_workspace_symbol_picker(cx: &mut Context) {
let doc = doc!(cx.editor);
if doc
.language_servers_with_feature(LanguageServerFeature::WorkspaceSymbols)
.next()
.is_some()
{
lsp::workspace_symbol_picker(cx);
} else {
syntax_workspace_symbol_picker(cx);
}
}

View File

@@ -164,6 +164,13 @@ pub fn dap_start_impl(
arr.iter().map(|v| v.replace(&pattern, &param)).collect(), arr.iter().map(|v| v.replace(&pattern, &param)).collect(),
), ),
DebugArgumentValue::Boolean(_) => value, DebugArgumentValue::Boolean(_) => value,
DebugArgumentValue::Table(map) => DebugArgumentValue::Table(
map.into_iter()
.map(|(mk, mv)| {
(mk.replace(&pattern, &param), mv.replace(&pattern, &param))
})
.collect(),
),
}; };
} }
} }
@@ -182,6 +189,9 @@ pub fn dap_start_impl(
DebugArgumentValue::Boolean(bool) => { DebugArgumentValue::Boolean(bool) => {
args.insert(k, to_value(bool).unwrap()); args.insert(k, to_value(bool).unwrap());
} }
DebugArgumentValue::Table(map) => {
args.insert(k, to_value(map).unwrap());
}
} }
} }

View File

@@ -100,7 +100,7 @@ struct PickerDiagnostic {
diag: lsp::Diagnostic, diag: lsp::Diagnostic,
} }
fn location_to_file_location(location: &Location) -> Option<FileLocation> { fn location_to_file_location(location: &Location) -> Option<FileLocation<'_>> {
let path = location.uri.as_path()?; let path = location.uri.as_path()?;
let line = Some(( let line = Some((
location.range.start.line as usize, location.range.start.line as usize,
@@ -231,6 +231,13 @@ fn diag_picker(
} }
} }
flat_diag.sort_by(|a, b| {
a.diag
.severity
.unwrap_or(lsp::DiagnosticSeverity::HINT)
.cmp(&b.diag.severity.unwrap_or(lsp::DiagnosticSeverity::HINT))
});
let styles = DiagnosticStyles { let styles = DiagnosticStyles {
hint: cx.editor.theme.get("hint"), hint: cx.editor.theme.get("hint"),
info: cx.editor.theme.get("info"), info: cx.editor.theme.get("info"),
@@ -582,7 +589,7 @@ struct CodeActionOrCommandItem {
impl ui::menu::Item for CodeActionOrCommandItem { impl ui::menu::Item for CodeActionOrCommandItem {
type Data = (); type Data = ();
fn format(&self, _data: &Self::Data) -> Row { fn format(&self, _data: &Self::Data) -> Row<'_> {
match &self.lsp_item { match &self.lsp_item {
lsp::CodeActionOrCommand::CodeAction(action) => action.title.as_str().into(), lsp::CodeActionOrCommand::CodeAction(action) => action.title.as_str().into(),
lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(), lsp::CodeActionOrCommand::Command(command) => command.title.as_str().into(),
@@ -928,7 +935,13 @@ where
} }
let call = move |editor: &mut Editor, compositor: &mut Compositor| { let call = move |editor: &mut Editor, compositor: &mut Compositor| {
if locations.is_empty() { if locations.is_empty() {
editor.set_error("No definition found."); editor.set_error(match feature {
LanguageServerFeature::GotoDeclaration => "No declaration found.",
LanguageServerFeature::GotoDefinition => "No definition found.",
LanguageServerFeature::GotoTypeDefinition => "No type definition found.",
LanguageServerFeature::GotoImplementation => "No implementation found.",
_ => "No location found.",
});
} else { } else {
goto_impl(editor, compositor, locations); goto_impl(editor, compositor, locations);
} }
@@ -1133,7 +1146,7 @@ pub fn rename_symbol(cx: &mut Context) {
let Some(language_server) = doc let Some(language_server) = doc
.language_servers_with_feature(LanguageServerFeature::RenameSymbol) .language_servers_with_feature(LanguageServerFeature::RenameSymbol)
.find(|ls| language_server_id.map_or(true, |id| id == ls.id())) .find(|ls| language_server_id.is_none_or(|id| id == ls.id()))
else { else {
cx.editor cx.editor
.set_error("No configured language server supports symbol renaming"); .set_error("No configured language server supports symbol renaming");

View File

@@ -0,0 +1,446 @@
use std::{
collections::HashSet,
iter,
path::{Path, PathBuf},
sync::Arc,
};
use dashmap::DashMap;
use futures_util::FutureExt;
use grep_regex::RegexMatcherBuilder;
use grep_searcher::{sinks, BinaryDetection, SearcherBuilder};
use helix_core::{
syntax::{Loader, QueryIterEvent},
Rope, RopeSlice, Selection, Syntax, Uri,
};
use helix_stdx::{
path,
rope::{self, RopeSliceExt},
};
use helix_view::{
align_view,
document::{from_reader, SCRATCH_BUFFER_NAME},
Align, Document, DocumentId, Editor,
};
use ignore::{DirEntry, WalkBuilder, WalkState};
use crate::{
filter_picker_entry,
ui::{
overlay::overlaid,
picker::{Injector, PathOrId},
Picker, PickerColumn,
},
};
use super::Context;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum TagKind {
Class,
Constant,
Function,
Interface,
Macro,
Module,
Struct,
Type,
}
impl TagKind {
fn as_str(&self) -> &'static str {
match self {
Self::Class => "class",
Self::Constant => "constant",
Self::Function => "function",
Self::Interface => "interface",
Self::Macro => "macro",
Self::Module => "module",
Self::Struct => "struct",
Self::Type => "type",
}
}
fn from_name(name: &str) -> Option<Self> {
match name {
"class" => Some(TagKind::Class),
"constant" => Some(TagKind::Constant),
"function" => Some(TagKind::Function),
"interface" => Some(TagKind::Interface),
"macro" => Some(TagKind::Macro),
"module" => Some(TagKind::Module),
"struct" => Some(TagKind::Struct),
"type" => Some(TagKind::Type),
_ => None,
}
}
}
// NOTE: Uri is cheap to clone and DocumentId is Copy
#[derive(Debug, Clone)]
enum UriOrDocumentId {
Uri(Uri),
Id(DocumentId),
}
impl UriOrDocumentId {
fn path_or_id(&self) -> Option<PathOrId<'_>> {
match self {
Self::Id(id) => Some(PathOrId::Id(*id)),
Self::Uri(uri) => uri.as_path().map(PathOrId::Path),
}
}
}
#[derive(Debug)]
struct Tag {
kind: TagKind,
name: String,
start: usize,
end: usize,
start_line: usize,
end_line: usize,
doc: UriOrDocumentId,
}
fn tags_iter<'a>(
syntax: &'a Syntax,
loader: &'a Loader,
text: RopeSlice<'a>,
doc: UriOrDocumentId,
pattern: Option<&'a rope::Regex>,
) -> impl Iterator<Item = Tag> + 'a {
let mut tags_iter = syntax.tags(text, loader, ..);
iter::from_fn(move || loop {
let QueryIterEvent::Match(mat) = tags_iter.next()? else {
continue;
};
let query = &loader
.tag_query(tags_iter.current_language())
.expect("must have a tags query to emit matches")
.query;
let Some(kind) = query
.capture_name(mat.capture)
.strip_prefix("definition.")
.and_then(TagKind::from_name)
else {
continue;
};
let range = mat.node.byte_range();
if pattern.is_some_and(|pattern| {
!pattern.is_match(text.regex_input_at_bytes(range.start as usize..range.end as usize))
}) {
continue;
}
let start = text.byte_to_char(range.start as usize);
let end = text.byte_to_char(range.end as usize);
return Some(Tag {
kind,
name: text.slice(start..end).to_string(),
start,
end,
start_line: text.char_to_line(start),
end_line: text.char_to_line(end),
doc: doc.clone(),
});
})
}
pub fn syntax_symbol_picker(cx: &mut Context) {
let doc = doc!(cx.editor);
let Some(syntax) = doc.syntax() else {
cx.editor
.set_error("Syntax tree is not available on this buffer");
return;
};
let doc_id = doc.id();
let text = doc.text().slice(..);
let loader = cx.editor.syn_loader.load();
let tags = tags_iter(syntax, &loader, text, UriOrDocumentId::Id(doc.id()), None);
let columns = vec![
PickerColumn::new("kind", |tag: &Tag, _| tag.kind.as_str().into()),
PickerColumn::new("name", |tag: &Tag, _| tag.name.as_str().into()),
];
let picker = Picker::new(
columns,
1, // name
tags,
(),
move |cx, tag, action| {
cx.editor.switch(doc_id, action);
let view = view_mut!(cx.editor);
let doc = doc_mut!(cx.editor, &doc_id);
doc.set_selection(view.id, Selection::single(tag.start, tag.end));
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center)
}
},
)
.with_preview(|_editor, tag| {
Some((tag.doc.path_or_id()?, Some((tag.start_line, tag.end_line))))
})
.truncate_start(false);
cx.push_layer(Box::new(overlaid(picker)));
}
pub fn syntax_workspace_symbol_picker(cx: &mut Context) {
#[derive(Debug)]
struct SearchState {
searcher_builder: SearcherBuilder,
walk_builder: WalkBuilder,
regex_matcher_builder: RegexMatcherBuilder,
rope_regex_builder: rope::RegexBuilder,
search_root: PathBuf,
/// A cache of files that have been parsed in prior searches.
syntax_cache: DashMap<PathBuf, Option<(Rope, Syntax)>>,
}
let mut searcher_builder = SearcherBuilder::new();
searcher_builder.binary_detection(BinaryDetection::quit(b'\x00'));
// Search from the workspace that the currently focused document is within. This behaves like global
// search most of the time but helps when you have two projects open in splits.
let search_root = if let Some(path) = doc!(cx.editor).path() {
helix_loader::find_workspace_in(path).0
} else {
helix_loader::find_workspace().0
};
let absolute_root = search_root
.canonicalize()
.unwrap_or_else(|_| search_root.clone());
let config = cx.editor.config();
let dedup_symlinks = config.file_picker.deduplicate_links;
let mut walk_builder = WalkBuilder::new(&search_root);
walk_builder
.hidden(config.file_picker.hidden)
.parents(config.file_picker.parents)
.ignore(config.file_picker.ignore)
.follow_links(config.file_picker.follow_symlinks)
.git_ignore(config.file_picker.git_ignore)
.git_global(config.file_picker.git_global)
.git_exclude(config.file_picker.git_exclude)
.max_depth(config.file_picker.max_depth)
.filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks))
.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"))
.add_custom_ignore_filename(".helix/ignore");
let mut regex_matcher_builder = RegexMatcherBuilder::new();
regex_matcher_builder.case_smart(config.search.smart_case);
let mut rope_regex_builder = rope::RegexBuilder::new();
rope_regex_builder.syntax(rope::Config::new().case_insensitive(config.search.smart_case));
let state = SearchState {
searcher_builder,
walk_builder,
regex_matcher_builder,
rope_regex_builder,
search_root,
syntax_cache: DashMap::default(),
};
let reg = cx.register.unwrap_or('/');
cx.editor.registers.last_search_register = reg;
let columns = vec![
PickerColumn::new("kind", |tag: &Tag, _| tag.kind.as_str().into()),
PickerColumn::new("name", |tag: &Tag, _| tag.name.as_str().into()).without_filtering(),
PickerColumn::new("path", |tag: &Tag, state: &SearchState| {
match &tag.doc {
UriOrDocumentId::Uri(uri) => {
if let Some(path) = uri.as_path() {
let path = if let Ok(stripped) = path.strip_prefix(&state.search_root) {
stripped
} else {
path
};
path.to_string_lossy().into()
} else {
uri.to_string().into()
}
}
// This picker only uses `Id` for scratch buffers for better display.
UriOrDocumentId::Id(_) => SCRATCH_BUFFER_NAME.into(),
}
}),
];
let get_tags = |query: &str,
editor: &mut Editor,
state: Arc<SearchState>,
injector: &Injector<_, _>| {
if query.len() < 3 {
return async { Ok(()) }.boxed();
}
// Attempt to find the tag in any open documents.
let pattern = match state.rope_regex_builder.build(query) {
Ok(pattern) => pattern,
Err(err) => return async { Err(anyhow::anyhow!(err)) }.boxed(),
};
let loader = editor.syn_loader.load();
for doc in editor.documents() {
let Some(syntax) = doc.syntax() else { continue };
let text = doc.text().slice(..);
let uri_or_id = doc
.uri()
.map(UriOrDocumentId::Uri)
.unwrap_or_else(|| UriOrDocumentId::Id(doc.id()));
for tag in tags_iter(syntax, &loader, text.slice(..), uri_or_id, Some(&pattern)) {
if injector.push(tag).is_err() {
return async { Ok(()) }.boxed();
}
}
}
if !state.search_root.exists() {
return async { Err(anyhow::anyhow!("Current working directory does not exist")) }
.boxed();
}
let matcher = match state.regex_matcher_builder.build(query) {
Ok(matcher) => {
// Clear any "Failed to compile regex" errors out of the statusline.
editor.clear_status();
matcher
}
Err(err) => {
log::info!(
"Failed to compile search pattern in workspace symbol search: {}",
err
);
return async { Err(anyhow::anyhow!("Failed to compile regex")) }.boxed();
}
};
let pattern = Arc::new(pattern);
let injector = injector.clone();
let loader = editor.syn_loader.load();
let documents: HashSet<_> = editor
.documents()
.filter_map(Document::path)
.cloned()
.collect();
async move {
let searcher = state.searcher_builder.build();
state.walk_builder.build_parallel().run(|| {
let mut searcher = searcher.clone();
let matcher = matcher.clone();
let injector = injector.clone();
let loader = loader.clone();
let documents = &documents;
let pattern = pattern.clone();
let syntax_cache = &state.syntax_cache;
Box::new(move |entry: Result<DirEntry, ignore::Error>| -> WalkState {
let entry = match entry {
Ok(entry) => entry,
Err(_) => return WalkState::Continue,
};
match entry.file_type() {
Some(entry) if entry.is_file() => {}
// skip everything else
_ => return WalkState::Continue,
};
let path = entry.path();
// If this document is open, skip it because we've already processed it above.
if documents.contains(path) {
return WalkState::Continue;
};
let mut quit = false;
let sink = sinks::UTF8(|_line, _content| {
if !syntax_cache.contains_key(path) {
// Read the file into a Rope and attempt to recognize the language
// and parse it with tree-sitter. Save the Rope and Syntax for future
// queries.
syntax_cache.insert(path.to_path_buf(), syntax_for_path(path, &loader));
};
let entry = syntax_cache.get(path).unwrap();
let Some((text, syntax)) = entry.value() else {
// If the file couldn't be parsed, move on.
return Ok(false);
};
let uri = Uri::from(path::normalize(path));
for tag in tags_iter(
syntax,
&loader,
text.slice(..),
UriOrDocumentId::Uri(uri),
Some(&pattern),
) {
if injector.push(tag).is_err() {
quit = true;
break;
}
}
// Quit after seeing the first regex match. We only care to find files
// that contain the pattern and then we run the tags query within
// those. The location and contents of a match are irrelevant - it's
// only important _if_ a file matches.
Ok(false)
});
if let Err(err) = searcher.search_path(&matcher, path, sink) {
log::info!("Workspace syntax search error: {}, {}", path.display(), err);
}
if quit {
WalkState::Quit
} else {
WalkState::Continue
}
})
});
Ok(())
}
.boxed()
};
let picker = Picker::new(
columns,
1, // name
[],
state,
move |cx, tag, action| {
let doc_id = match &tag.doc {
UriOrDocumentId::Id(id) => *id,
UriOrDocumentId::Uri(uri) => match cx.editor.open(uri.as_path().expect(""), action) {
Ok(id) => id,
Err(e) => {
cx.editor
.set_error(format!("Failed to open file '{uri:?}': {e}"));
return;
}
}
};
let doc = doc_mut!(cx.editor, &doc_id);
let view = view_mut!(cx.editor);
let len_chars = doc.text().len_chars();
if tag.start >= len_chars || tag.end > len_chars {
cx.editor.set_error("The location you jumped to does not exist anymore because the file has changed.");
return;
}
doc.set_selection(view.id, Selection::single(tag.start, tag.end));
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center)
}
},
)
.with_dynamic_query(get_tags, Some(275))
.with_preview(move |_editor, tag| {
Some((
tag.doc.path_or_id()?,
Some((tag.start_line, tag.end_line)),
))
})
.truncate_start(false);
cx.push_layer(Box::new(overlaid(picker)));
}
/// Create a Rope and language config for a given existing path without creating a full Document.
fn syntax_for_path(path: &Path, loader: &Loader) -> Option<(Rope, Syntax)> {
let mut file = std::fs::File::open(path).ok()?;
let (rope, _encoding, _has_bom) = from_reader(&mut file, None).ok()?;
let text = rope.slice(..);
let language = loader
.language_for_filename(path)
.or_else(|| loader.language_for_shebang(text))?;
Syntax::new(text, language, loader)
.ok()
.map(|syntax| (rope, syntax))
}

View File

@@ -29,15 +29,6 @@ pub struct TypableCommand {
pub signature: Signature, pub signature: Signature,
} }
impl TypableCommand {
fn completer_for_argument_number(&self, n: usize) -> &Completer {
match self.completer.positional_args.get(n) {
Some(completer) => completer,
_ => &self.completer.var_args,
}
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct CommandCompleter { pub struct CommandCompleter {
// Arguments with specific completion methods based on their position. // Arguments with specific completion methods based on their position.
@@ -68,6 +59,13 @@ impl CommandCompleter {
var_args: completer, var_args: completer,
} }
} }
fn for_argument_number(&self, n: usize) -> &Completer {
match self.positional_args.get(n) {
Some(completer) => completer,
_ => &self.var_args,
}
}
} }
fn quit(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyhow::Result<()> { fn quit(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyhow::Result<()> {
@@ -104,6 +102,10 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
return Ok(()); return Ok(());
} }
open_impl(cx, args, Action::Replace)
}
fn open_impl(cx: &mut compositor::Context, args: Args, action: Action) -> anyhow::Result<()> {
for arg in args { for arg in args {
let (path, pos) = crate::args::parse_file(&arg); let (path, pos) = crate::args::parse_file(&arg);
let path = helix_stdx::path::expand_tilde(path); let path = helix_stdx::path::expand_tilde(path);
@@ -113,7 +115,8 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
let callback = async move { let callback = async move {
let call: job::Callback = job::Callback::EditorCompositor(Box::new( let call: job::Callback = job::Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| { move |editor: &mut Editor, compositor: &mut Compositor| {
let picker = ui::file_picker(editor, path.into_owned()); let picker =
ui::file_picker(editor, path.into_owned()).with_default_action(action);
compositor.push(Box::new(overlaid(picker))); compositor.push(Box::new(overlaid(picker)));
}, },
)); ));
@@ -122,7 +125,7 @@ fn open(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
cx.jobs.callback(callback); cx.jobs.callback(callback);
} else { } else {
// Otherwise, just open the file // Otherwise, just open the file
let _ = cx.editor.open(&path, Action::Replace)?; let _ = cx.editor.open(&path, action)?;
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
doc.set_selection(view.id, pos); doc.set_selection(view.id, pos);
@@ -1469,7 +1472,14 @@ fn update(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
let (_view, doc) = current!(cx.editor); let (_view, doc) = current!(cx.editor);
if doc.is_modified() { if doc.is_modified() {
write(cx, args, event) write_impl(
cx,
None,
WriteOptions {
force: false,
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
},
)
} else { } else {
Ok(()) Ok(())
} }
@@ -1808,10 +1818,7 @@ fn vsplit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
if args.is_empty() { if args.is_empty() {
split(cx.editor, Action::VerticalSplit); split(cx.editor, Action::VerticalSplit);
} else { } else {
for arg in args { open_impl(cx, args, Action::VerticalSplit)?;
cx.editor
.open(&PathBuf::from(arg.as_ref()), Action::VerticalSplit)?;
}
} }
Ok(()) Ok(())
@@ -1825,10 +1832,7 @@ fn hsplit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
if args.is_empty() { if args.is_empty() {
split(cx.editor, Action::HorizontalSplit); split(cx.editor, Action::HorizontalSplit);
} else { } else {
for arg in args { open_impl(cx, args, Action::HorizontalSplit)?;
cx.editor
.open(&PathBuf::from(arg.as_ref()), Action::HorizontalSplit)?;
}
} }
Ok(()) Ok(())
@@ -2652,13 +2656,13 @@ const BUFFER_CLOSE_OTHERS_SIGNATURE: Signature = Signature {
// but Signature does not yet allow for var args. // but Signature does not yet allow for var args.
/// This command handles all of its input as-is with no quoting or flags. /// This command handles all of its input as-is with no quoting or flags.
const SHELL_SIGNATURE: Signature = Signature { pub const SHELL_SIGNATURE: Signature = Signature {
positionals: (1, Some(2)), positionals: (1, Some(2)),
raw_after: Some(1), raw_after: Some(1),
..Signature::DEFAULT ..Signature::DEFAULT
}; };
const SHELL_COMPLETER: CommandCompleter = CommandCompleter::positional(&[ pub const SHELL_COMPLETER: CommandCompleter = CommandCompleter::positional(&[
// Command name // Command name
completers::program, completers::program,
// Shell argument(s) // Shell argument(s)
@@ -3237,6 +3241,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
completer: CommandCompleter::none(), completer: CommandCompleter::none(),
signature: Signature { signature: Signature {
positionals: (0, Some(0)), positionals: (0, Some(0)),
flags: &[WRITE_NO_FORMAT_FLAG],
..Signature::DEFAULT ..Signature::DEFAULT
}, },
}, },
@@ -3735,7 +3740,7 @@ pub(super) fn command_mode(cx: &mut Context) {
cx.push_layer(Box::new(prompt)); cx.push_layer(Box::new(prompt));
} }
fn command_line_doc(input: &str) -> Option<Cow<str>> { fn command_line_doc(input: &str) -> Option<Cow<'_, str>> {
let (command, _, _) = command_line::split(input); let (command, _, _) = command_line::split(input);
let command = TYPABLE_COMMAND_MAP.get(command)?; let command = TYPABLE_COMMAND_MAP.get(command)?;
@@ -3824,14 +3829,15 @@ fn complete_command_line(editor: &Editor, input: &str) -> Vec<ui::prompt::Comple
.get(command) .get(command)
.map_or_else(Vec::new, |cmd| { .map_or_else(Vec::new, |cmd| {
let args_offset = command.len() + 1; let args_offset = command.len() + 1;
complete_command_args(editor, cmd, rest, args_offset) complete_command_args(editor, cmd.signature, &cmd.completer, rest, args_offset)
}) })
} }
} }
fn complete_command_args( pub fn complete_command_args(
editor: &Editor, editor: &Editor,
command: &TypableCommand, signature: Signature,
completer: &CommandCompleter,
input: &str, input: &str,
offset: usize, offset: usize,
) -> Vec<ui::prompt::Completion> { ) -> Vec<ui::prompt::Completion> {
@@ -3843,7 +3849,7 @@ fn complete_command_args(
let cursor = input.len(); let cursor = input.len();
let prefix = &input[..cursor]; let prefix = &input[..cursor];
let mut tokenizer = Tokenizer::new(prefix, false); let mut tokenizer = Tokenizer::new(prefix, false);
let mut args = Args::new(command.signature, false); let mut args = Args::new(signature, false);
let mut final_token = None; let mut final_token = None;
let mut is_last_token = true; let mut is_last_token = true;
@@ -3887,7 +3893,7 @@ fn complete_command_args(
.len() .len()
.checked_sub(1) .checked_sub(1)
.expect("completion state to be positional"); .expect("completion state to be positional");
let completer = command.completer_for_argument_number(n); let completer = completer.for_argument_number(n);
completer(editor, &token.content) completer(editor, &token.content)
.into_iter() .into_iter()
@@ -3896,7 +3902,7 @@ fn complete_command_args(
} }
CompletionState::Flag(_) => fuzzy_match( CompletionState::Flag(_) => fuzzy_match(
token.content.trim_start_matches('-'), token.content.trim_start_matches('-'),
command.signature.flags.iter().map(|flag| flag.name), signature.flags.iter().map(|flag| flag.name),
false, false,
) )
.into_iter() .into_iter()
@@ -3921,7 +3927,7 @@ fn complete_command_args(
.len() .len()
.checked_sub(1) .checked_sub(1)
.expect("completion state to be positional"); .expect("completion state to be positional");
command.completer_for_argument_number(n) completer.for_argument_number(n)
}); });
complete_expand(editor, &token, arg_completer, offset + token.content_start) complete_expand(editor, &token, arg_completer, offset + token.content_start)
} }

View File

@@ -136,6 +136,11 @@ impl Compositor {
Some(self.layers.remove(idx)) Some(self.layers.remove(idx))
} }
pub fn remove_type<T: 'static>(&mut self) {
let type_name = std::any::type_name::<T>();
self.layers
.retain(|component| component.type_name() != type_name);
}
pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool { pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool {
// If it is a key event, a macro is being recorded, and a macro isn't being replayed, // If it is a key event, a macro is being recorded, and a macro isn't being replayed,
// push the key event to the recording. // push the key event to the recording.

View File

@@ -1,7 +1,7 @@
use crate::keymap; use crate::keymap;
use crate::keymap::{merge_keys, KeyTrie}; use crate::keymap::{merge_keys, KeyTrie};
use helix_loader::merge_toml_values; use helix_loader::merge_toml_values;
use helix_view::document::Mode; use helix_view::{document::Mode, theme};
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Display; use std::fmt::Display;
@@ -11,7 +11,7 @@ use toml::de::Error as TomlError;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct Config { pub struct Config {
pub theme: Option<String>, pub theme: Option<theme::Config>,
pub keys: HashMap<Mode, KeyTrie>, pub keys: HashMap<Mode, KeyTrie>,
pub editor: helix_view::editor::Config, pub editor: helix_view::editor::Config,
} }
@@ -19,7 +19,7 @@ pub struct Config {
#[derive(Debug, Clone, PartialEq, Deserialize)] #[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct ConfigRaw { pub struct ConfigRaw {
pub theme: Option<String>, pub theme: Option<theme::Config>,
pub keys: Option<HashMap<Mode, KeyTrie>>, pub keys: Option<HashMap<Mode, KeyTrie>>,
pub editor: Option<toml::Value>, pub editor: Option<toml::Value>,
} }

View File

@@ -1,21 +1,24 @@
use std::sync::Arc; use std::sync::Arc;
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
use diagnostics::PullAllDocumentsDiagnosticHandler;
use helix_event::AsyncHook; use helix_event::AsyncHook;
use crate::config::Config; use crate::config::Config;
use crate::events; use crate::events;
use crate::handlers::auto_save::AutoSaveHandler; use crate::handlers::auto_save::AutoSaveHandler;
use crate::handlers::diagnostics::PullDiagnosticsHandler;
use crate::handlers::signature_help::SignatureHelpHandler; use crate::handlers::signature_help::SignatureHelpHandler;
pub use helix_view::handlers::Handlers; pub use helix_view::handlers::{word_index, Handlers};
use self::document_colors::DocumentColorsHandler; use self::document_colors::DocumentColorsHandler;
mod auto_save; mod auto_save;
pub mod completion; pub mod completion;
mod diagnostics; pub mod diagnostics;
mod document_colors; mod document_colors;
mod prompt;
mod signature_help; mod signature_help;
mod snippet; mod snippet;
@@ -26,12 +29,18 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
let signature_hints = SignatureHelpHandler::new().spawn(); let signature_hints = SignatureHelpHandler::new().spawn();
let auto_save = AutoSaveHandler::new().spawn(); let auto_save = AutoSaveHandler::new().spawn();
let document_colors = DocumentColorsHandler::default().spawn(); let document_colors = DocumentColorsHandler::default().spawn();
let word_index = word_index::Handler::spawn();
let pull_diagnostics = PullDiagnosticsHandler::default().spawn();
let pull_all_documents_diagnostics = PullAllDocumentsDiagnosticHandler::default().spawn();
let handlers = Handlers { let handlers = Handlers {
completions: helix_view::handlers::completion::CompletionHandler::new(event_tx), completions: helix_view::handlers::completion::CompletionHandler::new(event_tx),
signature_hints, signature_hints,
auto_save, auto_save,
document_colors, document_colors,
word_index,
pull_diagnostics,
pull_all_documents_diagnostics,
}; };
helix_view::handlers::register_hooks(&handlers); helix_view::handlers::register_hooks(&handlers);
@@ -41,5 +50,6 @@ pub fn setup(config: Arc<ArcSwap<Config>>) -> Handlers {
diagnostics::register_hooks(&handlers); diagnostics::register_hooks(&handlers);
snippet::register_hooks(&handlers); snippet::register_hooks(&handlers);
document_colors::register_hooks(&handlers); document_colors::register_hooks(&handlers);
prompt::register_hooks(&handlers);
handlers handlers
} }

View File

@@ -30,6 +30,7 @@ mod item;
mod path; mod path;
mod request; mod request;
mod resolve; mod resolve;
mod word;
async fn handle_response( async fn handle_response(
requests: &mut JoinSet<CompletionResponse>, requests: &mut JoinSet<CompletionResponse>,
@@ -82,7 +83,7 @@ async fn replace_completions(
fn show_completion( fn show_completion(
editor: &mut Editor, editor: &mut Editor,
compositor: &mut Compositor, compositor: &mut Compositor,
items: Vec<CompletionItem>, mut items: Vec<CompletionItem>,
context: HashMap<CompletionProvider, ResponseContext>, context: HashMap<CompletionProvider, ResponseContext>,
trigger: Trigger, trigger: Trigger,
) { ) {
@@ -101,6 +102,7 @@ fn show_completion(
if ui.completion.is_some() { if ui.completion.is_some() {
return; return;
} }
word::retain_valid_completions(trigger, doc, view.id, &mut items);
editor.handlers.completions.active_completions = context; editor.handlers.completions.active_completions = context;
let completion_area = ui.set_completion(editor, items, trigger.pos, size); let completion_area = ui.set_completion(editor, items, trigger.pos, size);

View File

@@ -67,6 +67,7 @@ impl LspCompletionItem {
} }
} }
#[allow(clippy::large_enum_variant)] // TODO: In a separate PR attempt the `Box<LspCompletionItem>` pattern.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum CompletionItem { pub enum CompletionItem {
Lsp(LspCompletionItem), Lsp(LspCompletionItem),

View File

@@ -28,6 +28,8 @@ use crate::job::{dispatch, dispatch_blocking};
use crate::ui; use crate::ui;
use crate::ui::editor::InsertEvent; use crate::ui::editor::InsertEvent;
use super::word;
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(super) enum TriggerKind { pub(super) enum TriggerKind {
Auto, Auto,
@@ -85,7 +87,7 @@ impl helix_event::AsyncHook for CompletionHandler {
if self if self
.trigger .trigger
.or(self.in_flight) .or(self.in_flight)
.map_or(true, |trigger| trigger.doc != doc || trigger.view != view) .is_none_or(|trigger| trigger.doc != doc || trigger.view != view)
{ {
self.trigger = Some(Trigger { self.trigger = Some(Trigger {
pos: trigger_pos, pos: trigger_pos,
@@ -242,10 +244,15 @@ fn request_completions(
doc.selection(view.id).clone(), doc.selection(view.id).clone(),
doc, doc,
handle.clone(), handle.clone(),
savepoint, savepoint.clone(),
) { ) {
requests.spawn_blocking(path_completion_request); requests.spawn_blocking(path_completion_request);
} }
if let Some(word_completion_request) =
word::completion(editor, trigger, handle.clone(), savepoint)
{
requests.spawn_blocking(word_completion_request);
}
let ui = compositor.find::<ui::EditorView>().unwrap(); let ui = compositor.find::<ui::EditorView>().unwrap();
ui.last_insert.1.push(InsertEvent::RequestCompletion); ui.last_insert.1.push(InsertEvent::RequestCompletion);

View File

@@ -0,0 +1,134 @@
use std::{borrow::Cow, sync::Arc};
use helix_core::{
self as core, chars::char_is_word, completion::CompletionProvider, movement, Transaction,
};
use helix_event::TaskHandle;
use helix_stdx::rope::RopeSliceExt as _;
use helix_view::{
document::SavePoint, handlers::completion::ResponseContext, Document, Editor, ViewId,
};
use super::{request::TriggerKind, CompletionItem, CompletionItems, CompletionResponse, Trigger};
const COMPLETION_KIND: &str = "word";
pub(super) fn completion(
editor: &Editor,
trigger: Trigger,
handle: TaskHandle,
savepoint: Arc<SavePoint>,
) -> Option<impl FnOnce() -> CompletionResponse> {
if !doc!(editor).word_completion_enabled() {
return None;
}
let config = editor.config().word_completion;
let doc_config = doc!(editor)
.language_config()
.and_then(|config| config.word_completion);
let trigger_length = doc_config
.and_then(|c| c.trigger_length)
.unwrap_or(config.trigger_length)
.get() as usize;
let (view, doc) = current_ref!(editor);
let rope = doc.text().clone();
let word_index = editor.handlers.word_index().clone();
let text = doc.text().slice(..);
let selection = doc.selection(view.id).clone();
let pos = selection.primary().cursor(text);
let cursor = movement::move_prev_word_start(text, core::Range::point(pos), 1);
if cursor.head == pos {
return None;
}
if trigger.kind != TriggerKind::Manual
&& text
.slice(cursor.head..)
.graphemes()
.take(trigger_length)
.take_while(|g| g.chars().all(char_is_word))
.count()
!= trigger_length
{
return None;
}
let typed_word_range = cursor.head..pos;
let typed_word = text.slice(typed_word_range.clone());
let edit_diff = if typed_word
.char(typed_word.len_chars().saturating_sub(1))
.is_whitespace()
{
0
} else {
typed_word.len_chars()
};
if handle.is_canceled() {
return None;
}
let future = move || {
let text = rope.slice(..);
let typed_word: Cow<_> = text.slice(typed_word_range).into();
let items = word_index
.matches(&typed_word)
.into_iter()
.filter(|word| word.as_str() != typed_word.as_ref())
.map(|word| {
let transaction = Transaction::change_by_selection(&rope, &selection, |range| {
let cursor = range.cursor(text);
(cursor - edit_diff, cursor, Some((&word).into()))
});
CompletionItem::Other(core::CompletionItem {
transaction,
label: word.into(),
kind: Cow::Borrowed(COMPLETION_KIND),
documentation: None,
provider: CompletionProvider::Word,
})
})
.collect();
CompletionResponse {
items: CompletionItems::Other(items),
provider: CompletionProvider::Word,
context: ResponseContext {
is_incomplete: false,
priority: 0,
savepoint,
},
}
};
Some(future)
}
pub(super) fn retain_valid_completions(
trigger: Trigger,
doc: &Document,
view_id: ViewId,
items: &mut Vec<CompletionItem>,
) {
if trigger.kind == TriggerKind::Manual {
return;
}
let text = doc.text().slice(..);
let cursor = doc.selection(view_id).primary().cursor(text);
if text
.get_char(cursor.saturating_sub(1))
.is_some_and(|ch| ch.is_whitespace())
{
items.retain(|item| {
!matches!(
item,
CompletionItem::Other(core::CompletionItem {
provider: CompletionProvider::Word,
..
})
)
});
}
}

View File

@@ -1,12 +1,28 @@
use helix_event::{register_hook, send_blocking}; use futures_util::stream::FuturesUnordered;
use std::collections::HashSet;
use std::mem;
use std::time::Duration;
use tokio::time::Instant;
use tokio_stream::StreamExt;
use helix_core::diagnostic::DiagnosticProvider;
use helix_core::syntax::config::LanguageServerFeature;
use helix_core::Uri;
use helix_event::{cancelable_future, register_hook, send_blocking};
use helix_lsp::{lsp, LanguageServerId};
use helix_view::document::Mode; use helix_view::document::Mode;
use helix_view::events::DiagnosticsDidChange; use helix_view::events::{
DiagnosticsDidChange, DocumentDidChange, DocumentDidOpen, LanguageServerInitialized,
};
use helix_view::handlers::diagnostics::DiagnosticEvent; use helix_view::handlers::diagnostics::DiagnosticEvent;
use helix_view::handlers::lsp::{PullAllDocumentsDiagnosticsEvent, PullDiagnosticsEvent};
use helix_view::handlers::Handlers; use helix_view::handlers::Handlers;
use helix_view::{DocumentId, Editor};
use crate::events::OnModeSwitch; use crate::events::OnModeSwitch;
use crate::job;
pub(super) fn register_hooks(_handlers: &Handlers) { pub(super) fn register_hooks(handlers: &Handlers) {
register_hook!(move |event: &mut DiagnosticsDidChange<'_>| { register_hook!(move |event: &mut DiagnosticsDidChange<'_>| {
if event.editor.mode != Mode::Insert { if event.editor.mode != Mode::Insert {
for (view, _) in event.editor.tree.views_mut() { for (view, _) in event.editor.tree.views_mut() {
@@ -21,4 +37,265 @@ pub(super) fn register_hooks(_handlers: &Handlers) {
} }
Ok(()) Ok(())
}); });
let tx = handlers.pull_diagnostics.clone();
let tx_all_documents = handlers.pull_all_documents_diagnostics.clone();
register_hook!(move |event: &mut DocumentDidChange<'_>| {
if event
.doc
.has_language_server_with_feature(LanguageServerFeature::PullDiagnostics)
&& !event.ghost_transaction
{
// Cancel the ongoing request, if present.
event.doc.pull_diagnostic_controller.cancel();
let document_id = event.doc.id();
send_blocking(&tx, PullDiagnosticsEvent { document_id });
let inter_file_dependencies_language_servers = event
.doc
.language_servers_with_feature(LanguageServerFeature::PullDiagnostics)
.filter(|language_server| {
language_server
.capabilities()
.diagnostic_provider
.as_ref()
.is_some_and(|diagnostic_provider| match diagnostic_provider {
lsp::DiagnosticServerCapabilities::Options(options) => {
options.inter_file_dependencies
}
lsp::DiagnosticServerCapabilities::RegistrationOptions(options) => {
options.diagnostic_options.inter_file_dependencies
}
})
})
.map(|language_server| language_server.id())
.collect();
send_blocking(
&tx_all_documents,
PullAllDocumentsDiagnosticsEvent {
language_servers: inter_file_dependencies_language_servers,
},
);
}
Ok(())
});
register_hook!(move |event: &mut DocumentDidOpen<'_>| {
request_document_diagnostics(event.editor, event.doc);
Ok(())
});
register_hook!(move |event: &mut LanguageServerInitialized<'_>| {
let doc_ids: Vec<_> = event.editor.documents.keys().copied().collect();
for doc_id in doc_ids {
request_document_diagnostics(event.editor, doc_id);
}
Ok(())
});
}
#[derive(Debug, Default)]
pub(super) struct PullDiagnosticsHandler {
document_ids: HashSet<DocumentId>,
}
impl helix_event::AsyncHook for PullDiagnosticsHandler {
type Event = PullDiagnosticsEvent;
fn handle_event(
&mut self,
event: Self::Event,
_timeout: Option<tokio::time::Instant>,
) -> Option<tokio::time::Instant> {
self.document_ids.insert(event.document_id);
Some(Instant::now() + Duration::from_millis(250))
}
fn finish_debounce(&mut self) {
let document_ids = mem::take(&mut self.document_ids);
job::dispatch_blocking(move |editor, _| {
for document_id in document_ids {
request_document_diagnostics(editor, document_id);
}
})
}
}
#[derive(Debug, Default)]
pub(super) struct PullAllDocumentsDiagnosticHandler {
language_servers: HashSet<LanguageServerId>,
}
impl helix_event::AsyncHook for PullAllDocumentsDiagnosticHandler {
type Event = PullAllDocumentsDiagnosticsEvent;
fn handle_event(
&mut self,
event: Self::Event,
_timeout: Option<tokio::time::Instant>,
) -> Option<tokio::time::Instant> {
self.language_servers.extend(&event.language_servers);
Some(Instant::now() + Duration::from_secs(1))
}
fn finish_debounce(&mut self) {
let language_servers = mem::take(&mut self.language_servers);
job::dispatch_blocking(move |editor, _| {
let documents: Vec<_> = editor.documents.keys().copied().collect();
for document in documents {
request_document_diagnostics_for_language_severs(
editor,
document,
language_servers.clone(),
);
}
})
}
}
fn request_document_diagnostics_for_language_severs(
editor: &mut Editor,
doc_id: DocumentId,
language_servers: HashSet<LanguageServerId>,
) {
let Some(doc) = editor.document_mut(doc_id) else {
return;
};
let cancel = doc.pull_diagnostic_controller.restart();
let mut futures: FuturesUnordered<_> = language_servers
.iter()
.filter_map(|x| doc.language_servers().find(|y| &y.id() == x))
.filter_map(|language_server| {
let future = language_server
.text_document_diagnostic(doc.identifier(), doc.previous_diagnostic_id.clone())?;
let identifier = language_server
.capabilities()
.diagnostic_provider
.as_ref()
.and_then(|diagnostic_provider| match diagnostic_provider {
lsp::DiagnosticServerCapabilities::Options(options) => {
options.identifier.clone()
}
lsp::DiagnosticServerCapabilities::RegistrationOptions(options) => {
options.diagnostic_options.identifier.clone()
}
});
let language_server_id = language_server.id();
let provider = DiagnosticProvider::Lsp {
server_id: language_server_id,
identifier,
};
let uri = doc.uri()?;
Some(async move {
let result = future.await;
(result, provider, uri)
})
})
.collect();
if futures.is_empty() {
return;
}
tokio::spawn(async move {
let mut retry_language_servers = HashSet::new();
loop {
match cancelable_future(futures.next(), &cancel).await {
Some(Some((Ok(result), provider, uri))) => {
job::dispatch(move |editor, _| {
handle_pull_diagnostics_response(editor, result, provider, uri, doc_id);
})
.await;
}
Some(Some((Err(err), DiagnosticProvider::Lsp { server_id, .. }, _))) => {
let parsed_cancellation_data = if let helix_lsp::Error::Rpc(error) = err {
error.data.and_then(|data| {
serde_json::from_value::<lsp::DiagnosticServerCancellationData>(data)
.ok()
})
} else {
log::error!("Pull diagnostic request failed: {err}");
continue;
};
if parsed_cancellation_data.is_some_and(|data| data.retrigger_request) {
retry_language_servers.insert(server_id);
}
}
Some(None) => break,
// The request was cancelled.
None => return,
}
}
if !retry_language_servers.is_empty() {
tokio::time::sleep(Duration::from_millis(500)).await;
job::dispatch(move |editor, _| {
request_document_diagnostics_for_language_severs(
editor,
doc_id,
retry_language_servers,
);
})
.await;
}
});
}
pub fn request_document_diagnostics(editor: &mut Editor, doc_id: DocumentId) {
let Some(doc) = editor.document(doc_id) else {
return;
};
let language_servers = doc
.language_servers_with_feature(LanguageServerFeature::PullDiagnostics)
.map(|language_servers| language_servers.id())
.collect();
request_document_diagnostics_for_language_severs(editor, doc_id, language_servers);
}
fn handle_pull_diagnostics_response(
editor: &mut Editor,
result: lsp::DocumentDiagnosticReportResult,
provider: DiagnosticProvider,
uri: Uri,
document_id: DocumentId,
) {
match result {
lsp::DocumentDiagnosticReportResult::Report(report) => {
let result_id = match report {
lsp::DocumentDiagnosticReport::Full(report) => {
editor.handle_lsp_diagnostics(
&provider,
uri,
None,
report.full_document_diagnostic_report.items,
);
report.full_document_diagnostic_report.result_id
}
lsp::DocumentDiagnosticReport::Unchanged(report) => {
Some(report.unchanged_document_diagnostic_report.result_id)
}
};
if let Some(doc) = editor.document_mut(document_id) {
doc.previous_diagnostic_id = result_id;
};
}
lsp::DocumentDiagnosticReportResult::Partial(_) => {}
};
} }

View File

@@ -0,0 +1,17 @@
use helix_event::register_hook;
use helix_view::events::DocumentFocusLost;
use helix_view::handlers::Handlers;
use crate::job::{self};
use crate::ui;
pub(super) fn register_hooks(_handlers: &Handlers) {
register_hook!(move |_event: &mut DocumentFocusLost<'_>| {
job::dispatch_blocking(move |_, compositor| {
if compositor.find::<ui::Prompt>().is_some() {
compositor.remove_type::<ui::Prompt>();
}
});
Ok(())
});
}

View File

@@ -1,22 +1,33 @@
use crate::config::{Config, ConfigLoadError}; use crate::config::{Config, ConfigLoadError};
use crossterm::{
style::{Color, StyledContent, Stylize},
tty::IsTty,
};
use helix_core::config::{default_lang_config, user_lang_config}; use helix_core::config::{default_lang_config, user_lang_config};
use helix_loader::grammar::load_runtime_file; use helix_loader::grammar::load_runtime_file;
use std::io::Write; use std::{
collections::HashSet,
io::{IsTerminal, Write},
};
use termina::{
style::{ColorSpec, StyleExt as _, Stylized},
Terminal as _,
};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum TsFeature { pub enum TsFeature {
Highlight, Highlight,
TextObject, TextObject,
AutoIndent, AutoIndent,
Tags,
RainbowBracket,
} }
impl TsFeature { impl TsFeature {
pub fn all() -> &'static [Self] { pub fn all() -> &'static [Self] {
&[Self::Highlight, Self::TextObject, Self::AutoIndent] &[
Self::Highlight,
Self::TextObject,
Self::AutoIndent,
Self::Tags,
Self::RainbowBracket,
]
} }
pub fn runtime_filename(&self) -> &'static str { pub fn runtime_filename(&self) -> &'static str {
@@ -24,6 +35,8 @@ impl TsFeature {
Self::Highlight => "highlights.scm", Self::Highlight => "highlights.scm",
Self::TextObject => "textobjects.scm", Self::TextObject => "textobjects.scm",
Self::AutoIndent => "indents.scm", Self::AutoIndent => "indents.scm",
Self::Tags => "tags.scm",
Self::RainbowBracket => "rainbows.scm",
} }
} }
@@ -32,6 +45,8 @@ impl TsFeature {
Self::Highlight => "Syntax Highlighting", Self::Highlight => "Syntax Highlighting",
Self::TextObject => "Treesitter Textobjects", Self::TextObject => "Treesitter Textobjects",
Self::AutoIndent => "Auto Indent", Self::AutoIndent => "Auto Indent",
Self::Tags => "Code Navigation Tags",
Self::RainbowBracket => "Rainbow Brackets",
} }
} }
@@ -40,6 +55,8 @@ impl TsFeature {
Self::Highlight => "Highlight", Self::Highlight => "Highlight",
Self::TextObject => "Textobject", Self::TextObject => "Textobject",
Self::AutoIndent => "Indent", Self::AutoIndent => "Indent",
Self::Tags => "Tags",
Self::RainbowBracket => "Rainbow",
} }
} }
} }
@@ -134,6 +151,15 @@ pub fn clipboard() -> std::io::Result<()> {
} }
pub fn languages_all() -> std::io::Result<()> { pub fn languages_all() -> std::io::Result<()> {
languages(None)
}
pub fn languages_selection() -> std::io::Result<()> {
let selection = helix_loader::grammar::get_grammar_names().unwrap_or_default();
languages(selection)
}
fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> {
let stdout = std::io::stdout(); let stdout = std::io::stdout();
let mut stdout = stdout.lock(); let mut stdout = stdout.lock();
@@ -160,21 +186,24 @@ pub fn languages_all() -> std::io::Result<()> {
headings.push(feat.short_title()) headings.push(feat.short_title())
} }
let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80); let terminal_cols = termina::PlatformTerminal::new()
.and_then(|terminal| terminal.get_dimensions())
.map(|size| size.cols)
.unwrap_or(80);
let column_width = terminal_cols as usize / headings.len(); let column_width = terminal_cols as usize / headings.len();
let is_terminal = std::io::stdout().is_tty(); let is_terminal = std::io::stdout().is_terminal();
let fit = |s: &str| -> StyledContent<String> { let fit = |s: &str| -> Stylized<'static> {
format!( format!(
"{:column_width$}", "{:column_width$}",
s.get(..column_width - 2) s.get(..column_width - 2)
.map(|s| format!("{}", s)) .map(|s| format!("{}", s))
.unwrap_or_else(|| s.to_string()) .unwrap_or_else(|| s.to_string())
) )
.stylize() .stylized()
}; };
let color = |s: StyledContent<String>, c: Color| if is_terminal { s.with(c) } else { s }; let color = |s: Stylized<'static>, c: ColorSpec| if is_terminal { s.foreground(c) } else { s };
let bold = |s: StyledContent<String>| if is_terminal { s.bold() } else { s }; let bold = |s: Stylized<'static>| if is_terminal { s.bold() } else { s };
for heading in headings { for heading in headings {
write!(stdout, "{}", bold(fit(heading)))?; write!(stdout, "{}", bold(fit(heading)))?;
@@ -187,15 +216,22 @@ pub fn languages_all() -> std::io::Result<()> {
let check_binary_with_name = |cmd: Option<(&str, &str)>| match cmd { let check_binary_with_name = |cmd: Option<(&str, &str)>| match cmd {
Some((name, cmd)) => match helix_stdx::env::which(cmd) { Some((name, cmd)) => match helix_stdx::env::which(cmd) {
Ok(_) => color(fit(&format!("{}", name)), Color::Green), Ok(_) => color(fit(&format!("{}", name)), ColorSpec::BRIGHT_GREEN),
Err(_) => color(fit(&format!("{}", name)), Color::Red), Err(_) => color(fit(&format!("{}", name)), ColorSpec::BRIGHT_RED),
}, },
None => color(fit("None"), Color::Yellow), None => color(fit("None"), ColorSpec::BRIGHT_YELLOW),
}; };
let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd))); let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd)));
for lang in &syn_loader_conf.language { for lang in &syn_loader_conf.language {
if selection
.as_ref()
.is_some_and(|s| !s.contains(&lang.language_id))
{
continue;
}
write!(stdout, "{}", fit(&lang.language_id))?; write!(stdout, "{}", fit(&lang.language_id))?;
let mut cmds = lang.language_servers.iter().filter_map(|ls| { let mut cmds = lang.language_servers.iter().filter_map(|ls| {
@@ -217,8 +253,8 @@ pub fn languages_all() -> std::io::Result<()> {
for ts_feat in TsFeature::all() { for ts_feat in TsFeature::all() {
match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() { match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() {
true => write!(stdout, "{}", color(fit(""), Color::Green))?, true => write!(stdout, "{}", color(fit(""), ColorSpec::BRIGHT_GREEN))?,
false => write!(stdout, "{}", color(fit(""), Color::Red))?, false => write!(stdout, "{}", color(fit(""), ColorSpec::BRIGHT_RED))?,
} }
} }
@@ -230,6 +266,14 @@ pub fn languages_all() -> std::io::Result<()> {
} }
} }
if selection.is_some() {
writeln!(
stdout,
"\nThis list is filtered according to the 'use-grammars' option in languages.toml file.\n\
To see the full list, use the '--health all' or '--health all-languages' option."
)?;
}
Ok(()) Ok(())
} }
@@ -391,9 +435,16 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<(
pub fn print_health(health_arg: Option<String>) -> std::io::Result<()> { pub fn print_health(health_arg: Option<String>) -> std::io::Result<()> {
match health_arg.as_deref() { match health_arg.as_deref() {
Some("languages") => languages_all()?, Some("languages") => languages_selection()?,
Some("all-languages") => languages_all()?,
Some("clipboard") => clipboard()?, Some("clipboard") => clipboard()?,
None | Some("all") => { None => {
general()?;
clipboard()?;
writeln!(std::io::stdout().lock())?;
languages_selection()?;
}
Some("all") => {
general()?; general()?;
clipboard()?; clipboard()?;
writeln!(std::io::stdout().lock())?; writeln!(std::io::stdout().lock())?;

View File

@@ -120,6 +120,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"e" => goto_prev_entry, "e" => goto_prev_entry,
"T" => goto_prev_test, "T" => goto_prev_test,
"p" => goto_prev_paragraph, "p" => goto_prev_paragraph,
"x" => goto_prev_xml_element,
"space" => add_newline_above, "space" => add_newline_above,
}, },
"]" => { "Right bracket" "]" => { "Right bracket"
@@ -134,6 +135,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"e" => goto_next_entry, "e" => goto_next_entry,
"T" => goto_next_test, "T" => goto_next_test,
"p" => goto_next_paragraph, "p" => goto_next_paragraph,
"x" => goto_next_xml_element,
"space" => add_newline_below, "space" => add_newline_below,
}, },
@@ -227,8 +229,8 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"E" => file_explorer_in_current_buffer_directory, "E" => file_explorer_in_current_buffer_directory,
"b" => buffer_picker, "b" => buffer_picker,
"j" => jumplist_picker, "j" => jumplist_picker,
"s" => symbol_picker, "s" => lsp_or_syntax_symbol_picker,
"S" => workspace_symbol_picker, "S" => lsp_or_syntax_workspace_symbol_picker,
"d" => diagnostics_picker, "d" => diagnostics_picker,
"D" => workspace_diagnostics_picker, "D" => workspace_diagnostics_picker,
"g" => changed_file_picker, "g" => changed_file_picker,

View File

@@ -1,5 +1,4 @@
use anyhow::{Context, Error, Result}; use anyhow::{Context, Error, Result};
use crossterm::event::EventStream;
use helix_loader::VERSION_AND_GIT_HASH; use helix_loader::VERSION_AND_GIT_HASH;
use helix_term::application::Application; use helix_term::application::Application;
use helix_term::args::Args; use helix_term::args::Args;
@@ -57,22 +56,24 @@ USAGE:
hx [FLAGS] [files]... hx [FLAGS] [files]...
ARGS: ARGS:
<files>... Sets the input file to use, position can also be specified via file[:row[:col]] <files>... Set the input file to use, position can also be specified via file[:row[:col]]
FLAGS: FLAGS:
-h, --help Prints help information -h, --help Print help information
--tutor Loads the tutorial --tutor Load the tutorial
--health [CATEGORY] Checks for potential errors in editor setup --health [CATEGORY] Check for potential errors in editor setup
CATEGORY can be a language or one of 'clipboard', 'languages' CATEGORY can be a language or one of 'clipboard', 'languages',
or 'all'. 'all' is the default if not specified. 'all-languages' or 'all'. 'languages' is filtered according to
-g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml user config, 'all-languages' and 'all' are not. If not specified,
-c, --config <file> Specifies a file to use for configuration the default is the same as 'all', but with languages filtering.
-v Increases logging verbosity each use for up to 3 times -g, --grammar {{fetch|build}} Fetch or builds tree-sitter grammars listed in languages.toml
--log <file> Specifies a file to use for logging -c, --config <file> Specify a file to use for configuration
-v Increase logging verbosity each use for up to 3 times
--log <file> Specify a file to use for logging
(default file: {}) (default file: {})
-V, --version Prints version information -V, --version Print version information
--vsplit Splits all given files vertically into different windows --vsplit Split all given files vertically into different windows
--hsplit Splits all given files horizontally into different windows --hsplit Split all given files horizontally into different windows
-w, --working-dir <path> Specify an initial working directory -w, --working-dir <path> Specify an initial working directory
+N Open the first given file at line number N +N Open the first given file at line number N
", ",
@@ -149,8 +150,9 @@ FLAGS:
// TODO: use the thread local executor to spawn the application task separately from the work pool // TODO: use the thread local executor to spawn the application task separately from the work pool
let mut app = Application::new(args, config, lang_loader).context("unable to start Helix")?; let mut app = Application::new(args, config, lang_loader).context("unable to start Helix")?;
let mut events = app.event_stream();
let exit_code = app.run(&mut EventStream::new()).await?; let exit_code = app.run(&mut events).await?;
Ok(exit_code) Ok(exit_code)
} }

View File

@@ -1,9 +1,9 @@
use crate::handlers::completion::LspCompletionItem;
use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent}; use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent};
use crate::{ use crate::{
compositor::{Component, Context, Event, EventResult}, compositor::{Component, Context, Event, EventResult},
handlers::completion::{ handlers::completion::{
trigger_auto_completion, CompletionItem, CompletionResponse, LspCompletionItem, trigger_auto_completion, CompletionItem, CompletionResponse, ResolveHandler,
ResolveHandler,
}, },
}; };
use helix_core::snippets::{ActiveSnippet, RenderedSnippet, Snippet}; use helix_core::snippets::{ActiveSnippet, RenderedSnippet, Snippet};
@@ -28,7 +28,7 @@ use std::cmp::Reverse;
impl menu::Item for CompletionItem { impl menu::Item for CompletionItem {
type Data = Style; type Data = Style;
fn format(&self, dir_style: &Self::Data) -> menu::Row { fn format(&self, dir_style: &Self::Data) -> menu::Row<'_> {
let deprecated = match self { let deprecated = match self {
CompletionItem::Lsp(LspCompletionItem { item, .. }) => { CompletionItem::Lsp(LspCompletionItem { item, .. }) => {
item.deprecated.unwrap_or_default() item.deprecated.unwrap_or_default()

View File

@@ -214,7 +214,7 @@ impl<'a> TextRenderer<'a> {
let tab_width = doc.tab_width(); let tab_width = doc.tab_width();
let tab = if ws_render.tab() == WhitespaceRenderValue::All { let tab = if ws_render.tab() == WhitespaceRenderValue::All {
std::iter::once(ws_chars.tab) std::iter::once(ws_chars.tab)
.chain(std::iter::repeat(ws_chars.tabpad).take(tab_width - 1)) .chain(std::iter::repeat_n(ws_chars.tabpad, tab_width - 1))
.collect() .collect()
} else { } else {
" ".repeat(tab_width) " ".repeat(tab_width)

View File

@@ -127,6 +127,18 @@ impl EditorView {
&text_annotations, &text_annotations,
)); ));
if doc
.language_config()
.and_then(|config| config.rainbow_brackets)
.unwrap_or(config.rainbow_brackets)
{
if let Some(overlay) =
Self::doc_rainbow_highlights(doc, view_offset.anchor, inner.height, theme, &loader)
{
overlays.push(overlay);
}
}
Self::doc_diagnostics_highlights_into(doc, theme, &mut overlays); Self::doc_diagnostics_highlights_into(doc, theme, &mut overlays);
if is_focused { if is_focused {
@@ -304,6 +316,27 @@ impl EditorView {
text_annotations.collect_overlay_highlights(range) text_annotations.collect_overlay_highlights(range)
} }
pub fn doc_rainbow_highlights(
doc: &Document,
anchor: usize,
height: u16,
theme: &Theme,
loader: &syntax::Loader,
) -> Option<OverlayHighlights> {
let syntax = doc.syntax()?;
let text = doc.text().slice(..);
let row = text.char_to_line(anchor.min(text.len_chars()));
let visible_range = Self::viewport_byte_range(text, row, height);
let start = syntax::child_for_byte_range(
&syntax.tree().root_node(),
visible_range.start as u32..visible_range.end as u32,
)
.map_or(visible_range.start as u32, |node| node.start_byte());
let range = start..visible_range.end as u32;
Some(syntax.rainbow_highlights(text, theme.rainbow_length(), loader, range))
}
/// Get highlight spans for document diagnostics /// Get highlight spans for document diagnostics
pub fn doc_diagnostics_highlights_into( pub fn doc_diagnostics_highlights_into(
doc: &Document, doc: &Document,
@@ -505,7 +538,7 @@ impl EditorView {
}; };
spans.push((selection_scope, range.anchor..selection_end)); spans.push((selection_scope, range.anchor..selection_end));
// add block cursors // add block cursors
// skip primary cursor if terminal is unfocused - crossterm cursor is used in that case // skip primary cursor if terminal is unfocused - terminal cursor is used in that case
if !selection_is_primary || (cursor_is_block && is_terminal_focused) { if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
spans.push((cursor_scope, cursor_start..range.head)); spans.push((cursor_scope, cursor_start..range.head));
} }
@@ -513,7 +546,7 @@ impl EditorView {
// Reverse case. // Reverse case.
let cursor_end = next_grapheme_boundary(text, range.head); let cursor_end = next_grapheme_boundary(text, range.head);
// add block cursors // add block cursors
// skip primary cursor if terminal is unfocused - crossterm cursor is used in that case // skip primary cursor if terminal is unfocused - terminal cursor is used in that case
if !selection_is_primary || (cursor_is_block && is_terminal_focused) { if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
spans.push((cursor_scope, range.head..cursor_end)); spans.push((cursor_scope, range.head..cursor_end));
} }
@@ -1126,6 +1159,8 @@ impl EditorView {
let editor = &mut cxt.editor; let editor = &mut cxt.editor;
if let Some((pos, view_id)) = pos_and_view(editor, row, column, true) { if let Some((pos, view_id)) = pos_and_view(editor, row, column, true) {
editor.focus(view_id);
let prev_view_id = view!(editor).id; let prev_view_id = view!(editor).id;
let doc = doc_mut!(editor, &view!(editor, view_id).doc); let doc = doc_mut!(editor, &view!(editor, view_id).doc);
@@ -1149,7 +1184,6 @@ impl EditorView {
self.clear_completion(editor); self.clear_completion(editor);
} }
editor.focus(view_id);
editor.ensure_cursor_in_view(view_id); editor.ensure_cursor_in_view(view_id);
return EventResult::Consumed(None); return EventResult::Consumed(None);
@@ -1597,7 +1631,7 @@ impl Component for EditorView {
if self.terminal_focused { if self.terminal_focused {
(pos, CursorKind::Hidden) (pos, CursorKind::Hidden)
} else { } else {
// use crossterm cursor when terminal loses focus // use terminal cursor when terminal loses focus
(pos, CursorKind::Underline) (pos, CursorKind::Underline)
} }
} }

View File

@@ -13,7 +13,7 @@ pub trait Item: Sync + Send + 'static {
/// Additional editor state that is used for label calculation. /// Additional editor state that is used for label calculation.
type Data: Sync + Send + 'static; type Data: Sync + Send + 'static;
fn format(&self, data: &Self::Data) -> Row; fn format(&self, data: &Self::Data) -> Row<'_>;
} }
pub type MenuCallback<T> = Box<dyn Fn(&mut Editor, Option<&T>, MenuEvent)>; pub type MenuCallback<T> = Box<dyn Fn(&mut Editor, Option<&T>, MenuEvent)>;

View File

@@ -185,6 +185,22 @@ pub fn raw_regex_prompt(
cx.push_layer(Box::new(prompt)); cx.push_layer(Box::new(prompt));
} }
/// We want to exclude files that the editor can't handle yet
fn get_excluded_types() -> ignore::types::Types {
use ignore::types::TypesBuilder;
let mut type_builder = TypesBuilder::new();
type_builder
.add(
"compressed",
"*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}",
)
.expect("Invalid type definition");
type_builder.negate("all");
type_builder
.build()
.expect("failed to build excluded_types")
}
#[derive(Debug)] #[derive(Debug)]
pub struct FilePickerData { pub struct FilePickerData {
root: PathBuf, root: PathBuf,
@@ -193,7 +209,7 @@ pub struct FilePickerData {
type FilePicker = Picker<PathBuf, FilePickerData>; type FilePicker = Picker<PathBuf, FilePickerData>;
pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker { pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
use ignore::{types::TypesBuilder, WalkBuilder}; use ignore::WalkBuilder;
use std::time::Instant; use std::time::Instant;
let config = editor.config(); let config = editor.config();
@@ -208,7 +224,8 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
let absolute_root = root.canonicalize().unwrap_or_else(|_| root.clone()); let absolute_root = root.canonicalize().unwrap_or_else(|_| root.clone());
let mut walk_builder = WalkBuilder::new(&root); let mut walk_builder = WalkBuilder::new(&root);
walk_builder
let mut files = walk_builder
.hidden(config.file_picker.hidden) .hidden(config.file_picker.hidden)
.parents(config.file_picker.parents) .parents(config.file_picker.parents)
.ignore(config.file_picker.ignore) .ignore(config.file_picker.ignore)
@@ -218,31 +235,18 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
.git_exclude(config.file_picker.git_exclude) .git_exclude(config.file_picker.git_exclude)
.sort_by_file_name(|name1, name2| name1.cmp(name2)) .sort_by_file_name(|name1, name2| name1.cmp(name2))
.max_depth(config.file_picker.max_depth) .max_depth(config.file_picker.max_depth)
.filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks)); .filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks))
.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"))
walk_builder.add_custom_ignore_filename(helix_loader::config_dir().join("ignore")); .add_custom_ignore_filename(".helix/ignore")
walk_builder.add_custom_ignore_filename(".helix/ignore"); .types(get_excluded_types())
// We want to exclude files that the editor can't handle yet
let mut type_builder = TypesBuilder::new();
type_builder
.add(
"compressed",
"*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}",
)
.expect("Invalid type definition");
type_builder.negate("all");
let excluded_types = type_builder
.build() .build()
.expect("failed to build excluded_types"); .filter_map(|entry| {
walk_builder.types(excluded_types); let entry = entry.ok()?;
let mut files = walk_builder.build().filter_map(|entry| { if !entry.file_type()?.is_file() {
let entry = entry.ok()?; return None;
if !entry.file_type()?.is_file() { }
return None; Some(entry.into_path())
} });
Some(entry.into_path())
});
log::debug!("file_picker init {:?}", Instant::now().duration_since(now)); log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
let columns = [PickerColumn::new( let columns = [PickerColumn::new(
@@ -304,7 +308,7 @@ type FileExplorer = Picker<(PathBuf, bool), (PathBuf, Style)>;
pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std::io::Error> { pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std::io::Error> {
let directory_style = editor.theme.get("ui.text.directory"); let directory_style = editor.theme.get("ui.text.directory");
let directory_content = directory_content(&root)?; let directory_content = directory_content(&root, editor)?;
let columns = [PickerColumn::new( let columns = [PickerColumn::new(
"path", "path",
@@ -350,24 +354,64 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
Ok(picker) Ok(picker)
} }
fn directory_content(path: &Path) -> Result<Vec<(PathBuf, bool)>, std::io::Error> { fn directory_content(root: &Path, editor: &Editor) -> Result<Vec<(PathBuf, bool)>, std::io::Error> {
let mut content: Vec<_> = std::fs::read_dir(path)? use ignore::WalkBuilder;
.flatten()
.map(|entry| { let config = editor.config();
(
entry.path(), let mut walk_builder = WalkBuilder::new(root);
entry.file_type().is_ok_and(|file_type| file_type.is_dir()),
) let mut content: Vec<(PathBuf, bool)> = walk_builder
.hidden(config.file_explorer.hidden)
.parents(config.file_explorer.parents)
.ignore(config.file_explorer.ignore)
.follow_links(config.file_explorer.follow_symlinks)
.git_ignore(config.file_explorer.git_ignore)
.git_global(config.file_explorer.git_global)
.git_exclude(config.file_explorer.git_exclude)
.max_depth(Some(1))
.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"))
.add_custom_ignore_filename(".helix/ignore")
.types(get_excluded_types())
.build()
.filter_map(|entry| {
entry
.map(|entry| {
let is_dir = entry
.file_type()
.is_some_and(|file_type| file_type.is_dir());
let mut path = entry.path().to_path_buf();
if is_dir && path != root && config.file_explorer.flatten_dirs {
while let Some(single_child_directory) = get_child_if_single_dir(&path) {
path = single_child_directory;
}
}
(path, is_dir)
})
.ok()
.filter(|entry| entry.0 != root)
}) })
.collect(); .collect();
content.sort_by(|(path1, is_dir1), (path2, is_dir2)| (!is_dir1, path1).cmp(&(!is_dir2, path2))); content.sort_by(|(path1, is_dir1), (path2, is_dir2)| (!is_dir1, path1).cmp(&(!is_dir2, path2)));
if path.parent().is_some() {
content.insert(0, (path.join(".."), true)); if root.parent().is_some() {
content.insert(0, (root.join(".."), true));
} }
Ok(content) Ok(content)
} }
fn get_child_if_single_dir(path: &Path) -> Option<PathBuf> {
let mut entries = path.read_dir().ok()?;
let entry = entries.next()?.ok()?;
if entries.next().is_none() && entry.file_type().is_ok_and(|file_type| file_type.is_dir()) {
Some(entry.path())
} else {
None
}
}
pub mod completers { pub mod completers {
use super::Utf8PathBuf; use super::Utf8PathBuf;
use crate::ui::prompt::Completion; use crate::ui::prompt::Completion;
@@ -740,3 +784,27 @@ pub mod completers {
completions completions
} }
} }
#[cfg(test)]
mod tests {
use std::fs::{create_dir, File};
use super::*;
#[test]
fn test_get_child_if_single_dir() {
let root = tempfile::tempdir().unwrap();
assert_eq!(get_child_if_single_dir(root.path()), None);
let dir = root.path().join("dir1");
create_dir(&dir).unwrap();
assert_eq!(get_child_if_single_dir(root.path()), Some(dir));
let file = root.path().join("file");
File::create(file).unwrap();
assert_eq!(get_child_if_single_dir(root.path()), None);
}
}

View File

@@ -258,6 +258,7 @@ pub struct Picker<T: 'static + Send + Sync, D: 'static> {
widths: Vec<Constraint>, widths: Vec<Constraint>,
callback_fn: PickerCallback<T>, callback_fn: PickerCallback<T>,
default_action: Action,
pub truncate_start: bool, pub truncate_start: bool,
/// Caches paths to documents /// Caches paths to documents
@@ -308,7 +309,10 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
F: Fn(&mut Context, &T, Action) + 'static, F: Fn(&mut Context, &T, Action) + 'static,
{ {
let columns: Arc<[_]> = columns.into_iter().collect(); let columns: Arc<[_]> = columns.into_iter().collect();
let matcher_columns = columns.iter().filter(|col| col.filter).count() as u32; let matcher_columns = columns
.iter()
.filter(|col: &&Column<T, D>| col.filter)
.count() as u32;
assert!(matcher_columns > 0); assert!(matcher_columns > 0);
let matcher = Nucleo::new( let matcher = Nucleo::new(
Config::DEFAULT, Config::DEFAULT,
@@ -382,6 +386,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
truncate_start: true, truncate_start: true,
show_preview: true, show_preview: true,
callback_fn: Box::new(callback_fn), callback_fn: Box::new(callback_fn),
default_action: Action::Replace,
completion_height: 0, completion_height: 0,
widths, widths,
preview_cache: HashMap::new(), preview_cache: HashMap::new(),
@@ -424,6 +429,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
self self
} }
pub fn with_initial_cursor(mut self, cursor: u32) -> Self {
self.cursor = cursor;
self
}
pub fn with_dynamic_query( pub fn with_dynamic_query(
mut self, mut self,
callback: DynQueryCallback<T, D>, callback: DynQueryCallback<T, D>,
@@ -440,6 +450,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
self self
} }
pub fn with_default_action(mut self, action: Action) -> Self {
self.default_action = action;
self
}
/// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`) /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
pub fn move_by(&mut self, amount: u32, direction: Direction) { pub fn move_by(&mut self, amount: u32, direction: Direction) {
let len = self.matcher.snapshot().matched_item_count(); let len = self.matcher.snapshot().matched_item_count();
@@ -595,11 +610,15 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
let preview = std::fs::metadata(&path) let preview = std::fs::metadata(&path)
.and_then(|metadata| { .and_then(|metadata| {
if metadata.is_dir() { if metadata.is_dir() {
let files = super::directory_content(&path)?; let files = super::directory_content(&path, editor)?;
let file_names: Vec<_> = files let file_names: Vec<_> = files
.iter() .iter()
.filter_map(|(path, is_dir)| { .filter_map(|(file_path, is_dir)| {
let name = path.file_name()?.to_string_lossy(); let name = file_path
.strip_prefix(&path)
.map(|p| Some(p.as_os_str()))
.unwrap_or_else(|_| file_path.file_name())?
.to_string_lossy();
if *is_dir { if *is_dir {
Some((format!("{}/", name), true)) Some((format!("{}/", name), true))
} else { } else {
@@ -881,7 +900,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
if let Some((preview, range)) = self.get_preview(cx.editor) { if let Some((preview, range)) = self.get_preview(cx.editor) {
let doc = match preview.document() { let doc = match preview.document() {
Some(doc) Some(doc)
if range.map_or(true, |(start, end)| { if range.is_none_or(|(start, end)| {
start <= end && end <= doc.text().len_lines() start <= end && end <= doc.text().len_lines()
}) => }) =>
{ {
@@ -1071,7 +1090,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
key!(Esc) | ctrl!('c') => return close_fn(self), key!(Esc) | ctrl!('c') => return close_fn(self),
alt!(Enter) => { alt!(Enter) => {
if let Some(option) = self.selection() { if let Some(option) = self.selection() {
(self.callback_fn)(ctx, option, Action::Replace); (self.callback_fn)(ctx, option, self.default_action);
} }
} }
key!(Enter) => { key!(Enter) => {
@@ -1095,7 +1114,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
self.handle_prompt_change(true); self.handle_prompt_change(true);
} else { } else {
if let Some(option) = self.selection() { if let Some(option) = self.selection() {
(self.callback_fn)(ctx, option, Action::Replace); (self.callback_fn)(ctx, option, self.default_action);
} }
if let Some(history_register) = self.prompt.history_register() { if let Some(history_register) = self.prompt.history_register() {
if let Err(err) = ctx if let Err(err) = ctx

View File

@@ -779,8 +779,7 @@ impl Component for Prompt {
col += self.line[self.cursor..] col += self.line[self.cursor..]
.graphemes(true) .graphemes(true)
.next() .next()
.unwrap() .map_or(0, |g| g.width());
.width();
} }
let line = area.height as usize - 1; let line = area.height as usize - 1;

View File

@@ -1,7 +1,5 @@
use std::borrow::Cow;
use helix_core::indent::IndentStyle; use helix_core::indent::IndentStyle;
use helix_core::{coords_at_pos, encoding, Position}; use helix_core::{coords_at_pos, encoding, unicode::width::UnicodeWidthStr, Position};
use helix_lsp::lsp::DiagnosticSeverity; use helix_lsp::lsp::DiagnosticSeverity;
use helix_view::document::DEFAULT_LANGUAGE_NAME; use helix_view::document::DEFAULT_LANGUAGE_NAME;
use helix_view::{ use helix_view::{
@@ -158,6 +156,7 @@ where
helix_view::editor::StatusLineElement::Spacer => render_spacer, helix_view::editor::StatusLineElement::Spacer => render_spacer,
helix_view::editor::StatusLineElement::VersionControl => render_version_control, helix_view::editor::StatusLineElement::VersionControl => render_version_control,
helix_view::editor::StatusLineElement::Register => render_register, helix_view::editor::StatusLineElement::Register => render_register,
helix_view::editor::StatusLineElement::CurrentWorkingDirectory => render_cwd,
} }
} }
@@ -168,18 +167,16 @@ where
let visible = context.focused; let visible = context.focused;
let config = context.editor.config(); let config = context.editor.config();
let modenames = &config.statusline.mode; let modenames = &config.statusline.mode;
let mode_str = match context.editor.mode() {
Mode::Insert => &modenames.insert,
Mode::Select => &modenames.select,
Mode::Normal => &modenames.normal,
};
let content = if visible { let content = if visible {
Cow::Owned(format!( format!(" {mode_str} ")
" {} ",
match context.editor.mode() {
Mode::Insert => &modenames.insert,
Mode::Select => &modenames.select,
Mode::Normal => &modenames.normal,
}
))
} else { } else {
// If not focused, explicitly leave an empty space instead of returning None. // If not focused, explicitly leave an empty space instead of returning None.
Cow::Borrowed(" ") " ".repeat(mode_str.width() + 2)
}; };
let style = if visible && config.color_modes { let style = if visible && config.color_modes {
match context.editor.mode() { match context.editor.mode() {
@@ -573,3 +570,16 @@ where
}, },
); );
} }
fn render_cwd<'a, F>(context: &mut RenderContext<'a>, write: F)
where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
{
let cwd = helix_stdx::env::current_working_dir();
let cwd = cwd
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string();
write(context, cwd.into())
}

View File

@@ -4,6 +4,8 @@ use super::*;
mod insert; mod insert;
mod movement; mod movement;
mod reverse_selection_contents;
mod rotate_selection_contents;
mod write; mod write;
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]

View File

@@ -0,0 +1,49 @@
use super::*;
const A: &str = indoc! {"
#(a|)#
#(b|)#
#(c|)#
#[d|]#
#(e|)#"
};
const A_REV: &str = indoc! {"
#(e|)#
#[d|]#
#(c|)#
#(b|)#
#(a|)#"
};
const B: &str = indoc! {"
#(a|)#
#(b|)#
#[c|]#
#(d|)#
#(e|)#"
};
const B_REV: &str = indoc! {"
#(e|)#
#(d|)#
#[c|]#
#(b|)#
#(a|)#"
};
const CMD: &str = "<space>?reverse_selection_contents<ret>";
#[tokio::test(flavor = "multi_thread")]
async fn reverse_selection_contents() -> anyhow::Result<()> {
test((A, CMD, A_REV)).await?;
test((B, CMD, B_REV)).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn reverse_selection_contents_with_count() -> anyhow::Result<()> {
test((B, format!("2{CMD}"), B)).await?;
test((B, format!("3{CMD}"), B_REV)).await?;
test((B, format!("4{CMD}"), B)).await?;
Ok(())
}

View File

@@ -0,0 +1,71 @@
use super::*;
// Progression: A -> B -> C -> D
// as we press `A-)`
const A: &str = indoc! {"
#(a|)#
#(b|)#
#(c|)#
#[d|]#
#(e|)#"
};
const B: &str = indoc! {"
#(e|)#
#(a|)#
#(b|)#
#(c|)#
#[d|]#"
};
const C: &str = indoc! {"
#[d|]#
#(e|)#
#(a|)#
#(b|)#
#(c|)#"
};
const D: &str = indoc! {"
#(c|)#
#[d|]#
#(e|)#
#(a|)#
#(b|)#"
};
#[tokio::test(flavor = "multi_thread")]
async fn rotate_selection_contents_forward_repeated() -> anyhow::Result<()> {
test((A, "<A-)>", B)).await?;
test((B, "<A-)>", C)).await?;
test((C, "<A-)>", D)).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn rotate_selection_contents_forward_with_count() -> anyhow::Result<()> {
test((A, "2<A-)>", C)).await?;
test((A, "3<A-)>", D)).await?;
test((B, "2<A-)>", D)).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn rotate_selection_contents_backward_repeated() -> anyhow::Result<()> {
test((D, "<A-(>", C)).await?;
test((C, "<A-(>", B)).await?;
test((B, "<A-(>", A)).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn rotate_selection_contents_backward_with_count() -> anyhow::Result<()> {
test((D, "2<A-(>", B)).await?;
test((D, "3<A-(>", A)).await?;
test((C, "2<A-(>", A)).await?;
Ok(())
}

View File

@@ -6,13 +6,17 @@ use std::{
}; };
use anyhow::bail; use anyhow::bail;
use crossterm::event::{Event, KeyEvent};
use helix_core::{diagnostic::Severity, test, Selection, Transaction}; use helix_core::{diagnostic::Severity, test, Selection, Transaction};
use helix_term::{application::Application, args::Args, config::Config, keymap::merge_keys}; use helix_term::{application::Application, args::Args, config::Config, keymap::merge_keys};
use helix_view::{current_ref, doc, editor::LspConfig, input::parse_macro, Editor}; use helix_view::{current_ref, doc, editor::LspConfig, input::parse_macro, Editor};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_stream::wrappers::UnboundedReceiverStream;
#[cfg(windows)]
use crossterm::event::{Event, KeyEvent};
#[cfg(not(windows))]
use termina::event::{Event, KeyEvent};
/// Specify how to set up the input text with line feeds /// Specify how to set up the input text with line feeds
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum LineFeedHandling { pub enum LineFeedHandling {

View File

@@ -12,7 +12,7 @@ repository.workspace = true
homepage.workspace = true homepage.workspace = true
[features] [features]
default = ["crossterm"] default = ["termina", "crossterm"]
[dependencies] [dependencies]
helix-view = { path = "../helix-view", features = ["term"] } helix-view = { path = "../helix-view", features = ["term"] }
@@ -21,7 +21,10 @@ helix-core = { path = "../helix-core" }
bitflags.workspace = true bitflags.workspace = true
cassowary = "0.3" cassowary = "0.3"
unicode-segmentation.workspace = true unicode-segmentation.workspace = true
crossterm = { version = "0.28", optional = true } termina = { workspace = true, optional = true }
termini = "1.0" termini = "1.0"
once_cell = "1.21" once_cell = "1.21"
log = "~0.4" log = "~0.4"
[target.'cfg(windows)'.dependencies]
crossterm = { version = "0.28", optional = true }

View File

@@ -14,10 +14,7 @@ use crossterm::{
terminal::{self, Clear, ClearType}, terminal::{self, Clear, ClearType},
Command, Command,
}; };
use helix_view::{ use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
editor::Config as EditorConfig,
graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle},
};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use std::{ use std::{
fmt, fmt,
@@ -74,17 +71,17 @@ impl Capabilities {
/// on the $TERM environment variable. If detection fails, returns /// on the $TERM environment variable. If detection fails, returns
/// a default value where no capability is supported, or just undercurl /// a default value where no capability is supported, or just undercurl
/// if config.undercurl is set. /// if config.undercurl is set.
pub fn from_env_or_default(config: &EditorConfig) -> Self { pub fn from_env_or_default(config: &Config) -> Self {
match termini::TermInfo::from_env() { match termini::TermInfo::from_env() {
Err(_) => Capabilities { Err(_) => Capabilities {
has_extended_underlines: config.undercurl, has_extended_underlines: config.force_enable_extended_underlines,
..Capabilities::default() ..Capabilities::default()
}, },
Ok(t) => Capabilities { Ok(t) => Capabilities {
// Smulx, VTE: https://unix.stackexchange.com/a/696253/246284 // Smulx, VTE: https://unix.stackexchange.com/a/696253/246284
// Su (used by kitty): https://sw.kovidgoyal.net/kitty/underlines // Su (used by kitty): https://sw.kovidgoyal.net/kitty/underlines
// WezTerm supports underlines but a lot of distros don't properly install its terminfo // WezTerm supports underlines but a lot of distros don't properly install its terminfo
has_extended_underlines: config.undercurl has_extended_underlines: config.force_enable_extended_underlines
|| t.extended_cap("Smulx").is_some() || t.extended_cap("Smulx").is_some()
|| t.extended_cap("Su").is_some() || t.extended_cap("Su").is_some()
|| vte_version() >= Some(5102) || vte_version() >= Some(5102)
@@ -98,6 +95,7 @@ impl Capabilities {
/// Terminal backend supporting a wide variety of terminals /// Terminal backend supporting a wide variety of terminals
pub struct CrosstermBackend<W: Write> { pub struct CrosstermBackend<W: Write> {
buffer: W, buffer: W,
config: Config,
capabilities: Capabilities, capabilities: Capabilities,
supports_keyboard_enhancement_protocol: OnceCell<bool>, supports_keyboard_enhancement_protocol: OnceCell<bool>,
mouse_capture_enabled: bool, mouse_capture_enabled: bool,
@@ -108,14 +106,15 @@ impl<W> CrosstermBackend<W>
where where
W: Write, W: Write,
{ {
pub fn new(buffer: W, config: &EditorConfig) -> CrosstermBackend<W> { pub fn new(buffer: W, config: Config) -> CrosstermBackend<W> {
// helix is not usable without colors, but crossterm will disable // helix is not usable without colors, but crossterm will disable
// them by default if NO_COLOR is set in the environment. Override // them by default if NO_COLOR is set in the environment. Override
// this behaviour. // this behaviour.
crossterm::style::force_color_output(true); crossterm::style::force_color_output(true);
CrosstermBackend { CrosstermBackend {
buffer, buffer,
capabilities: Capabilities::from_env_or_default(config), capabilities: Capabilities::from_env_or_default(&config),
config,
supports_keyboard_enhancement_protocol: OnceCell::new(), supports_keyboard_enhancement_protocol: OnceCell::new(),
mouse_capture_enabled: false, mouse_capture_enabled: false,
supports_bracketed_paste: true, supports_bracketed_paste: true,
@@ -157,7 +156,7 @@ impl<W> Backend for CrosstermBackend<W>
where where
W: Write, W: Write,
{ {
fn claim(&mut self, config: Config) -> io::Result<()> { fn claim(&mut self) -> io::Result<()> {
terminal::enable_raw_mode()?; terminal::enable_raw_mode()?;
execute!( execute!(
self.buffer, self.buffer,
@@ -173,7 +172,7 @@ where
Ok(_) => (), Ok(_) => (),
}; };
execute!(self.buffer, terminal::Clear(terminal::ClearType::All))?; execute!(self.buffer, terminal::Clear(terminal::ClearType::All))?;
if config.enable_mouse_capture { if self.config.enable_mouse_capture {
execute!(self.buffer, EnableMouseCapture)?; execute!(self.buffer, EnableMouseCapture)?;
self.mouse_capture_enabled = true; self.mouse_capture_enabled = true;
} }
@@ -198,15 +197,16 @@ where
} }
self.mouse_capture_enabled = config.enable_mouse_capture; self.mouse_capture_enabled = config.enable_mouse_capture;
} }
self.config = config;
Ok(()) Ok(())
} }
fn restore(&mut self, config: Config) -> io::Result<()> { fn restore(&mut self) -> io::Result<()> {
// reset cursor shape // reset cursor shape
self.buffer self.buffer
.write_all(self.capabilities.reset_cursor_command.as_bytes())?; .write_all(self.capabilities.reset_cursor_command.as_bytes())?;
if config.enable_mouse_capture { if self.config.enable_mouse_capture {
execute!(self.buffer, DisableMouseCapture)?; execute!(self.buffer, DisableMouseCapture)?;
} }
if self.supports_keyboard_enhancement_protocol() { if self.supports_keyboard_enhancement_protocol() {
@@ -223,20 +223,6 @@ where
terminal::disable_raw_mode() terminal::disable_raw_mode()
} }
fn force_restore() -> io::Result<()> {
let mut stdout = io::stdout();
// reset cursor shape
write!(stdout, "\x1B[0 q")?;
// Ignore errors on disabling, this might trigger on windows if we call
// disable without calling enable previously
let _ = execute!(stdout, DisableMouseCapture);
let _ = execute!(stdout, PopKeyboardEnhancementFlags);
let _ = execute!(stdout, DisableBracketedPaste);
execute!(stdout, DisableFocusChange, terminal::LeaveAlternateScreen)?;
terminal::disable_raw_mode()
}
fn draw<'a, I>(&mut self, content: I) -> io::Result<()> fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
where where
I: Iterator<Item = (u16, u16, &'a Cell)>, I: Iterator<Item = (u16, u16, &'a Cell)>,
@@ -316,11 +302,6 @@ where
execute!(self.buffer, Show, shape) execute!(self.buffer, Show, shape)
} }
fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
crossterm::cursor::position()
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
}
fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> { fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
execute!(self.buffer, MoveTo(x, y)) execute!(self.buffer, MoveTo(x, y))
} }
@@ -339,6 +320,14 @@ where
fn flush(&mut self) -> io::Result<()> { fn flush(&mut self) -> io::Result<()> {
self.buffer.flush() self.buffer.flush()
} }
fn supports_true_color(&self) -> bool {
false
}
fn get_theme_mode(&self) -> Option<helix_view::theme::Mode> {
None
}
} }
#[derive(Debug)] #[derive(Debug)]

View File

@@ -6,9 +6,14 @@ use crate::{buffer::Cell, terminal::Config};
use helix_view::graphics::{CursorKind, Rect}; use helix_view::graphics::{CursorKind, Rect};
#[cfg(feature = "crossterm")] #[cfg(all(feature = "termina", not(windows)))]
mod termina;
#[cfg(all(feature = "termina", not(windows)))]
pub use self::termina::TerminaBackend;
#[cfg(all(feature = "termina", windows))]
mod crossterm; mod crossterm;
#[cfg(feature = "crossterm")] #[cfg(all(feature = "termina", windows))]
pub use self::crossterm::CrosstermBackend; pub use self::crossterm::CrosstermBackend;
mod test; mod test;
@@ -17,13 +22,11 @@ pub use self::test::TestBackend;
/// Representation of a terminal backend. /// Representation of a terminal backend.
pub trait Backend { pub trait Backend {
/// Claims the terminal for TUI use. /// Claims the terminal for TUI use.
fn claim(&mut self, config: Config) -> Result<(), io::Error>; fn claim(&mut self) -> Result<(), io::Error>;
/// Update terminal configuration. /// Update terminal configuration.
fn reconfigure(&mut self, config: Config) -> Result<(), io::Error>; fn reconfigure(&mut self, config: Config) -> Result<(), io::Error>;
/// Restores the terminal to a normal state, undoes `claim` /// Restores the terminal to a normal state, undoes `claim`
fn restore(&mut self, config: Config) -> Result<(), io::Error>; fn restore(&mut self) -> Result<(), io::Error>;
/// Forcibly resets the terminal, ignoring errors and configuration
fn force_restore() -> Result<(), io::Error>;
/// Draws styled text to the terminal /// Draws styled text to the terminal
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error> fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
where where
@@ -32,8 +35,6 @@ pub trait Backend {
fn hide_cursor(&mut self) -> Result<(), io::Error>; fn hide_cursor(&mut self) -> Result<(), io::Error>;
/// Sets the cursor to the given shape /// Sets the cursor to the given shape
fn show_cursor(&mut self, kind: CursorKind) -> Result<(), io::Error>; fn show_cursor(&mut self, kind: CursorKind) -> Result<(), io::Error>;
/// Gets the current position of the cursor
fn get_cursor(&mut self) -> Result<(u16, u16), io::Error>;
/// Sets the cursor to the given position /// Sets the cursor to the given position
fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error>; fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error>;
/// Clears the terminal /// Clears the terminal
@@ -42,4 +43,6 @@ pub trait Backend {
fn size(&self) -> Result<Rect, io::Error>; fn size(&self) -> Result<Rect, io::Error>;
/// Flushes the terminal buffer /// Flushes the terminal buffer
fn flush(&mut self) -> Result<(), io::Error>; fn flush(&mut self) -> Result<(), io::Error>;
fn supports_true_color(&self) -> bool;
fn get_theme_mode(&self) -> Option<helix_view::theme::Mode>;
} }

View File

@@ -0,0 +1,649 @@
use std::io::{self, Write as _};
use helix_view::{
editor::KittyKeyboardProtocolConfig,
graphics::{CursorKind, Rect, UnderlineStyle},
theme::{self, Color, Modifier},
};
use termina::{
escape::{
csi::{self, Csi, SgrAttributes, SgrModifiers},
dcs::{self, Dcs},
},
style::{CursorStyle, RgbColor},
Event, OneBased, PlatformTerminal, Terminal as _, WindowSize,
};
use crate::{buffer::Cell, terminal::Config};
use super::Backend;
// These macros are helpers to set/unset modes like bracketed paste or enter/exit the alternate
// screen.
macro_rules! decset {
($mode:ident) => {
Csi::Mode(csi::Mode::SetDecPrivateMode(csi::DecPrivateMode::Code(
csi::DecPrivateModeCode::$mode,
)))
};
}
macro_rules! decreset {
($mode:ident) => {
Csi::Mode(csi::Mode::ResetDecPrivateMode(csi::DecPrivateMode::Code(
csi::DecPrivateModeCode::$mode,
)))
};
}
fn term_program() -> Option<String> {
// Some terminals don't set $TERM_PROGRAM
match std::env::var("TERM_PROGRAM") {
Err(_) => std::env::var("TERM").ok(),
Ok(term_program) => Some(term_program),
}
}
fn vte_version() -> Option<usize> {
std::env::var("VTE_VERSION").ok()?.parse().ok()
}
#[derive(Debug, Default, Clone, Copy)]
struct Capabilities {
kitty_keyboard: KittyKeyboardSupport,
synchronized_output: bool,
true_color: bool,
extended_underlines: bool,
theme_mode: Option<theme::Mode>,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
enum KittyKeyboardSupport {
/// The terminal doesn't support the protocol.
#[default]
None,
/// The terminal supports the protocol but we haven't checked yet whether it has full or
/// partial support for the flags we require.
Some,
/// The terminal only supports some of the flags we require.
Partial,
/// The terminal supports all flags require.
Full,
}
#[derive(Debug)]
pub struct TerminaBackend {
terminal: PlatformTerminal,
config: Config,
capabilities: Capabilities,
reset_cursor_command: String,
is_synchronized_output_set: bool,
}
impl TerminaBackend {
pub fn new(config: Config) -> io::Result<Self> {
let mut terminal = PlatformTerminal::new()?;
let (capabilities, reset_cursor_command) =
Self::detect_capabilities(&mut terminal, &config)?;
// In the case of a panic, reset the terminal eagerly. If we didn't do this and instead
// relied on `Drop`, the backtrace would be lost because it is printed before we would
// clear and exit the alternate screen.
let hook_reset_cursor_command = reset_cursor_command.clone();
terminal.set_panic_hook(move |term| {
let _ = write!(
term,
"{}{}{}{}{}{}{}{}{}{}{}",
Csi::Keyboard(csi::Keyboard::PopFlags(1)),
decreset!(MouseTracking),
decreset!(ButtonEventMouse),
decreset!(AnyEventMouse),
decreset!(RXVTMouse),
decreset!(SGRMouse),
&hook_reset_cursor_command,
decreset!(BracketedPaste),
decreset!(FocusTracking),
Csi::Edit(csi::Edit::EraseInDisplay(csi::EraseInDisplay::EraseDisplay)),
decreset!(ClearAndEnableAlternateScreen),
);
});
Ok(Self {
terminal,
config,
capabilities,
reset_cursor_command,
is_synchronized_output_set: false,
})
}
pub fn terminal(&self) -> &PlatformTerminal {
&self.terminal
}
fn detect_capabilities(
terminal: &mut PlatformTerminal,
config: &Config,
) -> io::Result<(Capabilities, String)> {
use std::time::{Duration, Instant};
// Colibri "midnight"
const TEST_COLOR: RgbColor = RgbColor::new(59, 34, 76);
terminal.enter_raw_mode()?;
let mut capabilities = Capabilities::default();
let start = Instant::now();
capabilities.kitty_keyboard = match config.kitty_keyboard_protocol {
KittyKeyboardProtocolConfig::Disabled => KittyKeyboardSupport::None,
KittyKeyboardProtocolConfig::Enabled => KittyKeyboardSupport::Full,
KittyKeyboardProtocolConfig::Auto => {
write!(terminal, "{}", Csi::Keyboard(csi::Keyboard::QueryFlags))?;
KittyKeyboardSupport::None
}
};
// Many terminal extensions can be detected by querying the terminal for the state of the
// extension and then sending a request for the primary device attributes (which is
// consistently supported by all terminals). If we receive the status of the feature (for
// example the current Kitty keyboard flags) then we know that the feature is supported.
// If we only receive the device attributes then we know it is not.
write!(
terminal,
"{}{}{}{}{}{}{}",
// Synchronized output
Csi::Mode(csi::Mode::QueryDecPrivateMode(csi::DecPrivateMode::Code(
csi::DecPrivateModeCode::SynchronizedOutput
))),
// Mode 2031 theme updates. Query the current theme.
Csi::Mode(csi::Mode::QueryTheme),
// True color and while we're at it, extended underlines:
// <https://github.com/termstandard/colors?tab=readme-ov-file#querying-the-terminal>
Csi::Sgr(csi::Sgr::Background(TEST_COLOR.into())),
Csi::Sgr(csi::Sgr::UnderlineColor(TEST_COLOR.into())),
Dcs::Request(dcs::DcsRequest::GraphicRendition),
Csi::Sgr(csi::Sgr::Reset),
// Finally request the primary device attributes
Csi::Device(csi::Device::RequestPrimaryDeviceAttributes),
)?;
terminal.flush()?;
let device_attributes = |event: &Event| {
matches!(
event,
Event::Csi(Csi::Device(csi::Device::DeviceAttributes(_)))
)
};
// TODO: tune this poll constant? Does it need to be longer when on an SSH connection?
let poll_duration = Duration::from_millis(100);
if terminal.poll(device_attributes, Some(poll_duration))? {
while terminal.poll(Event::is_escape, Some(Duration::ZERO))? {
match terminal.read(Event::is_escape)? {
Event::Csi(Csi::Keyboard(csi::Keyboard::ReportFlags(_))) => {
capabilities.kitty_keyboard = KittyKeyboardSupport::Some;
}
Event::Csi(Csi::Mode(csi::Mode::ReportDecPrivateMode {
mode: csi::DecPrivateMode::Code(csi::DecPrivateModeCode::SynchronizedOutput),
setting: csi::DecModeSetting::Set | csi::DecModeSetting::Reset,
})) => {
capabilities.synchronized_output = true;
}
Event::Csi(Csi::Mode(csi::Mode::ReportTheme(mode))) => {
capabilities.theme_mode = Some(mode.into());
}
Event::Dcs(dcs::Dcs::Response {
value: dcs::DcsResponse::GraphicRendition(sgrs),
..
}) => {
capabilities.true_color =
sgrs.contains(&csi::Sgr::Background(TEST_COLOR.into()));
capabilities.extended_underlines =
sgrs.contains(&csi::Sgr::UnderlineColor(TEST_COLOR.into()));
}
_ => (),
}
}
let end = Instant::now();
log::debug!(
"Detected terminal capabilities in {:?}: {capabilities:?}",
end.duration_since(start)
);
} else {
log::debug!("Failed to detect terminal capabilities within {poll_duration:?}. Using default capabilities only");
}
capabilities.extended_underlines |= config.force_enable_extended_underlines;
let mut reset_cursor_command =
Csi::Cursor(csi::Cursor::CursorStyle(CursorStyle::Default)).to_string();
if let Ok(t) = termini::TermInfo::from_env() {
capabilities.extended_underlines |= t.extended_cap("Smulx").is_some()
|| t.extended_cap("Su").is_some()
|| vte_version() >= Some(5102)
// HACK: once WezTerm can support DECRQSS/DECRPSS for SGR we can remove this line.
// <https://github.com/wezterm/wezterm/pull/6856>
|| matches!(term_program().as_deref(), Some("WezTerm"));
if let Some(termini::Value::Utf8String(se_str)) = t.extended_cap("Se") {
reset_cursor_command.push_str(se_str);
};
reset_cursor_command.push_str(
t.utf8_string_cap(termini::StringCapability::CursorNormal)
.unwrap_or(""),
);
log::debug!(
"Cursor reset escape sequence detected from terminfo: {reset_cursor_command:?}"
);
} else {
log::debug!("terminfo could not be read, using default cursor reset escape sequence: {reset_cursor_command:?}");
}
terminal.enter_cooked_mode()?;
Ok((capabilities, reset_cursor_command))
}
fn enable_mouse_capture(&mut self) -> io::Result<()> {
if self.config.enable_mouse_capture {
write!(
self.terminal,
"{}{}{}{}{}",
decset!(MouseTracking),
decset!(ButtonEventMouse),
decset!(AnyEventMouse),
decset!(RXVTMouse),
decset!(SGRMouse),
)?;
}
Ok(())
}
fn disable_mouse_capture(&mut self) -> io::Result<()> {
if self.config.enable_mouse_capture {
write!(
self.terminal,
"{}{}{}{}{}",
decreset!(MouseTracking),
decreset!(ButtonEventMouse),
decreset!(AnyEventMouse),
decreset!(RXVTMouse),
decreset!(SGRMouse),
)?;
}
Ok(())
}
fn enable_extensions(&mut self) -> io::Result<()> {
const KEYBOARD_FLAGS: csi::KittyKeyboardFlags =
csi::KittyKeyboardFlags::DISAMBIGUATE_ESCAPE_CODES
.union(csi::KittyKeyboardFlags::REPORT_ALTERNATE_KEYS);
match self.capabilities.kitty_keyboard {
KittyKeyboardSupport::None | KittyKeyboardSupport::Partial => (),
KittyKeyboardSupport::Full => {
write!(
self.terminal,
"{}",
Csi::Keyboard(csi::Keyboard::PushFlags(KEYBOARD_FLAGS))
)?;
}
KittyKeyboardSupport::Some => {
write!(
self.terminal,
"{}{}",
// Enable the flags we need.
Csi::Keyboard(csi::Keyboard::PushFlags(KEYBOARD_FLAGS)),
// Then request the current flags. We need to check if the terminal enabled
// all of the flags we require.
Csi::Keyboard(csi::Keyboard::QueryFlags),
)?;
self.terminal.flush()?;
let event = self.terminal.read(|event| {
matches!(
event,
Event::Csi(Csi::Keyboard(csi::Keyboard::ReportFlags(_)))
)
})?;
let Event::Csi(Csi::Keyboard(csi::Keyboard::ReportFlags(flags))) = event else {
unreachable!();
};
if flags != KEYBOARD_FLAGS {
log::info!("Turning off enhanced keyboard support because the terminal enabled different flags. Requested {KEYBOARD_FLAGS:?} but got {flags:?}");
write!(
self.terminal,
"{}",
Csi::Keyboard(csi::Keyboard::PopFlags(1))
)?;
self.terminal.flush()?;
self.capabilities.kitty_keyboard = KittyKeyboardSupport::Partial;
} else {
log::debug!(
"The terminal fully supports the requested keyboard enhancement flags"
);
self.capabilities.kitty_keyboard = KittyKeyboardSupport::Full;
}
}
}
if self.capabilities.theme_mode.is_some() {
// Enable mode 2031 theme mode notifications:
write!(self.terminal, "{}", decset!(Theme))?;
}
Ok(())
}
fn disable_extensions(&mut self) -> io::Result<()> {
if self.capabilities.kitty_keyboard == KittyKeyboardSupport::Full {
write!(
self.terminal,
"{}",
Csi::Keyboard(csi::Keyboard::PopFlags(1))
)?;
}
if self.capabilities.theme_mode.is_some() {
// Mode 2031 theme notifications.
write!(self.terminal, "{}", decreset!(Theme))?;
}
Ok(())
}
// See <https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036>.
// Synchronized output sequences tell the terminal when we are "starting to render" and
// stopping, enabling to make better choices about when it draws a frame. This avoids all
// kinds of ugly visual artifacts like tearing and flashing (i.e. the background color
// after clearing the terminal).
fn start_synchronized_render(&mut self) -> io::Result<()> {
if self.capabilities.synchronized_output && !self.is_synchronized_output_set {
write!(self.terminal, "{}", decset!(SynchronizedOutput))?;
self.is_synchronized_output_set = true;
}
Ok(())
}
fn end_sychronized_render(&mut self) -> io::Result<()> {
if self.is_synchronized_output_set {
write!(self.terminal, "{}", decreset!(SynchronizedOutput))?;
self.is_synchronized_output_set = false;
}
Ok(())
}
}
impl Backend for TerminaBackend {
fn claim(&mut self) -> io::Result<()> {
self.terminal.enter_raw_mode()?;
write!(
self.terminal,
"{}{}{}{}",
// Enter an alternate screen.
decset!(ClearAndEnableAlternateScreen),
decset!(BracketedPaste),
decset!(FocusTracking),
// Clear the buffer. `ClearAndEnableAlternateScreen` **should** do this but some
// things like mosh are buggy. See <https://github.com/helix-editor/helix/pull/1944>.
Csi::Edit(csi::Edit::EraseInDisplay(csi::EraseInDisplay::EraseDisplay)),
)?;
self.enable_mouse_capture()?;
self.enable_extensions()?;
Ok(())
}
fn reconfigure(&mut self, mut config: Config) -> io::Result<()> {
std::mem::swap(&mut self.config, &mut config);
if self.config.enable_mouse_capture != config.enable_mouse_capture {
if self.config.enable_mouse_capture {
self.enable_mouse_capture()?;
} else {
self.disable_mouse_capture()?;
}
}
self.capabilities.extended_underlines |= self.config.force_enable_extended_underlines;
Ok(())
}
fn restore(&mut self) -> io::Result<()> {
self.disable_extensions()?;
self.disable_mouse_capture()?;
write!(
self.terminal,
"{}{}{}{}",
&self.reset_cursor_command,
decreset!(BracketedPaste),
decreset!(FocusTracking),
decreset!(ClearAndEnableAlternateScreen),
)?;
self.terminal.flush()?;
self.terminal.enter_cooked_mode()?;
Ok(())
}
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
self.start_synchronized_render()?;
let mut fg = Color::Reset;
let mut bg = Color::Reset;
let mut underline_color = Color::Reset;
let mut underline_style = UnderlineStyle::Reset;
let mut modifier = Modifier::empty();
let mut last_pos: Option<(u16, u16)> = None;
for (x, y, cell) in content {
// Move the cursor if the previous location was not (x - 1, y)
if !matches!(last_pos, Some(p) if x == p.0 + 1 && y == p.1) {
write!(
self.terminal,
"{}",
Csi::Cursor(csi::Cursor::Position {
col: OneBased::from_zero_based(x),
line: OneBased::from_zero_based(y),
})
)?;
}
last_pos = Some((x, y));
let mut attributes = SgrAttributes::default();
if cell.fg != fg {
attributes.foreground = Some(cell.fg.into());
fg = cell.fg;
}
if cell.bg != bg {
attributes.background = Some(cell.bg.into());
bg = cell.bg;
}
if cell.modifier != modifier {
attributes.modifiers = diff_modifiers(modifier, cell.modifier);
modifier = cell.modifier;
}
// Set underline style and color separately from SgrAttributes. Some terminals seem
// to not like underline colors and styles being intermixed with other SGRs.
let mut new_underline_style = cell.underline_style;
if self.capabilities.extended_underlines {
if cell.underline_color != underline_color {
write!(
self.terminal,
"{}",
Csi::Sgr(csi::Sgr::UnderlineColor(cell.underline_color.into()))
)?;
underline_color = cell.underline_color;
}
} else {
match new_underline_style {
UnderlineStyle::Reset | UnderlineStyle::Line => (),
_ => new_underline_style = UnderlineStyle::Line,
}
}
if new_underline_style != underline_style {
write!(
self.terminal,
"{}",
Csi::Sgr(csi::Sgr::Underline(new_underline_style.into()))
)?;
underline_style = new_underline_style;
}
// `attributes` will be empty if nothing changed between two cells. Empty
// `SgrAttributes` behave the same as a `Sgr::Reset` rather than a 'no-op' though so
// we should avoid writing them if they're empty.
if !attributes.is_empty() {
write!(
self.terminal,
"{}",
Csi::Sgr(csi::Sgr::Attributes(attributes))
)?;
}
write!(self.terminal, "{}", &cell.symbol)?;
}
write!(self.terminal, "{}", Csi::Sgr(csi::Sgr::Reset))?;
self.end_sychronized_render()?;
Ok(())
}
fn hide_cursor(&mut self) -> io::Result<()> {
write!(self.terminal, "{}", decreset!(ShowCursor))?;
self.flush()
}
fn show_cursor(&mut self, kind: CursorKind) -> io::Result<()> {
let style = match kind {
CursorKind::Block => CursorStyle::SteadyBlock,
CursorKind::Bar => CursorStyle::SteadyBar,
CursorKind::Underline => CursorStyle::SteadyUnderline,
CursorKind::Hidden => unreachable!(),
};
write!(
self.terminal,
"{}{}",
decset!(ShowCursor),
Csi::Cursor(csi::Cursor::CursorStyle(style)),
)?;
self.flush()
}
fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
let col = OneBased::from_zero_based(x);
let line = OneBased::from_zero_based(y);
write!(
self.terminal,
"{}",
Csi::Cursor(csi::Cursor::Position { line, col })
)?;
self.flush()
}
fn clear(&mut self) -> io::Result<()> {
self.start_synchronized_render()?;
write!(
self.terminal,
"{}",
Csi::Edit(csi::Edit::EraseInDisplay(csi::EraseInDisplay::EraseDisplay))
)?;
self.flush()
}
fn size(&self) -> io::Result<Rect> {
let WindowSize { rows, cols, .. } = self.terminal.get_dimensions()?;
Ok(Rect::new(0, 0, cols, rows))
}
fn flush(&mut self) -> io::Result<()> {
self.terminal.flush()
}
fn supports_true_color(&self) -> bool {
self.capabilities.true_color
}
fn get_theme_mode(&self) -> Option<theme::Mode> {
self.capabilities.theme_mode
}
}
impl Drop for TerminaBackend {
fn drop(&mut self) {
// Avoid resetting the terminal while panicking because we set a panic hook above in
// `Self::new`.
if !std::thread::panicking() {
let _ = self.disable_extensions();
let _ = self.disable_mouse_capture();
let _ = write!(
self.terminal,
"{}{}{}{}",
&self.reset_cursor_command,
decreset!(BracketedPaste),
decreset!(FocusTracking),
decreset!(ClearAndEnableAlternateScreen),
);
// NOTE: Drop for Platform terminal resets the mode and flushes the buffer when not
// panicking.
}
}
}
fn diff_modifiers(from: Modifier, to: Modifier) -> SgrModifiers {
let mut modifiers = SgrModifiers::default();
let removed = from - to;
if removed.contains(Modifier::REVERSED) {
modifiers |= SgrModifiers::NO_REVERSE;
}
if removed.contains(Modifier::BOLD) && !to.contains(Modifier::DIM) {
modifiers |= SgrModifiers::INTENSITY_NORMAL;
}
if removed.contains(Modifier::DIM) {
modifiers |= SgrModifiers::INTENSITY_NORMAL;
}
if removed.contains(Modifier::ITALIC) {
modifiers |= SgrModifiers::NO_ITALIC;
}
if removed.contains(Modifier::CROSSED_OUT) {
modifiers |= SgrModifiers::NO_STRIKE_THROUGH;
}
if removed.contains(Modifier::HIDDEN) {
modifiers |= SgrModifiers::NO_INVISIBLE;
}
if removed.contains(Modifier::SLOW_BLINK) || removed.contains(Modifier::RAPID_BLINK) {
modifiers |= SgrModifiers::BLINK_NONE;
}
let added = to - from;
if added.contains(Modifier::REVERSED) {
modifiers |= SgrModifiers::REVERSE;
}
if added.contains(Modifier::BOLD) {
modifiers |= SgrModifiers::INTENSITY_BOLD;
}
if added.contains(Modifier::DIM) {
modifiers |= SgrModifiers::INTENSITY_DIM;
}
if added.contains(Modifier::ITALIC) {
modifiers |= SgrModifiers::ITALIC;
}
if added.contains(Modifier::CROSSED_OUT) {
modifiers |= SgrModifiers::STRIKE_THROUGH;
}
if added.contains(Modifier::HIDDEN) {
modifiers |= SgrModifiers::INVISIBLE;
}
if added.contains(Modifier::SLOW_BLINK) {
modifiers |= SgrModifiers::BLINK_SLOW;
}
if added.contains(Modifier::RAPID_BLINK) {
modifiers |= SgrModifiers::BLINK_RAPID;
}
modifiers
}

View File

@@ -107,7 +107,7 @@ impl TestBackend {
} }
impl Backend for TestBackend { impl Backend for TestBackend {
fn claim(&mut self, _config: Config) -> Result<(), io::Error> { fn claim(&mut self) -> Result<(), io::Error> {
Ok(()) Ok(())
} }
@@ -115,11 +115,7 @@ impl Backend for TestBackend {
Ok(()) Ok(())
} }
fn restore(&mut self, _config: Config) -> Result<(), io::Error> { fn restore(&mut self) -> Result<(), io::Error> {
Ok(())
}
fn force_restore() -> Result<(), io::Error> {
Ok(()) Ok(())
} }
@@ -143,10 +139,6 @@ impl Backend for TestBackend {
Ok(()) Ok(())
} }
fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
Ok(self.pos)
}
fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> { fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
self.pos = (x, y); self.pos = (x, y);
Ok(()) Ok(())
@@ -164,4 +156,12 @@ impl Backend for TestBackend {
fn flush(&mut self) -> Result<(), io::Error> { fn flush(&mut self) -> Result<(), io::Error> {
Ok(()) Ok(())
} }
fn supports_true_color(&self) -> bool {
false
}
fn get_theme_mode(&self) -> Option<helix_view::theme::Mode> {
None
}
} }

View File

@@ -1,133 +1,3 @@
//! [tui](https://github.com/fdehau/tui-rs) is a library used to build rich
//! terminal users interfaces and dashboards.
//!
//! ![](https://raw.githubusercontent.com/fdehau/tui-rs/master/assets/demo.gif)
//!
//! # Get started
//!
//! ## Adding `tui` as a dependency
//!
//! ```toml
//! [dependencies]
//! tui = "0.15"
//! crossterm = "0.19"
//! ```
//!
//! The same logic applies for all other available backends.
//!
//! ## Creating a `Terminal`
//!
//! Every application using `tui` should start by instantiating a `Terminal`. It is a light
//! abstraction over available backends that provides basic functionalities such as clearing the
//! screen, hiding the cursor, etc.
//!
//! ```rust,no_run
//! use std::io;
//! use helix_tui::Terminal;
//! use helix_tui::backend::CrosstermBackend;
//! use helix_view::editor::Config;
//!
//! fn main() -> Result<(), io::Error> {
//! let stdout = io::stdout();
//! let config = Config::default();
//! let backend = CrosstermBackend::new(stdout, &config);
//! let mut terminal = Terminal::new(backend)?;
//! Ok(())
//! }
//! ```
//!
//! You may also refer to the examples to find out how to create a `Terminal` for each available
//! backend.
//!
//! ## Building a User Interface (UI)
//!
//! Every component of your interface will be implementing the `Widget` trait. The library comes
//! with a predefined set of widgets that should meet most of your use cases. You are also free to
//! implement your own.
//!
//! Each widget follows a builder pattern API providing a default configuration along with methods
//! to customize them. The widget is then rendered using the `Frame::render_widget` which take
//! your widget instance an area to draw to.
//!
//! The following example renders a block of the size of the terminal:
//!
//! ```rust,no_run
//! use std::io;
//! use crossterm::terminal;
//! use helix_tui::Terminal;
//! use helix_tui::backend::CrosstermBackend;
//! use helix_tui::widgets::{Widget, Block, Borders};
//! use helix_tui::layout::{Layout, Constraint, Direction};
//! use helix_view::editor::Config;
//!
//! fn main() -> Result<(), io::Error> {
//! terminal::enable_raw_mode().unwrap();
//! let stdout = io::stdout();
//! let config = Config::default();
//! let backend = CrosstermBackend::new(stdout, &config);
//! let mut terminal = Terminal::new(backend)?;
//! // terminal.draw(|f| {
//! // let size = f.size();
//! // let block = Block::default()
//! // .title("Block")
//! // .borders(Borders::ALL);
//! // f.render_widget(block, size);
//! // })?;
//! Ok(())
//! }
//! ```
//!
//! ## Layout
//!
//! The library comes with a basic yet useful layout management object called `Layout`. As you may
//! see below and in the examples, the library makes heavy use of the builder pattern to provide
//! full customization. And `Layout` is no exception:
//!
//! ```rust,no_run
//! use std::io;
//! use crossterm::terminal;
//! use helix_tui::Terminal;
//! use helix_tui::backend::CrosstermBackend;
//! use helix_tui::widgets::{Widget, Block, Borders};
//! use helix_tui::layout::{Layout, Constraint, Direction};
//! use helix_view::editor::Config;
//!
//! fn main() -> Result<(), io::Error> {
//! terminal::enable_raw_mode().unwrap();
//! let stdout = io::stdout();
//! let config = Config::default();
//! let backend = CrosstermBackend::new(stdout, &config);
//! let mut terminal = Terminal::new(backend)?;
//! // terminal.draw(|f| {
//! // let chunks = Layout::default()
//! // .direction(Direction::Vertical)
//! // .margin(1)
//! // .constraints(
//! // [
//! // Constraint::Percentage(10),
//! // Constraint::Percentage(80),
//! // Constraint::Percentage(10)
//! // ].as_ref()
//! // )
//! // .split(f.size());
//! // let block = Block::default()
//! // .title("Block")
//! // .borders(Borders::ALL);
//! // f.render_widget(block, chunks[0]);
//! // let block = Block::default()
//! // .title("Block 2")
//! // .borders(Borders::ALL);
//! // f.render_widget(block, chunks[1]);
//! // })?;
//! Ok(())
//! }
//! ```
//!
//! This let you describe responsive terminal UI by nesting layouts. You should note that by
//! default the computed layout tries to fill the available space completely. So if for any reason
//! you might need a blank space somewhere, try to pass an additional constraint and don't use the
//! corresponding area.
pub mod backend; pub mod backend;
pub mod buffer; pub mod buffer;
pub mod layout; pub mod layout;

View File

@@ -2,7 +2,7 @@
//! Frontend for [Backend] //! Frontend for [Backend]
use crate::{backend::Backend, buffer::Buffer}; use crate::{backend::Backend, buffer::Buffer};
use helix_view::editor::Config as EditorConfig; use helix_view::editor::{Config as EditorConfig, KittyKeyboardProtocolConfig};
use helix_view::graphics::{CursorKind, Rect}; use helix_view::graphics::{CursorKind, Rect};
use std::io; use std::io;
@@ -24,12 +24,16 @@ pub struct Viewport {
#[derive(Debug)] #[derive(Debug)]
pub struct Config { pub struct Config {
pub enable_mouse_capture: bool, pub enable_mouse_capture: bool,
pub force_enable_extended_underlines: bool,
pub kitty_keyboard_protocol: KittyKeyboardProtocolConfig,
} }
impl From<EditorConfig> for Config { impl From<&EditorConfig> for Config {
fn from(config: EditorConfig) -> Self { fn from(config: &EditorConfig) -> Self {
Self { Self {
enable_mouse_capture: config.mouse, enable_mouse_capture: config.mouse,
force_enable_extended_underlines: config.undercurl,
kitty_keyboard_protocol: config.kitty_keyboard_protocol,
} }
} }
} }
@@ -69,6 +73,14 @@ where
viewport: Viewport, viewport: Viewport,
} }
/// Default terminal size: 80 columns, 24 lines
pub const DEFAULT_TERMINAL_SIZE: Rect = Rect {
x: 0,
y: 0,
width: 80,
height: 24,
};
impl<B> Terminal<B> impl<B> Terminal<B>
where where
B: Backend, B: Backend,
@@ -76,7 +88,7 @@ where
/// Wrapper around Terminal initialization. Each buffer is initialized with a blank string and /// Wrapper around Terminal initialization. Each buffer is initialized with a blank string and
/// default colors for the foreground and the background /// default colors for the foreground and the background
pub fn new(backend: B) -> io::Result<Terminal<B>> { pub fn new(backend: B) -> io::Result<Terminal<B>> {
let size = backend.size()?; let size = backend.size().unwrap_or(DEFAULT_TERMINAL_SIZE);
Terminal::with_options( Terminal::with_options(
backend, backend,
TerminalOptions { TerminalOptions {
@@ -102,16 +114,16 @@ where
}) })
} }
pub fn claim(&mut self, config: Config) -> io::Result<()> { pub fn claim(&mut self) -> io::Result<()> {
self.backend.claim(config) self.backend.claim()
} }
pub fn reconfigure(&mut self, config: Config) -> io::Result<()> { pub fn reconfigure(&mut self, config: Config) -> io::Result<()> {
self.backend.reconfigure(config) self.backend.reconfigure(config)
} }
pub fn restore(&mut self, config: Config) -> io::Result<()> { pub fn restore(&mut self) -> io::Result<()> {
self.backend.restore(config) self.backend.restore()
} }
// /// Get a Frame object which provides a consistent view into the terminal state for rendering. // /// Get a Frame object which provides a consistent view into the terminal state for rendering.
@@ -155,7 +167,7 @@ where
/// Queries the backend for size and resizes if it doesn't match the previous size. /// Queries the backend for size and resizes if it doesn't match the previous size.
pub fn autoresize(&mut self) -> io::Result<Rect> { pub fn autoresize(&mut self) -> io::Result<Rect> {
let size = self.size()?; let size = self.size();
if size != self.viewport.area { if size != self.viewport.area {
self.resize(size)?; self.resize(size)?;
}; };
@@ -218,10 +230,6 @@ where
Ok(()) Ok(())
} }
pub fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
self.backend.get_cursor()
}
pub fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> { pub fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
self.backend.set_cursor(x, y) self.backend.set_cursor(x, y)
} }
@@ -235,7 +243,7 @@ where
} }
/// Queries the real size of the backend. /// Queries the real size of the backend.
pub fn size(&self) -> io::Result<Rect> { pub fn size(&self) -> Rect {
self.backend.size() self.backend.size().unwrap_or(DEFAULT_TERMINAL_SIZE)
} }
} }

View File

@@ -374,6 +374,30 @@ impl<'a> Text<'a> {
self.lines.len() self.lines.len()
} }
/// Patch text with a new style. Only updates fields that are in the new style.
///
/// # Examples
///
/// ```rust
/// # use helix_tui::text::Text;
/// # use helix_view::graphics::{Color, Style};
/// let style1 = Style::default().fg(Color::Yellow);
/// let style2 = Style::default().fg(Color::Yellow).bg(Color::Black);
/// let mut half_styled_text = Text::styled(String::from("The first line\nThe second line"), style1);
/// let full_styled_text = Text::styled(String::from("The first line\nThe second line"), style2);
/// assert_ne!(half_styled_text, full_styled_text);
///
/// half_styled_text.patch_style(Style::default().bg(Color::Black));
/// assert_eq!(half_styled_text, full_styled_text);
/// ```
pub fn patch_style(&mut self, style: Style) {
for line in &mut self.lines {
for span in &mut line.0 {
span.style = span.style.patch(style);
}
}
}
/// Apply a new style to existing text. /// Apply a new style to existing text.
/// ///
/// # Examples /// # Examples
@@ -386,13 +410,13 @@ impl<'a> Text<'a> {
/// let styled_text = Text::styled(String::from("The first line\nThe second line"), style); /// let styled_text = Text::styled(String::from("The first line\nThe second line"), style);
/// assert_ne!(raw_text, styled_text); /// assert_ne!(raw_text, styled_text);
/// ///
/// raw_text.patch_style(style); /// raw_text.set_style(style);
/// assert_eq!(raw_text, styled_text); /// assert_eq!(raw_text, styled_text);
/// ``` /// ```
pub fn patch_style(&mut self, style: Style) { pub fn set_style(&mut self, style: Style) {
for line in &mut self.lines { for line in &mut self.lines {
for span in &mut line.0 { for span in &mut line.0 {
span.style = span.style.patch(style); span.style = style;
} }
} }
} }

View File

@@ -37,9 +37,15 @@ pub struct Cell<'a> {
impl Cell<'_> { impl Cell<'_> {
/// Set the `Style` of this cell. /// Set the `Style` of this cell.
pub fn style(mut self, style: Style) -> Self { pub fn style(mut self, style: Style) -> Self {
self.style = style; self.set_style(style);
self self
} }
/// Set the `Style` of this cell.
pub fn set_style(&mut self, style: Style) {
self.style = style;
self.content.patch_style(style);
}
} }
impl<'a, T> From<T> for Cell<'a> impl<'a, T> From<T> for Cell<'a>
@@ -453,6 +459,9 @@ impl Table<'_> {
}; };
if is_selected { if is_selected {
buf.set_style(table_row_area, self.highlight_style); buf.set_style(table_row_area, self.highlight_style);
for cell in &mut table_row.cells {
cell.set_style(self.highlight_style);
}
} }
let mut col = table_row_start_col; let mut col = table_row_start_col;
for (width, cell) in columns_widths.iter().zip(table_row.cells.iter()) { for (width, cell) in columns_widths.iter().zip(table_row.cells.iter()) {

Some files were not shown because too many files have changed in this diff Show More