mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Merge branch 'master' into issue-2719
Helix is handling narrow non-breaking spaces, update trailing whitespace tracker to take them into account
This commit is contained in:
commit
ba893751c2
@ -1,3 +1,17 @@
|
||||
# we use tokio_unstable to enable runtime::Handle::id so we can separate
|
||||
# globals from multiple parallel tests. If that function ever does get removed
|
||||
# its possible to replace (with some additional overhead and effort)
|
||||
# Annoyingly build.rustflags doesn't work here because it gets overwritten
|
||||
# if people have their own global target.<..> config (for example to enable mold)
|
||||
# specifying flags this way is more robust as they get merged
|
||||
# This still gets overwritten by RUST_FLAGS though, luckily it shouldn't be necessary
|
||||
# to set those most of the time. If downstream does overwrite this its not a huge
|
||||
# deal since it will only break tests anyway
|
||||
[target."cfg(all())"]
|
||||
rustflags = ["--cfg", "tokio_unstable", "-C", "target-feature=-crt-static"]
|
||||
|
||||
|
||||
[alias]
|
||||
xtask = "run --package xtask --"
|
||||
integration-test = "test --features integration --profile integration --workspace --test integration"
|
||||
|
||||
|
1
.envrc
1
.envrc
@ -1,5 +1,6 @@
|
||||
watch_file shell.nix
|
||||
watch_file flake.lock
|
||||
watch_file rust-toolchain.toml
|
||||
|
||||
# try to use flakes, if it fails use normal nix (ie. shell.nix)
|
||||
use flake || use nix
|
||||
|
10
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
10
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@ -55,6 +55,16 @@ body:
|
||||
placeholder: wezterm 20220101-133340-7edc5b5a
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: installation-method
|
||||
attributes:
|
||||
label: Installation Method
|
||||
description: >
|
||||
How you installed Helix - from a package manager like Homebrew or the
|
||||
AUR, built from source, downloaded a binary from the releases page, etc.
|
||||
placeholder: "source / brew / nixpkgs / flake / releases page"
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: helix-version
|
||||
attributes:
|
||||
|
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@ -7,6 +7,14 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
groups:
|
||||
tree-sitter:
|
||||
patterns:
|
||||
- "tree-sitter*"
|
||||
rust-dependencies:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
|
28
.github/workflows/build.yml
vendored
28
.github/workflows/build.yml
vendored
@ -12,9 +12,10 @@ jobs:
|
||||
check:
|
||||
name: Check (msrv)
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: Install stable toolchain
|
||||
uses: helix-editor/rust-toolchain@v1
|
||||
with:
|
||||
@ -22,6 +23,8 @@ jobs:
|
||||
override: true
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
shared-key: "build"
|
||||
|
||||
- name: Run cargo check
|
||||
run: cargo check
|
||||
@ -29,20 +32,23 @@ jobs:
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
HELIX_LOG_LEVEL: info
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@1.65
|
||||
uses: dtolnay/rust-toolchain@1.70
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
shared-key: "build"
|
||||
|
||||
- name: Cache test tree-sitter grammar
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: runtime/grammars
|
||||
key: ${{ runner.os }}-stable-v${{ env.CACHE_VERSION }}-tree-sitter-grammars-${{ hashFiles('languages.toml') }}
|
||||
@ -61,16 +67,19 @@ jobs:
|
||||
lints:
|
||||
name: Lints
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@1.65
|
||||
uses: dtolnay/rust-toolchain@1.70
|
||||
with:
|
||||
components: rustfmt, clippy
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
shared-key: "build"
|
||||
|
||||
- name: Run cargo fmt
|
||||
run: cargo fmt --all --check
|
||||
@ -86,14 +95,17 @@ jobs:
|
||||
docs:
|
||||
name: Docs
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule'
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@1.65
|
||||
uses: dtolnay/rust-toolchain@1.70
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
shared-key: "build"
|
||||
|
||||
- name: Validate queries
|
||||
run: cargo xtask query-check
|
||||
|
6
.github/workflows/cachix.yml
vendored
6
.github/workflows/cachix.yml
vendored
@ -11,13 +11,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install nix
|
||||
uses: cachix/install-nix-action@v21
|
||||
uses: cachix/install-nix-action@v26
|
||||
|
||||
- name: Authenticate with Cachix
|
||||
uses: cachix/cachix-action@v12
|
||||
uses: cachix/cachix-action@v14
|
||||
with:
|
||||
name: helix
|
||||
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||
|
20
.github/workflows/gh-pages.yml
vendored
20
.github/workflows/gh-pages.yml
vendored
@ -11,10 +11,10 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup mdBook
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
uses: peaceiris/actions-mdbook@v2
|
||||
with:
|
||||
mdbook-version: 'latest'
|
||||
# mdbook-version: '0.4.8'
|
||||
@ -26,16 +26,16 @@ jobs:
|
||||
OUTDIR=$(basename ${{ github.ref }})
|
||||
echo "OUTDIR=$OUTDIR" >> $GITHUB_ENV
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
||||
destination_dir: ./${{ env.OUTDIR }}
|
||||
|
||||
- name: Deploy stable
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
if: startswith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
||||
destination_dir: ./${{ env.OUTDIR }}
|
||||
|
30
.github/workflows/release.yml
vendored
30
.github/workflows/release.yml
vendored
@ -23,7 +23,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
@ -36,7 +36,7 @@ jobs:
|
||||
- name: Bundle grammars
|
||||
run: tar cJf grammars.tar.xz -C runtime/grammars/sources .
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: grammars
|
||||
path: grammars.tar.xz
|
||||
@ -70,11 +70,11 @@ jobs:
|
||||
rust: stable
|
||||
target: aarch64-unknown-linux-gnu
|
||||
cross: true
|
||||
- build: riscv64-linux
|
||||
os: ubuntu-latest
|
||||
rust: stable
|
||||
target: riscv64gc-unknown-linux-gnu
|
||||
cross: true
|
||||
# - build: riscv64-linux
|
||||
# os: ubuntu-latest
|
||||
# rust: stable
|
||||
# target: riscv64gc-unknown-linux-gnu
|
||||
# cross: true
|
||||
- build: x86_64-macos
|
||||
os: macos-latest
|
||||
rust: stable
|
||||
@ -103,10 +103,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download grammars
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
|
||||
- name: Move grammars under runtime
|
||||
if: "!startsWith(matrix.os, 'windows')"
|
||||
@ -160,7 +160,7 @@ jobs:
|
||||
|
||||
- name: Build AppImage
|
||||
shell: bash
|
||||
if: matrix.build == 'aarch64-linux' || matrix.build == 'x86_64-linux'
|
||||
if: matrix.build == 'x86_64-linux'
|
||||
run: |
|
||||
# Required as of 22.x https://github.com/AppImage/AppImageKit/wiki/FUSE
|
||||
sudo add-apt-repository universe
|
||||
@ -220,7 +220,7 @@ jobs:
|
||||
fi
|
||||
cp -r runtime dist
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bins-${{ matrix.build }}
|
||||
path: dist
|
||||
@ -231,9 +231,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
- uses: actions/download-artifact@v4
|
||||
|
||||
- name: Build archive
|
||||
shell: bash
|
||||
@ -263,7 +263,7 @@ jobs:
|
||||
mv bins-$platform/hx$exe $pkgname
|
||||
chmod +x $pkgname/hx$exe
|
||||
|
||||
if [[ "$platform" = "aarch64-linux" || "$platform" = "x86_64-linux" ]]; then
|
||||
if [[ "$platform" = "x86_64-linux" ]]; then
|
||||
mv bins-$platform/helix-*.AppImage* dist/
|
||||
fi
|
||||
|
||||
@ -288,7 +288,7 @@ jobs:
|
||||
overwrite: true
|
||||
|
||||
- name: Upload binaries as artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
if: env.preview == 'true'
|
||||
with:
|
||||
name: release
|
||||
|
5
.ignore
5
.ignore
@ -1,5 +0,0 @@
|
||||
# Things that we don't want ripgrep to search that we do want in git
|
||||
# https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#automatic-filtering
|
||||
|
||||
# Minified JS vendored from mdbook
|
||||
book/theme/highlight.js
|
515
CHANGELOG.md
515
CHANGELOG.md
@ -1,3 +1,516 @@
|
||||
# 24.03 (2024-03-30)
|
||||
|
||||
As always, a big thank you to all of the contributors! This release saw changes from 125 contributors.
|
||||
|
||||
Breaking changes:
|
||||
|
||||
- `suffix` file-types in the `file-types` key in language configuration have been removed ([#8006](https://github.com/helix-editor/helix/pull/8006))
|
||||
- The `file-types` key in language configuration no longer matches full filenames without a glob pattern ([#8006](https://github.com/helix-editor/helix/pull/8006))
|
||||
|
||||
Features:
|
||||
|
||||
- Open URLs with the `goto_file` command ([#5820](https://github.com/helix-editor/helix/pull/5820))
|
||||
- Support drawing a border around popups and menus ([#4313](https://github.com/helix-editor/helix/pull/4313), [#9508](https://github.com/helix-editor/helix/pull/9508))
|
||||
- Track long lived diagnostic sources like Clippy or `rustc` ([#6447](https://github.com/helix-editor/helix/pull/6447), [#9280](https://github.com/helix-editor/helix/pull/9280))
|
||||
- This improves the handling of diagnostics from sources that only update the diagnostic positions on save.
|
||||
- Add support for LSP `window/showDocument` requests ([#8865](https://github.com/helix-editor/helix/pull/8865))
|
||||
- Refactor ad-hoc hooks to use a new generic event system ([#8021](https://github.com/helix-editor/helix/pull/8021), [#9668](https://github.com/helix-editor/helix/pull/9668), [#9660](https://github.com/helix-editor/helix/pull/9660))
|
||||
- This improves the behavior of autocompletions. For example navigating in insert mode no longer automatically triggers completions.
|
||||
- Allow using globs in the language configuration `file-types` key ([#8006](https://github.com/helix-editor/helix/pull/8006))
|
||||
- Allow specifying required roots for situational LSP activation ([#8696](https://github.com/helix-editor/helix/pull/8696))
|
||||
- Extend selections using mouse clicks in select mode ([#5436](https://github.com/helix-editor/helix/pull/5436))
|
||||
- Toggle block comments ([#4718](https://github.com/helix-editor/helix/pull/4718), [#9894](https://github.com/helix-editor/helix/pull/9894))
|
||||
- Support LSP diagnostic tags ([#9780](https://github.com/helix-editor/helix/pull/9780))
|
||||
- Add a `file-absolute-path` statusline element ([#4535](https://github.com/helix-editor/helix/pull/4535))
|
||||
- Cross injection layers in tree-sitter motions (`A-p`/`A-o`/`A-i`/`A-n`) ([#5176](https://github.com/helix-editor/helix/pull/5176))
|
||||
- Add a Amp-editor-like jumping command ([#8875](https://github.com/helix-editor/helix/pull/8875))
|
||||
|
||||
Commands:
|
||||
|
||||
- `:move` - move buffers with LSP support ([#8584](https://github.com/helix-editor/helix/pull/8584))
|
||||
- Also see [#8949](https://github.com/helix-editor/helix/pull/8949) which made path changes conform to the LSP spec and fixed the behavior of this command.
|
||||
- `page_cursor_up`, `page_cursor_down`, `page_cursor_half_up`, `page_cursor_half_down` - commands for scrolling the cursor and page together ([#8015](https://github.com/helix-editor/helix/pull/8015))
|
||||
- `:yank-diagnostic` - yank the diagnostic(s) under the primary cursor ([#9640](https://github.com/helix-editor/helix/pull/9640))
|
||||
- `select_line_above` / `select_line_below` - extend or shrink a selection based on the direction and anchor ([#9080](https://github.com/helix-editor/helix/pull/9080))
|
||||
|
||||
Usability improvements:
|
||||
|
||||
- Make `roots` key of `[[language]]` entries in `languages.toml` configuration optional ([#8803](https://github.com/helix-editor/helix/pull/8803))
|
||||
- Exit select mode in commands that modify the buffer ([#8689](https://github.com/helix-editor/helix/pull/8689))
|
||||
- Use crossterm cursor when out of focus ([#6858](https://github.com/helix-editor/helix/pull/6858), [#8934](https://github.com/helix-editor/helix/pull/8934))
|
||||
- Join empty lines with only one space in `join_selections` ([#8989](https://github.com/helix-editor/helix/pull/8989))
|
||||
- Introduce a hybrid tree-sitter and contextual indentation heuristic ([#8307](https://github.com/helix-editor/helix/pull/8307))
|
||||
- Allow configuring the indentation heuristic ([#8307](https://github.com/helix-editor/helix/pull/8307))
|
||||
- Check for LSP rename support before showing rename prompt ([#9277](https://github.com/helix-editor/helix/pull/9277))
|
||||
- Normalize `S-<lower-ascii>` keymaps to uppercase ascii ([#9213](https://github.com/helix-editor/helix/pull/9213))
|
||||
- Add formatter status to `--health` output ([#7986](https://github.com/helix-editor/helix/pull/7986))
|
||||
- Change path normalization strategy to not resolve symlinks ([#9330](https://github.com/helix-editor/helix/pull/9330))
|
||||
- Select subtree within injections in `:tree-sitter-subtree` ([#9309](https://github.com/helix-editor/helix/pull/9309))
|
||||
- Use tilde expansion and normalization for `$HELIX_RUNTIME` paths ([1bc7aac](https://github.com/helix-editor/helix/commit/1bc7aac))
|
||||
- Improve failure message for LSP goto references ([#9382](https://github.com/helix-editor/helix/pull/9382))
|
||||
- Use injection syntax trees for bracket matching ([5e0b3cc](https://github.com/helix-editor/helix/commit/5e0b3cc))
|
||||
- Respect injections in `:tree-sitter-highlight-name` ([8b6565c](https://github.com/helix-editor/helix/commit/8b6565c))
|
||||
- Respect injections in `move_parent_node_end` ([035b8ea](https://github.com/helix-editor/helix/commit/035b8ea))
|
||||
- Use `gix` pipeline filter instead of manual CRLF implementation ([#9503](https://github.com/helix-editor/helix/pull/9503))
|
||||
- Follow Neovim's truecolor detection ([#9577](https://github.com/helix-editor/helix/pull/9577))
|
||||
- Reload language configuration with `:reload`, SIGHUP ([#9415](https://github.com/helix-editor/helix/pull/9415))
|
||||
- Allow numbers as bindings ([#8471](https://github.com/helix-editor/helix/pull/8471), [#9887](https://github.com/helix-editor/helix/pull/9887))
|
||||
- Respect undercurl config when terminfo is not available ([#9897](https://github.com/helix-editor/helix/pull/9897))
|
||||
- Ignore `.pijul`, `.hg`, `.jj` in addition to `.git` in file pickers configured to show hidden files ([#9935](https://github.com/helix-editor/helix/pull/9935))
|
||||
- Add completion for registers to `:clear-register` and `:yank-diagnostic` ([#9936](https://github.com/helix-editor/helix/pull/9936))
|
||||
- Repeat last motion for goto next/prev diagnostic ([#9966](https://github.com/helix-editor/helix/pull/9966))
|
||||
- Allow configuring a character to use when rendering narrow no-breaking space ([#9604](https://github.com/helix-editor/helix/pull/9604))
|
||||
- Switch to a streaming regex engine (regex-cursor crate) to significantly speed up regex-based commands and features ([#9422](https://github.com/helix-editor/helix/pull/9422), [#9756](https://github.com/helix-editor/helix/pull/9756), [#9891](https://github.com/helix-editor/helix/pull/9891))
|
||||
|
||||
Fixes:
|
||||
|
||||
- Swap `*` and `+` registers ([#8703](https://github.com/helix-editor/helix/pull/8703), [#8708](https://github.com/helix-editor/helix/pull/8708))
|
||||
- Use terminfo to reset terminal cursor style ([#8591](https://github.com/helix-editor/helix/pull/8591))
|
||||
- Fix precedence of `@align` captures in indentat computation ([#8659](https://github.com/helix-editor/helix/pull/8659))
|
||||
- Only render the preview if a Picker has a preview function ([#8667](https://github.com/helix-editor/helix/pull/8667))
|
||||
- Fix the precedence of `ui.virtual.whitespace` ([#8750](https://github.com/helix-editor/helix/pull/8750), [#8879](https://github.com/helix-editor/helix/pull/8879))
|
||||
- Fix crash in `:indent-style` ([#9087](https://github.com/helix-editor/helix/pull/9087))
|
||||
- Fix `didSave` text inclusion when sync capability is a kind variant ([#9101](https://github.com/helix-editor/helix/pull/9101))
|
||||
- Update the history of newly focused views ([#9271](https://github.com/helix-editor/helix/pull/9271))
|
||||
- Initialize diagnostics when opening a document ([#8873](https://github.com/helix-editor/helix/pull/8873))
|
||||
- Sync views when applying edits to unfocused views ([#9173](https://github.com/helix-editor/helix/pull/9173))
|
||||
- This fixes crashes that could occur from LSP workspace edits or `:write-all`.
|
||||
- Treat non-numeric `+arg`s passed in the CLI args as filenames ([#9333](https://github.com/helix-editor/helix/pull/9333))
|
||||
- Fix crash when using `mm` on an empty plaintext file ([2fb7e50](https://github.com/helix-editor/helix/commit/2fb7e50))
|
||||
- Ignore empty tree-sitter nodes in match bracket ([445f7a2](https://github.com/helix-editor/helix/commit/445f7a2))
|
||||
- Exit a language server if it sends a message with invalid JSON ([#9332](https://github.com/helix-editor/helix/pull/9332))
|
||||
- Handle failures to enable bracketed paste ([#9353](https://github.com/helix-editor/helix/pull/9353))
|
||||
- Gate all captures in a pattern behind `#is-not? local` predicates ([#9390](https://github.com/helix-editor/helix/pull/9390))
|
||||
- Make path changes LSP spec conformant ([#8949](https://github.com/helix-editor/helix/pull/8949))
|
||||
- Use range positions to determine `insert_newline` motion ([#9448](https://github.com/helix-editor/helix/pull/9448))
|
||||
- Fix division by zero when prompt completion area is too small ([#9524](https://github.com/helix-editor/helix/pull/9524))
|
||||
- Add changes to history in clipboard replacement typable commands ([#9625](https://github.com/helix-editor/helix/pull/9625))
|
||||
- Fix a crash in DAP with an unspecified `line` in breakpoints ([#9632](https://github.com/helix-editor/helix/pull/9632))
|
||||
- Fix space handling for filenames in bash completion ([#9702](https://github.com/helix-editor/helix/pull/9702), [#9708](https://github.com/helix-editor/helix/pull/9708))
|
||||
- Key diagnostics off of paths instead of LSP URIs ([#7367](https://github.com/helix-editor/helix/pull/7367))
|
||||
- Fix panic when using `join_selections_space` ([#9783](https://github.com/helix-editor/helix/pull/9783))
|
||||
- Fix panic when using `surround_replace`, `surround_delete` ([#9796](https://github.com/helix-editor/helix/pull/9796))
|
||||
- Fix panic in `surround_replace`, `surround_delete` with nested surrounds and multiple cursors ([#9815](https://github.com/helix-editor/helix/pull/9815))
|
||||
- Fix panic in `select_textobject_around` ([#9832](https://github.com/helix-editor/helix/pull/9832))
|
||||
- Don't stop reloading documents when reloading fails in `:reload-all` ([#9870](https://github.com/helix-editor/helix/pull/9870))
|
||||
- Prevent `shell_keep_pipe` from stopping on nonzero exit status codes ([#9817](https://github.com/helix-editor/helix/pull/9817))
|
||||
|
||||
Themes:
|
||||
|
||||
- Add `gruber-dark` ([#8598](https://github.com/helix-editor/helix/pull/8598))
|
||||
- Update `everblush` ([#8705](https://github.com/helix-editor/helix/pull/8705))
|
||||
- Update `papercolor` ([#8718](https://github.com/helix-editor/helix/pull/8718), [#8827](https://github.com/helix-editor/helix/pull/8827))
|
||||
- Add `polmandres` ([#8759](https://github.com/helix-editor/helix/pull/8759))
|
||||
- Add `starlight` ([#8787](https://github.com/helix-editor/helix/pull/8787))
|
||||
- Update `naysayer` ([#8838](https://github.com/helix-editor/helix/pull/8838))
|
||||
- Add modus operandi themes ([#8728](https://github.com/helix-editor/helix/pull/8728), [#9912](https://github.com/helix-editor/helix/pull/9912))
|
||||
- Update `rose_pine` ([#8946](https://github.com/helix-editor/helix/pull/8946))
|
||||
- Update `darcula` ([#8738](https://github.com/helix-editor/helix/pull/8738), [#9002](https://github.com/helix-editor/helix/pull/9002), [#9449](https://github.com/helix-editor/helix/pull/9449), [#9588](https://github.com/helix-editor/helix/pull/9588))
|
||||
- Add modus vivendi themes ([#8894](https://github.com/helix-editor/helix/pull/8894), [#9912](https://github.com/helix-editor/helix/pull/9912))
|
||||
- Add `horizon-dark` ([#9008](https://github.com/helix-editor/helix/pull/9008), [#9493](https://github.com/helix-editor/helix/pull/9493))
|
||||
- Update `noctis` ([#9123](https://github.com/helix-editor/helix/pull/9123))
|
||||
- Update `nord` ([#9135](https://github.com/helix-editor/helix/pull/9135))
|
||||
- Update monokai pro themes ([#9148](https://github.com/helix-editor/helix/pull/9148))
|
||||
- Update tokyonight themes ([#9099](https://github.com/helix-editor/helix/pull/9099), [#9724](https://github.com/helix-editor/helix/pull/9724), [#9789](https://github.com/helix-editor/helix/pull/9789))
|
||||
- Add `ttox` ([#8524](https://github.com/helix-editor/helix/pull/8524))
|
||||
- Add `voxed` ([#9164](https://github.com/helix-editor/helix/pull/9164))
|
||||
- Update `sonokai` ([#9370](https://github.com/helix-editor/helix/pull/9370), [#9376](https://github.com/helix-editor/helix/pull/9376), [#5379](https://github.com/helix-editor/helix/pull/5379))
|
||||
- Update `onedark`, `onedarker` ([#9397](https://github.com/helix-editor/helix/pull/9397))
|
||||
- Update `cyan_light` ([#9375](https://github.com/helix-editor/helix/pull/9375), [#9688](https://github.com/helix-editor/helix/pull/9688))
|
||||
- Add `gruvbox_light_soft`, `gruvbox_light_hard` ([#9266](https://github.com/helix-editor/helix/pull/9266))
|
||||
- Update GitHub themes ([#9487](https://github.com/helix-editor/helix/pull/9487))
|
||||
- Add `term16_dark`, `term16_light` ([#9477](https://github.com/helix-editor/helix/pull/9477))
|
||||
- Update Zed themes ([#9544](https://github.com/helix-editor/helix/pull/9544), [#9549](https://github.com/helix-editor/helix/pull/9549))
|
||||
- Add `curzon` ([#9553](https://github.com/helix-editor/helix/pull/9553))
|
||||
- Add `monokai_soda` ([#9651](https://github.com/helix-editor/helix/pull/9651))
|
||||
- Update catppuccin themes ([#9859](https://github.com/helix-editor/helix/pull/9859))
|
||||
- Update `rasmus` ([#9939](https://github.com/helix-editor/helix/pull/9939))
|
||||
- Update `dark_plus` ([#9949](https://github.com/helix-editor/helix/pull/9949), [628dcd5](https://github.com/helix-editor/helix/commit/628dcd5))
|
||||
- Update gruvbox themes ([#9960](https://github.com/helix-editor/helix/pull/9960))
|
||||
- Add jump label theming to `dracula` ([#9973](https://github.com/helix-editor/helix/pull/9973))
|
||||
- Add jump label theming to `horizon-dark` ([#9984](https://github.com/helix-editor/helix/pull/9984))
|
||||
- Add jump label theming to catppuccin themes ([2178adf](https://github.com/helix-editor/helix/commit/2178adf), [#9983](https://github.com/helix-editor/helix/pull/9983))
|
||||
- Add jump label theming to `onedark` themes ([da2dec1](https://github.com/helix-editor/helix/commit/da2dec1))
|
||||
- Add jump label theming to rose-pine themes ([#9981](https://github.com/helix-editor/helix/pull/9981))
|
||||
- Add jump label theming to Nord themes ([#10008](https://github.com/helix-editor/helix/pull/10008))
|
||||
- Add jump label theming to Monokai themes ([#10009](https://github.com/helix-editor/helix/pull/10009))
|
||||
- Add jump label theming to gruvbox themes ([#10012](https://github.com/helix-editor/helix/pull/10012))
|
||||
- Add jump label theming to `kanagawa` ([#10030](https://github.com/helix-editor/helix/pull/10030))
|
||||
- Update material themes ([#10043](https://github.com/helix-editor/helix/pull/10043))
|
||||
- Add `jetbrains_dark` ([#9967](https://github.com/helix-editor/helix/pull/9967))
|
||||
|
||||
New languages:
|
||||
|
||||
- Typst ([#7474](https://github.com/helix-editor/helix/pull/7474))
|
||||
- LPF ([#8536](https://github.com/helix-editor/helix/pull/8536))
|
||||
- GN ([#6969](https://github.com/helix-editor/helix/pull/6969))
|
||||
- DBML ([#8860](https://github.com/helix-editor/helix/pull/8860))
|
||||
- log ([#8916](https://github.com/helix-editor/helix/pull/8916))
|
||||
- Janet ([#9081](https://github.com/helix-editor/helix/pull/9081), [#9247](https://github.com/helix-editor/helix/pull/9247))
|
||||
- Agda ([#8285](https://github.com/helix-editor/helix/pull/8285))
|
||||
- Avro ([#9113](https://github.com/helix-editor/helix/pull/9113))
|
||||
- Smali ([#9089](https://github.com/helix-editor/helix/pull/9089))
|
||||
- HOCON ([#9203](https://github.com/helix-editor/helix/pull/9203))
|
||||
- Tact ([#9512](https://github.com/helix-editor/helix/pull/9512))
|
||||
- PKL ([#9515](https://github.com/helix-editor/helix/pull/9515))
|
||||
- CEL ([#9296](https://github.com/helix-editor/helix/pull/9296))
|
||||
- SpiceDB ([#9296](https://github.com/helix-editor/helix/pull/9296))
|
||||
- Hoon ([#9190](https://github.com/helix-editor/helix/pull/9190))
|
||||
- DockerCompose ([#9661](https://github.com/helix-editor/helix/pull/9661), [#9916](https://github.com/helix-editor/helix/pull/9916))
|
||||
- Groovy ([#9350](https://github.com/helix-editor/helix/pull/9350), [#9681](https://github.com/helix-editor/helix/pull/9681), [#9677](https://github.com/helix-editor/helix/pull/9677))
|
||||
- FIDL ([#9713](https://github.com/helix-editor/helix/pull/9713))
|
||||
- Powershell ([#9827](https://github.com/helix-editor/helix/pull/9827))
|
||||
- ld ([#9835](https://github.com/helix-editor/helix/pull/9835))
|
||||
- Hyperland config ([#9899](https://github.com/helix-editor/helix/pull/9899))
|
||||
- JSONC ([#9906](https://github.com/helix-editor/helix/pull/9906))
|
||||
- PHP Blade ([#9513](https://github.com/helix-editor/helix/pull/9513))
|
||||
- SuperCollider ([#9329](https://github.com/helix-editor/helix/pull/9329))
|
||||
- Koka ([#8727](https://github.com/helix-editor/helix/pull/8727))
|
||||
- PKGBUILD ([#9909](https://github.com/helix-editor/helix/pull/9909), [#9943](https://github.com/helix-editor/helix/pull/9943))
|
||||
- Ada ([#9908](https://github.com/helix-editor/helix/pull/9908))
|
||||
- Helm charts ([#9900](https://github.com/helix-editor/helix/pull/9900))
|
||||
- Ember.js templates ([#9902](https://github.com/helix-editor/helix/pull/9902))
|
||||
- Ohm ([#9991](https://github.com/helix-editor/helix/pull/9991))
|
||||
|
||||
Updated languages and queries:
|
||||
|
||||
- Add HTML injection queries for Rust ([#8603](https://github.com/helix-editor/helix/pull/8603))
|
||||
- Switch to tree-sitter-ron for RON ([#8624](https://github.com/helix-editor/helix/pull/8624))
|
||||
- Update and improve comment highlighting ([#8564](https://github.com/helix-editor/helix/pull/8564), [#9253](https://github.com/helix-editor/helix/pull/9253), [#9800](https://github.com/helix-editor/helix/pull/9800), [#10014](https://github.com/helix-editor/helix/pull/10014))
|
||||
- Highlight type parameters in Rust ([#8660](https://github.com/helix-editor/helix/pull/8660))
|
||||
- Change KDL tree-sitter parsers ([#8652](https://github.com/helix-editor/helix/pull/8652))
|
||||
- Update tree-sitter-markdown ([#8721](https://github.com/helix-editor/helix/pull/8721), [#10039](https://github.com/helix-editor/helix/pull/10039))
|
||||
- Update tree-sitter-purescript ([#8712](https://github.com/helix-editor/helix/pull/8712))
|
||||
- Add type parameter highlighting to TypeScript, Go, Haskell, OCaml and Kotlin ([#8718](https://github.com/helix-editor/helix/pull/8718))
|
||||
- Add indentation queries for Scheme and lisps using tree-sitter-scheme ([#8720](https://github.com/helix-editor/helix/pull/8720))
|
||||
- Recognize `meson_options.txt` as Meson ([#8794](https://github.com/helix-editor/helix/pull/8794))
|
||||
- Add language server configuration for Nushell ([#8878](https://github.com/helix-editor/helix/pull/8878))
|
||||
- Recognize `musicxml` as XML ([#8935](https://github.com/helix-editor/helix/pull/8935))
|
||||
- Update tree-sitter-rescript ([#8962](https://github.com/helix-editor/helix/pull/8962))
|
||||
- Update tree-sitter-python ([#8976](https://github.com/helix-editor/helix/pull/8976))
|
||||
- Recognize `.envrc.local` and `.envrc.private` as env ([#8988](https://github.com/helix-editor/helix/pull/8988))
|
||||
- Update tree-sitter-gleam ([#9003](https://github.com/helix-editor/helix/pull/9003), [9ceeea5](https://github.com/helix-editor/helix/commit/9ceeea5))
|
||||
- Update tree-sitter-d ([#9021](https://github.com/helix-editor/helix/pull/9021))
|
||||
- Fix R-markdown language name for LSP detection ([#9012](https://github.com/helix-editor/helix/pull/9012))
|
||||
- Add haskell-language-server LSP configuration ([#9111](https://github.com/helix-editor/helix/pull/9111))
|
||||
- Recognize `glif` as XML ([#9130](https://github.com/helix-editor/helix/pull/9130))
|
||||
- Recognize `.prettierrc` as JSON ([#9214](https://github.com/helix-editor/helix/pull/9214))
|
||||
- Add auto-pairs configuration for scheme ([#9232](https://github.com/helix-editor/helix/pull/9232))
|
||||
- Add textobject queries for Scala ([#9191](https://github.com/helix-editor/helix/pull/9191))
|
||||
- Add textobject queries for Protobuf ([#9184](https://github.com/helix-editor/helix/pull/9184))
|
||||
- Update tree-sitter-wren ([#8544](https://github.com/helix-editor/helix/pull/8544))
|
||||
- Add `spago.yaml` as an LSP root for PureScript ([#9362](https://github.com/helix-editor/helix/pull/9362))
|
||||
- Improve highlight and indent queries for Bash, Make and CSS ([#9393](https://github.com/helix-editor/helix/pull/9393))
|
||||
- Update tree-sitter-scala ([#9348](https://github.com/helix-editor/helix/pull/9348), [#9340](https://github.com/helix-editor/helix/pull/9340), [#9475](https://github.com/helix-editor/helix/pull/9475))
|
||||
- Recognize `.bash_history` as Bash ([#9401](https://github.com/helix-editor/helix/pull/9401))
|
||||
- Recognize Helix ignore files as ignore ([#9447](https://github.com/helix-editor/helix/pull/9447))
|
||||
- Inject SQL into Scala SQL strings ([#9428](https://github.com/helix-editor/helix/pull/9428))
|
||||
- Update gdscript textobjects ([#9288](https://github.com/helix-editor/helix/pull/9288))
|
||||
- Update Go queries ([#9510](https://github.com/helix-editor/helix/pull/9510), [#9525](https://github.com/helix-editor/helix/pull/9525))
|
||||
- Update tree-sitter-nushell ([#9502](https://github.com/helix-editor/helix/pull/9502))
|
||||
- Update tree-sitter-unison, add indent queries ([#9505](https://github.com/helix-editor/helix/pull/9505))
|
||||
- Update tree-sitter-slint ([#9551](https://github.com/helix-editor/helix/pull/9551), [#9698](https://github.com/helix-editor/helix/pull/9698))
|
||||
- Update tree-sitter-swift ([#9586](https://github.com/helix-editor/helix/pull/9586))
|
||||
- Add `fish_indent` as formatter for fish ([78ed3ad](https://github.com/helix-editor/helix/commit/78ed3ad))
|
||||
- Recognize `zon` as Zig ([#9582](https://github.com/helix-editor/helix/pull/9582))
|
||||
- Add a formatter for Odin ([#9537](https://github.com/helix-editor/helix/pull/9537))
|
||||
- Update tree-sitter-erlang ([#9627](https://github.com/helix-editor/helix/pull/9627), [fdcd461](https://github.com/helix-editor/helix/commit/fdcd461))
|
||||
- Capture Rust fields as argument textobjects ([#9637](https://github.com/helix-editor/helix/pull/9637))
|
||||
- Improve Dart textobjects ([#9644](https://github.com/helix-editor/helix/pull/9644))
|
||||
- Recognize `tmux.conf` as a bash file-type ([#9653](https://github.com/helix-editor/helix/pull/9653))
|
||||
- Add textobjects queries for Nix ([#9659](https://github.com/helix-editor/helix/pull/9659))
|
||||
- Add textobjects queries for HCL ([#9658](https://github.com/helix-editor/helix/pull/9658))
|
||||
- Recognize osm and osc extensions as XML ([#9697](https://github.com/helix-editor/helix/pull/9697))
|
||||
- Update tree-sitter-sql ([#9634](https://github.com/helix-editor/helix/pull/9634))
|
||||
- Recognize pde Processing files as Java ([#9741](https://github.com/helix-editor/helix/pull/9741))
|
||||
- Update tree-sitter-lua ([#9727](https://github.com/helix-editor/helix/pull/9727))
|
||||
- Switch tree-sitter-nim parsers ([#9722](https://github.com/helix-editor/helix/pull/9722))
|
||||
- Recognize GTK builder ui files as XML ([#9754](https://github.com/helix-editor/helix/pull/9754))
|
||||
- Add configuration for markdown-oxide language server ([#9758](https://github.com/helix-editor/helix/pull/9758))
|
||||
- Add a shebang for elvish ([#9779](https://github.com/helix-editor/helix/pull/9779))
|
||||
- Fix precedence of Svelte TypeScript injection ([#9777](https://github.com/helix-editor/helix/pull/9777))
|
||||
- Recognize common Dockerfile file types ([#9772](https://github.com/helix-editor/helix/pull/9772))
|
||||
- Recognize NUON files as Nu ([#9839](https://github.com/helix-editor/helix/pull/9839))
|
||||
- Add textobjects for Java native functions and constructors ([#9806](https://github.com/helix-editor/helix/pull/9806))
|
||||
- Fix "braket" typeo in JSX highlights ([#9910](https://github.com/helix-editor/helix/pull/9910))
|
||||
- Update tree-sitter-hurl ([#9775](https://github.com/helix-editor/helix/pull/9775))
|
||||
- Add textobjects queries for Vala ([#8541](https://github.com/helix-editor/helix/pull/8541))
|
||||
- Update tree-sitter-git-config ([9610254](https://github.com/helix-editor/helix/commit/9610254))
|
||||
- Recognize 'mmd' as Mermaid ([459eb9a](https://github.com/helix-editor/helix/commit/459eb9a))
|
||||
- Highlight Rust extern crate aliases ([c099dde](https://github.com/helix-editor/helix/commit/c099dde))
|
||||
- Improve parameter highlighting in C++ ([f5d95de](https://github.com/helix-editor/helix/commit/f5d95de))
|
||||
- Recognize 'rclone.conf' as INI ([#9959](https://github.com/helix-editor/helix/pull/9959))
|
||||
- Add injections for GraphQL and ERB in Ruby heredocs ([#10036](https://github.com/helix-editor/helix/pull/10036))
|
||||
- Add `main.odin` to Odin LSP roots ([#9968](https://github.com/helix-editor/helix/pull/9968))
|
||||
|
||||
Packaging:
|
||||
|
||||
- Allow user overlays in Nix grammars build ([#8749](https://github.com/helix-editor/helix/pull/8749))
|
||||
- Set Cargo feature resolver to v2 ([#8917](https://github.com/helix-editor/helix/pull/8917))
|
||||
- Use workspace inheritance for common Cargo metadata ([#8925](https://github.com/helix-editor/helix/pull/8925))
|
||||
- Remove sourcehut-based tree-sitter grammars from default build ([#9316](https://github.com/helix-editor/helix/pull/9316), [#9326](https://github.com/helix-editor/helix/pull/9326))
|
||||
- Add icon to Windows executable ([#9104](https://github.com/helix-editor/helix/pull/9104))
|
||||
|
||||
# 23.10 (2023-10-24)
|
||||
|
||||
A big shout out to all the contributors! We had 118 contributors in this release.
|
||||
|
||||
Breaking changes:
|
||||
|
||||
- Support multiple language servers per language ([#2507](https://github.com/helix-editor/helix/pull/2507))
|
||||
- This is a breaking change to language configuration
|
||||
|
||||
Features:
|
||||
|
||||
- Support multiple language servers per language ([#2507](https://github.com/helix-editor/helix/pull/2507), [#7082](https://github.com/helix-editor/helix/pull/7082), [#7286](https://github.com/helix-editor/helix/pull/7286), [#8374](https://github.com/helix-editor/helix/pull/8374))
|
||||
- Add a statusline element for the selected register ([#7222](https://github.com/helix-editor/helix/pull/7222))
|
||||
- Add `%`, `#`, `.`, `*` and `+` special registers ([#6985](https://github.com/helix-editor/helix/pull/6985))
|
||||
- Add initial support for LSP DidChangeWatchedFiles notifications ([#7665](https://github.com/helix-editor/helix/pull/7665))
|
||||
- Search buffer contents in `global_search` ([#5652](https://github.com/helix-editor/helix/pull/5652))
|
||||
- Add a "smart tab" command that intelligently jumps the cursor on tab ([#4443](https://github.com/helix-editor/helix/pull/4443))
|
||||
- Add a statusline element for whether a file is read-only ([#7222](https://github.com/helix-editor/helix/pull/7222), [#7875](https://github.com/helix-editor/helix/pull/7875))
|
||||
- Syntax highlight regex prompts ([#7738](https://github.com/helix-editor/helix/pull/7738))
|
||||
- Allow defining alignment in indent queries ([#5355](https://github.com/helix-editor/helix/pull/5355))
|
||||
- Show visual feedback in `surround_replace` ([#7588](https://github.com/helix-editor/helix/pull/7588))
|
||||
- Switch to Nucleo for fuzzy matching ([#7814](https://github.com/helix-editor/helix/pull/7814), [#8148](https://github.com/helix-editor/helix/pull/8148), [#8192](https://github.com/helix-editor/helix/pull/8192), [#8194](https://github.com/helix-editor/helix/pull/8194))
|
||||
- Insert a trailing newline on write ([#8157](https://github.com/helix-editor/helix/pull/8157))
|
||||
- Add a `-w`/`--working-dir` CLI flag for specifying a working directory on startup ([#8223](https://github.com/helix-editor/helix/pull/8223), [#8498](https://github.com/helix-editor/helix/pull/8498), [#8520](https://github.com/helix-editor/helix/pull/8520))
|
||||
- Accept a `+N` CLI argument to set the first file's line number ([#8521](https://github.com/helix-editor/helix/pull/8521))
|
||||
- Accept Helix-specific ignore files in `.helix/ignore` and `~/.config/helix/ignore` ([#8099](https://github.com/helix-editor/helix/pull/8099))
|
||||
|
||||
Commands:
|
||||
|
||||
- `merge_selections` (`A-minus`) - merge all selections into one selection that covers all ranges ([#7053](https://github.com/helix-editor/helix/pull/7053))
|
||||
- `move_prev_long_word_end` and `extend_prev_long_word_end` - move/extend to the end of the previous WORD ([#6905](https://github.com/helix-editor/helix/pull/6905))
|
||||
- `reverse_selection_contents` - swaps the values of each selection so they are reversed ([#7329](https://github.com/helix-editor/helix/pull/7329))
|
||||
- Add `:rl` and `:rla` aliases for `:reload` and `:reload-all` ([#7158](https://github.com/helix-editor/helix/pull/7158))
|
||||
- `yank_joined` - join the selections and yank to the selected register ([#7195](https://github.com/helix-editor/helix/pull/7195))
|
||||
- `:write-all!` (`:wa!`) - forcibly write all buffers to disk and create any necessary subdirectories ([#7577](https://github.com/helix-editor/helix/pull/7577))
|
||||
- `:redraw` - clear re-render the UI ([#6949](https://github.com/helix-editor/helix/pull/6949))
|
||||
- `:tree-sitter-highlight-name` - show the theme scope name of the highlight under the cursor ([#8170](https://github.com/helix-editor/helix/pull/8170))
|
||||
|
||||
Usability improvements:
|
||||
|
||||
- Allow cycling option values at runtime ([#4411](https://github.com/helix-editor/helix/pull/4411), [#7240](https://github.com/helix-editor/helix/pull/7240), [#7877](https://github.com/helix-editor/helix/pull/7877))
|
||||
- Exit gracefully on termination signals ([#7236](https://github.com/helix-editor/helix/pull/7236))
|
||||
- Add plaintext matching fallback to tree-sitter pair matching ([#4288](https://github.com/helix-editor/helix/pull/4288))
|
||||
- Persist register selection in pending keymaps ([0e08349](https://github.com/helix-editor/helix/commit/0e08349))
|
||||
- Propagate the count and register to command palette commands ([b394997](https://github.com/helix-editor/helix/commit/b394997))
|
||||
- Auto indent on `insert_at_line_start` ([#5837](https://github.com/helix-editor/helix/pull/5837))
|
||||
- Add a config option to control whether LSP completions are automatically inserted on preview ([#7189](https://github.com/helix-editor/helix/pull/7189))
|
||||
- Add a config option for default line endings ([#5621](https://github.com/helix-editor/helix/pull/5621), [#7357](https://github.com/helix-editor/helix/pull/7357))
|
||||
- Allow ANSI colors in themes ([#5119](https://github.com/helix-editor/helix/pull/5119))
|
||||
- Match pairs that don't form a standalone tree-sitter node ([#7242](https://github.com/helix-editor/helix/pull/7242))
|
||||
- Allow indent sizes of up to 16 columns ([#7429](https://github.com/helix-editor/helix/pull/7429))
|
||||
- Improve performance of mapping positions through changes ([#7408](https://github.com/helix-editor/helix/pull/7408), [8d39a81](https://github.com/helix-editor/helix/commit/8d39a81), [#7471](https://github.com/helix-editor/helix/pull/7471))
|
||||
- Mark buffers created from stdin as modified ([#7431](https://github.com/helix-editor/helix/pull/7431))
|
||||
- Forcibly shut down uninitialized language servers ([#7449](https://github.com/helix-editor/helix/pull/7449))
|
||||
- Add filename completer for shell prompts ([#7569](https://github.com/helix-editor/helix/pull/7569))
|
||||
- Allow binding F13-F24 ([#7672](https://github.com/helix-editor/helix/pull/7672))
|
||||
- Resolve LSP code actions ([#7677](https://github.com/helix-editor/helix/pull/7677), [#8421](https://github.com/helix-editor/helix/pull/8421))
|
||||
- Save an undo checkpoint before accepting completions ([#7747](https://github.com/helix-editor/helix/pull/7747))
|
||||
- Include gitignored files in debugger completions ([#7936](https://github.com/helix-editor/helix/pull/7936))
|
||||
- Make editor remember the last search register ([#5244](https://github.com/helix-editor/helix/pull/5244))
|
||||
- Open directories with `goto_file` ([#7909](https://github.com/helix-editor/helix/pull/7909))
|
||||
- Use relative path to open buffer in `goto_file` (`gf`) ([#7965](https://github.com/helix-editor/helix/pull/7965))
|
||||
- Support `default` color in themes ([#8083](https://github.com/helix-editor/helix/pull/8083), [#8114](https://github.com/helix-editor/helix/pull/8114))
|
||||
- Toggle between relative and absolute line numbers when the terminal loses focus ([#7955](https://github.com/helix-editor/helix/pull/7955))
|
||||
- Lower default idle-timeout to 250ms ([060e73a](https://github.com/helix-editor/helix/commit/060e73a))
|
||||
- Allow theming diff gutters separately from other diff colors ([#8343](https://github.com/helix-editor/helix/pull/8343))
|
||||
- Style bold/italic/strikethrough in markdown doc popups ([#8385](https://github.com/helix-editor/helix/pull/8385))
|
||||
- Maintain the cursor position and view when splitting with `:hsplit`/`:vsplit` ([#8109](https://github.com/helix-editor/helix/pull/8109))
|
||||
- Accept `-` in macros outside of `<`/`>` ([#8475](https://github.com/helix-editor/helix/pull/8475))
|
||||
- Show all language servers for each language in `--health` ([#7315](https://github.com/helix-editor/helix/pull/7315))
|
||||
- Don't break on hyphens in `:reflow` ([#8569](https://github.com/helix-editor/helix/pull/8569))
|
||||
|
||||
Fixes:
|
||||
|
||||
- Update diagnostics correctly on language server exit ([#7111](https://github.com/helix-editor/helix/pull/7111))
|
||||
- Fix off-by-one in `select_references_to_symbol_under_cursor` ([#7132](https://github.com/helix-editor/helix/pull/7132))
|
||||
- Extend selection with repeat-last-motion only if the original motion extended the selection ([#7159](https://github.com/helix-editor/helix/pull/7159))
|
||||
- Fix undefined behavior in the diff gutter ([#7227](https://github.com/helix-editor/helix/pull/7227))
|
||||
- Check that tab width is non-zero ([#7178](https://github.com/helix-editor/helix/pull/7178))
|
||||
- Fix styles being overwritten in table rows with multiple cells ([#7281](https://github.com/helix-editor/helix/pull/7281))
|
||||
- Add file for `--log` CLI arg in help text ([#7307](https://github.com/helix-editor/helix/pull/7307))
|
||||
- Fix underflow when repeating a completion that has a negative shift position ([#7322](https://github.com/helix-editor/helix/pull/7322))
|
||||
- Prefer longer matches in `select_next_sibling` and `select_prev_sibling` ([#7332](https://github.com/helix-editor/helix/pull/7332))
|
||||
- Preview scratch buffers in the jumplist picker ([#7331](https://github.com/helix-editor/helix/pull/7331))
|
||||
- Fix chunking by bytes in tree-sitter parsing ([#7417](https://github.com/helix-editor/helix/pull/7417))
|
||||
- Discard LSP publishDiagnostic from uninitialized servers ([#7467](https://github.com/helix-editor/helix/pull/7467))
|
||||
- Use negotiated position encoding for LSP workspace edits ([#7469](https://github.com/helix-editor/helix/pull/7469))
|
||||
- Fix error message for unknown gutter types in config ([#7534](https://github.com/helix-editor/helix/pull/7534))
|
||||
- Fix `:log-open` when `--log` CLI arg is specified ([#7573](https://github.com/helix-editor/helix/pull/7573), [#7585](https://github.com/helix-editor/helix/pull/7585))
|
||||
- Fix debouncing of LSP messages to fix the last message sticking around ([#7538](https://github.com/helix-editor/helix/pull/7538), [#8023](https://github.com/helix-editor/helix/pull/8023))
|
||||
- Fix crash when the current working directory is deleted ([#7185](https://github.com/helix-editor/helix/pull/7185))
|
||||
- Fix piping to Helix on macOS ([#5468](https://github.com/helix-editor/helix/pull/5468))
|
||||
- Fix crash when parsing overlapping injections ([#7621](https://github.com/helix-editor/helix/pull/7621))
|
||||
- Clear the statusline when the prompt is visible ([#7646](https://github.com/helix-editor/helix/pull/7646))
|
||||
- Fix range formatting error message typo ([#7823](https://github.com/helix-editor/helix/pull/7823))
|
||||
- Skip rendering gutters when gutter width exceeds view width ([#7821](https://github.com/helix-editor/helix/pull/7821))
|
||||
- Center the picker preview using visual lines ([#7837](https://github.com/helix-editor/helix/pull/7837))
|
||||
- Align view correctly for background buffers opened with `A-ret` ([#7691](https://github.com/helix-editor/helix/pull/7691))
|
||||
- Fix cursor resetting to block when quitting via a keybind ([#7931](https://github.com/helix-editor/helix/pull/7931))
|
||||
- Remove path completions for the `:new` command ([#8010](https://github.com/helix-editor/helix/pull/8010))
|
||||
- Use binary path resolved by `which` for formatter commands ([#8064](https://github.com/helix-editor/helix/pull/8064))
|
||||
- Handle crossterm's `hidden` modifier ([#8120](https://github.com/helix-editor/helix/pull/8120))
|
||||
- Clear completion when switching between windows with the mouse ([#8118](https://github.com/helix-editor/helix/pull/8118))
|
||||
- Eagerly remove the last picker (`<space>'`) when the picker has many items ([#8127](https://github.com/helix-editor/helix/pull/8127))
|
||||
- Fix find commands for buffers with non-LF line-endings ([#8111](https://github.com/helix-editor/helix/pull/8111))
|
||||
- Detect the tmux clipboard provider on macOS ([#8182](https://github.com/helix-editor/helix/pull/8182))
|
||||
- Fix syntax highlighting in dynamic picker preview pane ([#8206](https://github.com/helix-editor/helix/pull/8206))
|
||||
- Recognize HTML code tags with attributes as code in markdown previews ([#8397](https://github.com/helix-editor/helix/pull/8397))
|
||||
- Fix multicursor snippet placeholder directions ([#8423](https://github.com/helix-editor/helix/pull/8423))
|
||||
- Only show diagnostic highlights when diagnostics are enabled for a language server ([#8551](https://github.com/helix-editor/helix/pull/8551))
|
||||
|
||||
Themes:
|
||||
|
||||
- Improve the selection color in `ferra` ([#7138](https://github.com/helix-editor/helix/pull/7138))
|
||||
- Add `variable.other.member` theming to `spacebones_light` ([#7125](https://github.com/helix-editor/helix/pull/7125))
|
||||
- Update `autumn` and theme the soft-wrap indicator ([#7229](https://github.com/helix-editor/helix/pull/7229))
|
||||
- Add `gruvbox_dark_soft` ([#7139](https://github.com/helix-editor/helix/pull/7139))
|
||||
- Add `merionette` ([#7186](https://github.com/helix-editor/helix/pull/7186))
|
||||
- Add `zed_onedark` and `zed_onelight` ([#7250](https://github.com/helix-editor/helix/pull/7250))
|
||||
- Use light-gray for `onedarker` inlay hint theming ([#7433](https://github.com/helix-editor/helix/pull/7433))
|
||||
- Update the Nord theme to follow the style guidelines ([#7490](https://github.com/helix-editor/helix/pull/7490))
|
||||
- Tune `dark_plus` inlay hint colors ([#7611](https://github.com/helix-editor/helix/pull/7611))
|
||||
- Add `naysayer` ([#7570](https://github.com/helix-editor/helix/pull/7570))
|
||||
- Add `kaolin-dark`, `kaolin-light` and `kaolin-valley-dark` ([#7151](https://github.com/helix-editor/helix/pull/7151))
|
||||
- Fix selection highlighting in gruvbox variants ([#7717](https://github.com/helix-editor/helix/pull/7717))
|
||||
- Add soft-wrap indicator to `gruvbox` ([#7736](https://github.com/helix-editor/helix/pull/7736))
|
||||
- Add missing palette definitions in `everforest_dark` ([#7739](https://github.com/helix-editor/helix/pull/7739))
|
||||
- Increase diagnostics clarity in `pop-dark` ([#7702](https://github.com/helix-editor/helix/pull/7702))
|
||||
- Add `vim_dark_high_contrast` ([#7785](https://github.com/helix-editor/helix/pull/7785))
|
||||
- Add `new_moon` ([#7834](https://github.com/helix-editor/helix/pull/7834))
|
||||
- Add `yellowed` ([#7849](https://github.com/helix-editor/helix/pull/7849))
|
||||
- Improve comment readability for `autumn` ([#7939](https://github.com/helix-editor/helix/pull/7939))
|
||||
- Distinguish active bufferline buffer in `monokai` ([#7983](https://github.com/helix-editor/helix/pull/7983))
|
||||
- Update ruler colors in `nord` ([#7995](https://github.com/helix-editor/helix/pull/7995))
|
||||
- Update Catppuccin themes ([#8102](https://github.com/helix-editor/helix/pull/8102))
|
||||
- Add text focus scope and diagnostics undercurls for `nord` ([#8165](https://github.com/helix-editor/helix/pull/8165))
|
||||
- Add material theme collection ([#8211](https://github.com/helix-editor/helix/pull/8211))
|
||||
- Improve indent line color in `dracula` ([#8266](https://github.com/helix-editor/helix/pull/8266))
|
||||
- Clean up and refactor `papercolor` to use inheritance ([#8276](https://github.com/helix-editor/helix/pull/8276))
|
||||
- Fix `zenburn` inlay hint color ([#8278](https://github.com/helix-editor/helix/pull/8278)a)
|
||||
- Fix picker crash when previewing an invalid range ([e9d0bd7](https://github.com/helix-editor/helix/commit/e9d0bd7))
|
||||
- Correctly center items in the picker preview ([13d4463](https://github.com/helix-editor/helix/commit/13d4463))
|
||||
- Add `cyan_light` ([#8293](https://github.com/helix-editor/helix/pull/8293), [#8587](https://github.com/helix-editor/helix/pull/8587))
|
||||
- Theme HTML tags in `onedark` ([#8409](https://github.com/helix-editor/helix/pull/8409))
|
||||
- Refine `darcula` and `darcula-solid` themes ([#8412](https://github.com/helix-editor/helix/pull/8412))
|
||||
- Improve `nord` highlights ([#8414](https://github.com/helix-editor/helix/pull/8414))
|
||||
- Add `nord-night` ([#8549](https://github.com/helix-editor/helix/pull/8549))
|
||||
|
||||
New languages:
|
||||
|
||||
- Blueprint ([#7213](https://github.com/helix-editor/helix/pull/7213), [#8161](https://github.com/helix-editor/helix/pull/8161))
|
||||
- Forth ([#7256](https://github.com/helix-editor/helix/pull/7256), [#7334](https://github.com/helix-editor/helix/pull/7334))
|
||||
- t32 ([#7140](https://github.com/helix-editor/helix/pull/7140), [#7811](https://github.com/helix-editor/helix/pull/7811))
|
||||
- WebC ([#7290](https://github.com/helix-editor/helix/pull/7290))
|
||||
- Persistent DSL for Haskell ([#7261](https://github.com/helix-editor/helix/pull/7261))
|
||||
- F# ([#7619](https://github.com/helix-editor/helix/pull/7619), [#8024](https://github.com/helix-editor/helix/pull/8024))
|
||||
- Wren ([#7765](https://github.com/helix-editor/helix/pull/7765), [#7819](https://github.com/helix-editor/helix/pull/7819))
|
||||
- Unison ([#7724](https://github.com/helix-editor/helix/pull/7724))
|
||||
- Todo.txt ([#7835](https://github.com/helix-editor/helix/pull/7835))
|
||||
- Jinja and Handlebars ([#7233](https://github.com/helix-editor/helix/pull/7233))
|
||||
- Pod ([#7907](https://github.com/helix-editor/helix/pull/7907))
|
||||
- Strace ([#7928](https://github.com/helix-editor/helix/pull/7928))
|
||||
- Gemini ([#8070](https://github.com/helix-editor/helix/pull/8070))
|
||||
- GNU Assembler (GAS) ([#8291](https://github.com/helix-editor/helix/pull/8291))
|
||||
- JSON5 ([#8473](https://github.com/helix-editor/helix/pull/8473))
|
||||
- TEMPL ([#8540](https://github.com/helix-editor/helix/pull/8540))
|
||||
|
||||
Updated languages and queries:
|
||||
|
||||
- Add one to the ruler numbers for git-commit ([#7072](https://github.com/helix-editor/helix/pull/7072))
|
||||
- Recognize XAML files as XML ([#7083](https://github.com/helix-editor/helix/pull/7083))
|
||||
- Recognize `Cargo.lock` as TOML ([#7095](https://github.com/helix-editor/helix/pull/7095))
|
||||
- Use Rust grammar for Cairo ([c6d1430](https://github.com/helix-editor/helix/commit/c6d1430))
|
||||
- Update tree-sitter-nickel ([#7059](https://github.com/helix-editor/helix/pull/7059), [#7551](https://github.com/helix-editor/helix/pull/7551))
|
||||
- Tune auto-pair characters for Nickel ([#7059](https://github.com/helix-editor/helix/pull/7059))
|
||||
- Recognize `Vagrantfile` as Ruby ([#7112](https://github.com/helix-editor/helix/pull/7112))
|
||||
- Recognize hidden justfiles as Just ([#7088](https://github.com/helix-editor/helix/pull/7088))
|
||||
- Update Java and TypeScript highlight queries ([#7145](https://github.com/helix-editor/helix/pull/7145))
|
||||
- Recognize `.zimrc` as Bash ([#7146](https://github.com/helix-editor/helix/pull/7146))
|
||||
- Recognize `.gir` as XML ([#7152](https://github.com/helix-editor/helix/pull/7152))
|
||||
- Update tree-sitter-scala ([#7147](https://github.com/helix-editor/helix/pull/7147))
|
||||
- Recognize make file-type as Makefile ([#7212](https://github.com/helix-editor/helix/pull/7212))
|
||||
- Update tree-sitter-verilog ([#7262](https://github.com/helix-editor/helix/pull/7262))
|
||||
- Update tree-sitter-cpp ([#7285](https://github.com/helix-editor/helix/pull/7285))
|
||||
- Support core mode for delve debugger ([#7300](https://github.com/helix-editor/helix/pull/7300))
|
||||
- Add Fortran comment injections ([#7305](https://github.com/helix-editor/helix/pull/7305))
|
||||
- Switch Vue language server to `vue-language-server` ([#7312](https://github.com/helix-editor/helix/pull/7312))
|
||||
- Update tree-sitter-sql ([#7387](https://github.com/helix-editor/helix/pull/7387), [#8464](https://github.com/helix-editor/helix/pull/8464))
|
||||
- Replace the MATLAB tre-sitter grammar ([#7388](https://github.com/helix-editor/helix/pull/7388), [#7442](https://github.com/helix-editor/helix/pull/7442), [#7491](https://github.com/helix-editor/helix/pull/7491), [#7493](https://github.com/helix-editor/helix/pull/7493), [#7511](https://github.com/helix-editor/helix/pull/7511), [#7532](https://github.com/helix-editor/helix/pull/7532), [#8040](https://github.com/helix-editor/helix/pull/8040))
|
||||
- Highlight TOML table headers ([#7441](https://github.com/helix-editor/helix/pull/7441))
|
||||
- Recognize `cppm` file-type as C++ ([#7492](https://github.com/helix-editor/helix/pull/7492))
|
||||
- Refactor ecma language queries into private and public queries ([#7207](https://github.com/helix-editor/helix/pull/7207))
|
||||
- Update tree-sitter-dart ([#7576](https://github.com/helix-editor/helix/pull/7576))
|
||||
- Add shebang for nushell files ([#7606](https://github.com/helix-editor/helix/pull/7606))
|
||||
- Recognize systemd files as INI ([#7592](https://github.com/helix-editor/helix/pull/7592))
|
||||
- Update TypeScript, TSX and Svelte grammars ([#6874](https://github.com/helix-editor/helix/pull/6874))
|
||||
- Enable inlay hints in the Svelte language server ([#7622](https://github.com/helix-editor/helix/pull/7622))
|
||||
- Recognize `Brewfile`s as Ruby ([#7629](https://github.com/helix-editor/helix/pull/7629))
|
||||
- Add more file-types for R ([#7633](https://github.com/helix-editor/helix/pull/7633))
|
||||
- Switch tree-sitter-perl to official upstream parser ([#7644](https://github.com/helix-editor/helix/pull/7644), [#7947](https://github.com/helix-editor/helix/pull/7947))
|
||||
- Fix predicate typo in comment highlights ([#7732](https://github.com/helix-editor/helix/pull/7732))
|
||||
- Update tree-sitter-prql ([#7771](https://github.com/helix-editor/helix/pull/7771))
|
||||
- Recognize `.gitf` as JSON ([#7781](https://github.com/helix-editor/helix/pull/7781))
|
||||
- Switch V language server to `v-analyzer` ([#7760](https://github.com/helix-editor/helix/pull/7760))
|
||||
- Add protobuf language servers ([#7796](https://github.com/helix-editor/helix/pull/7796))
|
||||
- Update tree-sitter-zig ([#7803](https://github.com/helix-editor/helix/pull/7803))
|
||||
- Update tree-sitter-hare ([#7784](https://github.com/helix-editor/helix/pull/7784))
|
||||
- Add Java indent queries ([#7844](https://github.com/helix-editor/helix/pull/7844))
|
||||
- Update tree-sitter-scheme ([979933b](https://github.com/helix-editor/helix/commit/979933b))
|
||||
- Recognize `scm` as Scheme instead of TSQ ([5707151](https://github.com/helix-editor/helix/commit/5707151))
|
||||
- Update tree-sitter-git-commit ([#7831](https://github.com/helix-editor/helix/pull/7831))
|
||||
- Update JavaScript, TypeScript and TSX grammars ([#7852](https://github.com/helix-editor/helix/pull/7852))
|
||||
- Update tree-sitter-nu ([#7873](https://github.com/helix-editor/helix/pull/7873))
|
||||
- Fix YAML indentation ([#6768](https://github.com/helix-editor/helix/pull/6768))
|
||||
- Add `csharp-ls`, Pyright, Pylyzer and add roots for Python ([#7897](https://github.com/helix-editor/helix/pull/7897), [#8032](https://github.com/helix-editor/helix/pull/8032))
|
||||
- Update tree-sitter-slint ([#7893](https://github.com/helix-editor/helix/pull/7893))
|
||||
- Recognize more ZSH file-types as Bash ([#7930](https://github.com/helix-editor/helix/pull/7930))
|
||||
- Recognize `star` extension as Starlark ([#7922](https://github.com/helix-editor/helix/pull/7922))
|
||||
- Fix inline HTML tag highlighting in markdown ([#7960](https://github.com/helix-editor/helix/pull/7960))
|
||||
- Update tree-sitter-robot ([#7970](https://github.com/helix-editor/helix/pull/7970))
|
||||
- Highlight Dart 3 `sealed` and `base` keywords ([#7974](https://github.com/helix-editor/helix/pull/7974))
|
||||
- Add configuration for `ltex-ls` to the default `languages.toml` ([#7838](https://github.com/helix-editor/helix/pull/7838))
|
||||
- Update tree-sitter-strace ([#8087](https://github.com/helix-editor/helix/pull/8087))
|
||||
- Update tree-sitter-gleam, enable auto-format ([#8085](https://github.com/helix-editor/helix/pull/8085))
|
||||
- Update tree-sitter-esdl ([#8222](https://github.com/helix-editor/helix/pull/8222))
|
||||
- Expand ignore file-types ([#8220](https://github.com/helix-editor/helix/pull/8220))
|
||||
- Recognize feed related formats as XML ([#8232](https://github.com/helix-editor/helix/pull/8232))
|
||||
- Improve YAML injections ([#8217](https://github.com/helix-editor/helix/pull/8217))
|
||||
- Add shebangs for TypeScript, Julia, Java and OCaml ([95e994a](https://github.com/helix-editor/helix/commit/95e994a))
|
||||
- Highlight abbreviations in Scheme ([ef23847](https://github.com/helix-editor/helix/commit/ef23847))
|
||||
- Remove backtic auto-pair in OCaml ([#8260](https://github.com/helix-editor/helix/pull/8260))
|
||||
- Recognize `flake.lock` as JSON ([#8304](https://github.com/helix-editor/helix/pull/8304))
|
||||
- Add Python test script injection for Nix ([b4494e1](https://github.com/helix-editor/helix/commit/b4494e1))
|
||||
- Fix Nix comment injection precedence ([37e48f4](https://github.com/helix-editor/helix/commit/37e48f4))
|
||||
- Recognize editorconfig files as INI ([#8308](https://github.com/helix-editor/helix/pull/8308))
|
||||
- Recognize `.babelrc` as JSON ([#8309](https://github.com/helix-editor/helix/pull/8309))
|
||||
- Switch Purescript to its own tree-sitter parser ([#8306](https://github.com/helix-editor/helix/pull/8306), [#8338](https://github.com/helix-editor/helix/pull/8338), [#8527](https://github.com/helix-editor/helix/pull/8527))
|
||||
- Update Unison highlights ([#8315](https://github.com/helix-editor/helix/pull/8315))
|
||||
- Recognize `.webmanifest` as JSON ([#8342](https://github.com/helix-editor/helix/pull/8342))
|
||||
- Recognize polkit policy files as XML ([#8369](https://github.com/helix-editor/helix/pull/8369))
|
||||
- Recognize polkit rules files as JavaScript ([#8370](https://github.com/helix-editor/helix/pull/8370))
|
||||
- Update Go highlight queries ([#8399](https://github.com/helix-editor/helix/pull/8399))
|
||||
- Add shebangs for Makefiles ([#8410](https://github.com/helix-editor/helix/pull/8410))
|
||||
- Add file-type associations from VSCode ([#8388](https://github.com/helix-editor/helix/pull/8388))
|
||||
- Add validation to JSON/CSS language server configs ([#8433](https://github.com/helix-editor/helix/pull/8433))
|
||||
- Add a configuration for the tailwind language server ([#8442](https://github.com/helix-editor/helix/pull/8442))
|
||||
- Add a configuration for the ansible language server ([#7973](https://github.com/helix-editor/helix/pull/7973))
|
||||
- Add a configuration for the GraphQL language server ([#8492](https://github.com/helix-editor/helix/pull/8492))
|
||||
- Indent while statements in Bash ([#8528](https://github.com/helix-editor/helix/pull/8528))
|
||||
- Update tree-sitter-haskell and queries ([#8558](https://github.com/helix-editor/helix/pull/8558))
|
||||
|
||||
Packaging:
|
||||
|
||||
- Add an overlay to the Nix flake ([#7078](https://github.com/helix-editor/helix/pull/7078))
|
||||
- Check for `git` before fetching or building grammars ([#7320](https://github.com/helix-editor/helix/pull/7320))
|
||||
- Refactor Nix flake to use Crane ([#7763](https://github.com/helix-editor/helix/pull/7763))
|
||||
- Remove the aarch64 appimage from the release CI ([#7832](https://github.com/helix-editor/helix/pull/7832))
|
||||
- Add desktop and icon files to Nix flake output ([#7979](https://github.com/helix-editor/helix/pull/7979))
|
||||
- Build flake packages with the latest stable Rust ([#8133](https://github.com/helix-editor/helix/pull/8133))
|
||||
|
||||
# 23.05 (2023-05-18)
|
||||
|
||||
23.05 is a smaller release focusing on fixes. There were 88 contributors in this release. Thank you all!
|
||||
@ -1596,7 +2109,7 @@ # 0.2.0
|
||||
|
||||
- The `runtime/` directory is now properly detected on binary releases and
|
||||
on cargo run. `~/.config/helix/runtime` can also be used.
|
||||
- Registers can now be selected via " (for example `"ay`)
|
||||
- Registers can now be selected via " (for example, `"ay`)
|
||||
- Support for Nix files was added
|
||||
- Movement is now fully tested and matches Kakoune implementation
|
||||
- A per-file LSP symbol picker was added to space+s
|
||||
|
1386
Cargo.lock
generated
1386
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
17
Cargo.toml
@ -1,14 +1,17 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"helix-core",
|
||||
"helix-view",
|
||||
"helix-term",
|
||||
"helix-tui",
|
||||
"helix-lsp",
|
||||
"helix-event",
|
||||
"helix-dap",
|
||||
"helix-loader",
|
||||
"helix-vcs",
|
||||
"helix-parsec",
|
||||
"helix-stdx",
|
||||
"xtask",
|
||||
]
|
||||
|
||||
@ -32,3 +35,17 @@ inherits = "test"
|
||||
package.helix-core.opt-level = 2
|
||||
package.helix-tui.opt-level = 2
|
||||
package.helix-term.opt-level = 2
|
||||
|
||||
[workspace.dependencies]
|
||||
tree-sitter = { version = "0.22" }
|
||||
nucleo = "0.2.0"
|
||||
|
||||
[workspace.package]
|
||||
version = "24.3.0"
|
||||
edition = "2021"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
license = "MPL-2.0"
|
||||
rust-version = "1.70"
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
![Screenshot](./screenshot.png)
|
||||
|
||||
A Kakoune / Neovim inspired editor, written in Rust.
|
||||
A [Kakoune](https://github.com/mawww/kakoune) / [Neovim](https://github.com/neovim/neovim) inspired editor, written in Rust.
|
||||
|
||||
The editing model is very heavily based on Kakoune; during development I found
|
||||
myself agreeing with most of Kakoune's design decisions.
|
||||
@ -61,4 +61,4 @@ # Getting help
|
||||
|
||||
# Credits
|
||||
|
||||
Thanks to [@JakeHL](https://github.com/JakeHL) for designing the logo!
|
||||
Thanks to [@jakenvac](https://github.com/jakenvac) for designing the logo!
|
||||
|
@ -28,6 +28,7 @@
|
||||
"label" = "magenta"
|
||||
"namespace" = "magenta"
|
||||
"ui.help" = { fg = "white", bg = "black" }
|
||||
"ui.virtual.jump-label" = { fg = "blue", modifiers = ["bold", "underlined"] }
|
||||
|
||||
"markup.heading" = "blue"
|
||||
"markup.list" = "red"
|
||||
|
@ -3,10 +3,14 @@ authors = ["Blaž Hrastnik"]
|
||||
language = "en"
|
||||
multilingual = false
|
||||
src = "src"
|
||||
edit-url-template = "https://github.com/helix-editor/helix/tree/master/book/{path}?mode=edit"
|
||||
|
||||
[output.html]
|
||||
cname = "docs.helix-editor.com"
|
||||
default-theme = "colibri"
|
||||
preferred-dark-theme = "colibri"
|
||||
git-repository-url = "https://github.com/helix-editor/helix"
|
||||
edit-url-template = "https://github.com/helix-editor/helix/edit/master/book/{path}"
|
||||
additional-css = ["custom.css"]
|
||||
|
||||
[output.html.search]
|
||||
use-boolean-and = true
|
||||
|
231
book/custom.css
Normal file
231
book/custom.css
Normal file
@ -0,0 +1,231 @@
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
|
||||
.sidebar .sidebar-scrollbox {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.chapter {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
line-height: initial;
|
||||
margin: 0;
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
line-height: inherit;
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1,
|
||||
.content h2,
|
||||
.content h3,
|
||||
.content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content p,
|
||||
.content ol,
|
||||
.content ul,
|
||||
.content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
|
||||
.content ul ul,
|
||||
.content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
table td {
|
||||
padding: .75rem;
|
||||
border: none;
|
||||
}
|
||||
|
||||
table thead tr {
|
||||
border: none;
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
|
||||
table tbody tr:nth-child(2n) {
|
||||
background: unset;
|
||||
}
|
||||
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0, 0, 0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
}
|
||||
|
||||
.colibri .content .header {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* highlight.js theme, :where() is used to avoid increasing specificity */
|
||||
|
||||
:where(.colibri) .hljs {
|
||||
background: #2f1e2e;
|
||||
color: #a39e9b;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-comment,
|
||||
:where(.colibri) .hljs-quote {
|
||||
color: #8d8687;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-link,
|
||||
:where(.colibri) .hljs-meta,
|
||||
:where(.colibri) .hljs-name,
|
||||
:where(.colibri) .hljs-regexp,
|
||||
:where(.colibri) .hljs-selector-class,
|
||||
:where(.colibri) .hljs-selector-id,
|
||||
:where(.colibri) .hljs-tag,
|
||||
:where(.colibri) .hljs-template-variable,
|
||||
:where(.colibri) .hljs-variable {
|
||||
color: #ef6155;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-built_in,
|
||||
:where(.colibri) .hljs-deletion,
|
||||
:where(.colibri) .hljs-literal,
|
||||
:where(.colibri) .hljs-number,
|
||||
:where(.colibri) .hljs-params,
|
||||
:where(.colibri) .hljs-type {
|
||||
color: #f99b15;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-attribute,
|
||||
:where(.colibri) .hljs-section,
|
||||
:where(.colibri) .hljs-title {
|
||||
color: #fec418;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-addition,
|
||||
:where(.colibri) .hljs-bullet,
|
||||
:where(.colibri) .hljs-string,
|
||||
:where(.colibri) .hljs-symbol {
|
||||
color: #48b685;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-keyword,
|
||||
:where(.colibri) .hljs-selector-tag {
|
||||
color: #815ba4;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-strong {
|
||||
font-weight: 700;
|
||||
}
|
@ -51,7 +51,9 @@ ### `[editor]` Section
|
||||
| `auto-completion` | Enable automatic pop up of auto-completion | `true` |
|
||||
| `auto-format` | Enable automatic formatting on save | `true` |
|
||||
| `auto-save` | Enable automatic saving on the focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal | `false` |
|
||||
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant | `400` |
|
||||
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. | `250` |
|
||||
| `completion-timeout` | Time in milliseconds after typing a word character before completions are shown, set to 5 for instant. | `250` |
|
||||
| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` |
|
||||
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
|
||||
| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` |
|
||||
| `auto-info` | Whether to display info boxes | `true` |
|
||||
@ -62,6 +64,11 @@ ### `[editor]` Section
|
||||
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
|
||||
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |
|
||||
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` |
|
||||
| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` |
|
||||
| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` |
|
||||
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` |
|
||||
| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid`
|
||||
| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"`
|
||||
|
||||
### `[editor.statusline]` Section
|
||||
|
||||
@ -69,7 +76,7 @@ ### `[editor.statusline]` Section
|
||||
|
||||
The configuration distinguishes between three areas of the status line:
|
||||
|
||||
`[ ... ... LEFT ... ... | ... ... ... ... CENTER ... ... ... ... | ... ... RIGHT ... ... ]`
|
||||
`[ ... ... LEFT ... ... | ... ... ... CENTER ... ... ... | ... ... RIGHT ... ... ]`
|
||||
|
||||
Statusline elements can be defined as follows:
|
||||
|
||||
@ -87,9 +94,9 @@ ### `[editor.statusline]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name"]` |
|
||||
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` |
|
||||
| `center` | A list of elements aligned to the middle of the statusline | `[]` |
|
||||
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "position", "file-encoding"]` |
|
||||
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` |
|
||||
| `separator` | The character used to separate elements in the statusline | `"│"` |
|
||||
| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
|
||||
| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` |
|
||||
@ -102,10 +109,12 @@ ### `[editor.statusline]` Section
|
||||
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
|
||||
| `spinner` | A progress spinner indicating LSP activity |
|
||||
| `file-name` | The path/name of the opened file |
|
||||
| `file-absolute-path` | The absolute path/name of the opened file |
|
||||
| `file-base-name` | The basename of the opened file |
|
||||
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
|
||||
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
|
||||
| `file-line-ending` | The file line endings (CRLF or LF) |
|
||||
| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written |
|
||||
| `total-line-numbers` | The total line numbers of the opened file |
|
||||
| `file-type` | The type of the opened file |
|
||||
| `diagnostics` | The number of warnings and/or errors |
|
||||
@ -117,6 +126,7 @@ ### `[editor.statusline]` Section
|
||||
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
|
||||
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
|
||||
| `version-control` | The current branch name or detached commit hash of the opened workspace |
|
||||
| `register` | The current selected register |
|
||||
|
||||
### `[editor.lsp]` Section
|
||||
|
||||
@ -131,8 +141,8 @@ ### `[editor.lsp]` Section
|
||||
| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` |
|
||||
|
||||
[^1]: By default, a progress spinner is shown in the statusline beside the file path.
|
||||
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.
|
||||
Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances, please report any bugs you see so we can fix them!
|
||||
|
||||
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix. Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances. Please report any bugs you see so we can fix them!
|
||||
|
||||
### `[editor.cursor-shape]` Section
|
||||
|
||||
@ -161,15 +171,30 @@ ### `[editor.file-picker]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
|`hidden` | Enables ignoring hidden files | true
|
||||
|`follow-symlinks` | Follow symlinks instead of ignoring them | true
|
||||
|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | true
|
||||
|`parents` | Enables reading ignore files from parent directories | true
|
||||
|`ignore` | Enables reading `.ignore` files | true
|
||||
|`git-ignore` | Enables reading `.gitignore` files | true
|
||||
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludefile` option | true
|
||||
|`git-exclude` | Enables reading `.git/info/exclude` files | true
|
||||
|`max-depth` | Set with an integer value for maximum depth to recurse | Defaults to `None`.
|
||||
|`hidden` | Enables ignoring hidden files | `true`
|
||||
|`follow-symlinks` | Follow symlinks instead of ignoring them | `true`
|
||||
|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | `true`
|
||||
|`parents` | Enables reading ignore files from parent directories | `true`
|
||||
|`ignore` | Enables reading `.ignore` files | `true`
|
||||
|`git-ignore` | Enables reading `.gitignore` files | `true`
|
||||
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true`
|
||||
|`git-exclude` | Enables reading `.git/info/exclude` files | `true`
|
||||
|`max-depth` | Set with an integer value for maximum depth to recurse | Unset by default
|
||||
|
||||
Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files.
|
||||
|
||||
Additionally, you can use Helix-specific ignore files by creating a local `.helix/ignore` file in the current workspace or a global `ignore` file located in your Helix config directory:
|
||||
- Linux and Mac: `~/.config/helix/ignore`
|
||||
- Windows: `%AppData%\helix\ignore`
|
||||
|
||||
Example:
|
||||
|
||||
```ini
|
||||
# unignore in file picker and global search
|
||||
!.github/
|
||||
!.gitignore
|
||||
!.gitattributes
|
||||
```
|
||||
|
||||
### `[editor.auto-pairs]` Section
|
||||
|
||||
@ -200,7 +225,7 @@ ### `[editor.auto-pairs]` Section
|
||||
the editor setting is `false`, this will override the editor config in
|
||||
documents with this language.
|
||||
|
||||
Example `languages.toml` that adds <> and removes ''
|
||||
Example `languages.toml` that adds `<>` and removes `''`
|
||||
|
||||
```toml
|
||||
[[language]]
|
||||
@ -230,8 +255,8 @@ ### `[editor.whitespace]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
|-----|-------------|---------|
|
||||
| `render` | Whether to render whitespace. May either be `"all"` or `"none"`, or a table with sub-keys `space`, `nbsp`, `tab`, and `newline` | `"none"` |
|
||||
| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `newline` or `tabpad` | See example below |
|
||||
| `render` | Whether to render whitespace. May either be `all` or `none`, or a table with sub-keys `space`, `nbsp`, `nnbsp`, `tab`, and `newline` | `none` |
|
||||
| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `nnbsp`, `newline` or `tabpad` | See example below |
|
||||
|
||||
Example
|
||||
|
||||
@ -242,11 +267,14 @@ # or control each character
|
||||
[editor.whitespace.render]
|
||||
space = "all"
|
||||
tab = "all"
|
||||
nbsp = "none"
|
||||
nnbsp = "none"
|
||||
newline = "none"
|
||||
|
||||
[editor.whitespace.characters]
|
||||
space = "·"
|
||||
nbsp = "⍽"
|
||||
nnbsp = "␣"
|
||||
tab = "→"
|
||||
newline = "⏎"
|
||||
tabpad = "·" # Tabs will look like "→···" (depending on tab width)
|
||||
@ -317,7 +345,12 @@ #### `[editor.gutters.diagnostics]` Section
|
||||
|
||||
#### `[editor.gutters.diff]` Section
|
||||
|
||||
Currently unused
|
||||
The `diff` gutter option displays colored bars indicating whether a `git` diff represents that a line was added, removed or changed.
|
||||
These colors are controlled by the theme attributes `diff.plus`, `diff.minus` and `diff.delta`.
|
||||
|
||||
Other diff providers will eventually be supported by a future plugin system.
|
||||
|
||||
There are currently no options for this section.
|
||||
|
||||
#### `[editor.gutters.spacer]` Section
|
||||
|
||||
@ -344,3 +377,28 @@ ### `[editor.soft-wrap]` Section
|
||||
max-indent-retain = 0
|
||||
wrap-indicator = "" # set wrap-indicator to "" to hide it
|
||||
```
|
||||
|
||||
### `[editor.smart-tab]` Section
|
||||
|
||||
Options for navigating and editing using tab key.
|
||||
|
||||
| Key | Description | Default |
|
||||
|------------|-------------|---------|
|
||||
| `enable` | If set to true, then when the cursor is in a position with non-whitespace to its left, instead of inserting a tab, it will run `move_parent_node_end`. If there is only whitespace to the left, then it inserts a tab as normal. With the default bindings, to explicitly insert a tab character, press Shift-tab. | `true` |
|
||||
| `supersede-menu` | Normally, when a menu is on screen, such as when auto complete is triggered, the tab key is bound to cycling through the items. This means when menus are on screen, one cannot use the tab key to trigger the `smart-tab` command. If this option is set to true, the `smart-tab` command always takes precedence, which means one cannot use the tab key to cycle through menu items. One of the other bindings must be used instead, such as arrow keys or `C-n`/`C-p`. | `false` |
|
||||
|
||||
|
||||
Due to lack of support for S-tab in some terminals, the default keybindings don't fully embrace smart-tab editing experience. If you enjoy smart-tab navigation and a terminal that supports the [Enhanced Keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol), consider setting extra keybindings:
|
||||
|
||||
```
|
||||
[keys.normal]
|
||||
tab = "move_parent_node_end"
|
||||
S-tab = "move_parent_node_start"
|
||||
|
||||
[keys.insert]
|
||||
S-tab = "move_parent_node_start"
|
||||
|
||||
[keys.select]
|
||||
tab = "extend_parent_node_end"
|
||||
S-tab = "extend_parent_node_start"
|
||||
```
|
||||
|
@ -1,34 +1,44 @@
|
||||
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| ada | ✓ | ✓ | | `ada_language_server`, `ada_language_server` |
|
||||
| adl | ✓ | ✓ | ✓ | |
|
||||
| agda | ✓ | | | |
|
||||
| astro | ✓ | | | |
|
||||
| awk | ✓ | ✓ | | `awk-language-server` |
|
||||
| bash | ✓ | | ✓ | `bash-language-server` |
|
||||
| bash | ✓ | ✓ | ✓ | `bash-language-server` |
|
||||
| bass | ✓ | | | `bass` |
|
||||
| beancount | ✓ | | | |
|
||||
| bibtex | ✓ | | | `texlab` |
|
||||
| bicep | ✓ | | | `bicep-langserver` |
|
||||
| bitbake | ✓ | | | `bitbake-language-server` |
|
||||
| blade | ✓ | | | |
|
||||
| blueprint | ✓ | | | `blueprint-compiler` |
|
||||
| c | ✓ | ✓ | ✓ | `clangd` |
|
||||
| c-sharp | ✓ | ✓ | | `OmniSharp` |
|
||||
| cabal | | | | |
|
||||
| cabal | | | | `haskell-language-server-wrapper` |
|
||||
| cairo | ✓ | ✓ | ✓ | `cairo-language-server` |
|
||||
| capnp | ✓ | | ✓ | |
|
||||
| cel | ✓ | | | |
|
||||
| clojure | ✓ | | | `clojure-lsp` |
|
||||
| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
|
||||
| comment | ✓ | | | |
|
||||
| common-lisp | ✓ | | | `cl-lsp` |
|
||||
| common-lisp | ✓ | | ✓ | `cl-lsp` |
|
||||
| cpon | ✓ | | ✓ | |
|
||||
| cpp | ✓ | ✓ | ✓ | `clangd` |
|
||||
| crystal | ✓ | ✓ | | `crystalline` |
|
||||
| css | ✓ | | | `vscode-css-language-server` |
|
||||
| css | ✓ | | ✓ | `vscode-css-language-server` |
|
||||
| cue | ✓ | | | `cuelsp` |
|
||||
| d | ✓ | ✓ | ✓ | `serve-d` |
|
||||
| dart | ✓ | | ✓ | `dart` |
|
||||
| dart | ✓ | ✓ | ✓ | `dart` |
|
||||
| dbml | ✓ | | | |
|
||||
| devicetree | ✓ | | | |
|
||||
| dhall | ✓ | ✓ | | `dhall-lsp-server` |
|
||||
| diff | ✓ | | | |
|
||||
| docker-compose | ✓ | | ✓ | `docker-compose-langserver`, `yaml-language-server` |
|
||||
| dockerfile | ✓ | | | `docker-langserver` |
|
||||
| dot | ✓ | | | `dot-language-server` |
|
||||
| dtd | ✓ | | | |
|
||||
| earthfile | ✓ | ✓ | ✓ | `earthlyls` |
|
||||
| edoc | ✓ | | | |
|
||||
| eex | ✓ | | | |
|
||||
| ejs | ✓ | | | |
|
||||
@ -39,54 +49,76 @@
|
||||
| erb | ✓ | | | |
|
||||
| erlang | ✓ | ✓ | | `erlang_ls` |
|
||||
| esdl | ✓ | | | |
|
||||
| fidl | ✓ | | | |
|
||||
| fish | ✓ | ✓ | ✓ | |
|
||||
| forth | ✓ | | | `forth-lsp` |
|
||||
| fortran | ✓ | | ✓ | `fortls` |
|
||||
| fsharp | ✓ | | | `fsautocomplete` |
|
||||
| gas | ✓ | ✓ | | |
|
||||
| gdscript | ✓ | ✓ | ✓ | |
|
||||
| gemini | ✓ | | | |
|
||||
| git-attributes | ✓ | | | |
|
||||
| git-commit | ✓ | ✓ | | |
|
||||
| git-config | ✓ | | | |
|
||||
| git-ignore | ✓ | | | |
|
||||
| git-rebase | ✓ | | | |
|
||||
| gleam | ✓ | ✓ | | `gleam` |
|
||||
| glimmer | ✓ | | | `ember-language-server` |
|
||||
| glsl | ✓ | ✓ | ✓ | |
|
||||
| go | ✓ | ✓ | ✓ | `gopls` |
|
||||
| gn | ✓ | | | |
|
||||
| go | ✓ | ✓ | ✓ | `gopls`, `golangci-lint-langserver` |
|
||||
| godot-resource | ✓ | | | |
|
||||
| gomod | ✓ | | | `gopls` |
|
||||
| gotmpl | ✓ | | | `gopls` |
|
||||
| gowork | ✓ | | | `gopls` |
|
||||
| graphql | ✓ | | | |
|
||||
| graphql | ✓ | ✓ | | `graphql-lsp` |
|
||||
| groovy | ✓ | | | |
|
||||
| hare | ✓ | | | |
|
||||
| haskell | ✓ | ✓ | | `haskell-language-server-wrapper` |
|
||||
| hcl | ✓ | | ✓ | `terraform-ls` |
|
||||
| haskell-persistent | ✓ | | | |
|
||||
| hcl | ✓ | ✓ | ✓ | `terraform-ls` |
|
||||
| heex | ✓ | ✓ | | `elixir-ls` |
|
||||
| helm | ✓ | | | `helm_ls` |
|
||||
| hocon | ✓ | | ✓ | |
|
||||
| hoon | ✓ | | | |
|
||||
| hosts | ✓ | | | |
|
||||
| html | ✓ | | | `vscode-html-language-server` |
|
||||
| hurl | ✓ | | ✓ | |
|
||||
| hyprlang | ✓ | | ✓ | |
|
||||
| idris | | | | `idris2-lsp` |
|
||||
| iex | ✓ | | | |
|
||||
| ini | ✓ | | | |
|
||||
| java | ✓ | ✓ | | `jdtls` |
|
||||
| janet | ✓ | | | |
|
||||
| java | ✓ | ✓ | ✓ | `jdtls` |
|
||||
| javascript | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| jinja | ✓ | | | |
|
||||
| jsdoc | ✓ | | | |
|
||||
| json | ✓ | | ✓ | `vscode-json-language-server` |
|
||||
| json | ✓ | ✓ | ✓ | `vscode-json-language-server` |
|
||||
| json5 | ✓ | | | |
|
||||
| jsonc | ✓ | | ✓ | `vscode-json-language-server` |
|
||||
| jsonnet | ✓ | | | `jsonnet-language-server` |
|
||||
| jsx | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| julia | ✓ | ✓ | ✓ | `julia` |
|
||||
| just | ✓ | ✓ | ✓ | |
|
||||
| kdl | ✓ | | | |
|
||||
| kdl | ✓ | ✓ | ✓ | |
|
||||
| koka | ✓ | | ✓ | `koka` |
|
||||
| kotlin | ✓ | | | `kotlin-language-server` |
|
||||
| latex | ✓ | ✓ | | `texlab` |
|
||||
| ld | ✓ | | ✓ | |
|
||||
| ldif | ✓ | | | |
|
||||
| lean | ✓ | | | `lean` |
|
||||
| ledger | ✓ | | | |
|
||||
| llvm | ✓ | ✓ | ✓ | |
|
||||
| llvm-mir | ✓ | ✓ | ✓ | |
|
||||
| llvm-mir-yaml | ✓ | | ✓ | |
|
||||
| log | ✓ | | | |
|
||||
| lpf | ✓ | | | |
|
||||
| lua | ✓ | ✓ | ✓ | `lua-language-server` |
|
||||
| make | ✓ | | | |
|
||||
| make | ✓ | | ✓ | |
|
||||
| markdoc | ✓ | | | `markdoc-ls` |
|
||||
| markdown | ✓ | | | `marksman` |
|
||||
| markdown | ✓ | | | `marksman`, `markdown-oxide` |
|
||||
| markdown.inline | ✓ | | | |
|
||||
| matlab | ✓ | | | |
|
||||
| matlab | ✓ | ✓ | ✓ | |
|
||||
| mermaid | ✓ | | | |
|
||||
| meson | ✓ | | ✓ | |
|
||||
| mint | | | | `mint` |
|
||||
@ -94,11 +126,13 @@
|
||||
| nasm | ✓ | ✓ | | |
|
||||
| nickel | ✓ | | ✓ | `nls` |
|
||||
| nim | ✓ | ✓ | ✓ | `nimlangserver` |
|
||||
| nix | ✓ | | | `nil` |
|
||||
| nu | ✓ | | | |
|
||||
| nix | ✓ | ✓ | | `nil` |
|
||||
| nu | ✓ | | | `nu` |
|
||||
| nunjucks | ✓ | | | |
|
||||
| ocaml | ✓ | | ✓ | `ocamllsp` |
|
||||
| ocaml-interface | ✓ | | | `ocamllsp` |
|
||||
| odin | ✓ | | ✓ | `ols` |
|
||||
| ohm | ✓ | ✓ | ✓ | |
|
||||
| opencl | ✓ | ✓ | ✓ | `clangd` |
|
||||
| openscad | ✓ | | | `openscad-lsp` |
|
||||
| org | ✓ | | | |
|
||||
@ -107,17 +141,22 @@
|
||||
| pem | ✓ | | | |
|
||||
| perl | ✓ | ✓ | ✓ | `perlnavigator` |
|
||||
| php | ✓ | ✓ | ✓ | `intelephense` |
|
||||
| php-only | ✓ | | | |
|
||||
| pkgbuild | ✓ | ✓ | ✓ | `pkgbuild-language-server`, `bash-language-server` |
|
||||
| pkl | ✓ | | ✓ | |
|
||||
| po | ✓ | ✓ | | |
|
||||
| pod | ✓ | | | |
|
||||
| ponylang | ✓ | ✓ | ✓ | |
|
||||
| powershell | ✓ | | | |
|
||||
| prisma | ✓ | | | `prisma-language-server` |
|
||||
| prolog | | | | `swipl` |
|
||||
| protobuf | ✓ | | ✓ | |
|
||||
| protobuf | ✓ | ✓ | ✓ | `bufls`, `pb` |
|
||||
| prql | ✓ | | | |
|
||||
| purescript | ✓ | | | `purescript-language-server` |
|
||||
| purescript | ✓ | ✓ | | `purescript-language-server` |
|
||||
| python | ✓ | ✓ | ✓ | `pylsp` |
|
||||
| qml | ✓ | | ✓ | `qmlls` |
|
||||
| r | ✓ | | | `R` |
|
||||
| racket | ✓ | | | `racket` |
|
||||
| racket | ✓ | | ✓ | `racket` |
|
||||
| regex | ✓ | | | |
|
||||
| rego | ✓ | | | `regols` |
|
||||
| rescript | ✓ | ✓ | | `rescript-language-server` |
|
||||
@ -128,41 +167,54 @@
|
||||
| ruby | ✓ | ✓ | ✓ | `solargraph` |
|
||||
| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
|
||||
| sage | ✓ | ✓ | | |
|
||||
| scala | ✓ | | ✓ | `metals` |
|
||||
| scheme | ✓ | | | |
|
||||
| scala | ✓ | ✓ | ✓ | `metals` |
|
||||
| scheme | ✓ | | ✓ | |
|
||||
| scss | ✓ | | | `vscode-css-language-server` |
|
||||
| slint | ✓ | | ✓ | `slint-lsp` |
|
||||
| slint | ✓ | ✓ | ✓ | `slint-lsp` |
|
||||
| smali | ✓ | | ✓ | |
|
||||
| smithy | ✓ | | | `cs` |
|
||||
| sml | ✓ | | | |
|
||||
| solidity | ✓ | | | `solc` |
|
||||
| solidity | ✓ | ✓ | | `solc` |
|
||||
| spicedb | ✓ | | | |
|
||||
| sql | ✓ | | | |
|
||||
| sshclientconfig | ✓ | | | |
|
||||
| starlark | ✓ | ✓ | | |
|
||||
| svelte | ✓ | | | `svelteserver` |
|
||||
| strace | ✓ | | | |
|
||||
| supercollider | ✓ | | | |
|
||||
| svelte | ✓ | | ✓ | `svelteserver` |
|
||||
| sway | ✓ | ✓ | ✓ | `forc` |
|
||||
| swift | ✓ | | | `sourcekit-lsp` |
|
||||
| t32 | ✓ | | | |
|
||||
| tablegen | ✓ | ✓ | ✓ | |
|
||||
| tact | ✓ | ✓ | ✓ | |
|
||||
| task | ✓ | | | |
|
||||
| tcl | ✓ | | ✓ | |
|
||||
| templ | ✓ | | | `templ` |
|
||||
| tfvars | ✓ | | ✓ | `terraform-ls` |
|
||||
| toml | ✓ | | | `taplo` |
|
||||
| todotxt | ✓ | | | |
|
||||
| toml | ✓ | ✓ | | `taplo` |
|
||||
| tsq | ✓ | | | |
|
||||
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| twig | ✓ | | | |
|
||||
| typescript | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| typst | ✓ | | | `typst-lsp` |
|
||||
| ungrammar | ✓ | | | |
|
||||
| unison | ✓ | | ✓ | |
|
||||
| uxntal | ✓ | | | |
|
||||
| v | ✓ | ✓ | ✓ | `v` |
|
||||
| vala | ✓ | | | `vala-language-server` |
|
||||
| v | ✓ | ✓ | ✓ | `v-analyzer` |
|
||||
| vala | ✓ | ✓ | | `vala-language-server` |
|
||||
| verilog | ✓ | ✓ | | `svlangserver` |
|
||||
| vhdl | ✓ | | | `vhdl_ls` |
|
||||
| vhs | ✓ | | | |
|
||||
| vue | ✓ | | | `vls` |
|
||||
| vue | ✓ | | | `vue-language-server` |
|
||||
| wast | ✓ | | | |
|
||||
| wat | ✓ | | | |
|
||||
| webc | ✓ | | | |
|
||||
| wgsl | ✓ | | | `wgsl_analyzer` |
|
||||
| wit | ✓ | | ✓ | |
|
||||
| wren | ✓ | ✓ | ✓ | |
|
||||
| xit | ✓ | | | |
|
||||
| xml | ✓ | | ✓ | |
|
||||
| yaml | ✓ | | ✓ | `yaml-language-server` |
|
||||
| yaml | ✓ | | ✓ | `yaml-language-server`, `ansible-language-server` |
|
||||
| yuck | ✓ | | | |
|
||||
| zig | ✓ | ✓ | ✓ | `zls` |
|
||||
|
@ -17,13 +17,14 @@
|
||||
| `:write-buffer-close!`, `:wbc!` | Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt) |
|
||||
| `:new`, `:n` | Create a new scratch buffer. |
|
||||
| `:format`, `:fmt` | Format the file using the LSP formatter. |
|
||||
| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.) |
|
||||
| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.) |
|
||||
| `:line-ending` | Set the document's default line ending. Options: crlf, lf. |
|
||||
| `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. |
|
||||
| `:later`, `:lat` | Jump to a later point in edit history. Accepts a number of steps or a time span. |
|
||||
| `:write-quit`, `:wq`, `:x` | Write changes to disk and close the current view. Accepts an optional path (:wq some/path.txt) |
|
||||
| `:write-quit!`, `:wq!`, `:x!` | Write changes to disk and close the current view forcefully. Accepts an optional path (:wq! some/path.txt) |
|
||||
| `:write-all`, `:wa` | Write changes from all buffers to disk. |
|
||||
| `:write-all!`, `:wa!` | Forcefully write changes from all buffers to disk creating necessary subdirectories. |
|
||||
| `:write-quit-all`, `:wqa`, `:xa` | Write changes from all buffers to disk and close all views. |
|
||||
| `:write-quit-all!`, `:wqa!`, `:xa!` | Write changes from all buffers to disk and close all views forcefully (ignoring unsaved changes). |
|
||||
| `:quit-all`, `:qa` | Close all views. |
|
||||
@ -31,6 +32,7 @@
|
||||
| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
|
||||
| `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). |
|
||||
| `:theme` | Change the editor theme (show current theme if no name specified). |
|
||||
| `:yank-join` | Yank joined selections. A separator can be provided as first argument. Default value is newline. |
|
||||
| `:clipboard-yank` | Yank main selection into system clipboard. |
|
||||
| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
|
||||
| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
|
||||
@ -46,13 +48,14 @@
|
||||
| `:show-directory`, `:pwd` | Show the current working directory. |
|
||||
| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
|
||||
| `:character-info`, `:char` | Get info about the character under the primary cursor. |
|
||||
| `:reload` | Discard changes and reload from the source file. |
|
||||
| `:reload-all` | Discard changes and reload all documents from the source files. |
|
||||
| `:reload`, `:rl` | Discard changes and reload from the source file. |
|
||||
| `:reload-all`, `:rla` | Discard changes and reload all documents from the source files. |
|
||||
| `:update`, `:u` | Write changes only if the file has been modified. |
|
||||
| `:lsp-workspace-command` | Open workspace command picker |
|
||||
| `:lsp-restart` | Restarts the language servers used by the current doc |
|
||||
| `:lsp-stop` | Stops the language servers that are used by the current doc |
|
||||
| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
|
||||
| `:tree-sitter-highlight-name` | Display name of tree-sitter highlight scope under the cursor. |
|
||||
| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
|
||||
| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
|
||||
| `:debug-eval` | Evaluate expression in current debug context. |
|
||||
@ -81,3 +84,6 @@
|
||||
| `:run-shell-command`, `:sh` | Run a shell command |
|
||||
| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. |
|
||||
| `:clear-register` | Clear given register. If no argument is provided, clear all registers. |
|
||||
| `:redraw` | Clear and re-render the whole UI |
|
||||
| `:move` | Move the current buffer and its corresponding file to a different path |
|
||||
| `:yank-diagnostic` | Yank diagnostic(s) under primary cursor to register, or clipboard by default |
|
||||
|
@ -36,6 +36,7 @@ ## Queries
|
||||
3. Refer to the
|
||||
[tree-sitter website](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries)
|
||||
for more information on writing queries.
|
||||
4. A list of highlight captures can be found [on the themes page](https://docs.helix-editor.com/themes.html#scopes).
|
||||
|
||||
> 💡 In Helix, the first matching query takes precedence when evaluating
|
||||
> queries, which is different from other editors such as Neovim where the last
|
||||
@ -51,3 +52,4 @@ ## Common issues
|
||||
grammars.
|
||||
- If a parser is causing a segfault, or you want to remove it, make sure to
|
||||
remove the compiled parser located at `runtime/grammars/<name>.so`.
|
||||
- If you are attempting to add queries and Helix is unable to locate them, ensure that the environment variable `HELIX_RUNTIME` is set to the location of the `runtime` folder you're developing in.
|
||||
|
@ -1,76 +1,308 @@
|
||||
# Adding indent queries
|
||||
|
||||
Helix uses tree-sitter to correctly indent new lines. This requires
|
||||
a tree-sitter grammar and an `indent.scm` query file placed in
|
||||
`runtime/queries/{language}/indents.scm`. The indentation for a line
|
||||
is calculated by traversing the syntax tree from the lowest node at the
|
||||
beginning of the new line. Each of these nodes contributes to the total
|
||||
indent when it is captured by the query (in what way depends on the name
|
||||
of the capture).
|
||||
Helix uses tree-sitter to correctly indent new lines. This requires a tree-
|
||||
sitter grammar and an `indent.scm` query file placed in `runtime/queries/
|
||||
{language}/indents.scm`. The indentation for a line is calculated by traversing
|
||||
the syntax tree from the lowest node at the beginning of the new line (see
|
||||
[Indent queries](#indent-queries)). Each of these nodes contributes to the total
|
||||
indent when it is captured by the query (in what way depends on the name of
|
||||
the capture.
|
||||
|
||||
Note that it matters where these added indents begin. For example,
|
||||
multiple indent level increases that start on the same line only increase
|
||||
the total indent level by 1.
|
||||
the total indent level by 1. See [Capture types](#capture-types).
|
||||
|
||||
## Scopes
|
||||
By default, Helix uses the `hybrid` indentation heuristic. This means that
|
||||
indent queries are not used to compute the expected absolute indentation of a
|
||||
line but rather the expected difference in indentation between the new and an
|
||||
already existing line. This difference is then added to the actual indentation
|
||||
of the already existing line. Since this makes errors in the indent queries
|
||||
harder to find, it is recommended to disable it when testing via
|
||||
`:set indent-heuristic tree-sitter`. The rest of this guide assumes that
|
||||
the `tree-sitter` heuristic is used.
|
||||
|
||||
Added indents don't always apply to the whole node. For example, in most
|
||||
cases when a node should be indented, we actually only want everything
|
||||
except for its first line to be indented. For this, there are several
|
||||
scopes (more scopes may be added in the future if required):
|
||||
## Indent queries
|
||||
|
||||
- `all`:
|
||||
This scope applies to the whole captured node. This is only different from
|
||||
`tail` when the captured node is the first node on its line.
|
||||
When Helix is inserting a new line through `o`, `O`, or `<ret>`, to determine
|
||||
the indent level for the new line, the query in `indents.scm` is run on the
|
||||
document. The starting position of the query is the end of the line above where
|
||||
a new line will be inserted.
|
||||
|
||||
- `tail`:
|
||||
This scope applies to everything except for the first line of the
|
||||
captured node.
|
||||
For `o`, the inserted line is the line below the cursor, so that starting
|
||||
position of the query is the end of the current line.
|
||||
|
||||
Every capture type has a default scope which should do the right thing
|
||||
in most situations. When a different scope is required, this can be
|
||||
changed by using a `#set!` declaration anywhere in the pattern:
|
||||
```scm
|
||||
(assignment_expression
|
||||
right: (_) @indent
|
||||
(#set! "scope" "all"))
|
||||
```rust
|
||||
fn need_hero(some_hero: Hero, life: Life) -> {
|
||||
matches!(some_hero, Hero { // ←─────────────────╮
|
||||
strong: true,//←╮ ↑ ↑ │
|
||||
fast: true, // │ │ ╰── query start │
|
||||
sure: true, // │ ╰───── cursor ├─ traversal
|
||||
soon: true, // ╰──────── new line inserted │ start node
|
||||
}) && // │
|
||||
// ↑ │
|
||||
// ╰───────────────────────────────────────────────╯
|
||||
some_hero > life
|
||||
}
|
||||
```
|
||||
|
||||
## Capture types
|
||||
For `O`, the newly inserted line is the *current* line, so the starting position
|
||||
of the query is the end of the line above the cursor.
|
||||
|
||||
```rust
|
||||
fn need_hero(some_hero: Hero, life: Life) -> { // ←─╮
|
||||
matches!(some_hero, Hero { // ←╮ ↑ │
|
||||
strong: true,// ↑ ╭───╯ │ │
|
||||
fast: true, // │ │ query start ─╯ │
|
||||
sure: true, // ╰───┼ cursor ├─ traversal
|
||||
soon: true, // ╰ new line inserted │ start node
|
||||
}) && // │
|
||||
some_hero > life // │
|
||||
} // ←──────────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
From this starting node, the syntax tree is traversed up until the root node.
|
||||
Each indent capture is collected along the way, and then combined according to
|
||||
their [capture types](#capture-types) and [scopes](#scopes) to a final indent
|
||||
level for the line.
|
||||
|
||||
### Capture types
|
||||
|
||||
- `@indent` (default scope `tail`):
|
||||
Increase the indent level by 1. Multiple occurrences in the same line
|
||||
don't stack. If there is at least one `@indent` and one `@outdent`
|
||||
capture on the same line, the indent level isn't changed at all.
|
||||
|
||||
Increase the indent level by 1. Multiple occurrences in the same line *do not*
|
||||
stack. If there is at least one `@indent` and one `@outdent` capture on the
|
||||
same line, the indent level isn't changed at all.
|
||||
- `@outdent` (default scope `all`):
|
||||
Decrease the indent level by 1. The same rules as for `@indent` apply.
|
||||
|
||||
Decrease the indent level by 1. The same rules as for `@indent` apply.
|
||||
- `@indent.always` (default scope `tail`):
|
||||
Increase the indent level by 1. Multiple occurrences on the same line *do*
|
||||
stack. The final indent level is `@indent.always` – `@outdent.always`. If
|
||||
an `@indent` and an `@indent.always` are on the same line, the `@indent` is
|
||||
ignored.
|
||||
- `@outdent.always` (default scope `all`):
|
||||
Decrease the indent level by 1. The same rules as for `@indent.always` apply.
|
||||
- `@align` (default scope `all`):
|
||||
Align everything inside this node to some anchor. The anchor is given
|
||||
by the start of the node captured by `@anchor` in the same pattern.
|
||||
Every pattern with an `@align` should contain exactly one `@anchor`.
|
||||
Indent (and outdent) for nodes below (in terms of their starting line)
|
||||
the `@align` node is added to the indentation required for alignment.
|
||||
- `@extend`:
|
||||
Extend the range of this node to the end of the line and to lines that
|
||||
are indented more than the line that this node starts on. This is useful
|
||||
for languages like Python, where for the purpose of indentation some nodes
|
||||
(like functions or classes) should also contain indented lines that follow them.
|
||||
|
||||
Extend the range of this node to the end of the line and to lines that are
|
||||
indented more than the line that this node starts on. This is useful for
|
||||
languages like Python, where for the purpose of indentation some nodes (like
|
||||
functions or classes) should also contain indented lines that follow them.
|
||||
- `@extend.prevent-once`:
|
||||
Prevents the first extension of an ancestor of this node. For example, in Python
|
||||
a return expression always ends the block that it is in. Note that this only stops the
|
||||
extension of the next `@extend` capture. If multiple ancestors are captured,
|
||||
only the extension of the innermost one is prevented. All other ancestors are unaffected
|
||||
(regardless of whether the innermost ancestor would actually have been extended).
|
||||
Prevents the first extension of an ancestor of this node. For example, in Python
|
||||
a return expression always ends the block that it is in. Note that this only
|
||||
stops the extension of the next `@extend` capture. If multiple ancestors are
|
||||
captured, only the extension of the innermost one is prevented. All other
|
||||
ancestors are unaffected (regardless of whether the innermost ancestor would
|
||||
actually have been extended).
|
||||
|
||||
#### `@indent` / `@outdent`
|
||||
|
||||
Consider this example:
|
||||
|
||||
```rust
|
||||
fn shout(things: Vec<Thing>) {
|
||||
// ↑
|
||||
// ├───────────────────────╮ indent level
|
||||
// @indent ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄
|
||||
// │
|
||||
let it_all = |out| { things.filter(|thing| { // │ 1
|
||||
// ↑ ↑ │
|
||||
// ├───────────────────────┼─────┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄
|
||||
// @indent @indent │
|
||||
// │ 2
|
||||
thing.can_do_with(out) // │
|
||||
})}; // ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄
|
||||
//↑↑↑ │ 1
|
||||
} //╰┼┴──────────────────────────────────────────────┴┄┄┄┄┄┄┄┄┄┄┄┄┄┄
|
||||
// 3x @outdent
|
||||
```
|
||||
|
||||
```scm
|
||||
((block) @indent)
|
||||
["}" ")"] @outdent
|
||||
```
|
||||
|
||||
Note how on the second line, we have two blocks begin on the same line. In this
|
||||
case, since both captures occur on the same line, they are combined and only
|
||||
result in a net increase of 1. Also note that the closing `}`s are part of the
|
||||
`@indent` captures, but the 3 `@outdent`s also combine into 1 and result in that
|
||||
line losing one indent level.
|
||||
|
||||
#### `@extend` / `@extend.prevent-once`
|
||||
|
||||
For an example of where `@extend` can be useful, consider Python, which is
|
||||
whitespace-sensitive.
|
||||
|
||||
```scm
|
||||
]
|
||||
(parenthesized_expression)
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
] @indent
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
class Hero:
|
||||
def __init__(self, strong, fast, sure, soon):# ←─╮
|
||||
self.is_strong = strong # │
|
||||
self.is_fast = fast # ╭─── query start │
|
||||
self.is_sure = sure # │ ╭─ cursor │
|
||||
self.is_soon = soon # │ │ │
|
||||
# ↑ ↑ │ │ │
|
||||
# │ ╰──────╯ │ │
|
||||
# ╰─────────────────────╯ │
|
||||
# ├─ traversal
|
||||
def need_hero(self, life): # │ start node
|
||||
return ( # │
|
||||
self.is_strong # │
|
||||
and self.is_fast # │
|
||||
and self.is_sure # │
|
||||
and self.is_soon # │
|
||||
and self > life # │
|
||||
) # ←─────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
Without braces to catch the scope of the function, the smallest descendant of
|
||||
the cursor on a line feed ends up being the entire inside of the class. Because
|
||||
of this, it will miss the entire function node and its indent capture, leading
|
||||
to an indent level one too small.
|
||||
|
||||
To address this case, `@extend` tells helix to "extend" the captured node's span
|
||||
to the line feed and every consecutive line that has a greater indent level than
|
||||
the line of the node.
|
||||
|
||||
```scm
|
||||
(parenthesized_expression) @indent
|
||||
|
||||
]
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
] @indent @extend
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
class Hero:
|
||||
def __init__(self, strong, fast, sure, soon):# ←─╮
|
||||
self.is_strong = strong # │
|
||||
self.is_fast = fast # ╭─── query start ├─ traversal
|
||||
self.is_sure = sure # │ ╭─ cursor │ start node
|
||||
self.is_soon = soon # │ │ ←───────────────╯
|
||||
# ↑ ↑ │ │
|
||||
# │ ╰──────╯ │
|
||||
# ╰─────────────────────╯
|
||||
def need_hero(self, life):
|
||||
return (
|
||||
self.is_strong
|
||||
and self.is_fast
|
||||
and self.is_sure
|
||||
and self.is_soon
|
||||
and self > life
|
||||
)
|
||||
```
|
||||
|
||||
Furthermore, there are some cases where extending to everything with a greater
|
||||
indent level may not be desirable. Consider the `need_hero` function above. If
|
||||
our cursor is on the last line of the returned expression.
|
||||
|
||||
```python
|
||||
class Hero:
|
||||
def __init__(self, strong, fast, sure, soon):
|
||||
self.is_strong = strong
|
||||
self.is_fast = fast
|
||||
self.is_sure = sure
|
||||
self.is_soon = soon
|
||||
|
||||
def need_hero(self, life):
|
||||
return (
|
||||
self.is_strong
|
||||
and self.is_fast
|
||||
and self.is_sure
|
||||
and self.is_soon
|
||||
and self > life
|
||||
) # ←─── cursor
|
||||
#←────────── where cursor should go on new line
|
||||
```
|
||||
|
||||
In Python, the are a few tokens that will always end a scope, such as a return
|
||||
statement. Since the scope ends, so should the indent level. But because the
|
||||
function span is extended to every line with a greater indent level, a new line
|
||||
would just continue on the same level. And an `@outdent` would not help us here
|
||||
either, since it would cause everything in the parentheses to become outdented
|
||||
as well.
|
||||
|
||||
To help, we need to signal an end to the extension. We can do this with
|
||||
`@extend.prevent-once`.
|
||||
|
||||
```scm
|
||||
(parenthesized_expression) @indent
|
||||
|
||||
]
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
] @indent @extend
|
||||
|
||||
(return_statement) @extend.prevent-once
|
||||
```
|
||||
|
||||
#### `@indent.always` / `@outdent.always`
|
||||
|
||||
As mentioned before, normally if there is more than one `@indent` or `@outdent`
|
||||
capture on the same line, they are combined.
|
||||
|
||||
Sometimes, there are cases when you may want to ensure that every indent capture
|
||||
is additive, regardless of how many occur on the same line. Consider this
|
||||
example in YAML.
|
||||
|
||||
```yaml
|
||||
- foo: bar
|
||||
# ↑ ↑
|
||||
# │ ╰─────────────── start of map
|
||||
# ╰───────────────── start of list element
|
||||
baz: quux # ←─── cursor
|
||||
# ←───────────── where the cursor should go on a new line
|
||||
garply: waldo
|
||||
- quux:
|
||||
bar: baz
|
||||
xyzzy: thud
|
||||
fred: plugh
|
||||
```
|
||||
|
||||
In YAML, you often have lists of maps. In these cases, the syntax is such that
|
||||
the list element and the map both start on the same line. But we really do want
|
||||
to start an indentation for each of these so that subsequent keys in the map
|
||||
hang over the list and align properly. This is where `@indent.always` helps.
|
||||
|
||||
```scm
|
||||
((block_sequence_item) @item @indent.always @extend
|
||||
(#not-one-line? @item))
|
||||
|
||||
((block_mapping_pair
|
||||
key: (_) @key
|
||||
value: (_) @val
|
||||
(#not-same-line? @key @val)
|
||||
) @indent.always @extend
|
||||
)
|
||||
```
|
||||
|
||||
## Predicates
|
||||
|
||||
In some cases, an S-expression cannot express exactly what pattern should be matched.
|
||||
For that, tree-sitter allows for predicates to appear anywhere within a pattern,
|
||||
similar to how `#set!` declarations work:
|
||||
|
||||
```scm
|
||||
(some_kind
|
||||
(child_kind) @indent
|
||||
(#predicate? arg1 arg2 ...)
|
||||
)
|
||||
```
|
||||
|
||||
The number of arguments depends on the predicate that's used.
|
||||
Each argument is either a capture (`@name`) or a string (`"some string"`).
|
||||
The following predicates are supported by tree-sitter:
|
||||
@ -83,6 +315,10 @@ ## Predicates
|
||||
The first argument (a capture) must/must not match the regex given in the
|
||||
second argument (a string).
|
||||
|
||||
- `#any-of?`/`#not-any-of?`:
|
||||
The first argument (a capture) must/must not be one of the other arguments
|
||||
(strings).
|
||||
|
||||
Additionally, we support some custom predicates for indent queries:
|
||||
|
||||
- `#not-kind-eq?`:
|
||||
@ -91,3 +327,47 @@ ## Predicates
|
||||
|
||||
- `#same-line?`/`#not-same-line?`:
|
||||
The captures given by the 2 arguments must/must not start on the same line.
|
||||
|
||||
- `#one-line?`/`#not-one-line?`:
|
||||
The captures given by the fist argument must/must span a total of one line.
|
||||
|
||||
### Scopes
|
||||
|
||||
Added indents don't always apply to the whole node. For example, in most
|
||||
cases when a node should be indented, we actually only want everything
|
||||
except for its first line to be indented. For this, there are several
|
||||
scopes (more scopes may be added in the future if required):
|
||||
|
||||
- `tail`:
|
||||
This scope applies to everything except for the first line of the
|
||||
captured node.
|
||||
- `all`:
|
||||
This scope applies to the whole captured node. This is only different from
|
||||
`tail` when the captured node is the first node on its line.
|
||||
|
||||
For example, imagine we have the following function
|
||||
|
||||
```rust
|
||||
fn aha() { // ←─────────────────────────────────────╮
|
||||
let take = "on me"; // ←──────────────╮ scope: │
|
||||
let take = "me on"; // ├─ "tail" ├─ (block) @indent
|
||||
let ill = be_gone_days(1 || 2); // │ │
|
||||
} // ←───────────────────────────────────┴──────────┴─ "}" @outdent
|
||||
// scope: "all"
|
||||
```
|
||||
|
||||
We can write the following query with the `#set!` declaration:
|
||||
|
||||
```scm
|
||||
((block) @indent
|
||||
(#set! "scope" "tail"))
|
||||
("}" @outdent
|
||||
(#set! "scope" "all"))
|
||||
```
|
||||
|
||||
As we can see, the "tail" scope covers the node, except for the first line.
|
||||
Everything up to and including the closing brace gets an indent level of 1.
|
||||
Then, on the closing brace, we encounter an outdent with a scope of "all", which
|
||||
means the first line is included, and the indent level is cancelled out on this
|
||||
line. (Note these scopes are the defaults for `@indent` and `@outdent`—they are
|
||||
written explicitly for demonstration.)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Adding Injection Queries
|
||||
|
||||
Writing language injection queries allows one to highlight a specific node as a different language.
|
||||
In addition to the [standard](upstream-docs) language injection options used by tree-sitter, there
|
||||
In addition to the [standard][upstream-docs] language injection options used by tree-sitter, there
|
||||
are a few Helix specific extensions that allow for more control.
|
||||
|
||||
And example of a simple query that would highlight all strings as bash in Nix:
|
||||
@ -54,4 +54,7 @@ ## Predicates
|
||||
The first argument (a capture) must match the regex given in the
|
||||
second argument (a string).
|
||||
|
||||
- `#any-of?` (standard):
|
||||
The first argument (a capture) must be one of the other arguments (strings).
|
||||
|
||||
[upstream-docs]: http://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection
|
||||
|
@ -25,6 +25,8 @@ # Adding textobject queries
|
||||
| `parameter.inside` |
|
||||
| `comment.inside` |
|
||||
| `comment.around` |
|
||||
| `entry.inside` |
|
||||
| `entry.around` |
|
||||
|
||||
[Example query files][textobject-examples] can be found in the helix GitHub repository.
|
||||
|
||||
@ -44,4 +46,4 @@ ## Queries for textobject based navigation
|
||||
|
||||
[tree-sitter-queries]: https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
|
||||
[tree-sitter-captures]: https://tree-sitter.github.io/tree-sitter/using-parsers#capturing-nodes
|
||||
[textobject-examples]: https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+filename%3Atextobjects.scm&type=Code&ref=advsearch&l=&l=
|
||||
[textobject-examples]: https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+path%3A%2A%2A/textobjects.scm&type=Code&ref=advsearch&l=&l=
|
||||
|
@ -6,12 +6,14 @@ # Installing Helix
|
||||
- [Linux](#linux)
|
||||
- [Ubuntu](#ubuntu)
|
||||
- [Fedora/RHEL](#fedorarhel)
|
||||
- [Arch Linux community](#arch-linux-community)
|
||||
- [Arch Linux extra](#arch-linux-extra)
|
||||
- [NixOS](#nixos)
|
||||
- [Flatpak](#flatpak)
|
||||
- [Snap](#snap)
|
||||
- [AppImage](#appimage)
|
||||
- [macOS](#macos)
|
||||
- [Homebrew Core](#homebrew-core)
|
||||
- [MacPorts](#macports)
|
||||
- [Windows](#windows)
|
||||
- [Winget](#winget)
|
||||
- [Scoop](#scoop)
|
||||
@ -63,20 +65,26 @@ ### Ubuntu
|
||||
|
||||
### Fedora/RHEL
|
||||
|
||||
Enable the `COPR` repository for Helix:
|
||||
|
||||
```sh
|
||||
sudo dnf copr enable varlad/helix
|
||||
sudo dnf install helix
|
||||
```
|
||||
|
||||
### Arch Linux community
|
||||
### Arch Linux extra
|
||||
|
||||
Releases are available in the `community` repository:
|
||||
Releases are available in the `extra` repository:
|
||||
|
||||
```sh
|
||||
sudo pacman -S helix
|
||||
```
|
||||
|
||||
> 💡 When installed from the `extra` repository, run Helix with `helix` instead of `hx`.
|
||||
>
|
||||
> For example:
|
||||
> ```sh
|
||||
> helix --health
|
||||
> ```
|
||||
> to check health
|
||||
|
||||
Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available
|
||||
in the AUR, which builds the master branch.
|
||||
|
||||
@ -104,6 +112,16 @@ ### Flatpak
|
||||
flatpak run com.helix_editor.Helix
|
||||
```
|
||||
|
||||
### Snap
|
||||
|
||||
Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with:
|
||||
|
||||
```sh
|
||||
snap install --classic helix
|
||||
```
|
||||
|
||||
This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`.
|
||||
|
||||
### AppImage
|
||||
|
||||
Install Helix using the Linux [AppImage](https://appimage.org/) format.
|
||||
@ -122,6 +140,12 @@ ### Homebrew Core
|
||||
brew install helix
|
||||
```
|
||||
|
||||
### MacPorts
|
||||
|
||||
```sh
|
||||
port install helix
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
@ -159,9 +183,13 @@ ## Building from source
|
||||
|
||||
Requirements:
|
||||
|
||||
Clone the Helix GitHub repository into a directory of your choice. The
|
||||
examples in this documentation assume installation into either `~/src/` on
|
||||
Linux and macOS, or `%userprofile%\src\` on Windows.
|
||||
|
||||
- The [Rust toolchain](https://www.rust-lang.org/tools/install)
|
||||
- The [Git version control system](https://git-scm.com/)
|
||||
- A c++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
|
||||
If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
|
||||
|
||||
@ -171,19 +199,21 @@ ## Building from source
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
|
||||
2. Compile from source:
|
||||
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
|
||||
> 💡 If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD`
|
||||
|
||||
> 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
|
||||
> grammars with `hx --grammar fetch` and compile them with
|
||||
@ -195,18 +225,22 @@ ### Configuring Helix's runtime files
|
||||
|
||||
#### Linux and macOS
|
||||
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files and add it to your `~/.bashrc` or equivalent:
|
||||
The **runtime** directory is one below the Helix source, so either export a
|
||||
`HELIX_RUNTIME` environment variable to point to that directory and add it to
|
||||
your `~/.bashrc` or equivalent:
|
||||
|
||||
```sh
|
||||
HELIX_RUNTIME=/home/user-name/src/helix/runtime
|
||||
export HELIX_RUNTIME=~/src/helix/runtime
|
||||
```
|
||||
|
||||
Or, create a symlink in `~/.config/helix` that links to the source code directory:
|
||||
Or, create a symbolic link:
|
||||
|
||||
```sh
|
||||
ln -s $PWD/runtime ~/.config/helix/runtime
|
||||
ln -Ts $PWD/runtime ~/.config/helix/runtime
|
||||
```
|
||||
|
||||
If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again.
|
||||
|
||||
#### Windows
|
||||
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
|
||||
@ -238,12 +272,32 @@ #### Multiple runtime directories
|
||||
1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
|
||||
developing and testing helix only).
|
||||
2. `runtime/` subdirectory of OS-dependent helix user config directory.
|
||||
3. `$HELIX_RUNTIME`.
|
||||
4. `runtime/` subdirectory of path to Helix executable.
|
||||
3. `$HELIX_RUNTIME`
|
||||
4. Distribution-specific fallback directory (set at compile time—not run time—
|
||||
with the `HELIX_DEFAULT_RUNTIME` environment variable)
|
||||
5. `runtime/` subdirectory of path to Helix executable.
|
||||
|
||||
This order also sets the priority for selecting which file will be used if multiple runtime
|
||||
directories have files with the same name.
|
||||
|
||||
#### Note to packagers
|
||||
|
||||
If you are making a package of Helix for end users, to provide a good out of
|
||||
the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment
|
||||
variable at build time (before invoking `cargo build`) to a directory which
|
||||
will store the final runtime files after installation. For example, say you want
|
||||
to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build
|
||||
script could follow are:
|
||||
|
||||
1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime`
|
||||
1. `cargo build --profile opt --locked --path helix-term`
|
||||
1. `cp -r runtime $BUILD_DIR/usr/lib/helix/`
|
||||
1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx`
|
||||
|
||||
This way the resulting `hx` binary will always look for its runtime directory in
|
||||
`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix`
|
||||
or `HELIX_RUNTIME`.
|
||||
|
||||
### Validating the installation
|
||||
|
||||
To make sure everything is set up as expected you should run the Helix health
|
||||
|
@ -12,6 +12,7 @@ # Keymap
|
||||
- [Match mode](#match-mode)
|
||||
- [Window mode](#window-mode)
|
||||
- [Space mode](#space-mode)
|
||||
- [Comment mode](#comment-mode)
|
||||
- [Popup](#popup)
|
||||
- [Unimpaired](#unimpaired)
|
||||
- [Insert mode](#insert-mode)
|
||||
@ -25,6 +26,8 @@ # Keymap
|
||||
|
||||
## Normal mode
|
||||
|
||||
Normal mode is the default mode when you launch helix. You can return to it from other modes by pressing the `Escape` key.
|
||||
|
||||
### Movement
|
||||
|
||||
> NOTE: Unlike Vim, `f`, `F`, `t` and `T` are not confined to the current line.
|
||||
@ -46,13 +49,13 @@ ### Movement
|
||||
| `T` | Find 'till previous char | `till_prev_char` |
|
||||
| `F` | Find previous char | `find_prev_char` |
|
||||
| `G` | Go to line number `<n>` | `goto_line` |
|
||||
| `Alt-.` | Repeat last motion (`f`, `t` or `m`) | `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` |
|
||||
| `End` | Move to the end of the line | `goto_line_end` |
|
||||
| `Ctrl-b`, `PageUp` | Move page up | `page_up` |
|
||||
| `Ctrl-f`, `PageDown` | Move page down | `page_down` |
|
||||
| `Ctrl-u` | Move half page up | `half_page_up` |
|
||||
| `Ctrl-d` | Move half page down | `half_page_down` |
|
||||
| `Ctrl-u` | Move cursor and page half page up | `page_cursor_half_up` |
|
||||
| `Ctrl-d` | Move cursor and page half page down | `page_cursor_half_down` |
|
||||
| `Ctrl-i` | Jump forward on the jumplist | `jump_forward` |
|
||||
| `Ctrl-o` | Jump backward on the jumplist | `jump_backward` |
|
||||
| `Ctrl-s` | Save the current selection to the jumplist | `save_selection` |
|
||||
@ -180,18 +183,18 @@ #### View mode
|
||||
useful when you're simply looking over text and not actively editing it.
|
||||
|
||||
|
||||
| Key | Description | Command |
|
||||
| ----- | ----------- | ------- |
|
||||
| `z`, `c` | Vertically center the line | `align_view_center` |
|
||||
| `t` | Align the line to the top of the screen | `align_view_top` |
|
||||
| `b` | Align the line to the bottom of the screen | `align_view_bottom` |
|
||||
| `m` | Align the line to the middle of the screen (horizontally) | `align_view_middle` |
|
||||
| `j`, `down` | Scroll the view downwards | `scroll_down` |
|
||||
| `k`, `up` | Scroll the view upwards | `scroll_up` |
|
||||
| `Ctrl-f`, `PageDown` | Move page down | `page_down` |
|
||||
| `Ctrl-b`, `PageUp` | Move page up | `page_up` |
|
||||
| `Ctrl-d` | Move half page down | `half_page_down` |
|
||||
| `Ctrl-u` | Move half page up | `half_page_up` |
|
||||
| Key | Description | Command |
|
||||
| ----- | ----------- | ------- |
|
||||
| `z`, `c` | Vertically center the line | `align_view_center` |
|
||||
| `t` | Align the line to the top of the screen | `align_view_top` |
|
||||
| `b` | Align the line to the bottom of the screen | `align_view_bottom` |
|
||||
| `m` | Align the line to the middle of the screen (horizontally) | `align_view_middle` |
|
||||
| `j`, `down` | Scroll the view downwards | `scroll_down` |
|
||||
| `k`, `up` | Scroll the view upwards | `scroll_up` |
|
||||
| `Ctrl-f`, `PageDown` | Move page down | `page_down` |
|
||||
| `Ctrl-b`, `PageUp` | Move page up | `page_up` |
|
||||
| `Ctrl-u` | Move cursor and page half page up | `page_cursor_half_up` |
|
||||
| `Ctrl-d` | Move cursor and page half page down | `page_cursor_half_down` |
|
||||
|
||||
#### Goto mode
|
||||
|
||||
@ -203,7 +206,7 @@ #### Goto mode
|
||||
| ----- | ----------- | ------- |
|
||||
| `g` | Go to line number `<n>` else start of file | `goto_file_start` |
|
||||
| `e` | Go to the end of the file | `goto_last_line` |
|
||||
| `f` | Go to files in the selection | `goto_file` |
|
||||
| `f` | Go to files in the selections | `goto_file` |
|
||||
| `h` | Go to the start of the line | `goto_line_start` |
|
||||
| `l` | Go to the end of the line | `goto_line_end` |
|
||||
| `s` | Go to first non-whitespace character of the line | `goto_first_nonwhitespace` |
|
||||
@ -221,6 +224,7 @@ #### Goto mode
|
||||
| `.` | Go to last modification in current file | `goto_last_modification` |
|
||||
| `j` | Move down textual (instead of visual) line | `move_line_down` |
|
||||
| `k` | Move up textual (instead of visual) line | `move_line_up` |
|
||||
| `w` | Show labels at each word and select the word that belongs to the entered labels | `goto_word` |
|
||||
|
||||
#### Match mode
|
||||
|
||||
@ -251,8 +255,8 @@ #### Window mode
|
||||
| `w`, `Ctrl-w` | Switch to next window | `rotate_view` |
|
||||
| `v`, `Ctrl-v` | Vertical right split | `vsplit` |
|
||||
| `s`, `Ctrl-s` | Horizontal bottom split | `hsplit` |
|
||||
| `f` | Go to files in the selection in horizontal splits | `goto_file` |
|
||||
| `F` | Go to files in the selection in vertical splits | `goto_file` |
|
||||
| `f` | Go to files in the selections in horizontal splits | `goto_file` |
|
||||
| `F` | Go to files in the selections in vertical splits | `goto_file` |
|
||||
| `h`, `Ctrl-h`, `Left` | Move to left split | `jump_view_left` |
|
||||
| `j`, `Ctrl-j`, `Down` | Move to split below | `jump_view_down` |
|
||||
| `k`, `Ctrl-k`, `Up` | Move to split above | `jump_view_up` |
|
||||
@ -276,7 +280,8 @@ #### Space mode
|
||||
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
|
||||
| `b` | Open buffer picker | `buffer_picker` |
|
||||
| `j` | Open jumplist picker | `jumplist_picker` |
|
||||
| `g` | Debug (experimental) | N/A |
|
||||
| `g` | Open changed file picker | `changed_file_picker` |
|
||||
| `G` | Debug (experimental) | N/A |
|
||||
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
|
||||
| `s` | Open document symbol picker (**LSP**) | `symbol_picker` |
|
||||
| `S` | Open workspace symbol picker (**LSP**) | `workspace_symbol_picker` |
|
||||
@ -287,9 +292,12 @@ #### Space mode
|
||||
| `h` | Select symbol references (**LSP**) | `select_references_to_symbol_under_cursor` |
|
||||
| `'` | Open last fuzzy picker | `last_picker` |
|
||||
| `w` | Enter [window mode](#window-mode) | N/A |
|
||||
| `c` | Comment/uncomment selections | `toggle_comments` |
|
||||
| `C` | Block comment/uncomment selections | `toggle_block_comments` |
|
||||
| `Alt-c` | Line comment/uncomment selections | `toggle_line_comments` |
|
||||
| `p` | Paste system clipboard after selections | `paste_clipboard_after` |
|
||||
| `P` | Paste system clipboard before selections | `paste_clipboard_before` |
|
||||
| `y` | Join and yank selections to clipboard | `yank_joined_to_clipboard` |
|
||||
| `y` | Yank selections to clipboard | `yank_to_clipboard` |
|
||||
| `Y` | Yank main selection to clipboard | `yank_main_selection_to_clipboard` |
|
||||
| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
|
||||
| `/` | Global search in workspace folder | `global_search` |
|
||||
@ -337,6 +345,8 @@ #### Unimpaired
|
||||
|
||||
## Insert mode
|
||||
|
||||
Accessed by typing `i` in [normal mode](#normal-mode).
|
||||
|
||||
Insert mode bindings are minimal by default. Helix is designed to
|
||||
be a modal editor, and this is reflected in the user experience and internal
|
||||
mechanics. Changes to the text are only saved for undos when
|
||||
@ -390,9 +400,11 @@ ## Insert mode
|
||||
|
||||
## Select / extend mode
|
||||
|
||||
Accessed by typing `v` in [normal mode](#normal-mode).
|
||||
|
||||
Select mode echoes Normal mode, but changes any movements to extend
|
||||
selections rather than replace them. Goto motions are also changed to
|
||||
extend, so that `vgl` for example extends the selection to the end of
|
||||
extend, so that `vgl`, for example, extends the selection to the end of
|
||||
the line.
|
||||
|
||||
Search is also affected. By default, `n` and `N` will remove the current
|
||||
@ -405,19 +417,20 @@ ## Picker
|
||||
|
||||
Keys to use within picker. Remapping currently not supported.
|
||||
|
||||
| Key | Description |
|
||||
| ----- | ------------- |
|
||||
| `Shift-Tab`, `Up`, `Ctrl-p` | Previous entry |
|
||||
| `Tab`, `Down`, `Ctrl-n` | Next entry |
|
||||
| `PageUp`, `Ctrl-u` | Page up |
|
||||
| `PageDown`, `Ctrl-d` | Page down |
|
||||
| `Home` | Go to first entry |
|
||||
| `End` | Go to last entry |
|
||||
| `Enter` | Open selected |
|
||||
| `Ctrl-s` | Open horizontally |
|
||||
| `Ctrl-v` | Open vertically |
|
||||
| `Ctrl-t` | Toggle preview |
|
||||
| `Escape`, `Ctrl-c` | Close picker |
|
||||
| Key | Description |
|
||||
| ----- | ------------- |
|
||||
| `Shift-Tab`, `Up`, `Ctrl-p` | Previous entry |
|
||||
| `Tab`, `Down`, `Ctrl-n` | Next entry |
|
||||
| `PageUp`, `Ctrl-u` | Page up |
|
||||
| `PageDown`, `Ctrl-d` | Page down |
|
||||
| `Home` | Go to first entry |
|
||||
| `End` | Go to last entry |
|
||||
| `Enter` | Open selected |
|
||||
| `Alt-Enter` | Open selected in the background without closing the picker |
|
||||
| `Ctrl-s` | Open horizontally |
|
||||
| `Ctrl-v` | Open vertically |
|
||||
| `Ctrl-t` | Toggle preview |
|
||||
| `Escape`, `Ctrl-c` | Close picker |
|
||||
|
||||
## Prompt
|
||||
|
||||
|
@ -7,24 +7,24 @@ ## `languages.toml` files
|
||||
|
||||
There are three possible locations for a `languages.toml` file:
|
||||
|
||||
1. In the Helix source code, this lives in the
|
||||
1. In the Helix source code, which lives in the
|
||||
[Helix repository](https://github.com/helix-editor/helix/blob/master/languages.toml).
|
||||
It provides the default configurations for languages and language servers.
|
||||
|
||||
2. In your [configuration directory](./configuration.md). This overrides values
|
||||
from the built-in language configuration. For example to disable
|
||||
from the built-in language configuration. For example, to disable
|
||||
auto-LSP-formatting in Rust:
|
||||
|
||||
```toml
|
||||
# in <config_dir>/helix/languages.toml
|
||||
```toml
|
||||
# in <config_dir>/helix/languages.toml
|
||||
|
||||
[language-server.mylang-lsp]
|
||||
command = "mylang-lsp"
|
||||
[language-server.mylang-lsp]
|
||||
command = "mylang-lsp"
|
||||
|
||||
[[language]]
|
||||
name = "rust"
|
||||
auto-format = false
|
||||
```
|
||||
[[language]]
|
||||
name = "rust"
|
||||
auto-format = false
|
||||
```
|
||||
|
||||
3. In a `.helix` folder in your project. Language configuration may also be
|
||||
overridden local to a project by creating a `languages.toml` file in a
|
||||
@ -42,7 +42,7 @@ ## Language configuration
|
||||
scope = "source.mylang"
|
||||
injection-regex = "mylang"
|
||||
file-types = ["mylang", "myl"]
|
||||
comment-token = "#"
|
||||
comment-tokens = "#"
|
||||
indent = { tab-width = 2, unit = " " }
|
||||
formatter = { command = "mylang-formatter" , args = ["--stdin"] }
|
||||
language-servers = [ "mylang-lsp" ]
|
||||
@ -61,13 +61,16 @@ ## Language configuration
|
||||
| `roots` | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
|
||||
| `auto-format` | Whether to autoformat this language when saving |
|
||||
| `diagnostic-severity` | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) |
|
||||
| `comment-token` | The token to use as a comment-token |
|
||||
| `comment-tokens` | The tokens to use as a comment token, either a single token `"//"` or an array `["//", "///", "//!"]` (the first token will be used for commenting). Also configurable as `comment-token` for backwards compatibility|
|
||||
| `block-comment-tokens`| The start and end tokens for a multiline comment either an array or single table of `{ start = "/*", end = "*/"}`. The first set of tokens will be used for commenting, any pairs in the array can be uncommented |
|
||||
| `indent` | The indent to use. Has sub keys `unit` (the text inserted into the document when indenting; usually set to N spaces or `"\t"` for tabs) and `tab-width` (the number of spaces rendered for a tab) |
|
||||
| `language-servers` | The Language Servers used for this language. See below for more information in the section [Configuring Language Servers for a language](#configuring-language-servers-for-a-language) |
|
||||
| `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) |
|
||||
| `formatter` | The formatter for the language, it will take precedence over the lsp when defined. The formatter must be able to take the original file as input from stdin and write the formatted file to stdout |
|
||||
| `soft-wrap` | [editor.softwrap](./configuration.md#editorsoft-wrap-section)
|
||||
| `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` |
|
||||
| `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.
|
||||
|
||||
### File-type detection and the `file-types` key
|
||||
|
||||
@ -76,24 +79,26 @@ ### File-type detection and the `file-types` key
|
||||
example:
|
||||
|
||||
```toml
|
||||
file-types = ["Makefile", "toml", { suffix = ".git/config" }]
|
||||
file-types = ["toml", { glob = "Makefile" }, { glob = ".git/config" }, { glob = ".github/workflows/*.yaml" } ]
|
||||
```
|
||||
|
||||
When determining a language configuration to use, Helix searches the file-types
|
||||
with the following priorities:
|
||||
|
||||
1. Exact match: if the filename of a file is an exact match of a string in a
|
||||
`file-types` list, that language wins. In the example above, `"Makefile"`
|
||||
will match against `Makefile` files.
|
||||
2. Extension: if there are no exact matches, any `file-types` string that
|
||||
matches the file extension of a given file wins. In the example above, the
|
||||
`"toml"` matches files like `Cargo.toml` or `languages.toml`.
|
||||
3. Suffix: if there are still no matches, any values in `suffix` tables
|
||||
are checked against the full path of the given file. In the example above,
|
||||
the `{ suffix = ".git/config" }` would match against any `config` files
|
||||
in `.git` directories. Note: `/` is used as the directory separator but is
|
||||
replaced at runtime with the appropriate path separator for the operating
|
||||
system, so this rule would match against `.git\config` files on Windows.
|
||||
1. Glob: values in `glob` tables are checked against the full path of the given
|
||||
file. Globs are standard Unix-style path globs (e.g. the kind you use in Shell)
|
||||
and can be used to match paths for a specific prefix, suffix, directory, etc.
|
||||
In the above example, the `{ glob = "Makefile" }` config would match files
|
||||
with the name `Makefile`, the `{ glob = ".git/config" }` config would match
|
||||
`config` files in `.git` directories, and the `{ glob = ".github/workflows/*.yaml" }`
|
||||
config would match any `yaml` files in `.github/workflow` directories. Note
|
||||
that globs should always use the Unix path separator `/` even on Windows systems;
|
||||
the matcher will automatically take the machine-specific separators into account.
|
||||
If the glob isn't an absolute path or doesn't already start with a glob prefix,
|
||||
`*/` will automatically be added to ensure it matches for any subdirectory.
|
||||
2. Extension: if there are no glob matches, any `file-types` string that matches
|
||||
the file extension of a given file wins. In the example above, the `"toml"`
|
||||
config matches files like `Cargo.toml` or `languages.toml`.
|
||||
|
||||
## Language Server configuration
|
||||
|
||||
@ -118,17 +123,18 @@ ## Language Server configuration
|
||||
|
||||
These are the available options for a language server.
|
||||
|
||||
| Key | Description |
|
||||
| ---- | ----------- |
|
||||
| `command` | The name or path of the language server binary to execute. Binaries must be in `$PATH` |
|
||||
| `args` | A list of arguments to pass to the language server binary |
|
||||
| `config` | LSP initialization options |
|
||||
| `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` |
|
||||
| `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` |
|
||||
| Key | Description |
|
||||
| ---- | ----------- |
|
||||
| `command` | The name or path of the language server binary to execute. Binaries must be in `$PATH` |
|
||||
| `args` | A list of arguments to pass to the language server binary |
|
||||
| `config` | LSP initialization options |
|
||||
| `timeout` | The maximum time a request to the language server may take, in seconds. Defaults to `20` |
|
||||
| `environment` | Any environment variables that will be used when starting the language server `{ "KEY1" = "Value1", "KEY2" = "Value2" }` |
|
||||
| `required-root-patterns` | A list of `glob` patterns to look for in the working directory. The language server is started if at least one of them is found. |
|
||||
|
||||
A `format` sub-table within `config` can be used to pass extra formatting options to
|
||||
[Document Formatting Requests](https://github.com/microsoft/language-server-protocol/blob/gh-pages/_specifications/specification-3-17.md#document-formatting-request--leftwards_arrow_with_hook).
|
||||
For example with typescript:
|
||||
[Document Formatting Requests](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting).
|
||||
For example, with typescript:
|
||||
|
||||
```toml
|
||||
[language-server.typescript-language-server]
|
||||
@ -144,11 +150,13 @@ ### Configuring Language Servers for a language
|
||||
|
||||
Different languages can use the same language server instance, e.g. `typescript-language-server` is used for javascript, jsx, tsx and typescript by default.
|
||||
|
||||
The definition order of language servers affects the order in the results list of code action menu.
|
||||
|
||||
In case multiple language servers are specified in the `language-servers` attribute of a `language`,
|
||||
it's often useful to only enable/disable certain language-server features for these language servers.
|
||||
|
||||
For example `efm-lsp-prettier` of the previous example is used only with a formatting command `prettier`,
|
||||
so everything else should be handled by the `typescript-language-server` (which is configured by default)
|
||||
As an example, `efm-lsp-prettier` of the previous example is used only with a formatting command `prettier`,
|
||||
so everything else should be handled by the `typescript-language-server` (which is configured by default).
|
||||
The language configuration for typescript could look like this:
|
||||
|
||||
```toml
|
||||
@ -166,10 +174,10 @@ ### Configuring Language Servers for a language
|
||||
```
|
||||
|
||||
Each requested LSP feature is prioritized in the order of the `language-servers` array.
|
||||
For example the first `goto-definition` supported language server (in this case `typescript-language-server`) will be taken for the relevant LSP request (command `goto_definition`).
|
||||
For example, the first `goto-definition` supported language server (in this case `typescript-language-server`) will be taken for the relevant LSP request (command `goto_definition`).
|
||||
The features `diagnostics`, `code-action`, `completion`, `document-symbols` and `workspace-symbols` are an exception to that rule, as they are working for all language servers at the same time and are merged together, if enabled for the language.
|
||||
If no `except-features` or `only-features` is given all features for the language server are enabled.
|
||||
If a language server itself doesn't support a feature the next language server array entry will be tried (and so on).
|
||||
If no `except-features` or `only-features` is given, all features for the language server are enabled.
|
||||
If a language server itself doesn't support a feature, the next language server array entry will be tried (and so on).
|
||||
|
||||
The list of supported features is:
|
||||
|
||||
|
@ -36,13 +36,6 @@ ### Overview
|
||||
user-submitted themes
|
||||
[here](https://github.com/helix-editor/helix/blob/master/runtime/themes).
|
||||
|
||||
### Using the linter
|
||||
|
||||
Use the supplied linting tool to check for errors and missing scopes:
|
||||
|
||||
```sh
|
||||
cargo xtask themelint onedark # replace onedark with <name>
|
||||
```
|
||||
|
||||
## The details of theme creation
|
||||
|
||||
@ -70,6 +63,7 @@ ### Color palettes
|
||||
|
||||
| Color Name |
|
||||
| --- |
|
||||
| `default` |
|
||||
| `black` |
|
||||
| `red` |
|
||||
| `green` |
|
||||
@ -154,6 +148,7 @@ #### Syntax highlighting
|
||||
|
||||
- `type` - Types
|
||||
- `builtin` - Primitive types provided by the language (`int`, `usize`)
|
||||
- `parameter` - Generic type parameters (`T`)
|
||||
- `enum`
|
||||
- `variant`
|
||||
- `constructor`
|
||||
@ -244,9 +239,13 @@ #### Syntax highlighting
|
||||
|
||||
- `diff` - version control changes
|
||||
- `plus` - additions
|
||||
- `gutter` - gutter indicator
|
||||
- `minus` - deletions
|
||||
- `gutter` - gutter indicator
|
||||
- `delta` - modifications
|
||||
- `moved` - renamed or moved files/changes
|
||||
- `conflict` - merge conflicts
|
||||
- `gutter` - gutter indicator
|
||||
|
||||
#### Interface
|
||||
|
||||
@ -291,11 +290,14 @@ #### Interface
|
||||
| `ui.statusline.insert` | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
|
||||
| `ui.statusline.select` | Statusline mode during select mode ([only if `editor.color-modes` is enabled][editor-section]) |
|
||||
| `ui.statusline.separator` | Separator character in statusline |
|
||||
| `ui.bufferline` | Style for the buffer line |
|
||||
| `ui.bufferline.active` | Style for the active buffer in buffer line |
|
||||
| `ui.bufferline.background` | Style for bufferline background |
|
||||
| `ui.popup` | Documentation popups (e.g. Space + k) |
|
||||
| `ui.popup.info` | Prompt for multiple key options |
|
||||
| `ui.window` | Borderlines separating splits |
|
||||
| `ui.help` | Description box for commands |
|
||||
| `ui.text` | Command prompts, popup text, etc. |
|
||||
| `ui.text` | Default text style, command prompts, popup text, etc. |
|
||||
| `ui.text.focus` | The currently selected line in the picker |
|
||||
| `ui.text.inactive` | Same as `ui.text` but when the text is inactive (e.g. suggestions) |
|
||||
| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
|
||||
@ -306,6 +308,7 @@ #### Interface
|
||||
| `ui.virtual.inlay-hint.parameter` | Style for inlay hints of kind `parameter` (LSPs are not required to set a kind) |
|
||||
| `ui.virtual.inlay-hint.type` | Style for inlay hints of kind `type` (LSPs are not required to set a kind) |
|
||||
| `ui.virtual.wrap` | Soft-wrap indicator (see the [`editor.soft-wrap` config][editor-section]) |
|
||||
| `ui.virtual.jump-label` | Style for virtual jump labels |
|
||||
| `ui.menu` | Code and command completion menus |
|
||||
| `ui.menu.selected` | Selected autocomplete item |
|
||||
| `ui.menu.scroll` | `fg` sets thumb color, `bg` sets track color of scrollbar |
|
||||
@ -325,5 +328,7 @@ #### Interface
|
||||
| `diagnostic.info` | Diagnostics info (editing area) |
|
||||
| `diagnostic.warning` | Diagnostics warning (editing area) |
|
||||
| `diagnostic.error` | Diagnostics error (editing area) |
|
||||
| `diagnostic.unnecessary` | Diagnostics with unnecessary tag (editing area) |
|
||||
| `diagnostic.deprecated` | Diagnostics with deprecated tag (editing area) |
|
||||
|
||||
[editor-section]: ./configuration.md#editor-section
|
||||
|
@ -37,19 +37,35 @@ ### User-defined registers
|
||||
- `"hc` - Store the selection in register `h` and then change it (delete and enter insert mode).
|
||||
- `"md` - Store the selection in register `m` and delete it.
|
||||
|
||||
### Special registers
|
||||
### Default registers
|
||||
|
||||
Commands that use registers, like yank (`y`), use a default register if none is specified.
|
||||
These registers are used as defaults:
|
||||
|
||||
| Register character | Contains |
|
||||
| --- | --- |
|
||||
| `/` | Last search |
|
||||
| `:` | Last executed command |
|
||||
| `"` | Last yanked text |
|
||||
| `_` | Black hole |
|
||||
| `@` | Last recorded macro |
|
||||
|
||||
The system clipboard is not directly supported by a special register. Instead, special commands and keybindings are provided. Refer to the
|
||||
[key map](keymap.md#space-mode) for more details.
|
||||
### Special registers
|
||||
|
||||
The black hole register is a no-op register, meaning that no data will be read or written to it.
|
||||
Some registers have special behavior when read from and written to.
|
||||
|
||||
| Register character | When read | When written |
|
||||
| --- | --- | --- |
|
||||
| `_` | No values are returned | All values are discarded |
|
||||
| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable |
|
||||
| `.` | Contents of the current selections | This register is not writable |
|
||||
| `%` | Name of the current file | This register is not writable |
|
||||
| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard |
|
||||
| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard |
|
||||
|
||||
When yanking multiple selections to the clipboard registers, the selections
|
||||
are joined with newlines. Pasting from these registers will paste multiple
|
||||
selections if the clipboard was last yanked to by the Helix session. Otherwise
|
||||
the clipboard contents are pasted as one selection.
|
||||
|
||||
## Surround
|
||||
|
||||
@ -96,13 +112,13 @@ ## Selecting and manipulating text with textobjects
|
||||
| `(`, `[`, `'`, etc. | Specified surround pairs |
|
||||
| `m` | The closest surround pair |
|
||||
| `f` | Function |
|
||||
| `c` | Class |
|
||||
| `t` | Type (or Class) |
|
||||
| `a` | Argument/parameter |
|
||||
| `o` | Comment |
|
||||
| `t` | Test |
|
||||
| `c` | Comment |
|
||||
| `T` | Test |
|
||||
| `g` | Change |
|
||||
|
||||
> 💡 `f`, `c`, 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
|
||||
some grammars][lang-support] currently have the query file implemented.
|
||||
Contributions are welcome!
|
||||
@ -112,7 +128,7 @@ ## Navigating using tree-sitter textobjects
|
||||
Navigating between functions, classes, parameters, and other elements is
|
||||
possible using tree-sitter and textobject queries. For
|
||||
example to move to the next function use `]f`, to move to previous
|
||||
class use `[c`, and so on.
|
||||
type use `[t`, and so on.
|
||||
|
||||
![Tree-sitter-nav-demo][tree-sitter-nav-demo]
|
||||
|
||||
|
@ -1,660 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// Fix back button cache problem
|
||||
window.onunload = function () { };
|
||||
|
||||
// Global variable, shared between modules
|
||||
function playground_text(playground) {
|
||||
let code_block = playground.querySelector("code");
|
||||
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
return editor.getValue();
|
||||
} else {
|
||||
return code_block.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
(function codeSnippets() {
|
||||
function fetch_with_timeout(url, options, timeout = 6000) {
|
||||
return Promise.race([
|
||||
fetch(url, options),
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout))
|
||||
]);
|
||||
}
|
||||
|
||||
var playgrounds = Array.from(document.querySelectorAll(".playground"));
|
||||
if (playgrounds.length > 0) {
|
||||
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
// get list of crates available in the rust playground
|
||||
let playground_crates = response.crates.map(item => item["id"]);
|
||||
playgrounds.forEach(block => handle_crate_list_update(block, playground_crates));
|
||||
});
|
||||
}
|
||||
|
||||
function handle_crate_list_update(playground_block, playground_crates) {
|
||||
// update the play buttons after receiving the response
|
||||
update_play_button(playground_block, playground_crates);
|
||||
|
||||
// and install on change listener to dynamically update ACE editors
|
||||
if (window.ace) {
|
||||
let code_block = playground_block.querySelector("code");
|
||||
if (code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.addEventListener("change", function (e) {
|
||||
update_play_button(playground_block, playground_crates);
|
||||
});
|
||||
// add Ctrl-Enter command to execute rust code
|
||||
editor.commands.addCommand({
|
||||
name: "run",
|
||||
bindKey: {
|
||||
win: "Ctrl-Enter",
|
||||
mac: "Ctrl-Enter"
|
||||
},
|
||||
exec: _editor => run_rust_code(playground_block)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updates the visibility of play button based on `no_run` class and
|
||||
// used crates vs ones available on http://play.rust-lang.org
|
||||
function update_play_button(pre_block, playground_crates) {
|
||||
var play_button = pre_block.querySelector(".play-button");
|
||||
|
||||
// skip if code is `no_run`
|
||||
if (pre_block.querySelector('code').classList.contains("no_run")) {
|
||||
play_button.classList.add("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
// get list of `extern crate`'s from snippet
|
||||
var txt = playground_text(pre_block);
|
||||
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
|
||||
var snippet_crates = [];
|
||||
var item;
|
||||
while (item = re.exec(txt)) {
|
||||
snippet_crates.push(item[1]);
|
||||
}
|
||||
|
||||
// check if all used crates are available on play.rust-lang.org
|
||||
var all_available = snippet_crates.every(function (elem) {
|
||||
return playground_crates.indexOf(elem) > -1;
|
||||
});
|
||||
|
||||
if (all_available) {
|
||||
play_button.classList.remove("hidden");
|
||||
} else {
|
||||
play_button.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function run_rust_code(code_block) {
|
||||
var result_block = code_block.querySelector(".result");
|
||||
if (!result_block) {
|
||||
result_block = document.createElement('code');
|
||||
result_block.className = 'result hljs language-bash';
|
||||
|
||||
code_block.append(result_block);
|
||||
}
|
||||
|
||||
let text = playground_text(code_block);
|
||||
let classes = code_block.querySelector('code').classList;
|
||||
let has_2018 = classes.contains("edition2018");
|
||||
let edition = has_2018 ? "2018" : "2015";
|
||||
|
||||
var params = {
|
||||
version: "stable",
|
||||
optimize: "0",
|
||||
code: text,
|
||||
edition: edition
|
||||
};
|
||||
|
||||
if (text.indexOf("#![feature") !== -1) {
|
||||
params.version = "nightly";
|
||||
}
|
||||
|
||||
result_block.innerText = "Running...";
|
||||
|
||||
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(params)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => result_block.innerText = response.result)
|
||||
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
||||
}
|
||||
|
||||
// Syntax highlighting Configuration
|
||||
hljs.configure({
|
||||
tabReplace: ' ', // 4 spaces
|
||||
languages: [], // Languages used for auto-detection
|
||||
});
|
||||
|
||||
let code_nodes = Array
|
||||
.from(document.querySelectorAll('code'))
|
||||
// Don't highlight `inline code` blocks in headers.
|
||||
.filter(function (node) {return !node.parentElement.classList.contains("header"); });
|
||||
|
||||
if (window.ace) {
|
||||
// language-rust class needs to be removed for editable
|
||||
// blocks or highlightjs will capture events
|
||||
Array
|
||||
.from(document.querySelectorAll('code.editable'))
|
||||
.forEach(function (block) { block.classList.remove('language-rust'); });
|
||||
|
||||
Array
|
||||
.from(document.querySelectorAll('code:not(.editable)'))
|
||||
.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
} else {
|
||||
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
}
|
||||
|
||||
// Adding the hljs class gives code blocks the color css
|
||||
// even if highlighting doesn't apply
|
||||
code_nodes.forEach(function (block) { block.classList.add('hljs'); });
|
||||
|
||||
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
|
||||
|
||||
var lines = Array.from(block.querySelectorAll('.boring'));
|
||||
// If no lines were hidden, return
|
||||
if (!lines.length) { return; }
|
||||
block.classList.add("hide-boring");
|
||||
|
||||
var buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
buttons.innerHTML = "<button class=\"fa fa-eye\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
|
||||
|
||||
// add expand button
|
||||
var pre_block = block.parentNode;
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
|
||||
pre_block.querySelector('.buttons').addEventListener('click', function (e) {
|
||||
if (e.target.classList.contains('fa-eye')) {
|
||||
e.target.classList.remove('fa-eye');
|
||||
e.target.classList.add('fa-eye-slash');
|
||||
e.target.title = 'Hide lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.remove('hide-boring');
|
||||
} else if (e.target.classList.contains('fa-eye-slash')) {
|
||||
e.target.classList.remove('fa-eye-slash');
|
||||
e.target.classList.add('fa-eye');
|
||||
e.target.title = 'Show hidden lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.add('hide-boring');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
Array.from(document.querySelectorAll('pre code')).forEach(function (block) {
|
||||
var pre_block = block.parentNode;
|
||||
if (!pre_block.classList.contains('playground')) {
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var clipButton = document.createElement('button');
|
||||
clipButton.className = 'fa fa-copy clip-button';
|
||||
clipButton.title = 'Copy to clipboard';
|
||||
clipButton.setAttribute('aria-label', clipButton.title);
|
||||
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
|
||||
|
||||
buttons.insertBefore(clipButton, buttons.firstChild);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Process playground code blocks
|
||||
Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) {
|
||||
// Add play button
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var runCodeButton = document.createElement('button');
|
||||
runCodeButton.className = 'fa fa-play play-button';
|
||||
runCodeButton.hidden = true;
|
||||
runCodeButton.title = 'Run this code';
|
||||
runCodeButton.setAttribute('aria-label', runCodeButton.title);
|
||||
|
||||
buttons.insertBefore(runCodeButton, buttons.firstChild);
|
||||
runCodeButton.addEventListener('click', function (e) {
|
||||
run_rust_code(pre_block);
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
var copyCodeClipboardButton = document.createElement('button');
|
||||
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
|
||||
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
|
||||
copyCodeClipboardButton.title = 'Copy to clipboard';
|
||||
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
|
||||
|
||||
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
|
||||
}
|
||||
|
||||
let code_block = pre_block.querySelector("code");
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
var undoChangesButton = document.createElement('button');
|
||||
undoChangesButton.className = 'fa fa-history reset-button';
|
||||
undoChangesButton.title = 'Undo changes';
|
||||
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
|
||||
|
||||
buttons.insertBefore(undoChangesButton, buttons.firstChild);
|
||||
|
||||
undoChangesButton.addEventListener('click', function () {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.setValue(editor.originalCode);
|
||||
editor.clearSelection();
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function themes() {
|
||||
var html = document.querySelector('html');
|
||||
var themeToggleButton = document.getElementById('theme-toggle');
|
||||
var themePopup = document.getElementById('theme-list');
|
||||
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
|
||||
var stylesheets = {
|
||||
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
|
||||
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
|
||||
highlight: document.querySelector("[href$='highlight.css']"),
|
||||
};
|
||||
|
||||
function showThemes() {
|
||||
themePopup.style.display = 'block';
|
||||
themeToggleButton.setAttribute('aria-expanded', true);
|
||||
themePopup.querySelector("button#" + get_theme()).focus();
|
||||
}
|
||||
|
||||
function hideThemes() {
|
||||
themePopup.style.display = 'none';
|
||||
themeToggleButton.setAttribute('aria-expanded', false);
|
||||
themeToggleButton.focus();
|
||||
}
|
||||
|
||||
function get_theme() {
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||
if (theme === null || theme === undefined) {
|
||||
return default_theme;
|
||||
} else {
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
|
||||
function set_theme(theme, store = true) {
|
||||
let ace_theme;
|
||||
|
||||
if (theme == 'coal' || theme == 'navy') {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = false;
|
||||
stylesheets.highlight.disabled = true;
|
||||
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else if (theme == 'ayu') {
|
||||
stylesheets.ayuHighlight.disabled = false;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = true;
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = false;
|
||||
ace_theme = "ace/theme/dawn";
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;
|
||||
}, 1);
|
||||
|
||||
if (window.ace && window.editors) {
|
||||
window.editors.forEach(function (editor) {
|
||||
editor.setTheme(ace_theme);
|
||||
});
|
||||
}
|
||||
|
||||
var previousTheme = get_theme();
|
||||
|
||||
if (store) {
|
||||
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
|
||||
}
|
||||
|
||||
html.classList.remove(previousTheme);
|
||||
html.classList.add(theme);
|
||||
}
|
||||
|
||||
// Set theme
|
||||
var theme = get_theme();
|
||||
|
||||
set_theme(theme, false);
|
||||
|
||||
themeToggleButton.addEventListener('click', function () {
|
||||
if (themePopup.style.display === 'block') {
|
||||
hideThemes();
|
||||
} else {
|
||||
showThemes();
|
||||
}
|
||||
});
|
||||
|
||||
themePopup.addEventListener('click', function (e) {
|
||||
var theme = e.target.id || e.target.parentElement.id;
|
||||
set_theme(theme);
|
||||
});
|
||||
|
||||
themePopup.addEventListener('focusout', function(e) {
|
||||
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
|
||||
if (!!e.relatedTarget && !themeToggleButton.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
|
||||
document.addEventListener('click', function(e) {
|
||||
if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (!themePopup.contains(e.target)) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'Escape':
|
||||
e.preventDefault();
|
||||
hideThemes();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.previousElementSibling) {
|
||||
li.previousElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.nextElementSibling) {
|
||||
li.nextElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'Home':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:first-child button').focus();
|
||||
break;
|
||||
case 'End':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:last-child button').focus();
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function sidebar() {
|
||||
var html = document.querySelector("html");
|
||||
var sidebar = document.getElementById("sidebar");
|
||||
var sidebarLinks = document.querySelectorAll('#sidebar a');
|
||||
var sidebarToggleButton = document.getElementById("sidebar-toggle");
|
||||
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
|
||||
var firstContact = null;
|
||||
|
||||
function showSidebar() {
|
||||
html.classList.remove('sidebar-hidden')
|
||||
html.classList.add('sidebar-visible');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', 0);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||
sidebar.setAttribute('aria-hidden', false);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||
}
|
||||
|
||||
|
||||
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
|
||||
|
||||
function toggleSection(ev) {
|
||||
ev.currentTarget.parentElement.classList.toggle('expanded');
|
||||
}
|
||||
|
||||
Array.from(sidebarAnchorToggles).forEach(function (el) {
|
||||
el.addEventListener('click', toggleSection);
|
||||
});
|
||||
|
||||
function hideSidebar() {
|
||||
html.classList.remove('sidebar-visible')
|
||||
html.classList.add('sidebar-hidden');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', -1);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||
sidebar.setAttribute('aria-hidden', true);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
||||
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
var current_width = parseInt(
|
||||
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
|
||||
if (current_width < 150) {
|
||||
document.documentElement.style.setProperty('--sidebar-width', '150px');
|
||||
}
|
||||
showSidebar();
|
||||
} else if (html.classList.contains("sidebar-visible")) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (getComputedStyle(sidebar)['transform'] === 'none') {
|
||||
hideSidebar();
|
||||
} else {
|
||||
showSidebar();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
|
||||
|
||||
function initResize(e) {
|
||||
window.addEventListener('mousemove', resize, false);
|
||||
window.addEventListener('mouseup', stopResize, false);
|
||||
html.classList.add('sidebar-resizing');
|
||||
}
|
||||
function resize(e) {
|
||||
var pos = (e.clientX - sidebar.offsetLeft);
|
||||
if (pos < 20) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
showSidebar();
|
||||
}
|
||||
pos = Math.min(pos, window.innerWidth - 100);
|
||||
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
|
||||
}
|
||||
}
|
||||
//on mouseup remove windows functions mousemove & mouseup
|
||||
function stopResize(e) {
|
||||
html.classList.remove('sidebar-resizing');
|
||||
window.removeEventListener('mousemove', resize, false);
|
||||
window.removeEventListener('mouseup', stopResize, false);
|
||||
}
|
||||
|
||||
document.addEventListener('touchstart', function (e) {
|
||||
firstContact = {
|
||||
x: e.touches[0].clientX,
|
||||
time: Date.now()
|
||||
};
|
||||
}, { passive: true });
|
||||
|
||||
document.addEventListener('touchmove', function (e) {
|
||||
if (!firstContact)
|
||||
return;
|
||||
|
||||
var curX = e.touches[0].clientX;
|
||||
var xDiff = curX - firstContact.x,
|
||||
tDiff = Date.now() - firstContact.time;
|
||||
|
||||
if (tDiff < 250 && Math.abs(xDiff) >= 150) {
|
||||
if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300))
|
||||
showSidebar();
|
||||
else if (xDiff < 0 && curX < 300)
|
||||
hideSidebar();
|
||||
|
||||
firstContact = null;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
// Scroll sidebar to current active section
|
||||
var activeSection = document.getElementById("sidebar").querySelector(".active");
|
||||
if (activeSection) {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
||||
activeSection.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
})();
|
||||
|
||||
(function chapterNavigation() {
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (window.search && window.search.hasFocus()) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'ArrowRight':
|
||||
e.preventDefault();
|
||||
var nextButton = document.querySelector('.nav-chapters.next');
|
||||
if (nextButton) {
|
||||
window.location.href = nextButton.href;
|
||||
}
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
e.preventDefault();
|
||||
var previousButton = document.querySelector('.nav-chapters.previous');
|
||||
if (previousButton) {
|
||||
window.location.href = previousButton.href;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function clipboard() {
|
||||
var clipButtons = document.querySelectorAll('.clip-button');
|
||||
|
||||
function hideTooltip(elem) {
|
||||
elem.firstChild.innerText = "";
|
||||
elem.className = 'fa fa-copy clip-button';
|
||||
}
|
||||
|
||||
function showTooltip(elem, msg) {
|
||||
elem.firstChild.innerText = msg;
|
||||
elem.className = 'fa fa-copy tooltipped';
|
||||
}
|
||||
|
||||
var clipboardSnippets = new ClipboardJS('.clip-button', {
|
||||
text: function (trigger) {
|
||||
hideTooltip(trigger);
|
||||
let playground = trigger.closest("pre");
|
||||
return playground_text(playground);
|
||||
}
|
||||
});
|
||||
|
||||
Array.from(clipButtons).forEach(function (clipButton) {
|
||||
clipButton.addEventListener('mouseout', function (e) {
|
||||
hideTooltip(e.currentTarget);
|
||||
});
|
||||
});
|
||||
|
||||
clipboardSnippets.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
showTooltip(e.trigger, "Copied!");
|
||||
});
|
||||
|
||||
clipboardSnippets.on('error', function (e) {
|
||||
showTooltip(e.trigger, "Clipboard error!");
|
||||
});
|
||||
})();
|
||||
|
||||
(function scrollToTop () {
|
||||
var menuTitle = document.querySelector('.menu-title');
|
||||
|
||||
menuTitle.addEventListener('click', function () {
|
||||
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
})();
|
||||
|
||||
(function controlMenu() {
|
||||
var menu = document.getElementById('menu-bar');
|
||||
|
||||
(function controlPosition() {
|
||||
var scrollTop = document.scrollingElement.scrollTop;
|
||||
var prevScrollTop = scrollTop;
|
||||
var minMenuY = -menu.clientHeight - 50;
|
||||
// When the script loads, the page can be at any scroll (e.g. if you reforesh it).
|
||||
menu.style.top = scrollTop + 'px';
|
||||
// Same as parseInt(menu.style.top.slice(0, -2), but faster
|
||||
var topCache = menu.style.top.slice(0, -2);
|
||||
menu.classList.remove('sticky');
|
||||
var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster
|
||||
document.addEventListener('scroll', function () {
|
||||
scrollTop = Math.max(document.scrollingElement.scrollTop, 0);
|
||||
// `null` means that it doesn't need to be updated
|
||||
var nextSticky = null;
|
||||
var nextTop = null;
|
||||
var scrollDown = scrollTop > prevScrollTop;
|
||||
var menuPosAbsoluteY = topCache - scrollTop;
|
||||
if (scrollDown) {
|
||||
nextSticky = false;
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextTop = prevScrollTop;
|
||||
}
|
||||
} else {
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextSticky = true;
|
||||
} else if (menuPosAbsoluteY < minMenuY) {
|
||||
nextTop = prevScrollTop + minMenuY;
|
||||
}
|
||||
}
|
||||
if (nextSticky === true && stickyCache === false) {
|
||||
menu.classList.add('sticky');
|
||||
stickyCache = true;
|
||||
} else if (nextSticky === false && stickyCache === true) {
|
||||
menu.classList.remove('sticky');
|
||||
stickyCache = false;
|
||||
}
|
||||
if (nextTop !== null) {
|
||||
menu.style.top = nextTop + 'px';
|
||||
topCache = nextTop;
|
||||
}
|
||||
prevScrollTop = scrollTop;
|
||||
}, { passive: true });
|
||||
})();
|
||||
(function controlBorder() {
|
||||
menu.classList.remove('bordered');
|
||||
document.addEventListener('scroll', function () {
|
||||
if (menu.offsetTop === 0) {
|
||||
menu.classList.remove('bordered');
|
||||
} else {
|
||||
menu.classList.add('bordered');
|
||||
}
|
||||
}, { passive: true });
|
||||
})();
|
||||
})();
|
@ -1,499 +0,0 @@
|
||||
/* CSS for UI elements (a.k.a. chrome) */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
::-webkit-scrollbar {
|
||||
background: var(--bg);
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
html {
|
||||
scrollbar-color: var(--scrollbar) var(--bg);
|
||||
}
|
||||
#searchresults a,
|
||||
.content a:link,
|
||||
a:visited,
|
||||
a > .hljs {
|
||||
color: var(--links);
|
||||
}
|
||||
.content a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Menu Bar */
|
||||
|
||||
#menu-bar,
|
||||
#menu-bar-hover-placeholder {
|
||||
z-index: 101;
|
||||
margin: auto calc(0px - var(--page-padding));
|
||||
}
|
||||
#menu-bar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
background-color: var(--bg);
|
||||
border-bottom-color: var(--bg);
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
}
|
||||
#menu-bar.sticky,
|
||||
.js #menu-bar-hover-placeholder:hover + #menu-bar,
|
||||
.js #menu-bar:hover,
|
||||
.js.sidebar-visible #menu-bar {
|
||||
position: -webkit-sticky;
|
||||
position: sticky;
|
||||
top: 0 !important;
|
||||
}
|
||||
#menu-bar-hover-placeholder {
|
||||
position: sticky;
|
||||
position: -webkit-sticky;
|
||||
top: 0;
|
||||
height: var(--menu-bar-height);
|
||||
}
|
||||
#menu-bar.bordered {
|
||||
border-bottom-color: var(--table-border-color);
|
||||
}
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
position: relative;
|
||||
padding: 0 8px;
|
||||
z-index: 10;
|
||||
line-height: var(--menu-bar-height);
|
||||
cursor: pointer;
|
||||
transition: color 0.5s;
|
||||
}
|
||||
@media only screen and (max-width: 420px) {
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
padding: 0 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-button {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: inherit;
|
||||
}
|
||||
.icon-button i {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.right-buttons {
|
||||
margin: 0 15px;
|
||||
}
|
||||
.right-buttons a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.left-buttons {
|
||||
display: flex;
|
||||
margin: 0 5px;
|
||||
}
|
||||
.no-js .left-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
display: inline-block;
|
||||
font-weight: 200;
|
||||
font-size: 2.4rem;
|
||||
line-height: var(--menu-bar-height);
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.js .menu-title {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.menu-bar,
|
||||
.menu-bar:visited,
|
||||
.nav-chapters,
|
||||
.nav-chapters:visited,
|
||||
.mobile-nav-chapters,
|
||||
.mobile-nav-chapters:visited,
|
||||
.menu-bar .icon-button,
|
||||
.menu-bar a i {
|
||||
color: var(--icons);
|
||||
}
|
||||
|
||||
.menu-bar i:hover,
|
||||
.menu-bar .icon-button:hover,
|
||||
.nav-chapters:hover,
|
||||
.mobile-nav-chapters i:hover {
|
||||
color: var(--icons-hover);
|
||||
}
|
||||
|
||||
/* Nav Icons */
|
||||
|
||||
.nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
max-width: 150px;
|
||||
min-width: 90px;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
flex-direction: column;
|
||||
|
||||
transition: color 0.5s, background-color 0.5s;
|
||||
}
|
||||
|
||||
.nav-chapters:hover {
|
||||
text-decoration: none;
|
||||
background-color: var(--theme-hover);
|
||||
transition: background-color 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.nav-wrapper {
|
||||
margin-top: 50px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
width: 90px;
|
||||
border-radius: 5px;
|
||||
background-color: var(--sidebar-bg);
|
||||
}
|
||||
|
||||
.previous {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.next {
|
||||
float: right;
|
||||
right: var(--page-padding);
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1080px) {
|
||||
.nav-wide-wrapper { display: none; }
|
||||
.nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1380px) {
|
||||
.sidebar-visible .nav-wide-wrapper { display: none; }
|
||||
.sidebar-visible .nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
|
||||
:not(pre) > .hljs {
|
||||
display: inline;
|
||||
padding: 0.1em 0.3em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
:not(pre):not(a):not(td):not(p) > .hljs {
|
||||
color: var(--inline-code-color);
|
||||
overflow-x: initial;
|
||||
}
|
||||
|
||||
a:hover > .hljs {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
pre {
|
||||
position: relative;
|
||||
}
|
||||
pre > .buttons {
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
|
||||
color: var(--sidebar-fg);
|
||||
cursor: pointer;
|
||||
}
|
||||
pre > .buttons :hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
pre > .buttons i {
|
||||
margin-left: 8px;
|
||||
}
|
||||
pre > .buttons button {
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: inherit;
|
||||
}
|
||||
pre > .result {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Search */
|
||||
|
||||
#searchresults a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
mark {
|
||||
border-radius: 2px;
|
||||
padding: 0 3px 1px 3px;
|
||||
margin: 0 -3px -1px -3px;
|
||||
background-color: var(--search-mark-bg);
|
||||
transition: background-color 300ms linear;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
mark.fade-out {
|
||||
background-color: rgba(0,0,0,0) !important;
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
.searchbar-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
#searchbar {
|
||||
width: 100%;
|
||||
margin: 5px auto 0px auto;
|
||||
padding: 10px 16px;
|
||||
transition: box-shadow 300ms ease-in-out;
|
||||
border: 1px solid var(--searchbar-border-color);
|
||||
border-radius: 3px;
|
||||
background-color: var(--searchbar-bg);
|
||||
color: var(--searchbar-fg);
|
||||
}
|
||||
#searchbar:focus,
|
||||
#searchbar.active {
|
||||
box-shadow: 0 0 3px var(--searchbar-shadow-color);
|
||||
}
|
||||
|
||||
.searchresults-header {
|
||||
font-weight: bold;
|
||||
font-size: 1em;
|
||||
padding: 18px 0 0 5px;
|
||||
color: var(--searchresults-header-fg);
|
||||
}
|
||||
|
||||
.searchresults-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
border-bottom: 1px dashed var(--searchresults-border-color);
|
||||
}
|
||||
|
||||
ul#searchresults {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
ul#searchresults li {
|
||||
margin: 10px 0px;
|
||||
padding: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
ul#searchresults li.focus {
|
||||
background-color: var(--searchresults-li-bg);
|
||||
}
|
||||
ul#searchresults span.teaser {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin: 5px 0 0 20px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
ul#searchresults span.teaser em {
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--sidebar-width);
|
||||
font-size: 0.875em;
|
||||
box-sizing: border-box;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior-y: contain;
|
||||
background-color: var(--sidebar-bg);
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
.sidebar-resizing {
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .sidebar {
|
||||
transition: transform 0.3s; /* Animation: slide away */
|
||||
}
|
||||
.sidebar code {
|
||||
line-height: 2em;
|
||||
}
|
||||
.sidebar .sidebar-scrollbox {
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
.sidebar .sidebar-resize-handle {
|
||||
position: absolute;
|
||||
cursor: col-resize;
|
||||
width: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
.js .sidebar .sidebar-resize-handle {
|
||||
cursor: col-resize;
|
||||
width: 5px;
|
||||
}
|
||||
.sidebar-hidden .sidebar {
|
||||
transform: translateX(calc(0px - var(--sidebar-width)));
|
||||
}
|
||||
.sidebar::-webkit-scrollbar {
|
||||
background: var(--sidebar-bg);
|
||||
}
|
||||
.sidebar::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: translateX(var(--sidebar-width));
|
||||
}
|
||||
@media only screen and (min-width: 620px) {
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: none;
|
||||
margin-left: var(--sidebar-width);
|
||||
}
|
||||
}
|
||||
|
||||
.chapter {
|
||||
list-style: none outside none;
|
||||
padding-left: 0;
|
||||
margin: .25rem 0;
|
||||
}
|
||||
|
||||
.chapter ol {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chapter li {
|
||||
display: flex;
|
||||
color: var(--sidebar-non-existent);
|
||||
}
|
||||
.chapter li a {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
|
||||
.chapter li a:hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li a.active {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li > a.toggle {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
padding: 0 10px;
|
||||
user-select: none;
|
||||
opacity: 0.68;
|
||||
}
|
||||
|
||||
.chapter li > a.toggle div {
|
||||
transition: transform 0.5s;
|
||||
}
|
||||
|
||||
/* collapse the section */
|
||||
.chapter li:not(.expanded) + li > ol {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.chapter li.expanded > a.toggle div {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.spacer {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
margin: 5px 0px;
|
||||
}
|
||||
.chapter .spacer {
|
||||
background-color: var(--sidebar-spacer);
|
||||
}
|
||||
|
||||
@media (-moz-touch-enabled: 1), (pointer: coarse) {
|
||||
.chapter li a { padding: 5px 0; }
|
||||
.spacer { margin: 10px 0; }
|
||||
}
|
||||
|
||||
.section {
|
||||
list-style: none outside none;
|
||||
padding-left: 2rem;
|
||||
line-height: 1.9em;
|
||||
}
|
||||
|
||||
/* Theme Menu Popup */
|
||||
|
||||
.theme-popup {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: var(--menu-bar-height);
|
||||
z-index: 1000;
|
||||
border-radius: 4px;
|
||||
font-size: 0.7em;
|
||||
color: var(--fg);
|
||||
background: var(--theme-popup-bg);
|
||||
border: 1px solid var(--theme-popup-border);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: none;
|
||||
}
|
||||
.theme-popup .default {
|
||||
color: var(--icons);
|
||||
}
|
||||
.theme-popup .theme {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 2px 10px;
|
||||
line-height: 25px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
background: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
.theme-popup .theme:hover {
|
||||
background-color: var(--theme-hover);
|
||||
}
|
||||
.theme-popup .theme:hover:first-child,
|
||||
.theme-popup .theme:hover:last-child {
|
||||
border-top-left-radius: inherit;
|
||||
border-top-right-radius: inherit;
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
/* Base styles and content styles */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
:root {
|
||||
/* Browser default font-size is 16px, this way 1 rem = 10px */
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
/* TODO: replace with self hosted fonts */
|
||||
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
color: var(--fg);
|
||||
background-color: var(--bg);
|
||||
text-size-adjust: none;
|
||||
}
|
||||
|
||||
/* @supports (font-variation-settings: normal) { */
|
||||
/* html { font-family: 'Inter var', sans-serif; } */
|
||||
/* } */
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-size: 1.6rem;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace !important;
|
||||
font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
|
||||
}
|
||||
|
||||
/* Don't change font size in headers. */
|
||||
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
|
||||
font-size: unset;
|
||||
}
|
||||
|
||||
.left { float: left; }
|
||||
.right { float: right; }
|
||||
.boring { opacity: 0.6; }
|
||||
.hide-boring .boring { display: none; }
|
||||
.hidden { display: none !important; }
|
||||
|
||||
h2, h3 { margin-top: 2.5em; }
|
||||
h4, h5 { margin-top: 2em; }
|
||||
|
||||
.header + .header h3,
|
||||
.header + .header h4,
|
||||
.header + .header h5 {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
h1:target::before,
|
||||
h2:target::before,
|
||||
h3:target::before,
|
||||
h4:target::before,
|
||||
h5:target::before,
|
||||
h6:target::before {
|
||||
display: inline-block;
|
||||
content: "»";
|
||||
margin-left: -30px;
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
/* This is broken on Safari as of version 14, but is fixed
|
||||
in Safari Technology Preview 117 which I think will be Safari 14.2.
|
||||
https://bugs.webkit.org/show_bug.cgi?id=218076
|
||||
*/
|
||||
:target {
|
||||
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
|
||||
}
|
||||
|
||||
.page {
|
||||
outline: 0;
|
||||
padding: 0 var(--page-padding);
|
||||
margin-top: calc(0px - var(--menu-bar-height)); /* Compensate for the #menu-bar-hover-placeholder */
|
||||
}
|
||||
.page-wrapper {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .page-wrapper {
|
||||
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
.content main {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1, .content h2, .content h3, .content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
.content p, .content ol, .content ul, .content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
.content ul ul, .content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
.content p { line-height: 1.45em; }
|
||||
.content ol { line-height: 1.45em; }
|
||||
.content ul { line-height: 1.45em; }
|
||||
.content a { text-decoration: none; }
|
||||
.content a:hover { text-decoration: underline; }
|
||||
.content img { max-width: 100%; }
|
||||
.content .header:link,
|
||||
.content .header:visited {
|
||||
color: var(--fg);
|
||||
color: var(--heading-fg);
|
||||
}
|
||||
.content .header:link,
|
||||
.content .header:visited:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
table {
|
||||
margin: 0 auto;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
table td {
|
||||
padding: .75rem;
|
||||
width: auto;
|
||||
}
|
||||
table thead {
|
||||
background: var(--table-header-bg);
|
||||
}
|
||||
table thead td {
|
||||
font-weight: 700;
|
||||
border: none;
|
||||
}
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
table thead tr {
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
/* Alternate background colors for rows */
|
||||
table tbody tr:nth-child(2n) {
|
||||
/* background: var(--table-alternate-bg); */
|
||||
}
|
||||
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
}
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
:not(.footnote-definition) + .footnote-definition,
|
||||
.footnote-definition + :not(.footnote-definition) {
|
||||
margin-top: 2em;
|
||||
}
|
||||
.footnote-definition {
|
||||
font-size: 0.9em;
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
.footnote-definition p {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.tooltiptext {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
color: #fff;
|
||||
background-color: #333;
|
||||
transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */
|
||||
left: -8px; /* Half of the width of the icon */
|
||||
top: -35px;
|
||||
font-size: 0.8em;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
padding: 5px 8px;
|
||||
margin: 5px;
|
||||
z-index: 1000;
|
||||
}
|
||||
.tooltipped .tooltiptext {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.chapter li.part-title {
|
||||
color: var(--sidebar-fg);
|
||||
margin: 5px 0px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.result-no-output {
|
||||
font-style: italic;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
|
||||
#sidebar,
|
||||
#menu-bar,
|
||||
.nav-chapters,
|
||||
.mobile-nav-chapters {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#page-wrapper.page-wrapper {
|
||||
transform: none;
|
||||
margin-left: 0px;
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
#content {
|
||||
max-width: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.page {
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #666666;
|
||||
border-radius: 5px;
|
||||
|
||||
/* Force background to be printed in Chrome */
|
||||
-webkit-print-color-adjust: exact;
|
||||
}
|
||||
|
||||
pre > .buttons {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
a, a:visited, a:active, a:hover {
|
||||
color: #4183c4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
page-break-inside: avoid;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
page-break-inside: avoid;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.fa {
|
||||
display: none !important;
|
||||
}
|
@ -1,411 +0,0 @@
|
||||
|
||||
/* Globals */
|
||||
|
||||
:root {
|
||||
--sidebar-width: 300px;
|
||||
--page-padding: 15px;
|
||||
--content-max-width: 750px;
|
||||
--menu-bar-height: 50px;
|
||||
}
|
||||
|
||||
/* Themes */
|
||||
|
||||
.ayu {
|
||||
--bg: hsl(210, 25%, 8%);
|
||||
--fg: #c5c5c5;
|
||||
|
||||
--sidebar-bg: #14191f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #5c6773;
|
||||
--sidebar-active: #ffb454;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #0096cf;
|
||||
|
||||
--inline-code-color: #ffb454;
|
||||
|
||||
--theme-popup-bg: #14191f;
|
||||
--theme-popup-border: #5c6773;
|
||||
--theme-hover: #191f26;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(210, 25%, 13%);
|
||||
--table-header-bg: hsl(210, 25%, 28%);
|
||||
--table-alternate-bg: hsl(210, 25%, 11%);
|
||||
|
||||
--searchbar-border-color: #848484;
|
||||
--searchbar-bg: #424242;
|
||||
--searchbar-fg: #fff;
|
||||
--searchbar-shadow-color: #d4c89f;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #252932;
|
||||
--search-mark-bg: #e3b171;
|
||||
--hljs-background: #191f26;
|
||||
--hljs-color: #e6e1cf;
|
||||
--hljs-quote: #5c6773;
|
||||
--hljs-variable: #ff7733;
|
||||
--hljs-type: #ffee99;
|
||||
--hljs-title: #b8cc52;
|
||||
--hljs-symbol: #ffb454;
|
||||
--hljs-selector-tag: #ff7733;
|
||||
--hljs-selector-tag: #36a3d9;
|
||||
--hljs-selector-tag: #00568d;
|
||||
--hljs-selector-tag: #91b362;
|
||||
--hljs-selector-tag: #d96c75;
|
||||
}
|
||||
|
||||
.coal {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
--hljs-background: #969896;
|
||||
--hljs-color: #cc6666;
|
||||
--hljs-quote: #de935f;
|
||||
--hljs-variable: #f0c674;
|
||||
--hljs-type: #b5bd68;
|
||||
--hljs-title: #8abeb7;
|
||||
--hljs-symbol: #81a2be;
|
||||
--hljs-selector-tag: #b294bb;
|
||||
--hljs-selector-tag: #1d1f21;
|
||||
--hljs-selector-tag: #c5c8c6;
|
||||
--hljs-selector-tag: #718c00;
|
||||
--hljs-selector-tag: #c82829;
|
||||
}
|
||||
|
||||
.light {
|
||||
--bg: hsl(0, 0%, 100%);
|
||||
--fg: hsl(0, 0%, 0%);
|
||||
|
||||
--sidebar-bg: #fafafa;
|
||||
--sidebar-fg: hsl(0, 0%, 0%);
|
||||
--sidebar-non-existent: #aaaaaa;
|
||||
--sidebar-active: #1f1fff;
|
||||
--sidebar-spacer: #f4f4f4;
|
||||
|
||||
--scrollbar: #8F8F8F;
|
||||
|
||||
--icons: #747474;
|
||||
--icons-hover: #000000;
|
||||
|
||||
--links: #20609f;
|
||||
|
||||
--inline-code-color: #301900;
|
||||
|
||||
--theme-popup-bg: #fafafa;
|
||||
--theme-popup-border: #cccccc;
|
||||
--theme-hover: #e6e6e6;
|
||||
|
||||
--quote-bg: hsl(197, 37%, 96%);
|
||||
--quote-border: hsl(197, 37%, 91%);
|
||||
|
||||
--table-border-color: hsl(0, 0%, 95%);
|
||||
--table-header-bg: hsl(0, 0%, 80%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #e4f2fe;
|
||||
--search-mark-bg: #a2cff5;
|
||||
--hljs-background: #f6f7f6;
|
||||
--hljs-color: #000;
|
||||
--hljs-quote: #575757;
|
||||
--hljs-variable: #d70025;
|
||||
--hljs-type: #b21e00;
|
||||
--hljs-title: #0030f2;
|
||||
--hljs-symbol: #008200;
|
||||
--hljs-selector-tag: #9d00ec;
|
||||
}
|
||||
|
||||
.navy {
|
||||
--bg: hsl(226, 23%, 11%);
|
||||
--fg: #bcbdd0;
|
||||
|
||||
--sidebar-bg: #282d3f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #2b79a2;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: #282e40;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 16%);
|
||||
--table-header-bg: hsl(226, 23%, 31%);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
|
||||
--hljs-background: #969896;
|
||||
--hljs-color: #cc6666;
|
||||
--hljs-quote: #de935f;
|
||||
--hljs-variable: #f0c674;
|
||||
--hljs-type: #b5bd68;
|
||||
--hljs-title: #8abeb7;
|
||||
--hljs-symbol: #81a2be;
|
||||
--hljs-selector-tag: #b294bb;
|
||||
--hljs-selector-tag: #1d1f21;
|
||||
--hljs-selector-tag: #c5c8c6;
|
||||
--hljs-selector-tag: #718c00;
|
||||
--hljs-selector-tag: #c82829;
|
||||
}
|
||||
|
||||
.rust {
|
||||
--bg: hsl(60, 9%, 87%);
|
||||
--fg: #262625;
|
||||
|
||||
--sidebar-bg: #3b2e2a;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #e69f67;
|
||||
--sidebar-spacer: #45373a;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #262625;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #6e6b5e;
|
||||
|
||||
--theme-popup-bg: #e1e1db;
|
||||
--theme-popup-border: #b38f6b;
|
||||
--theme-hover: #99908a;
|
||||
|
||||
--quote-bg: hsl(60, 5%, 75%);
|
||||
--quote-border: hsl(60, 5%, 70%);
|
||||
|
||||
--table-border-color: hsl(60, 9%, 82%);
|
||||
--table-header-bg: #b3a497;
|
||||
--table-alternate-bg: hsl(60, 9%, 84%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #dec2a2;
|
||||
--search-mark-bg: #e69f67;
|
||||
--hljs-background: #f6f7f6;
|
||||
--hljs-color: #000;
|
||||
--hljs-quote: #575757;
|
||||
--hljs-variable: #d70025;
|
||||
--hljs-type: #b21e00;
|
||||
--hljs-title: #0030f2;
|
||||
--hljs-symbol: #008200;
|
||||
--hljs-selector-tag: #9d00ec;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.light.no-js {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
}
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #acff5;
|
||||
--hljs-background: #2f1e2e;
|
||||
--hljs-color: #a39e9b;
|
||||
--hljs-quote: #8d8687;
|
||||
--hljs-variable: #ef6155;
|
||||
--hljs-type: #f99b15;
|
||||
--hljs-title: #fec418;
|
||||
--hljs-symbol: #48b685;
|
||||
--hljs-selector-tag: #815ba4;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
/*
|
||||
--bg: #ffffff;
|
||||
--fg: #452859;
|
||||
--fg: #5a5977;
|
||||
--heading-fg: #281733;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #6F44F0;
|
||||
|
||||
--inline-code-color: #a39e9b;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: rgba(0, 0, 0, 0);
|
||||
--quote-border: hsl(226, 15%, 75%);
|
||||
|
||||
--table-border-color: #5a5977;
|
||||
--table-border-color: hsl(201deg 10% 67%);
|
||||
--table-header-bg: hsl(0, 0%, 100%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
--table-border-line: hsl(201deg, 20%, 92%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
--hljs-background: #TODO;
|
||||
--hljs-color: #TODO;
|
||||
--hljs-quote: #TODO;
|
||||
--hljs-variable: #TODO;
|
||||
--hljs-type: #TODO;
|
||||
--hljs-title: #TODO;
|
||||
--hljs-symbol: #TODO;
|
||||
--hljs-selector-tag: #TODO;
|
||||
*/
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
pre code.hljs {
|
||||
display:block;
|
||||
overflow-x:auto;
|
||||
padding:1em
|
||||
}
|
||||
code.hljs {
|
||||
padding:3px 5px
|
||||
}
|
||||
.hljs {
|
||||
background: var(--hljs-background);
|
||||
color: var(--hljs-color);
|
||||
}
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: var(--hljs-quote)
|
||||
}
|
||||
.hljs-link,
|
||||
.hljs-meta,
|
||||
.hljs-name,
|
||||
.hljs-regexp,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-id,
|
||||
.hljs-tag,
|
||||
.hljs-template-variable,
|
||||
.hljs-variable {
|
||||
color: var(--hljs-variable)
|
||||
}
|
||||
.hljs-built_in,
|
||||
.hljs-deletion,
|
||||
.hljs-literal,
|
||||
.hljs-number,
|
||||
.hljs-params,
|
||||
.hljs-type {
|
||||
color: var(--hljs-type)
|
||||
}
|
||||
.hljs-attribute,
|
||||
.hljs-section,
|
||||
.hljs-title {
|
||||
color: var(--hljs-title)
|
||||
}
|
||||
.hljs-addition,
|
||||
.hljs-bullet,
|
||||
.hljs-string,
|
||||
.hljs-symbol {
|
||||
color: var(--hljs-symbol)
|
||||
}
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag {
|
||||
color: var(--hljs-selector-tag)
|
||||
}
|
||||
.hljs-emphasis {
|
||||
font-style:italic
|
||||
}
|
||||
.hljs-strong {
|
||||
font-weight:700
|
||||
}
|
6
book/theme/highlight.js
vendored
6
book/theme/highlight.js
vendored
File diff suppressed because one or more lines are too long
@ -1,11 +1,11 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="{{ language }}" class="sidebar-visible no-js {{ default_theme }}">
|
||||
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
{{#if is_print }}
|
||||
<meta name="robots" content="noindex" />
|
||||
<meta name="robots" content="noindex">
|
||||
{{/if}}
|
||||
{{#if base_url}}
|
||||
<base href="{{ base_url }}">
|
||||
@ -15,10 +15,9 @@
|
||||
<!-- Custom HTML head -->
|
||||
{{> head}}
|
||||
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{{ description }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
|
||||
{{#if favicon_svg}}
|
||||
<link rel="icon" href="{{ path_to_root }}favicon.svg">
|
||||
@ -35,8 +34,6 @@
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@200;400;500;700&display=swap" rel="stylesheet">
|
||||
{{#if copy_fonts}}
|
||||
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
|
||||
{{/if}}
|
||||
@ -53,18 +50,19 @@
|
||||
|
||||
{{#if mathjax_support}}
|
||||
<!-- MathJax -->
|
||||
<script async type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
{{/if}}
|
||||
</head>
|
||||
<body>
|
||||
<body class="sidebar-visible no-js">
|
||||
<div id="body-container">
|
||||
<!-- Provide site root to javascript -->
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
var path_to_root = "{{ path_to_root }}";
|
||||
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
|
||||
</script>
|
||||
|
||||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
try {
|
||||
var theme = localStorage.getItem('mdbook-theme');
|
||||
var sidebar = localStorage.getItem('mdbook-sidebar');
|
||||
@ -80,27 +78,34 @@
|
||||
</script>
|
||||
|
||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||||
var html = document.querySelector('html');
|
||||
html.classList.remove('no-js')
|
||||
html.classList.remove('{{ default_theme }}')
|
||||
html.classList.add(theme);
|
||||
html.classList.add('js');
|
||||
var body = document.querySelector('body');
|
||||
body.classList.remove('no-js')
|
||||
body.classList.add('js');
|
||||
</script>
|
||||
|
||||
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
|
||||
|
||||
<!-- Hide / unhide sidebar before it is displayed -->
|
||||
<script type="text/javascript">
|
||||
var html = document.querySelector('html');
|
||||
var sidebar = 'hidden';
|
||||
<script>
|
||||
var body = document.querySelector('body');
|
||||
var sidebar = null;
|
||||
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
||||
if (document.body.clientWidth >= 1080) {
|
||||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
||||
sidebar = sidebar || 'visible';
|
||||
} else {
|
||||
sidebar = 'hidden';
|
||||
}
|
||||
html.classList.remove('sidebar-visible');
|
||||
html.classList.add("sidebar-" + sidebar);
|
||||
sidebar_toggle.checked = sidebar === 'visible';
|
||||
body.classList.remove('sidebar-visible');
|
||||
body.classList.add("sidebar-" + sidebar);
|
||||
</script>
|
||||
|
||||
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
||||
@ -110,26 +115,48 @@
|
||||
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
|
||||
</nav>
|
||||
|
||||
<!-- Track and set sidebar scroll position -->
|
||||
<script>
|
||||
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
|
||||
sidebarScrollbox.addEventListener('click', function(e) {
|
||||
if (e.target.tagName === 'A') {
|
||||
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
|
||||
}
|
||||
}, { passive: true });
|
||||
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
|
||||
sessionStorage.removeItem('sidebar-scroll');
|
||||
if (sidebarScrollTop) {
|
||||
// preserve sidebar scroll position when navigating via links within sidebar
|
||||
sidebarScrollbox.scrollTop = sidebarScrollTop;
|
||||
} else {
|
||||
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
|
||||
var activeSection = document.querySelector('#sidebar .active');
|
||||
if (activeSection) {
|
||||
activeSection.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
||||
<div class="page">
|
||||
{{> header}}
|
||||
<div id="menu-bar-hover-placeholder"></div>
|
||||
<div id="menu-bar" class="menu-bar sticky bordered">
|
||||
<div id="menu-bar" class="menu-bar sticky">
|
||||
<div class="left-buttons">
|
||||
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
||||
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
||||
<i class="fa fa-bars"></i>
|
||||
</button>
|
||||
</label>
|
||||
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
||||
<i class="fa fa-paint-brush"></i>
|
||||
</button>
|
||||
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
||||
<li role="none"><button role="menuitem" class="theme" id="light">{{ theme_option "Light" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="rust">{{ theme_option "Rust" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="coal">{{ theme_option "Coal" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="navy">{{ theme_option "Navy" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="ayu">{{ theme_option "Ayu" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="colibri">{{ theme_option "Colibri" }}</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="colibri">Colibri</button></li>
|
||||
</ul>
|
||||
{{#if search_enabled}}
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
@ -151,13 +178,19 @@
|
||||
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{#if git_repository_edit_url}}
|
||||
<a href="{{git_repository_edit_url}}" title="Suggest an edit" aria-label="Suggest an edit">
|
||||
<i id="git-edit-button" class="fa fa-edit"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if search_enabled}}
|
||||
<div id="search-wrapper" class="hidden">
|
||||
<form id="searchbar-outer" class="searchbar-outer">
|
||||
<input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
</form>
|
||||
<div id="searchresults-outer" class="searchresults-outer hidden">
|
||||
<div id="searchresults-header" class="searchresults-header"></div>
|
||||
@ -168,7 +201,7 @@
|
||||
{{/if}}
|
||||
|
||||
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
||||
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
||||
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
||||
@ -190,7 +223,7 @@
|
||||
{{/previous}}
|
||||
|
||||
{{#next}}
|
||||
<a rel="next" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/next}}
|
||||
@ -208,7 +241,7 @@
|
||||
{{/previous}}
|
||||
|
||||
{{#next}}
|
||||
<a rel="next" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
{{/next}}
|
||||
@ -216,10 +249,12 @@
|
||||
|
||||
</div>
|
||||
|
||||
{{#if livereload}}
|
||||
{{#if live_reload_endpoint}}
|
||||
<!-- Livereload script (if served using the cli tool) -->
|
||||
<script type="text/javascript">
|
||||
var socket = new WebSocket("{{{livereload}}}");
|
||||
<script>
|
||||
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsAddress = wsProtocol + "//" + location.host + "/" + "{{{live_reload_endpoint}}}";
|
||||
const socket = new WebSocket(wsAddress);
|
||||
socket.onmessage = function (event) {
|
||||
if (event.data === "reload") {
|
||||
socket.close();
|
||||
@ -235,7 +270,7 @@
|
||||
|
||||
{{#if google_analytics}}
|
||||
<!-- Google Analytics Tag -->
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
var localAddrs = ["localhost", "127.0.0.1", ""];
|
||||
|
||||
// make sure we don't activate google analytics if the developer is
|
||||
@ -253,43 +288,43 @@
|
||||
{{/if}}
|
||||
|
||||
{{#if playground_line_numbers}}
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
window.playground_line_numbers = true;
|
||||
</script>
|
||||
{{/if}}
|
||||
|
||||
{{#if playground_copyable}}
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
window.playground_copyable = true;
|
||||
</script>
|
||||
{{/if}}
|
||||
|
||||
{{#if playground_js}}
|
||||
<script src="{{ path_to_root }}ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}editor.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}mode-rust.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}theme-dawn.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}theme-tomorrow_night.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}ace.js"></script>
|
||||
<script src="{{ path_to_root }}editor.js"></script>
|
||||
<script src="{{ path_to_root }}mode-rust.js"></script>
|
||||
<script src="{{ path_to_root }}theme-dawn.js"></script>
|
||||
<script src="{{ path_to_root }}theme-tomorrow_night.js"></script>
|
||||
{{/if}}
|
||||
|
||||
{{#if search_js}}
|
||||
<script src="{{ path_to_root }}elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}mark.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}searcher.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}elasticlunr.min.js"></script>
|
||||
<script src="{{ path_to_root }}mark.min.js"></script>
|
||||
<script src="{{ path_to_root }}searcher.js"></script>
|
||||
{{/if}}
|
||||
|
||||
<script src="{{ path_to_root }}clipboard.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}highlight.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}book.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{ path_to_root }}clipboard.min.js"></script>
|
||||
<script src="{{ path_to_root }}highlight.js"></script>
|
||||
<script src="{{ path_to_root }}book.js"></script>
|
||||
|
||||
<!-- Custom JS scripts -->
|
||||
{{#each additional_js}}
|
||||
<script type="text/javascript" src="{{ ../path_to_root }}{{this}}"></script>
|
||||
<script src="{{ ../path_to_root }}{{this}}"></script>
|
||||
{{/each}}
|
||||
|
||||
{{#if is_print}}
|
||||
{{#if mathjax_support}}
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
MathJax.Hub.Register.StartupHook('End', function() {
|
||||
window.setTimeout(window.print, 100);
|
||||
@ -297,7 +332,7 @@
|
||||
});
|
||||
</script>
|
||||
{{else}}
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
window.setTimeout(window.print, 100);
|
||||
});
|
||||
@ -305,5 +340,6 @@
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -5,16 +5,27 @@
|
||||
<project_license>MPL-2.0</project_license>
|
||||
<name>Helix</name>
|
||||
<summary>A post-modern text editor</summary>
|
||||
<summary xml:lang="ar">مُحَرِّرُ نُصُوصٍ سَابِقٌ لِعَهدِه</summary>
|
||||
<developer id="com.helix_editor">
|
||||
<name>Blaž Hrastnik</name>
|
||||
</developer>
|
||||
|
||||
<description>
|
||||
<p>
|
||||
Helix is a terminal-based text editor inspired by Kakoune / Neovim and written in Rust.
|
||||
</p>
|
||||
<p xml:lang="ar">
|
||||
مُحَرِّرُ نُصُوصٍ يَعمَلُ فِي الطَّرَفِيَّة، مُستَلهَمٌ مِن Kakoune وَ Neovim وَمَكتُوبٌ بِلُغَةِ رَست البَرمَجِيَّة.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Vim-like modal editing</li>
|
||||
<li xml:lang="ar">تَحرِيرٌ وَضعِيٌّ شَبيهٌ بِـVim</li>
|
||||
<li>Multiple selections</li>
|
||||
<li xml:lang="ar">تَحدِيدَاتٌ لِلنَّصِ مُتَعَدِّدَة</li>
|
||||
<li>Built-in language server support</li>
|
||||
<li xml:lang="ar">دَعْمٌ مُدمَجٌ لِخَوادِمِ اللُّغَات</li>
|
||||
<li>Smart, incremental syntax highlighting and code editing via tree-sitter</li>
|
||||
<li xml:lang="ar">تَحرِيرُ التَّعلِيمَاتِ البَّرمَجِيَّةِ مَعَ تَمييزٍ لِلتَّركِيبِ النَّحُويِّ بِواسِطَةِ tree-sitter</li>
|
||||
</ul>
|
||||
</description>
|
||||
|
||||
@ -36,6 +47,12 @@
|
||||
<content_rating type="oars-1.1" />
|
||||
|
||||
<releases>
|
||||
<release version="24.03" date="2024-03-30">
|
||||
<url>https://helix-editor.com/news/release-24-03-highlights/</url>
|
||||
</release>
|
||||
<release version="23.10" date="2023-10-24">
|
||||
<url>https://helix-editor.com/news/release-23-10-highlights/</url>
|
||||
</release>
|
||||
<release version="23.05" date="2023-05-18">
|
||||
<url>https://github.com/helix-editor/helix/releases/tag/23.05</url>
|
||||
</release>
|
||||
@ -56,9 +73,9 @@
|
||||
</release>
|
||||
</releases>
|
||||
|
||||
<requires>
|
||||
<recommends>
|
||||
<control>keyboard</control>
|
||||
</requires>
|
||||
</recommends>
|
||||
|
||||
<categories>
|
||||
<category>Utility</category>
|
||||
|
@ -1,6 +1,7 @@
|
||||
[Desktop Entry]
|
||||
Name=Helix
|
||||
GenericName=Text Editor
|
||||
GenericName[ar]=مُحَرِّرُ نُصُوص
|
||||
GenericName[de]=Texteditor
|
||||
GenericName[fr]=Éditeur de texte
|
||||
GenericName[ru]=Текстовый редактор
|
||||
@ -9,7 +10,7 @@ GenericName[tr]=Metin Düzenleyici
|
||||
Comment=Edit text files
|
||||
Comment[af]=Redigeer tekslêers
|
||||
Comment[am]=የጽሑፍ ፋይሎች ያስተካክሉ
|
||||
Comment[ar]=حرّر ملفات نصية
|
||||
Comment[ar]=مُحَرِّرُ مِلَفَّاتٍ نَصِّيَّة
|
||||
Comment[az]=Mətn fayllarını redaktə edin
|
||||
Comment[be]=Рэдагаваньне тэкставых файлаў
|
||||
Comment[bg]=Редактиране на текстови файлове
|
||||
@ -79,6 +80,7 @@ Exec=hx %F
|
||||
Terminal=true
|
||||
Type=Application
|
||||
Keywords=Text;editor;
|
||||
Keywords[ar]=نص;نصوص;محرر;
|
||||
Keywords[fr]=Texte;éditeur;
|
||||
Keywords[ru]=текст;текстовый редактор;
|
||||
Keywords[sr]=Текст;едитор;
|
||||
|
@ -5,19 +5,20 @@ _hx() {
|
||||
# $1 command name
|
||||
# $2 word being completed
|
||||
# $3 word preceding
|
||||
COMPREPLY=()
|
||||
|
||||
case "$3" in
|
||||
-g | --grammar)
|
||||
COMPREPLY=($(compgen -W "fetch build" -- $2))
|
||||
COMPREPLY="$(compgen -W 'fetch build' -- $2)"
|
||||
;;
|
||||
--health)
|
||||
local languages=$(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g')
|
||||
COMPREPLY=($(compgen -W "$languages" -- $2))
|
||||
COMPREPLY="$(compgen -W """$languages""" -- $2)"
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config --log" -- $2))
|
||||
COMPREPLY="$(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config --log" -- """$2""")"
|
||||
;;
|
||||
esac
|
||||
} && complete -o filenames -F _hx hx
|
||||
|
||||
local IFS=$'\n'
|
||||
COMPREPLY=($COMPREPLY)
|
||||
} && complete -o filenames -F _hx hx
|
||||
|
BIN
contrib/helix-256p.ico
Normal file
BIN
contrib/helix-256p.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 KiB |
@ -29,9 +29,15 @@ # Auto generated documentation
|
||||
cargo xtask docgen
|
||||
```
|
||||
|
||||
inside the project. We use [xtask][xtask] as an ad-hoc task runner and
|
||||
thus do not require any dependencies other than `cargo` (You don't have
|
||||
to `cargo install` anything either).
|
||||
inside the project. We use [xtask][xtask] as an ad-hoc task runner.
|
||||
|
||||
To preview the book itself, install [mdbook][mdbook]. Then, run
|
||||
|
||||
```shell
|
||||
mdbook serve book
|
||||
```
|
||||
|
||||
and visit [http://localhost:3000](http://localhost:3000).
|
||||
|
||||
# Testing
|
||||
|
||||
@ -58,4 +64,5 @@ ## Minimum Stable Rust Version (MSRV) Policy
|
||||
[architecture.md]: ./architecture.md
|
||||
[docs]: https://docs.helix-editor.com/
|
||||
[xtask]: https://github.com/matklad/cargo-xtask
|
||||
[mdbook]: https://rust-lang.github.io/mdBook/guide/installation.html
|
||||
[helpers.rs]: ../helix-term/tests/test/helpers.rs
|
||||
|
@ -1,16 +1,23 @@
|
||||
## Checklist
|
||||
|
||||
Helix releases are versioned in the Calendar Versioning scheme:
|
||||
`YY.0M(.MICRO)`, for example `22.05` for May of 2022. In these instructions
|
||||
we'll use `<tag>` as a placeholder for the tag being published.
|
||||
`YY.0M(.MICRO)`, for example, `22.05` for May of 2022, or in a patch release,
|
||||
`22.05.1`. In these instructions we'll use `<tag>` as a placeholder for the tag
|
||||
being published.
|
||||
|
||||
* Merge the changelog PR
|
||||
* Add new `<release>` entry in `contrib/Helix.appdata.xml` with release information according to the [AppStream spec](https://www.freedesktop.org/software/appstream/docs/sect-Metadata-Releases.html)
|
||||
* Tag and push
|
||||
* `git tag -s -m "<tag>" -a <tag> && git push`
|
||||
* Make sure to switch to master and pull first
|
||||
* Edit the `VERSION` file and change the date to the next planned release
|
||||
* Releases are planned to happen every two months, so `22.05` would change to `22.07`
|
||||
* Edit the `Cargo.toml` file and change the date in the `version` field to the next planned release
|
||||
* Due to Cargo having a strict requirement on SemVer with 3 or more version
|
||||
numbers, a `0` is required in the micro version; however, unless we are
|
||||
publishing a patch release after a major release, the `.0` is dropped in
|
||||
the user facing version.
|
||||
* Releases are planned to happen every two months, so `22.05.0` would change to `22.07.0`
|
||||
* If we are pushing a patch/bugfix release in the same month as the previous
|
||||
release, bump the micro version, e.g. `22.07.0` to `22.07.1`
|
||||
* Wait for the Release CI to finish
|
||||
* It will automatically turn the git tag into a GitHub release when it uploads artifacts
|
||||
* Edit the new release
|
||||
@ -30,7 +37,7 @@ ## Changelog Curation
|
||||
|
||||
The changelog is currently created manually by reading through commits in the
|
||||
log since the last release. GitHub's compare view is a nice way to approach
|
||||
this. For example when creating the 22.07 release notes, this compare link
|
||||
this. For example, when creating the 22.07 release notes, this compare link
|
||||
may be used
|
||||
|
||||
```
|
||||
@ -57,4 +64,4 @@ ## Changelog Curation
|
||||
> release. For the full log, check out the git log.
|
||||
|
||||
Typically, small changes like dependencies or documentation updates, refactors,
|
||||
or meta changes like GitHub Actions work are left out.
|
||||
or meta changes like GitHub Actions work are left out.
|
||||
|
@ -20,5 +20,5 @@ # Goals
|
||||
* **Built-in tools** for working with code bases efficiently. Most projects aren't a single file, and an editor should handle that as a first-class use case. In Helix's case, this means (among other things) a fuzzy-search file navigator and LSP support.
|
||||
* **Edit anything** that comes up when coding, within reason. Whether it's a 200 MB XML file, a megabyte of minified javascript on a single line, or Japanese text encoded in ShiftJIS, you should be able to open it and edit it without problems. (Note: this doesn't mean handle every esoteric use case. Sometimes you do just need a specialized tool, and Helix isn't that.)
|
||||
* **Configurable**, within reason. Although the defaults should be good, not everyone will agree on what "good" is. Within the bounds of Helix's core interaction models, it should be reasonably configurable so that it can be "good" for more people. This means, for example, custom key maps among other things.
|
||||
* **Extensible**, within reason. Although we want Helix to be productive out-of-the-box, it's not practical or desirable to cram every useful feature and use case into the core editor. The basics should be built-in, but you should be able to extend it with additional functionality as needed. Right now we're thinking Wasm-based plugins.
|
||||
* **Extensible**, within reason. Although we want Helix to be productive out-of-the-box, it's not practical or desirable to cram every useful feature and use case into the core editor. The basics should be built-in, but you should be able to extend it with additional functionality as needed.
|
||||
* **Clean code base.** Sometimes other factors (e.g. significant performance gains, important features, correctness, etc.) will trump strict readability, but we nevertheless want to keep the code base straightforward and easy to understand to the extent we can.
|
||||
|
258
flake.lock
258
flake.lock
@ -1,126 +1,22 @@
|
||||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1681175776,
|
||||
"narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "445a3d222947632b5593112bb817850e8a9cf737",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"ref": "v0.12.1",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"dream2nix": {
|
||||
"inputs": {
|
||||
"all-cabal-json": [
|
||||
"nci"
|
||||
],
|
||||
"crane": "crane",
|
||||
"devshell": [
|
||||
"nci"
|
||||
],
|
||||
"drv-parts": "drv-parts",
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-parts": [
|
||||
"nci",
|
||||
"parts"
|
||||
],
|
||||
"flake-utils-pre-commit": [
|
||||
"nci"
|
||||
],
|
||||
"ghc-utils": [
|
||||
"nci"
|
||||
],
|
||||
"gomod2nix": [
|
||||
"nci"
|
||||
],
|
||||
"mach-nix": [
|
||||
"nci"
|
||||
],
|
||||
"nix-pypi-fetcher": [
|
||||
"nci"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nci",
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgsV1": "nixpkgsV1",
|
||||
"poetry2nix": [
|
||||
"nci"
|
||||
],
|
||||
"pre-commit-hooks": [
|
||||
"nci"
|
||||
],
|
||||
"pruned-racket-catalog": [
|
||||
"nci"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683212002,
|
||||
"narHash": "sha256-EObtqyQsv9v+inieRY5cvyCMCUI5zuU5qu+1axlJCPM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "dream2nix",
|
||||
"rev": "fbfb09d2ab5ff761d822dd40b4a1def81651d096",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "dream2nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"drv-parts": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"nci",
|
||||
"dream2nix",
|
||||
"flake-compat"
|
||||
],
|
||||
"flake-parts": [
|
||||
"nci",
|
||||
"dream2nix",
|
||||
"flake-parts"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nci",
|
||||
"dream2nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1680698112,
|
||||
"narHash": "sha256-FgnobN/DvCjEsc0UAZEAdPLkL4IZi2ZMnu2K2bUaElc=",
|
||||
"owner": "davhau",
|
||||
"repo": "drv-parts",
|
||||
"rev": "e8c2ec1157dc1edb002989669a0dbd935f430201",
|
||||
"lastModified": 1709610799,
|
||||
"narHash": "sha256-5jfLQx0U9hXbi2skYMGodDJkIgffrjIOgMRjZqms2QE=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "81c393c776d5379c030607866afef6406ca1be57",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "davhau",
|
||||
"repo": "drv-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
@ -129,11 +25,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"lastModified": 1709126324,
|
||||
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -142,55 +38,13 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"mk-naked-shell": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1681286841,
|
||||
"narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=",
|
||||
"owner": "yusdacra",
|
||||
"repo": "mk-naked-shell",
|
||||
"rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "yusdacra",
|
||||
"repo": "mk-naked-shell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nci": {
|
||||
"inputs": {
|
||||
"dream2nix": "dream2nix",
|
||||
"mk-naked-shell": "mk-naked-shell",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"parts": "parts",
|
||||
"rust-overlay": [
|
||||
"rust-overlay"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683699050,
|
||||
"narHash": "sha256-UWKQpzVcSshB+sU2O8CCHjOSTQrNS7Kk9V3+UeBsJpg=",
|
||||
"owner": "yusdacra",
|
||||
"repo": "nix-cargo-integration",
|
||||
"rev": "ed27173cd1b223f598343ea3c15aacb1d140feac",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "yusdacra",
|
||||
"repo": "nix-cargo-integration",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1683408522,
|
||||
"narHash": "sha256-9kcPh6Uxo17a3kK3XCHhcWiV1Yu1kYj22RHiymUhMkU=",
|
||||
"lastModified": 1709479366,
|
||||
"narHash": "sha256-n6F0n8UV6lnTZbYPl1A9q1BS0p4hduAv1mGAP17CVd0=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "897876e4c484f1e8f92009fd11b7d988a121a4e7",
|
||||
"rev": "b8697e57f10292a6165a20f03d2f42920dfaf973",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -200,99 +54,29 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"dir": "lib",
|
||||
"lastModified": 1682879489,
|
||||
"narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "lib",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgsV1": {
|
||||
"locked": {
|
||||
"lastModified": 1678500271,
|
||||
"narHash": "sha256-tRBLElf6f02HJGG0ZR7znMNFv/Uf7b2fFInpTHiHaSE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5eb98948b66de29f899c7fe27ae112a47964baf8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": [
|
||||
"nci",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683560683,
|
||||
"narHash": "sha256-XAygPMN5Xnk/W2c1aW0jyEa6lfMDZWlQgiNtmHXytPc=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "006c75898cf814ef9497252b022e91c946ba8e17",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"parts_2": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683560683,
|
||||
"narHash": "sha256-XAygPMN5Xnk/W2c1aW0jyEa6lfMDZWlQgiNtmHXytPc=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "006c75898cf814ef9497252b022e91c946ba8e17",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nci": "nci",
|
||||
"crane": "crane",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"parts": "parts_2",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"flake-utils": [
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683771545,
|
||||
"narHash": "sha256-we0GYcKTo2jRQGmUGrzQ9VH0OYAUsJMCsK8UkF+vZUA=",
|
||||
"lastModified": 1709604635,
|
||||
"narHash": "sha256-le4fwmWmjGRYWwkho0Gr7mnnZndOOe4XGbLw68OvF40=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "c57e210faf68e5d5386f18f1b17ad8365d25e4ed",
|
||||
"rev": "e86c0fb5d3a22a5f30d7f64ecad88643fe26449d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
323
flake.nix
323
flake.nix
@ -3,166 +3,193 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
flake-utils.follows = "flake-utils";
|
||||
};
|
||||
};
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
nci = {
|
||||
url = "github:yusdacra/nix-cargo-integration";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.rust-overlay.follows = "rust-overlay";
|
||||
};
|
||||
parts.url = "github:hercules-ci/flake-parts";
|
||||
};
|
||||
|
||||
outputs = inp: let
|
||||
mkRootPath = rel:
|
||||
builtins.path {
|
||||
path = "${toString ./.}/${rel}";
|
||||
name = rel;
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
crane,
|
||||
flake-utils,
|
||||
rust-overlay,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [(import rust-overlay)];
|
||||
};
|
||||
filteredSource = let
|
||||
pathsToIgnore = [
|
||||
".envrc"
|
||||
".ignore"
|
||||
".github"
|
||||
".gitignore"
|
||||
"logo.svg"
|
||||
"logo_dark.svg"
|
||||
"logo_light.svg"
|
||||
"rust-toolchain.toml"
|
||||
"rustfmt.toml"
|
||||
"runtime"
|
||||
"screenshot.png"
|
||||
"book"
|
||||
"contrib"
|
||||
"docs"
|
||||
"README.md"
|
||||
"CHANGELOG.md"
|
||||
"shell.nix"
|
||||
"default.nix"
|
||||
"grammars.nix"
|
||||
"flake.nix"
|
||||
"flake.lock"
|
||||
];
|
||||
ignorePaths = path: type: let
|
||||
inherit (inp.nixpkgs) lib;
|
||||
# split the nix store path into its components
|
||||
components = lib.splitString "/" path;
|
||||
# drop off the `/nix/hash-source` section from the path
|
||||
relPathComponents = lib.drop 4 components;
|
||||
# reassemble the path components
|
||||
relPath = lib.concatStringsSep "/" relPathComponents;
|
||||
in
|
||||
lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
|
||||
in
|
||||
builtins.path {
|
||||
name = "helix-source";
|
||||
path = toString ./.;
|
||||
# filter out unnecessary paths
|
||||
filter = ignorePaths;
|
||||
};
|
||||
in
|
||||
inp.parts.lib.mkFlake {inputs = inp;} {
|
||||
imports = [inp.nci.flakeModule inp.parts.flakeModules.easyOverlay];
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-linux"
|
||||
"aarch64-darwin"
|
||||
"i686-linux"
|
||||
];
|
||||
perSystem = {
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
makeOverridableHelix = old: config: let
|
||||
grammars = pkgs.callPackage ./grammars.nix config;
|
||||
runtimeDir = pkgs.runCommand "helix-runtime" {} ''
|
||||
mkdir -p $out
|
||||
ln -s ${mkRootPath "runtime"}/* $out
|
||||
rm -r $out/grammars
|
||||
ln -s ${grammars} $out/grammars
|
||||
'';
|
||||
helix-wrapped =
|
||||
pkgs.runCommand
|
||||
old.name
|
||||
{
|
||||
inherit (old) pname version;
|
||||
meta = old.meta or {};
|
||||
passthru =
|
||||
(old.passthru or {})
|
||||
// {
|
||||
unwrapped = old;
|
||||
};
|
||||
nativeBuildInputs = [pkgs.makeWrapper];
|
||||
makeWrapperArgs = config.makeWrapperArgs or [];
|
||||
}
|
||||
''
|
||||
cp -rs --no-preserve=mode,ownership ${old} $out
|
||||
wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
|
||||
'';
|
||||
mkRootPath = rel:
|
||||
builtins.path {
|
||||
path = "${toString ./.}/${rel}";
|
||||
name = rel;
|
||||
};
|
||||
filteredSource = let
|
||||
pathsToIgnore = [
|
||||
".envrc"
|
||||
".ignore"
|
||||
".github"
|
||||
".gitignore"
|
||||
"logo_dark.svg"
|
||||
"logo_light.svg"
|
||||
"rust-toolchain.toml"
|
||||
"rustfmt.toml"
|
||||
"runtime"
|
||||
"screenshot.png"
|
||||
"book"
|
||||
"docs"
|
||||
"README.md"
|
||||
"CHANGELOG.md"
|
||||
"shell.nix"
|
||||
"default.nix"
|
||||
"grammars.nix"
|
||||
"flake.nix"
|
||||
"flake.lock"
|
||||
];
|
||||
ignorePaths = path: type: let
|
||||
inherit (nixpkgs) lib;
|
||||
# split the nix store path into its components
|
||||
components = lib.splitString "/" path;
|
||||
# drop off the `/nix/hash-source` section from the path
|
||||
relPathComponents = lib.drop 4 components;
|
||||
# reassemble the path components
|
||||
relPath = lib.concatStringsSep "/" relPathComponents;
|
||||
in
|
||||
helix-wrapped
|
||||
// {
|
||||
override = makeOverridableHelix old;
|
||||
lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
|
||||
in
|
||||
builtins.path {
|
||||
name = "helix-source";
|
||||
path = toString ./.;
|
||||
# filter out unnecessary paths
|
||||
filter = ignorePaths;
|
||||
};
|
||||
makeOverridableHelix = old: config: let
|
||||
grammars = pkgs.callPackage ./grammars.nix config;
|
||||
runtimeDir = pkgs.runCommand "helix-runtime" {} ''
|
||||
mkdir -p $out
|
||||
ln -s ${mkRootPath "runtime"}/* $out
|
||||
rm -r $out/grammars
|
||||
ln -s ${grammars} $out/grammars
|
||||
'';
|
||||
helix-wrapped =
|
||||
pkgs.runCommand
|
||||
old.name
|
||||
{
|
||||
inherit (old) pname version;
|
||||
meta = old.meta or {};
|
||||
passthru =
|
||||
helix-wrapped.passthru
|
||||
(old.passthru or {})
|
||||
// {
|
||||
wrapper = old: makeOverridableHelix old config;
|
||||
unwrapped = old;
|
||||
};
|
||||
};
|
||||
stdenv =
|
||||
if pkgs.stdenv.isLinux
|
||||
then pkgs.stdenv
|
||||
else pkgs.clangStdenv;
|
||||
rustFlagsEnv =
|
||||
if stdenv.isLinux
|
||||
then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
|
||||
else "$RUSTFLAGS";
|
||||
in {
|
||||
nci.projects."helix-project".relPath = "";
|
||||
nci.crates."helix-term" = {
|
||||
overrides = {
|
||||
add-meta.override = _: {meta.mainProgram = "hx";};
|
||||
add-inputs.overrideAttrs = prev: {
|
||||
buildInputs = (prev.buildInputs or []) ++ [stdenv.cc.cc.lib];
|
||||
};
|
||||
disable-grammar-builds = {
|
||||
# disable fetching and building of tree-sitter grammars in the helix-term build.rs
|
||||
HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
|
||||
};
|
||||
disable-tests = {checkPhase = ":";};
|
||||
set-stdenv.override = _: {inherit stdenv;};
|
||||
set-filtered-src.override = _: {src = filteredSource;};
|
||||
};
|
||||
};
|
||||
|
||||
packages.helix-unwrapped = config.nci.outputs."helix-term".packages.release;
|
||||
packages.helix-unwrapped-dev = config.nci.outputs."helix-term".packages.dev;
|
||||
packages.helix = makeOverridableHelix config.packages.helix-unwrapped {};
|
||||
packages.helix-dev = makeOverridableHelix config.packages.helix-unwrapped-dev {};
|
||||
packages.default = config.packages.helix;
|
||||
|
||||
overlayAttrs = {
|
||||
inherit (config.packages) helix;
|
||||
};
|
||||
|
||||
devShells.default = config.nci.outputs."helix-project".devShell.overrideAttrs (old: {
|
||||
nativeBuildInputs =
|
||||
(old.nativeBuildInputs or [])
|
||||
++ (with pkgs; [lld_13 cargo-flamegraph rust-analyzer])
|
||||
++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
|
||||
++ (lib.optional stdenv.isLinux pkgs.lldb)
|
||||
++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
|
||||
shellHook = ''
|
||||
export HELIX_RUNTIME="$PWD/runtime"
|
||||
export RUST_BACKTRACE="1"
|
||||
export RUSTFLAGS="${rustFlagsEnv}"
|
||||
nativeBuildInputs = [pkgs.makeWrapper];
|
||||
makeWrapperArgs = config.makeWrapperArgs or [];
|
||||
}
|
||||
''
|
||||
cp -rs --no-preserve=mode,ownership ${old} $out
|
||||
wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
|
||||
'';
|
||||
});
|
||||
in
|
||||
helix-wrapped
|
||||
// {
|
||||
override = makeOverridableHelix old;
|
||||
passthru =
|
||||
helix-wrapped.passthru
|
||||
// {
|
||||
wrapper = old: makeOverridableHelix old config;
|
||||
};
|
||||
};
|
||||
stdenv =
|
||||
if pkgs.stdenv.isLinux
|
||||
then pkgs.stdenv
|
||||
else pkgs.clangStdenv;
|
||||
rustFlagsEnv =
|
||||
if stdenv.isLinux
|
||||
then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
|
||||
else "$RUSTFLAGS";
|
||||
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
craneLibMSRV = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
craneLibStable = (crane.mkLib pkgs).overrideToolchain pkgs.pkgsBuildHost.rust-bin.stable.latest.default;
|
||||
commonArgs = {
|
||||
inherit stdenv;
|
||||
inherit (craneLibMSRV.crateNameFromCargoToml {cargoToml = ./helix-term/Cargo.toml;}) pname;
|
||||
inherit (craneLibMSRV.crateNameFromCargoToml {cargoToml = ./Cargo.toml;}) version;
|
||||
src = filteredSource;
|
||||
# disable fetching and building of tree-sitter grammars in the helix-term build.rs
|
||||
HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
|
||||
buildInputs = [stdenv.cc.cc.lib];
|
||||
# disable tests
|
||||
doCheck = false;
|
||||
meta.mainProgram = "hx";
|
||||
};
|
||||
cargoArtifacts = craneLibMSRV.buildDepsOnly commonArgs;
|
||||
in {
|
||||
packages = {
|
||||
helix-unwrapped = craneLibStable.buildPackage (commonArgs
|
||||
// {
|
||||
cargoArtifacts = craneLibStable.buildDepsOnly commonArgs;
|
||||
postInstall = ''
|
||||
mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps $out/share/icons/hicolor/256x256/apps
|
||||
cp contrib/Helix.desktop $out/share/applications
|
||||
cp logo.svg $out/share/icons/hicolor/scalable/apps/helix.svg
|
||||
cp contrib/helix.png $out/share/icons/hicolor/256x256/apps
|
||||
'';
|
||||
});
|
||||
helix = makeOverridableHelix self.packages.${system}.helix-unwrapped {};
|
||||
default = self.packages.${system}.helix;
|
||||
};
|
||||
|
||||
checks = {
|
||||
# Build the crate itself
|
||||
inherit (self.packages.${system}) helix;
|
||||
|
||||
clippy = craneLibMSRV.cargoClippy (commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
|
||||
fmt = craneLibMSRV.cargoFmt commonArgs;
|
||||
|
||||
doc = craneLibMSRV.cargoDoc (commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
|
||||
test = craneLibMSRV.cargoTest (commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = builtins.attrValues self.checks.${system};
|
||||
nativeBuildInputs = with pkgs;
|
||||
[lld_13 cargo-flamegraph rust-analyzer]
|
||||
++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
|
||||
++ (lib.optional stdenv.isLinux pkgs.lldb)
|
||||
++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
|
||||
shellHook = ''
|
||||
export HELIX_RUNTIME="$PWD/runtime"
|
||||
export RUST_BACKTRACE="1"
|
||||
export RUSTFLAGS="${rustFlagsEnv}"
|
||||
'';
|
||||
};
|
||||
})
|
||||
// {
|
||||
overlays.default = final: prev: {
|
||||
inherit (self.packages.${final.system}) helix;
|
||||
};
|
||||
};
|
||||
|
||||
|
57
grammars.nix
57
grammars.nix
@ -5,6 +5,7 @@
|
||||
runCommand,
|
||||
yj,
|
||||
includeGrammarIf ? _: true,
|
||||
grammarOverlays ? [],
|
||||
...
|
||||
}: let
|
||||
# HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
|
||||
@ -27,7 +28,17 @@
|
||||
owner = builtins.elemAt match 0;
|
||||
repo = builtins.elemAt match 1;
|
||||
};
|
||||
gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar;
|
||||
# If `use-grammars.only` is set, use only those grammars.
|
||||
# If `use-grammars.except` is set, use all other grammars.
|
||||
# Otherwise use all grammars.
|
||||
useGrammar = grammar:
|
||||
if languagesConfig?use-grammars.only then
|
||||
builtins.elem grammar.name languagesConfig.use-grammars.only
|
||||
else if languagesConfig?use-grammars.except then
|
||||
!(builtins.elem grammar.name languagesConfig.use-grammars.except)
|
||||
else true;
|
||||
grammarsToUse = builtins.filter useGrammar languagesConfig.grammar;
|
||||
gitGrammars = builtins.filter isGitGrammar grammarsToUse;
|
||||
buildGrammar = grammar: let
|
||||
gh = toGitHubFetcher grammar.source.git;
|
||||
sourceGit = builtins.fetchTree {
|
||||
@ -48,22 +59,22 @@
|
||||
then sourceGitHub
|
||||
else sourceGit;
|
||||
in
|
||||
stdenv.mkDerivation rec {
|
||||
stdenv.mkDerivation {
|
||||
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
||||
|
||||
pname = "helix-tree-sitter-${grammar.name}";
|
||||
version = grammar.source.rev;
|
||||
|
||||
src =
|
||||
if builtins.hasAttr "subpath" grammar.source
|
||||
then "${source}/${grammar.source.subpath}"
|
||||
else source;
|
||||
src = source;
|
||||
sourceRoot = if builtins.hasAttr "subpath" grammar.source then
|
||||
"source/${grammar.source.subpath}"
|
||||
else
|
||||
"source";
|
||||
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
|
||||
FLAGS = [
|
||||
"-I${src}/src"
|
||||
"-Isrc"
|
||||
"-g"
|
||||
"-O3"
|
||||
"-fPIC"
|
||||
@ -76,13 +87,13 @@
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
if [[ -e "$src/src/scanner.cc" ]]; then
|
||||
$CXX -c "$src/src/scanner.cc" -o scanner.o $FLAGS
|
||||
elif [[ -e "$src/src/scanner.c" ]]; then
|
||||
$CC -c "$src/src/scanner.c" -o scanner.o $FLAGS
|
||||
if [[ -e src/scanner.cc ]]; then
|
||||
$CXX -c src/scanner.cc -o scanner.o $FLAGS
|
||||
elif [[ -e src/scanner.c ]]; then
|
||||
$CC -c src/scanner.c -o scanner.o $FLAGS
|
||||
fi
|
||||
|
||||
$CC -c "$src/src/parser.c" -o parser.o $FLAGS
|
||||
$CC -c src/parser.c -o parser.o $FLAGS
|
||||
$CXX -shared -o $NAME.so *.o
|
||||
|
||||
ls -al
|
||||
@ -105,15 +116,17 @@
|
||||
'';
|
||||
};
|
||||
grammarsToBuild = builtins.filter includeGrammarIf gitGrammars;
|
||||
builtGrammars =
|
||||
builtins.map (grammar: {
|
||||
inherit (grammar) name;
|
||||
artifact = buildGrammar grammar;
|
||||
})
|
||||
grammarsToBuild;
|
||||
grammarLinks =
|
||||
builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
|
||||
builtGrammars;
|
||||
builtGrammars = builtins.map (grammar: {
|
||||
inherit (grammar) name;
|
||||
value = buildGrammar grammar;
|
||||
}) grammarsToBuild;
|
||||
extensibleGrammars =
|
||||
lib.makeExtensible (self: builtins.listToAttrs builtGrammars);
|
||||
overlayedGrammars = lib.pipe extensibleGrammars
|
||||
(builtins.map (overlay: grammar: grammar.extend overlay) grammarOverlays);
|
||||
grammarLinks = lib.mapAttrsToList
|
||||
(name: artifact: "ln -s ${artifact}/${name}.so $out/${name}.so")
|
||||
(lib.filterAttrs (n: v: lib.isDerivation v) overlayedGrammars);
|
||||
in
|
||||
runCommand "consolidated-helix-grammars" {} ''
|
||||
mkdir -p $out
|
||||
|
@ -1,43 +1,45 @@
|
||||
[package]
|
||||
name = "helix-core"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
description = "Helix editor core editing primitives"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
include = ["src/**/*", "README.md"]
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
[features]
|
||||
unicode-lines = ["ropey/unicode_lines"]
|
||||
integration = []
|
||||
|
||||
[dependencies]
|
||||
helix-loader = { version = "0.6", path = "../helix-loader" }
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-loader = { path = "../helix-loader" }
|
||||
|
||||
ropey = { version = "1.6.0", default-features = false, features = ["simd"] }
|
||||
smallvec = "1.10"
|
||||
ropey = { version = "1.6.1", default-features = false, features = ["simd"] }
|
||||
smallvec = "1.13"
|
||||
smartstring = "1.0.1"
|
||||
unicode-segmentation = "1.10"
|
||||
unicode-segmentation = "1.11"
|
||||
unicode-width = "0.1"
|
||||
unicode-general-category = "0.6"
|
||||
# slab = "0.4.2"
|
||||
slotmap = "1.0"
|
||||
tree-sitter = "0.20"
|
||||
once_cell = "1.17"
|
||||
tree-sitter.workspace = true
|
||||
once_cell = "1.19"
|
||||
arc-swap = "1"
|
||||
regex = "1"
|
||||
bitflags = "2.3"
|
||||
ahash = "0.8.3"
|
||||
hashbrown = { version = "0.13.2", features = ["raw"] }
|
||||
bitflags = "2.5"
|
||||
ahash = "0.8.11"
|
||||
hashbrown = { version = "0.14.3", features = ["raw"] }
|
||||
dunce = "1.0"
|
||||
|
||||
log = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
toml = "0.7"
|
||||
toml = "0.8"
|
||||
|
||||
imara-diff = "0.1.0"
|
||||
|
||||
@ -46,8 +48,12 @@ encoding_rs = "0.8"
|
||||
chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] }
|
||||
|
||||
etcetera = "0.8"
|
||||
textwrap = "0.16.0"
|
||||
textwrap = "0.16.1"
|
||||
|
||||
nucleo.workspace = true
|
||||
parking_lot = "0.12"
|
||||
globset = "0.4.14"
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = { version = "1", default-features = false }
|
||||
indoc = "2.0.1"
|
||||
indoc = "2.0.5"
|
||||
|
@ -1,9 +1,12 @@
|
||||
//! This module contains the functionality toggle comments on lines over the selection
|
||||
//! using the comment character defined in the user's `languages.toml`
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
find_first_non_whitespace_char, Change, Rope, RopeSlice, Selection, Tendril, Transaction,
|
||||
syntax::BlockCommentToken, Change, Range, Rope, RopeSlice, Selection, Tendril, Transaction,
|
||||
};
|
||||
use helix_stdx::rope::RopeSliceExt;
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Given text, a comment token, and a set of line indices, returns the following:
|
||||
@ -22,12 +25,12 @@ fn find_line_comment(
|
||||
) -> (bool, Vec<usize>, usize, usize) {
|
||||
let mut commented = true;
|
||||
let mut to_change = Vec::new();
|
||||
let mut min = usize::MAX; // minimum col for find_first_non_whitespace_char
|
||||
let mut min = usize::MAX; // minimum col for first_non_whitespace_char
|
||||
let mut margin = 1;
|
||||
let token_len = token.chars().count();
|
||||
for line in lines {
|
||||
let line_slice = text.line(line);
|
||||
if let Some(pos) = find_first_non_whitespace_char(line_slice) {
|
||||
if let Some(pos) = line_slice.first_non_whitespace_char() {
|
||||
let len = line_slice.len_chars();
|
||||
|
||||
if pos < min {
|
||||
@ -94,6 +97,222 @@ pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&st
|
||||
Transaction::change(doc, changes.into_iter())
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum CommentChange {
|
||||
Commented {
|
||||
range: Range,
|
||||
start_pos: usize,
|
||||
end_pos: usize,
|
||||
start_margin: bool,
|
||||
end_margin: bool,
|
||||
start_token: String,
|
||||
end_token: String,
|
||||
},
|
||||
Uncommented {
|
||||
range: Range,
|
||||
start_pos: usize,
|
||||
end_pos: usize,
|
||||
start_token: String,
|
||||
end_token: String,
|
||||
},
|
||||
Whitespace {
|
||||
range: Range,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn find_block_comments(
|
||||
tokens: &[BlockCommentToken],
|
||||
text: RopeSlice,
|
||||
selection: &Selection,
|
||||
) -> (bool, Vec<CommentChange>) {
|
||||
let mut commented = true;
|
||||
let mut only_whitespace = true;
|
||||
let mut comment_changes = Vec::with_capacity(selection.len());
|
||||
let default_tokens = tokens.first().cloned().unwrap_or_default();
|
||||
// TODO: check if this can be removed on MSRV bump
|
||||
#[allow(clippy::redundant_clone)]
|
||||
let mut start_token = default_tokens.start.clone();
|
||||
#[allow(clippy::redundant_clone)]
|
||||
let mut end_token = default_tokens.end.clone();
|
||||
|
||||
let mut tokens = tokens.to_vec();
|
||||
// sort the tokens by length, so longer tokens will match first
|
||||
tokens.sort_by(|a, b| {
|
||||
if a.start.len() == b.start.len() {
|
||||
b.end.len().cmp(&a.end.len())
|
||||
} else {
|
||||
b.start.len().cmp(&a.start.len())
|
||||
}
|
||||
});
|
||||
for range in selection {
|
||||
let selection_slice = range.slice(text);
|
||||
if let (Some(start_pos), Some(end_pos)) = (
|
||||
selection_slice.first_non_whitespace_char(),
|
||||
selection_slice.last_non_whitespace_char(),
|
||||
) {
|
||||
let mut line_commented = false;
|
||||
let mut after_start = 0;
|
||||
let mut before_end = 0;
|
||||
let len = (end_pos + 1) - start_pos;
|
||||
|
||||
for BlockCommentToken { start, end } in &tokens {
|
||||
let start_len = start.chars().count();
|
||||
let end_len = end.chars().count();
|
||||
after_start = start_pos + start_len;
|
||||
before_end = end_pos.saturating_sub(end_len);
|
||||
|
||||
if len >= start_len + end_len {
|
||||
let start_fragment = selection_slice.slice(start_pos..after_start);
|
||||
let end_fragment = selection_slice.slice(before_end + 1..end_pos + 1);
|
||||
|
||||
// block commented with these tokens
|
||||
if start_fragment == start.as_str() && end_fragment == end.as_str() {
|
||||
start_token = start.to_string();
|
||||
end_token = end.to_string();
|
||||
line_commented = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !line_commented {
|
||||
comment_changes.push(CommentChange::Uncommented {
|
||||
range: *range,
|
||||
start_pos,
|
||||
end_pos,
|
||||
start_token: default_tokens.start.clone(),
|
||||
end_token: default_tokens.end.clone(),
|
||||
});
|
||||
commented = false;
|
||||
} else {
|
||||
comment_changes.push(CommentChange::Commented {
|
||||
range: *range,
|
||||
start_pos,
|
||||
end_pos,
|
||||
start_margin: selection_slice
|
||||
.get_char(after_start)
|
||||
.map_or(false, |c| c == ' '),
|
||||
end_margin: after_start != before_end
|
||||
&& selection_slice
|
||||
.get_char(before_end)
|
||||
.map_or(false, |c| c == ' '),
|
||||
start_token: start_token.to_string(),
|
||||
end_token: end_token.to_string(),
|
||||
});
|
||||
}
|
||||
only_whitespace = false;
|
||||
} else {
|
||||
comment_changes.push(CommentChange::Whitespace { range: *range });
|
||||
}
|
||||
}
|
||||
if only_whitespace {
|
||||
commented = false;
|
||||
}
|
||||
(commented, comment_changes)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn create_block_comment_transaction(
|
||||
doc: &Rope,
|
||||
selection: &Selection,
|
||||
commented: bool,
|
||||
comment_changes: Vec<CommentChange>,
|
||||
) -> (Transaction, SmallVec<[Range; 1]>) {
|
||||
let mut changes: Vec<Change> = Vec::with_capacity(selection.len() * 2);
|
||||
let mut ranges: SmallVec<[Range; 1]> = SmallVec::with_capacity(selection.len());
|
||||
let mut offs = 0;
|
||||
for change in comment_changes {
|
||||
if commented {
|
||||
if let CommentChange::Commented {
|
||||
range,
|
||||
start_pos,
|
||||
end_pos,
|
||||
start_token,
|
||||
end_token,
|
||||
start_margin,
|
||||
end_margin,
|
||||
} = change
|
||||
{
|
||||
let from = range.from();
|
||||
changes.push((
|
||||
from + start_pos,
|
||||
from + start_pos + start_token.len() + start_margin as usize,
|
||||
None,
|
||||
));
|
||||
changes.push((
|
||||
from + end_pos - end_token.len() - end_margin as usize + 1,
|
||||
from + end_pos + 1,
|
||||
None,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// uncommented so manually map ranges through changes
|
||||
match change {
|
||||
CommentChange::Uncommented {
|
||||
range,
|
||||
start_pos,
|
||||
end_pos,
|
||||
start_token,
|
||||
end_token,
|
||||
} => {
|
||||
let from = range.from();
|
||||
changes.push((
|
||||
from + start_pos,
|
||||
from + start_pos,
|
||||
Some(Tendril::from(format!("{} ", start_token))),
|
||||
));
|
||||
changes.push((
|
||||
from + end_pos + 1,
|
||||
from + end_pos + 1,
|
||||
Some(Tendril::from(format!(" {}", end_token))),
|
||||
));
|
||||
|
||||
let offset = start_token.chars().count() + end_token.chars().count() + 2;
|
||||
ranges.push(
|
||||
Range::new(from + offs, from + offs + end_pos + 1 + offset)
|
||||
.with_direction(range.direction()),
|
||||
);
|
||||
offs += offset;
|
||||
}
|
||||
CommentChange::Commented { range, .. } | CommentChange::Whitespace { range } => {
|
||||
ranges.push(Range::new(range.from() + offs, range.to() + offs));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(Transaction::change(doc, changes.into_iter()), ranges)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn toggle_block_comments(
|
||||
doc: &Rope,
|
||||
selection: &Selection,
|
||||
tokens: &[BlockCommentToken],
|
||||
) -> Transaction {
|
||||
let text = doc.slice(..);
|
||||
let (commented, comment_changes) = find_block_comments(tokens, text, selection);
|
||||
let (mut transaction, ranges) =
|
||||
create_block_comment_transaction(doc, selection, commented, comment_changes);
|
||||
if !commented {
|
||||
transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
|
||||
}
|
||||
transaction
|
||||
}
|
||||
|
||||
pub fn split_lines_of_selection(text: RopeSlice, selection: &Selection) -> Selection {
|
||||
let mut ranges = SmallVec::new();
|
||||
for range in selection.ranges() {
|
||||
let (line_start, line_end) = range.line_range(text.slice(..));
|
||||
let mut pos = text.line_to_char(line_start);
|
||||
for line in text.slice(pos..text.line_to_char(line_end + 1)).lines() {
|
||||
let start = pos;
|
||||
pos += line.len_chars();
|
||||
ranges.push(Range::new(start, pos));
|
||||
}
|
||||
}
|
||||
Selection::new(ranges, 0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
@ -149,4 +368,49 @@ fn test_find_line_comment() {
|
||||
|
||||
// TODO: account for uncommenting with uneven comment indentation
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_block_comments() {
|
||||
// three lines 5 characters.
|
||||
let mut doc = Rope::from("1\n2\n3");
|
||||
// select whole document
|
||||
let selection = Selection::single(0, doc.len_chars());
|
||||
|
||||
let text = doc.slice(..);
|
||||
|
||||
let res = find_block_comments(&[BlockCommentToken::default()], text, &selection);
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
(
|
||||
false,
|
||||
vec![CommentChange::Uncommented {
|
||||
range: Range::new(0, 5),
|
||||
start_pos: 0,
|
||||
end_pos: 4,
|
||||
start_token: "/*".to_string(),
|
||||
end_token: "*/".to_string(),
|
||||
}]
|
||||
)
|
||||
);
|
||||
|
||||
// comment
|
||||
let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]);
|
||||
transaction.apply(&mut doc);
|
||||
|
||||
assert_eq!(doc, "/* 1\n2\n3 */");
|
||||
|
||||
// uncomment
|
||||
let selection = Selection::single(0, doc.len_chars());
|
||||
let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]);
|
||||
transaction.apply(&mut doc);
|
||||
assert_eq!(doc, "1\n2\n3");
|
||||
|
||||
// don't panic when there is just a space in comment
|
||||
doc = Rope::from("/* */");
|
||||
let selection = Selection::single(0, doc.len_chars());
|
||||
let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]);
|
||||
transaction.apply(&mut doc);
|
||||
assert_eq!(doc, "");
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,45 @@
|
||||
/// Syntax configuration loader based on built-in languages.toml.
|
||||
pub fn default_syntax_loader() -> crate::syntax::Configuration {
|
||||
use crate::syntax::{Configuration, Loader, LoaderError};
|
||||
|
||||
/// Language configuration based on built-in languages.toml.
|
||||
pub fn default_lang_config() -> Configuration {
|
||||
helix_loader::config::default_lang_config()
|
||||
.try_into()
|
||||
.expect("Could not serialize built-in languages.toml")
|
||||
.expect("Could not deserialize built-in languages.toml")
|
||||
}
|
||||
/// Syntax configuration loader based on user configured languages.toml.
|
||||
pub fn user_syntax_loader() -> Result<crate::syntax::Configuration, toml::de::Error> {
|
||||
|
||||
/// Language configuration loader based on built-in languages.toml.
|
||||
pub fn default_lang_loader() -> Loader {
|
||||
Loader::new(default_lang_config()).expect("Could not compile loader for default config")
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LanguageLoaderError {
|
||||
DeserializeError(toml::de::Error),
|
||||
LoaderError(LoaderError),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LanguageLoaderError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::DeserializeError(err) => write!(f, "Failed to parse language config: {err}"),
|
||||
Self::LoaderError(err) => write!(f, "Failed to compile language config: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for LanguageLoaderError {}
|
||||
|
||||
/// Language configuration based on user configured languages.toml.
|
||||
pub fn user_lang_config() -> Result<Configuration, toml::de::Error> {
|
||||
helix_loader::config::user_lang_config()?.try_into()
|
||||
}
|
||||
|
||||
/// Language configuration loader based on user configured languages.toml.
|
||||
pub fn user_lang_loader() -> Result<Loader, LanguageLoaderError> {
|
||||
let config: Configuration = helix_loader::config::user_lang_config()
|
||||
.map_err(LanguageLoaderError::DeserializeError)?
|
||||
.try_into()
|
||||
.map_err(LanguageLoaderError::DeserializeError)?;
|
||||
|
||||
Loader::new(config).map_err(LanguageLoaderError::LoaderError)
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ pub enum DiagnosticTag {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Diagnostic {
|
||||
pub range: Range,
|
||||
// whether this diagnostic ends at the end of(or inside) a word
|
||||
pub ends_at_word: bool,
|
||||
pub starts_at_word: bool,
|
||||
pub zero_width: bool,
|
||||
pub line: usize,
|
||||
pub message: String,
|
||||
pub severity: Option<Severity>,
|
||||
|
@ -116,7 +116,7 @@ fn default() -> Self {
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentFormatter<'t> {
|
||||
text_fmt: &'t TextFormat,
|
||||
annotations: &'t TextAnnotations,
|
||||
annotations: &'t TextAnnotations<'t>,
|
||||
|
||||
/// The visual position at the end of the last yielded word boundary
|
||||
visual_pos: Position,
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::doc_formatter::{DocumentFormatter, TextFormat};
|
||||
use crate::text_annotations::{InlineAnnotation, Overlay, TextAnnotations};
|
||||
|
||||
@ -105,7 +103,7 @@ fn overlay_text(text: &str, char_pos: usize, softwrap: bool, overlays: &[Overlay
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
text.into(),
|
||||
&TextFormat::new_test(softwrap),
|
||||
TextAnnotations::default().add_overlay(overlays.into(), None),
|
||||
TextAnnotations::default().add_overlay(overlays, None),
|
||||
char_pos,
|
||||
)
|
||||
.0
|
||||
@ -142,7 +140,7 @@ fn annotate_text(text: &str, softwrap: bool, annotations: &[InlineAnnotation]) -
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
text.into(),
|
||||
&TextFormat::new_test(softwrap),
|
||||
TextAnnotations::default().add_inline_annotations(annotations.into(), None),
|
||||
TextAnnotations::default().add_inline_annotations(annotations, None),
|
||||
0,
|
||||
)
|
||||
.0
|
||||
@ -164,15 +162,24 @@ fn annotation() {
|
||||
"foo foo foo foo \n.foo foo foo foo \n.foo foo foo "
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotation_and_overlay() {
|
||||
let annotations = [InlineAnnotation {
|
||||
char_idx: 0,
|
||||
text: "fooo".into(),
|
||||
}];
|
||||
let overlay = [Overlay {
|
||||
char_idx: 0,
|
||||
grapheme: "\t".into(),
|
||||
}];
|
||||
assert_eq!(
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
"bbar".into(),
|
||||
&TextFormat::new_test(false),
|
||||
TextAnnotations::default()
|
||||
.add_inline_annotations(Rc::new([InlineAnnotation::new(0, "fooo")]), None)
|
||||
.add_overlay(Rc::new([Overlay::new(0, "\t")]), None),
|
||||
.add_inline_annotations(annotations.as_slice(), None)
|
||||
.add_overlay(overlay.as_slice(), None),
|
||||
0,
|
||||
)
|
||||
.0
|
||||
|
43
helix-core/src/fuzzy.rs
Normal file
43
helix-core/src/fuzzy.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use std::ops::DerefMut;
|
||||
|
||||
use nucleo::pattern::{Atom, AtomKind, CaseMatching};
|
||||
use nucleo::Config;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
pub struct LazyMutex<T> {
|
||||
inner: Mutex<Option<T>>,
|
||||
init: fn() -> T,
|
||||
}
|
||||
|
||||
impl<T> LazyMutex<T> {
|
||||
pub const fn new(init: fn() -> T) -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(None),
|
||||
init,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lock(&self) -> impl DerefMut<Target = T> + '_ {
|
||||
parking_lot::MutexGuard::map(self.inner.lock(), |val| val.get_or_insert_with(self.init))
|
||||
}
|
||||
}
|
||||
|
||||
pub static MATCHER: LazyMutex<nucleo::Matcher> = LazyMutex::new(nucleo::Matcher::default);
|
||||
|
||||
/// convenience function to easily fuzzy match
|
||||
/// on a (relatively small list of inputs). This is not recommended for building a full tui
|
||||
/// application that can match large numbers of matches as all matching is done on the current
|
||||
/// thread, effectively blocking the UI
|
||||
pub fn fuzzy_match<T: AsRef<str>>(
|
||||
pattern: &str,
|
||||
items: impl IntoIterator<Item = T>,
|
||||
path: bool,
|
||||
) -> Vec<(T, u16)> {
|
||||
let mut matcher = MATCHER.lock();
|
||||
matcher.config = Config::DEFAULT;
|
||||
if path {
|
||||
matcher.config.set_match_paths();
|
||||
}
|
||||
let pattern = Atom::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy, false);
|
||||
pattern.match_list(items, &mut matcher)
|
||||
}
|
@ -278,23 +278,6 @@ pub fn ensure_grapheme_boundary_prev(slice: RopeSlice, char_idx: usize) -> usize
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the passed byte index if it's already a grapheme boundary,
|
||||
/// or the next grapheme boundary byte index if not.
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn ensure_grapheme_boundary_next_byte(slice: RopeSlice, byte_idx: usize) -> usize {
|
||||
if byte_idx == 0 {
|
||||
byte_idx
|
||||
} else {
|
||||
// TODO: optimize so we're not constructing grapheme cursor twice
|
||||
if is_grapheme_boundary_byte(slice, byte_idx) {
|
||||
byte_idx
|
||||
} else {
|
||||
next_grapheme_boundary_byte(slice, byte_idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether the given char position is a grapheme boundary.
|
||||
#[must_use]
|
||||
pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
|
||||
@ -425,6 +408,85 @@ fn next(&mut self) -> Option<RopeSlice<'a>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over the graphemes of a `RopeSlice` in reverse.
|
||||
#[derive(Clone)]
|
||||
pub struct RevRopeGraphemes<'a> {
|
||||
text: RopeSlice<'a>,
|
||||
chunks: Chunks<'a>,
|
||||
cur_chunk: &'a str,
|
||||
cur_chunk_start: usize,
|
||||
cursor: GraphemeCursor,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for RevRopeGraphemes<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("RevRopeGraphemes")
|
||||
.field("text", &self.text)
|
||||
.field("chunks", &self.chunks)
|
||||
.field("cur_chunk", &self.cur_chunk)
|
||||
.field("cur_chunk_start", &self.cur_chunk_start)
|
||||
// .field("cursor", &self.cursor)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RevRopeGraphemes<'a> {
|
||||
#[must_use]
|
||||
pub fn new(slice: RopeSlice) -> RevRopeGraphemes {
|
||||
let (mut chunks, mut cur_chunk_start, _, _) = slice.chunks_at_byte(slice.len_bytes());
|
||||
chunks.reverse();
|
||||
let first_chunk = chunks.next().unwrap_or("");
|
||||
cur_chunk_start -= first_chunk.len();
|
||||
RevRopeGraphemes {
|
||||
text: slice,
|
||||
chunks,
|
||||
cur_chunk: first_chunk,
|
||||
cur_chunk_start,
|
||||
cursor: GraphemeCursor::new(slice.len_bytes(), slice.len_bytes(), true),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for RevRopeGraphemes<'a> {
|
||||
type Item = RopeSlice<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<RopeSlice<'a>> {
|
||||
let a = self.cursor.cur_cursor();
|
||||
let b;
|
||||
loop {
|
||||
match self
|
||||
.cursor
|
||||
.prev_boundary(self.cur_chunk, self.cur_chunk_start)
|
||||
{
|
||||
Ok(None) => {
|
||||
return None;
|
||||
}
|
||||
Ok(Some(n)) => {
|
||||
b = n;
|
||||
break;
|
||||
}
|
||||
Err(GraphemeIncomplete::PrevChunk) => {
|
||||
self.cur_chunk = self.chunks.next().unwrap_or("");
|
||||
self.cur_chunk_start -= self.cur_chunk.len();
|
||||
}
|
||||
Err(GraphemeIncomplete::PreContext(idx)) => {
|
||||
let (chunk, byte_idx, _, _) = self.text.chunk_at_byte(idx.saturating_sub(1));
|
||||
self.cursor.provide_context(chunk, byte_idx);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
if a >= self.cur_chunk_start + self.cur_chunk.len() {
|
||||
Some(self.text.byte_slice(b..a))
|
||||
} else {
|
||||
let a2 = a - self.cur_chunk_start;
|
||||
let b2 = b - self.cur_chunk_start;
|
||||
Some((&self.cur_chunk[b2..a2]).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A highly compressed Cow<'a, str> that holds
|
||||
/// atmost u31::MAX bytes and is readonly
|
||||
pub struct GraphemeStr<'a> {
|
||||
@ -481,7 +543,7 @@ fn from(g: String) -> Self {
|
||||
let ptr = Box::into_raw(g.into_bytes().into_boxed_slice()) as *mut u8;
|
||||
GraphemeStr {
|
||||
ptr: unsafe { NonNull::new_unchecked(ptr) },
|
||||
len: i32::try_from(len).unwrap() as u32,
|
||||
len: (i32::try_from(len).unwrap() as u32) | Self::MASK_OWNED,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ fn default() -> Self {
|
||||
revisions: vec![Revision {
|
||||
parent: 0,
|
||||
last_child: None,
|
||||
transaction: Transaction::from(ChangeSet::new(&Rope::new())),
|
||||
inversion: Transaction::from(ChangeSet::new(&Rope::new())),
|
||||
transaction: Transaction::from(ChangeSet::new("".into())),
|
||||
inversion: Transaction::from(ChangeSet::new("".into())),
|
||||
timestamp: Instant::now(),
|
||||
}],
|
||||
current: 0,
|
||||
|
@ -27,7 +27,7 @@ pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
|
||||
let date_time = NaiveDateTime::parse_from_str(date_time, format.fmt).ok()?;
|
||||
Some(
|
||||
date_time
|
||||
.checked_add_signed(Duration::minutes(amount))?
|
||||
.checked_add_signed(Duration::try_minutes(amount)?)?
|
||||
.format(format.fmt)
|
||||
.to_string(),
|
||||
)
|
||||
@ -35,14 +35,15 @@ pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
|
||||
(true, false) => {
|
||||
let date = NaiveDate::parse_from_str(date_time, format.fmt).ok()?;
|
||||
Some(
|
||||
date.checked_add_signed(Duration::days(amount))?
|
||||
date.checked_add_signed(Duration::try_days(amount)?)?
|
||||
.format(format.fmt)
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
(false, true) => {
|
||||
let time = NaiveTime::parse_from_str(date_time, format.fmt).ok()?;
|
||||
let (adjusted_time, _) = time.overflowing_add_signed(Duration::minutes(amount));
|
||||
let (adjusted_time, _) =
|
||||
time.overflowing_add_signed(Duration::try_minutes(amount)?);
|
||||
Some(adjusted_time.format(format.fmt).to_string())
|
||||
}
|
||||
(false, false) => None,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@
|
||||
pub mod diagnostic;
|
||||
pub mod diff;
|
||||
pub mod doc_formatter;
|
||||
pub mod fuzzy;
|
||||
pub mod graphemes;
|
||||
pub mod history;
|
||||
pub mod increment;
|
||||
@ -16,9 +17,7 @@
|
||||
pub mod match_brackets;
|
||||
pub mod movement;
|
||||
pub mod object;
|
||||
pub mod path;
|
||||
mod position;
|
||||
pub mod register;
|
||||
pub mod search;
|
||||
pub mod selection;
|
||||
pub mod shellwords;
|
||||
@ -38,10 +37,9 @@ pub mod unicode {
|
||||
|
||||
pub use helix_loader::find_workspace;
|
||||
|
||||
pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
|
||||
line.chars().position(|ch| !ch.is_whitespace())
|
||||
}
|
||||
mod rope_reader;
|
||||
|
||||
pub use rope_reader::RopeReader;
|
||||
pub use ropey::{self, str_utils, Rope, RopeBuilder, RopeSlice};
|
||||
|
||||
// pub use tendril::StrTendril as Tendril;
|
||||
@ -66,5 +64,5 @@ pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> {
|
||||
|
||||
pub use diagnostic::Diagnostic;
|
||||
|
||||
pub use line_ending::{LineEnding, DEFAULT_LINE_ENDING};
|
||||
pub use line_ending::{LineEnding, NATIVE_LINE_ENDING};
|
||||
pub use transaction::{Assoc, Change, ChangeSet, Deletion, Operation, Transaction};
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{Rope, RopeSlice};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
|
||||
pub const NATIVE_LINE_ENDING: LineEnding = LineEnding::Crlf;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::LF;
|
||||
pub const NATIVE_LINE_ENDING: LineEnding = LineEnding::LF;
|
||||
|
||||
/// Represents one of the valid Unicode line endings.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
|
@ -1,7 +1,15 @@
|
||||
use std::iter;
|
||||
|
||||
use ropey::RopeSlice;
|
||||
use tree_sitter::Node;
|
||||
|
||||
use crate::{Rope, Syntax};
|
||||
use crate::movement::Direction::{self, Backward, Forward};
|
||||
use crate::Syntax;
|
||||
|
||||
const MAX_PLAINTEXT_SCAN: usize = 10000;
|
||||
const MATCH_LIMIT: usize = 16;
|
||||
|
||||
// Limit matching pairs to only ( ) { } [ ] < > ' ' " "
|
||||
const PAIRS: &[(char, char)] = &[
|
||||
('(', ')'),
|
||||
('{', '}'),
|
||||
@ -11,17 +19,17 @@
|
||||
('\"', '\"'),
|
||||
];
|
||||
|
||||
// limit matching pairs to only ( ) { } [ ] < > ' ' " "
|
||||
|
||||
// Returns the position of the matching bracket under cursor.
|
||||
//
|
||||
// If the cursor is one the opening bracket, the position of
|
||||
// the closing bracket is returned. If the cursor in the closing
|
||||
// bracket, the position of the opening bracket is returned.
|
||||
//
|
||||
// If the cursor is not on a bracket, `None` is returned.
|
||||
/// Returns the position of the matching bracket under cursor.
|
||||
///
|
||||
/// If the cursor is on the opening bracket, the position of
|
||||
/// the closing bracket is returned. If the cursor on the closing
|
||||
/// bracket, the position of the opening bracket is returned.
|
||||
///
|
||||
/// If the cursor is not on a bracket, `None` is returned.
|
||||
///
|
||||
/// If no matching bracket is found, `None` is returned.
|
||||
#[must_use]
|
||||
pub fn find_matching_bracket(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
|
||||
pub fn find_matching_bracket(syntax: &Syntax, doc: RopeSlice, pos: usize) -> Option<usize> {
|
||||
if pos >= doc.len_chars() || !is_valid_bracket(doc.char(pos)) {
|
||||
return None;
|
||||
}
|
||||
@ -39,46 +47,159 @@ pub fn find_matching_bracket(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<
|
||||
//
|
||||
// If no surrounding scope is found, the function returns `None`.
|
||||
#[must_use]
|
||||
pub fn find_matching_bracket_fuzzy(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
|
||||
pub fn find_matching_bracket_fuzzy(syntax: &Syntax, doc: RopeSlice, pos: usize) -> Option<usize> {
|
||||
find_pair(syntax, doc, pos, true)
|
||||
}
|
||||
|
||||
fn find_pair(syntax: &Syntax, doc: &Rope, pos: usize, traverse_parents: bool) -> Option<usize> {
|
||||
let tree = syntax.tree();
|
||||
let pos = doc.char_to_byte(pos);
|
||||
fn find_pair(
|
||||
syntax: &Syntax,
|
||||
doc: RopeSlice,
|
||||
pos_: usize,
|
||||
traverse_parents: bool,
|
||||
) -> Option<usize> {
|
||||
let pos = doc.char_to_byte(pos_);
|
||||
|
||||
let mut node = tree.root_node().named_descendant_for_byte_range(pos, pos)?;
|
||||
let root = syntax.tree_for_byte_range(pos, pos + 1).root_node();
|
||||
let mut node = root.descendant_for_byte_range(pos, pos + 1)?;
|
||||
|
||||
loop {
|
||||
let (start_byte, end_byte) = surrounding_bytes(doc, &node)?;
|
||||
let (start_char, end_char) = (doc.byte_to_char(start_byte), doc.byte_to_char(end_byte));
|
||||
if node.is_named() {
|
||||
let (start_byte, end_byte) = surrounding_bytes(doc, &node)?;
|
||||
let (start_char, end_char) = (doc.byte_to_char(start_byte), doc.byte_to_char(end_byte));
|
||||
|
||||
if is_valid_pair(doc, start_char, end_char) {
|
||||
if end_byte == pos {
|
||||
return Some(start_char);
|
||||
if is_valid_pair(doc, start_char, end_char) {
|
||||
if end_byte == pos {
|
||||
return Some(start_char);
|
||||
}
|
||||
|
||||
// We return the end char if the cursor is either on the start char
|
||||
// or at some arbitrary position between start and end char.
|
||||
if traverse_parents || start_byte == pos {
|
||||
return Some(end_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
// this node itselt wasn't a pair but maybe its siblings are
|
||||
|
||||
// check if we are *on* the pair (special cased so we don't look
|
||||
// at the current node twice and to jump to the start on that case)
|
||||
if let Some(open) = as_close_pair(doc, &node) {
|
||||
if let Some(pair_start) = find_pair_end(doc, node.prev_sibling(), open, Backward) {
|
||||
return Some(pair_start);
|
||||
}
|
||||
// We return the end char if the cursor is either on the start char
|
||||
// or at some arbitrary position between start and end char.
|
||||
return Some(end_char);
|
||||
}
|
||||
|
||||
if traverse_parents {
|
||||
node = node.parent()?;
|
||||
} else {
|
||||
return None;
|
||||
if !traverse_parents {
|
||||
// check if we are *on* the opening pair (special cased here as
|
||||
// an opptimization since we only care about bracket on the cursor
|
||||
// here)
|
||||
if let Some(close) = as_open_pair(doc, &node) {
|
||||
if let Some(pair_end) = find_pair_end(doc, node.next_sibling(), close, Forward) {
|
||||
return Some(pair_end);
|
||||
}
|
||||
}
|
||||
if node.is_named() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for close in
|
||||
iter::successors(node.next_sibling(), |node| node.next_sibling()).take(MATCH_LIMIT)
|
||||
{
|
||||
let Some(open) = as_close_pair(doc, &close) else {
|
||||
continue;
|
||||
};
|
||||
if find_pair_end(doc, Some(node), open, Backward).is_some() {
|
||||
return doc.try_byte_to_char(close.start_byte()).ok();
|
||||
}
|
||||
}
|
||||
let Some(parent) = node.parent() else {
|
||||
break;
|
||||
};
|
||||
node = parent;
|
||||
}
|
||||
let node = root.named_descendant_for_byte_range(pos, pos + 1)?;
|
||||
if node.child_count() != 0 {
|
||||
return None;
|
||||
}
|
||||
let node_start = doc.byte_to_char(node.start_byte());
|
||||
find_matching_bracket_plaintext(doc.byte_slice(node.byte_range()), pos_ - node_start)
|
||||
.map(|pos| pos + node_start)
|
||||
}
|
||||
|
||||
/// Returns the position of the matching bracket under cursor.
|
||||
/// This function works on plain text and ignores tree-sitter grammar.
|
||||
/// The search is limited to `MAX_PLAINTEXT_SCAN` characters
|
||||
///
|
||||
/// If the cursor is on the opening bracket, the position of
|
||||
/// the closing bracket is returned. If the cursor on the closing
|
||||
/// bracket, the position of the opening bracket is returned.
|
||||
///
|
||||
/// If the cursor is not on a bracket, `None` is returned.
|
||||
///
|
||||
/// If no matching bracket is found, `None` is returned.
|
||||
#[must_use]
|
||||
pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> {
|
||||
// Don't do anything when the cursor is not on top of a bracket.
|
||||
let bracket = doc.get_char(cursor_pos)?;
|
||||
if !is_valid_bracket(bracket) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Determine the direction of the matching.
|
||||
let is_fwd = is_forward_bracket(bracket);
|
||||
let chars_iter = if is_fwd {
|
||||
doc.chars_at(cursor_pos + 1)
|
||||
} else {
|
||||
doc.chars_at(cursor_pos).reversed()
|
||||
};
|
||||
|
||||
let mut open_cnt = 1;
|
||||
|
||||
for (i, candidate) in chars_iter.take(MAX_PLAINTEXT_SCAN).enumerate() {
|
||||
if candidate == bracket {
|
||||
open_cnt += 1;
|
||||
} else if is_valid_pair(
|
||||
doc,
|
||||
if is_fwd {
|
||||
cursor_pos
|
||||
} else {
|
||||
cursor_pos - i - 1
|
||||
},
|
||||
if is_fwd {
|
||||
cursor_pos + i + 1
|
||||
} else {
|
||||
cursor_pos
|
||||
},
|
||||
) {
|
||||
// Return when all pending brackets have been closed.
|
||||
if open_cnt == 1 {
|
||||
return Some(if is_fwd {
|
||||
cursor_pos + i + 1
|
||||
} else {
|
||||
cursor_pos - i - 1
|
||||
});
|
||||
}
|
||||
open_cnt -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn is_valid_bracket(c: char) -> bool {
|
||||
PAIRS.iter().any(|(l, r)| *l == c || *r == c)
|
||||
}
|
||||
|
||||
fn is_valid_pair(doc: &Rope, start_char: usize, end_char: usize) -> bool {
|
||||
fn is_forward_bracket(c: char) -> bool {
|
||||
PAIRS.iter().any(|(l, _)| *l == c)
|
||||
}
|
||||
|
||||
fn is_valid_pair(doc: RopeSlice, start_char: usize, end_char: usize) -> bool {
|
||||
PAIRS.contains(&(doc.char(start_char), doc.char(end_char)))
|
||||
}
|
||||
|
||||
fn surrounding_bytes(doc: &Rope, node: &Node) -> Option<(usize, usize)> {
|
||||
fn surrounding_bytes(doc: RopeSlice, node: &Node) -> Option<(usize, usize)> {
|
||||
let len = doc.len_bytes();
|
||||
|
||||
let start_byte = node.start_byte();
|
||||
@ -90,3 +211,91 @@ fn surrounding_bytes(doc: &Rope, node: &Node) -> Option<(usize, usize)> {
|
||||
|
||||
Some((start_byte, end_byte))
|
||||
}
|
||||
|
||||
/// Tests if this node is a pair close char and returns the expected open char
|
||||
fn as_close_pair(doc: RopeSlice, node: &Node) -> Option<char> {
|
||||
let close = as_char(doc, node)?.1;
|
||||
PAIRS
|
||||
.iter()
|
||||
.find_map(|&(open, close_)| (close_ == close).then_some(open))
|
||||
}
|
||||
|
||||
/// Checks if `node` or its siblings (at most MATCH_LIMIT nodes) is the specified closing char
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The position of the found node or `None` otherwise
|
||||
fn find_pair_end(
|
||||
doc: RopeSlice,
|
||||
node: Option<Node>,
|
||||
end_char: char,
|
||||
direction: Direction,
|
||||
) -> Option<usize> {
|
||||
let advance = match direction {
|
||||
Forward => Node::next_sibling,
|
||||
Backward => Node::prev_sibling,
|
||||
};
|
||||
iter::successors(node, advance)
|
||||
.take(MATCH_LIMIT)
|
||||
.find_map(|node| {
|
||||
let (pos, c) = as_char(doc, &node)?;
|
||||
(end_char == c).then_some(pos)
|
||||
})
|
||||
}
|
||||
|
||||
/// Tests if this node is a pair close char and returns the expected open char
|
||||
fn as_open_pair(doc: RopeSlice, node: &Node) -> Option<char> {
|
||||
let open = as_char(doc, node)?.1;
|
||||
PAIRS
|
||||
.iter()
|
||||
.find_map(|&(open_, close)| (open_ == open).then_some(close))
|
||||
}
|
||||
|
||||
/// If node is a single char return it (and its char position)
|
||||
fn as_char(doc: RopeSlice, node: &Node) -> Option<(usize, char)> {
|
||||
// TODO: multi char/non ASCII pairs
|
||||
if node.byte_range().len() != 1 {
|
||||
return None;
|
||||
}
|
||||
let pos = doc.try_byte_to_char(node.start_byte()).ok()?;
|
||||
Some((pos, doc.char(pos)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn find_matching_bracket_empty_file() {
|
||||
let actual = find_matching_bracket_plaintext("".into(), 0);
|
||||
assert_eq!(actual, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_matching_bracket_current_line_plaintext() {
|
||||
let assert = |input: &str, pos, expected| {
|
||||
let input = RopeSlice::from(input);
|
||||
let actual = find_matching_bracket_plaintext(input, pos);
|
||||
assert_eq!(expected, actual.unwrap());
|
||||
|
||||
let actual = find_matching_bracket_plaintext(input, expected);
|
||||
assert_eq!(pos, actual.unwrap(), "expected symmetrical behaviour");
|
||||
};
|
||||
|
||||
assert("(hello)", 0, 6);
|
||||
assert("((hello))", 0, 8);
|
||||
assert("((hello))", 1, 7);
|
||||
assert("(((hello)))", 2, 8);
|
||||
|
||||
assert("key: ${value}", 6, 12);
|
||||
assert("key: ${value} # (some comment)", 16, 29);
|
||||
|
||||
assert("(paren (paren {bracket}))", 0, 24);
|
||||
assert("(paren (paren {bracket}))", 7, 23);
|
||||
assert("(paren (paren {bracket}))", 14, 22);
|
||||
|
||||
assert("(prev line\n ) (middle) ( \n next line)", 0, 12);
|
||||
assert("(prev line\n ) (middle) ( \n next line)", 14, 21);
|
||||
assert("(prev line\n ) (middle) ( \n next line)", 23, 36);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::iter;
|
||||
use std::{cmp::Reverse, iter};
|
||||
|
||||
use ropey::iter::Chars;
|
||||
use tree_sitter::{Node, QueryCursor};
|
||||
@ -16,7 +16,7 @@
|
||||
syntax::LanguageConfiguration,
|
||||
text_annotations::TextAnnotations,
|
||||
textobject::TextObject,
|
||||
visual_offset_from_block, Range, RopeSlice,
|
||||
visual_offset_from_block, Range, RopeSlice, Selection, Syntax,
|
||||
};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
@ -177,6 +177,10 @@ pub fn move_prev_word_start(slice: RopeSlice, range: Range, count: usize) -> Ran
|
||||
word_move(slice, range, count, WordMotionTarget::PrevWordStart)
|
||||
}
|
||||
|
||||
pub fn move_prev_word_end(slice: RopeSlice, range: Range, count: usize) -> Range {
|
||||
word_move(slice, range, count, WordMotionTarget::PrevWordEnd)
|
||||
}
|
||||
|
||||
pub fn move_next_long_word_start(slice: RopeSlice, range: Range, count: usize) -> Range {
|
||||
word_move(slice, range, count, WordMotionTarget::NextLongWordStart)
|
||||
}
|
||||
@ -189,8 +193,8 @@ pub fn move_prev_long_word_start(slice: RopeSlice, range: Range, count: usize) -
|
||||
word_move(slice, range, count, WordMotionTarget::PrevLongWordStart)
|
||||
}
|
||||
|
||||
pub fn move_prev_word_end(slice: RopeSlice, range: Range, count: usize) -> Range {
|
||||
word_move(slice, range, count, WordMotionTarget::PrevWordEnd)
|
||||
pub fn move_prev_long_word_end(slice: RopeSlice, range: Range, count: usize) -> Range {
|
||||
word_move(slice, range, count, WordMotionTarget::PrevLongWordEnd)
|
||||
}
|
||||
|
||||
fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTarget) -> Range {
|
||||
@ -199,6 +203,7 @@ fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTar
|
||||
WordMotionTarget::PrevWordStart
|
||||
| WordMotionTarget::PrevLongWordStart
|
||||
| WordMotionTarget::PrevWordEnd
|
||||
| WordMotionTarget::PrevLongWordEnd
|
||||
);
|
||||
|
||||
// Special-case early-out.
|
||||
@ -377,6 +382,7 @@ pub enum WordMotionTarget {
|
||||
NextLongWordStart,
|
||||
NextLongWordEnd,
|
||||
PrevLongWordStart,
|
||||
PrevLongWordEnd,
|
||||
}
|
||||
|
||||
pub trait CharHelpers {
|
||||
@ -393,6 +399,7 @@ fn range_to_target(&mut self, target: WordMotionTarget, origin: Range) -> Range
|
||||
WordMotionTarget::PrevWordStart
|
||||
| WordMotionTarget::PrevLongWordStart
|
||||
| WordMotionTarget::PrevWordEnd
|
||||
| WordMotionTarget::PrevLongWordEnd
|
||||
);
|
||||
|
||||
// Reverse the iterator if needed for the motion direction.
|
||||
@ -479,7 +486,7 @@ fn reached_target(target: WordMotionTarget, prev_ch: char, next_ch: char) -> boo
|
||||
is_word_boundary(prev_ch, next_ch)
|
||||
&& (!prev_ch.is_whitespace() || char_is_line_ending(next_ch))
|
||||
}
|
||||
WordMotionTarget::NextLongWordStart => {
|
||||
WordMotionTarget::NextLongWordStart | WordMotionTarget::PrevLongWordEnd => {
|
||||
is_long_word_boundary(prev_ch, next_ch)
|
||||
&& (char_is_line_ending(next_ch) || !next_ch.is_whitespace())
|
||||
}
|
||||
@ -520,10 +527,10 @@ pub fn goto_treesitter_object(
|
||||
let node = match dir {
|
||||
Direction::Forward => nodes
|
||||
.filter(|n| n.start_byte() > byte_pos)
|
||||
.min_by_key(|n| n.start_byte())?,
|
||||
.min_by_key(|n| (n.start_byte(), Reverse(n.end_byte())))?,
|
||||
Direction::Backward => nodes
|
||||
.filter(|n| n.end_byte() < byte_pos)
|
||||
.max_by_key(|n| n.end_byte())?,
|
||||
.max_by_key(|n| (n.end_byte(), Reverse(n.start_byte())))?,
|
||||
};
|
||||
|
||||
let len = slice.len_bytes();
|
||||
@ -549,6 +556,80 @@ pub fn goto_treesitter_object(
|
||||
last_range
|
||||
}
|
||||
|
||||
fn find_parent_start(mut node: Node) -> Option<Node> {
|
||||
let start = node.start_byte();
|
||||
|
||||
while node.start_byte() >= start || !node.is_named() {
|
||||
node = node.parent()?;
|
||||
}
|
||||
|
||||
Some(node)
|
||||
}
|
||||
|
||||
pub fn move_parent_node_end(
|
||||
syntax: &Syntax,
|
||||
text: RopeSlice,
|
||||
selection: Selection,
|
||||
dir: Direction,
|
||||
movement: Movement,
|
||||
) -> Selection {
|
||||
selection.transform(|range| {
|
||||
let start_from = text.char_to_byte(range.from());
|
||||
let start_to = text.char_to_byte(range.to());
|
||||
|
||||
let mut node = match syntax.named_descendant_for_byte_range(start_from, start_to) {
|
||||
Some(node) => node,
|
||||
None => {
|
||||
log::debug!(
|
||||
"no descendant found for byte range: {} - {}",
|
||||
start_from,
|
||||
start_to
|
||||
);
|
||||
return range;
|
||||
}
|
||||
};
|
||||
|
||||
let mut end_head = match dir {
|
||||
// moving forward, we always want to move one past the end of the
|
||||
// current node, so use the end byte of the current node, which is an exclusive
|
||||
// end of the range
|
||||
Direction::Forward => text.byte_to_char(node.end_byte()),
|
||||
|
||||
// moving backward, we want the cursor to land on the start char of
|
||||
// the current node, or if it is already at the start of a node, to traverse up to
|
||||
// the parent
|
||||
Direction::Backward => {
|
||||
let end_head = text.byte_to_char(node.start_byte());
|
||||
|
||||
// if we're already on the beginning, look up to the parent
|
||||
if end_head == range.cursor(text) {
|
||||
node = find_parent_start(node).unwrap_or(node);
|
||||
text.byte_to_char(node.start_byte())
|
||||
} else {
|
||||
end_head
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if movement == Movement::Move {
|
||||
// preserve direction of original range
|
||||
if range.direction() == Direction::Forward {
|
||||
Range::new(end_head, end_head + 1)
|
||||
} else {
|
||||
Range::new(end_head + 1, end_head)
|
||||
}
|
||||
} else {
|
||||
// if we end up with a forward range, then adjust it to be one past
|
||||
// where we want
|
||||
if end_head >= range.anchor {
|
||||
end_head += 1;
|
||||
}
|
||||
|
||||
Range::new(range.anchor, end_head)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use ropey::Rope;
|
||||
@ -1445,6 +1526,100 @@ fn test_behaviour_when_moving_to_end_of_next_long_words() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_behaviour_when_moving_to_end_of_prev_long_words() {
|
||||
let tests = [
|
||||
(
|
||||
"Basic backward motion from the middle of a word",
|
||||
vec![(1, Range::new(3, 3), Range::new(4, 0))],
|
||||
),
|
||||
("Starting from after boundary retreats the anchor",
|
||||
vec![(1, Range::new(0, 9), Range::new(8, 0))],
|
||||
),
|
||||
(
|
||||
"Jump to end of a word succeeded by whitespace",
|
||||
vec![(1, Range::new(10, 10), Range::new(10, 4))],
|
||||
),
|
||||
(
|
||||
" Jump to start of line from end of word preceded by whitespace",
|
||||
vec![(1, Range::new(3, 4), Range::new(4, 0))],
|
||||
),
|
||||
("Previous anchor is irrelevant for backward motions",
|
||||
vec![(1, Range::new(12, 5), Range::new(6, 0))]),
|
||||
(
|
||||
" Starting from whitespace moves to first space in sequence",
|
||||
vec![(1, Range::new(0, 4), Range::new(4, 0))],
|
||||
),
|
||||
("Identifiers_with_underscores are considered a single word",
|
||||
vec![(1, Range::new(0, 20), Range::new(20, 0))]),
|
||||
(
|
||||
"Jumping\n \nback through a newline selects whitespace",
|
||||
vec![(1, Range::new(0, 13), Range::new(12, 8))],
|
||||
),
|
||||
(
|
||||
"Jumping to start of word from the end selects the word",
|
||||
vec![(1, Range::new(6, 7), Range::new(7, 0))],
|
||||
),
|
||||
(
|
||||
"alphanumeric.!,and.?=punctuation are treated exactly the same",
|
||||
vec![(1, Range::new(29, 30), Range::new(30, 0))],
|
||||
),
|
||||
(
|
||||
"... ... punctuation and spaces behave as expected",
|
||||
vec![
|
||||
(1, Range::new(0, 10), Range::new(9, 3)),
|
||||
(1, Range::new(10, 6), Range::new(7, 3)),
|
||||
],
|
||||
),
|
||||
(".._.._ punctuation is joined by underscores into a single block",
|
||||
vec![(1, Range::new(0, 6), Range::new(6, 0))]),
|
||||
(
|
||||
"Newlines\n\nare bridged seamlessly.",
|
||||
vec![(1, Range::new(0, 10), Range::new(8, 0))],
|
||||
),
|
||||
(
|
||||
"Jumping \n\n\n\n\nback from within a newline group selects previous block",
|
||||
vec![(1, Range::new(0, 13), Range::new(11, 7))],
|
||||
),
|
||||
(
|
||||
"Failed motions do not modify the range",
|
||||
vec![(0, Range::new(3, 0), Range::new(3, 0))],
|
||||
),
|
||||
(
|
||||
"Multiple motions at once resolve correctly",
|
||||
vec![(3, Range::new(19, 19), Range::new(8, 0))],
|
||||
),
|
||||
(
|
||||
"Excessive motions are performed partially",
|
||||
vec![(999, Range::new(40, 40), Range::new(9, 0))],
|
||||
),
|
||||
(
|
||||
"", // Edge case of moving backwards in empty string
|
||||
vec![(1, Range::new(0, 0), Range::new(0, 0))],
|
||||
),
|
||||
(
|
||||
"\n\n\n\n\n", // Edge case of moving backwards in all newlines
|
||||
vec![(1, Range::new(5, 5), Range::new(0, 0))],
|
||||
),
|
||||
(" \n \nJumping back through alternated space blocks and newlines selects the space blocks",
|
||||
vec![
|
||||
(1, Range::new(0, 8), Range::new(7, 4)),
|
||||
(1, Range::new(7, 4), Range::new(3, 0)),
|
||||
]),
|
||||
("ヒーリ..クス multibyte characters behave as normal characters, including when interacting with punctuation",
|
||||
vec![
|
||||
(1, Range::new(0, 8), Range::new(7, 0)),
|
||||
]),
|
||||
];
|
||||
|
||||
for (sample, scenario) in tests {
|
||||
for (count, begin, expected_end) in scenario.into_iter() {
|
||||
let range = move_prev_long_word_end(Rope::from(sample).slice(..), begin, count);
|
||||
assert_eq!(range, expected_end, "Case failed: [{}]", sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_behaviour_when_moving_to_prev_paragraph_single() {
|
||||
let tests = [
|
||||
|
@ -1,42 +1,92 @@
|
||||
use crate::{Range, RopeSlice, Selection, Syntax};
|
||||
use tree_sitter::Node;
|
||||
use crate::{syntax::TreeCursor, Range, RopeSlice, Selection, Syntax};
|
||||
|
||||
pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
select_node_impl(syntax, text, selection, |mut node, from, to| {
|
||||
while node.start_byte() == from && node.end_byte() == to {
|
||||
node = node.parent()?;
|
||||
let cursor = &mut syntax.walk();
|
||||
|
||||
selection.transform(|range| {
|
||||
let from = text.char_to_byte(range.from());
|
||||
let to = text.char_to_byte(range.to());
|
||||
|
||||
let byte_range = from..to;
|
||||
cursor.reset_to_byte_range(from, to);
|
||||
|
||||
while cursor.node().byte_range() == byte_range {
|
||||
if !cursor.goto_parent() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Some(node)
|
||||
|
||||
let node = cursor.node();
|
||||
let from = text.byte_to_char(node.start_byte());
|
||||
let to = text.byte_to_char(node.end_byte());
|
||||
|
||||
Range::new(to, from).with_direction(range.direction())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn shrink_selection(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
select_node_impl(syntax, text, selection, |descendant, _from, _to| {
|
||||
descendant.child(0).or(Some(descendant))
|
||||
select_node_impl(syntax, text, selection, |cursor| {
|
||||
cursor.goto_first_child();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn select_sibling<F>(
|
||||
syntax: &Syntax,
|
||||
pub fn select_next_sibling(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
select_node_impl(syntax, text, selection, |cursor| {
|
||||
while !cursor.goto_next_sibling() {
|
||||
if !cursor.goto_parent() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn select_all_siblings(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
selection.transform_iter(|range| {
|
||||
let mut cursor = syntax.walk();
|
||||
let (from, to) = range.into_byte_range(text);
|
||||
cursor.reset_to_byte_range(from, to);
|
||||
|
||||
if !cursor.goto_parent_with(|parent| parent.child_count() > 1) {
|
||||
return vec![range].into_iter();
|
||||
}
|
||||
|
||||
select_children(&mut cursor, text, range).into_iter()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn select_all_children(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
selection.transform_iter(|range| {
|
||||
let mut cursor = syntax.walk();
|
||||
let (from, to) = range.into_byte_range(text);
|
||||
cursor.reset_to_byte_range(from, to);
|
||||
select_children(&mut cursor, text, range).into_iter()
|
||||
})
|
||||
}
|
||||
|
||||
fn select_children<'n>(
|
||||
cursor: &'n mut TreeCursor<'n>,
|
||||
text: RopeSlice,
|
||||
selection: Selection,
|
||||
sibling_fn: &F,
|
||||
) -> Selection
|
||||
where
|
||||
F: Fn(Node) -> Option<Node>,
|
||||
{
|
||||
select_node_impl(syntax, text, selection, |descendant, _from, _to| {
|
||||
find_sibling_recursive(descendant, sibling_fn)
|
||||
})
|
||||
range: Range,
|
||||
) -> Vec<Range> {
|
||||
let children = cursor
|
||||
.named_children()
|
||||
.map(|child| Range::from_node(child, text, range.direction()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !children.is_empty() {
|
||||
children
|
||||
} else {
|
||||
vec![range]
|
||||
}
|
||||
}
|
||||
|
||||
fn find_sibling_recursive<F>(node: Node, sibling_fn: F) -> Option<Node>
|
||||
where
|
||||
F: Fn(Node) -> Option<Node>,
|
||||
{
|
||||
sibling_fn(node).or_else(|| {
|
||||
node.parent()
|
||||
.and_then(|node| find_sibling_recursive(node, sibling_fn))
|
||||
pub fn select_prev_sibling(syntax: &Syntax, text: RopeSlice, selection: Selection) -> Selection {
|
||||
select_node_impl(syntax, text, selection, |cursor| {
|
||||
while !cursor.goto_prev_sibling() {
|
||||
if !cursor.goto_parent() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -44,33 +94,25 @@ fn select_node_impl<F>(
|
||||
syntax: &Syntax,
|
||||
text: RopeSlice,
|
||||
selection: Selection,
|
||||
select_fn: F,
|
||||
motion: F,
|
||||
) -> Selection
|
||||
where
|
||||
F: Fn(Node, usize, usize) -> Option<Node>,
|
||||
F: Fn(&mut TreeCursor),
|
||||
{
|
||||
let tree = syntax.tree();
|
||||
let cursor = &mut syntax.walk();
|
||||
|
||||
selection.transform(|range| {
|
||||
let from = text.char_to_byte(range.from());
|
||||
let to = text.char_to_byte(range.to());
|
||||
|
||||
let node = match tree
|
||||
.root_node()
|
||||
.descendant_for_byte_range(from, to)
|
||||
.and_then(|node| select_fn(node, from, to))
|
||||
{
|
||||
Some(node) => node,
|
||||
None => return range,
|
||||
};
|
||||
cursor.reset_to_byte_range(from, to);
|
||||
|
||||
motion(cursor);
|
||||
|
||||
let node = cursor.node();
|
||||
let from = text.byte_to_char(node.start_byte());
|
||||
let to = text.byte_to_char(node.end_byte());
|
||||
|
||||
if range.head < range.anchor {
|
||||
Range::new(to, from)
|
||||
} else {
|
||||
Range::new(from, to)
|
||||
}
|
||||
Range::new(from, to).with_direction(range.direction())
|
||||
})
|
||||
}
|
||||
|
@ -1,164 +0,0 @@
|
||||
use etcetera::home_dir;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
/// Replaces users home directory from `path` with tilde `~` if the directory
|
||||
/// is available, otherwise returns the path unchanged.
|
||||
pub fn fold_home_dir(path: &Path) -> PathBuf {
|
||||
if let Ok(home) = home_dir() {
|
||||
if let Ok(stripped) = path.strip_prefix(&home) {
|
||||
return PathBuf::from("~").join(stripped);
|
||||
}
|
||||
}
|
||||
|
||||
path.to_path_buf()
|
||||
}
|
||||
|
||||
/// Expands tilde `~` into users home directory if available, otherwise returns the path
|
||||
/// unchanged. The tilde will only be expanded when present as the first component of the path
|
||||
/// and only slash follows it.
|
||||
pub fn expand_tilde(path: &Path) -> PathBuf {
|
||||
let mut components = path.components().peekable();
|
||||
if let Some(Component::Normal(c)) = components.peek() {
|
||||
if c == &"~" {
|
||||
if let Ok(home) = home_dir() {
|
||||
// it's ok to unwrap, the path starts with `~`
|
||||
return home.join(path.strip_prefix("~").unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path.to_path_buf()
|
||||
}
|
||||
|
||||
/// Normalize a path, removing things like `.` and `..`.
|
||||
///
|
||||
/// CAUTION: This does not resolve symlinks (unlike
|
||||
/// [`std::fs::canonicalize`]). This may cause incorrect or surprising
|
||||
/// behavior at times. This should be used carefully. Unfortunately,
|
||||
/// [`std::fs::canonicalize`] can be hard to use correctly, since it can often
|
||||
/// fail, or on Windows returns annoying device paths. This is a problem Cargo
|
||||
/// needs to improve on.
|
||||
/// Copied from cargo: <https://github.com/rust-lang/cargo/blob/070e459c2d8b79c5b2ac5218064e7603329c92ae/crates/cargo-util/src/paths.rs#L81>
|
||||
pub fn get_normalized_path(path: &Path) -> PathBuf {
|
||||
// normalization strategy is to canonicalize first ancestor path that exists (i.e., canonicalize as much as possible),
|
||||
// then run handrolled normalization on the non-existent remainder
|
||||
let (base, path) = path
|
||||
.ancestors()
|
||||
.find_map(|base| {
|
||||
let canonicalized_base = dunce::canonicalize(base).ok()?;
|
||||
let remainder = path.strip_prefix(base).ok()?.into();
|
||||
Some((canonicalized_base, remainder))
|
||||
})
|
||||
.unwrap_or_else(|| (PathBuf::new(), PathBuf::from(path)));
|
||||
|
||||
if path.as_os_str().is_empty() {
|
||||
return base;
|
||||
}
|
||||
|
||||
let mut components = path.components().peekable();
|
||||
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
|
||||
components.next();
|
||||
PathBuf::from(c.as_os_str())
|
||||
} else {
|
||||
PathBuf::new()
|
||||
};
|
||||
|
||||
for component in components {
|
||||
match component {
|
||||
Component::Prefix(..) => unreachable!(),
|
||||
Component::RootDir => {
|
||||
ret.push(component.as_os_str());
|
||||
}
|
||||
Component::CurDir => {}
|
||||
Component::ParentDir => {
|
||||
ret.pop();
|
||||
}
|
||||
Component::Normal(c) => {
|
||||
ret.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
base.join(ret)
|
||||
}
|
||||
|
||||
/// Returns the canonical, absolute form of a path with all intermediate components normalized.
|
||||
///
|
||||
/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
|
||||
/// here if the path exists, just normalize it's components.
|
||||
pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
|
||||
let path = expand_tilde(path);
|
||||
let path = if path.is_relative() {
|
||||
std::env::current_dir().map(|current_dir| current_dir.join(path))?
|
||||
} else {
|
||||
path
|
||||
};
|
||||
|
||||
Ok(get_normalized_path(path.as_path()))
|
||||
}
|
||||
|
||||
pub fn get_relative_path(path: &Path) -> PathBuf {
|
||||
let path = PathBuf::from(path);
|
||||
let path = if path.is_absolute() {
|
||||
let cwdir = std::env::current_dir()
|
||||
.map(|path| get_normalized_path(&path))
|
||||
.expect("couldn't determine current directory");
|
||||
get_normalized_path(&path)
|
||||
.strip_prefix(cwdir)
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or(path)
|
||||
} else {
|
||||
path
|
||||
};
|
||||
fold_home_dir(&path)
|
||||
}
|
||||
|
||||
/// Returns a truncated filepath where the basepart of the path is reduced to the first
|
||||
/// char of the folder and the whole filename appended.
|
||||
///
|
||||
/// Also strip the current working directory from the beginning of the path.
|
||||
/// Note that this function does not check if the truncated path is unambiguous.
|
||||
///
|
||||
/// ```
|
||||
/// use helix_core::path::get_truncated_path;
|
||||
/// use std::path::Path;
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// get_truncated_path("/home/cnorris/documents/jokes.txt").as_path(),
|
||||
/// Path::new("/h/c/d/jokes.txt")
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// get_truncated_path("jokes.txt").as_path(),
|
||||
/// Path::new("jokes.txt")
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// get_truncated_path("/jokes.txt").as_path(),
|
||||
/// Path::new("/jokes.txt")
|
||||
/// );
|
||||
/// assert_eq!(
|
||||
/// get_truncated_path("/h/c/d/jokes.txt").as_path(),
|
||||
/// Path::new("/h/c/d/jokes.txt")
|
||||
/// );
|
||||
/// assert_eq!(get_truncated_path("").as_path(), Path::new(""));
|
||||
/// ```
|
||||
///
|
||||
pub fn get_truncated_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
let cwd = std::env::current_dir().unwrap_or_default();
|
||||
let path = path
|
||||
.as_ref()
|
||||
.strip_prefix(cwd)
|
||||
.unwrap_or_else(|_| path.as_ref());
|
||||
let file = path.file_name().unwrap_or_default();
|
||||
let base = path.parent().unwrap_or_else(|| Path::new(""));
|
||||
let mut ret = PathBuf::new();
|
||||
for d in base {
|
||||
ret.push(
|
||||
d.to_string_lossy()
|
||||
.chars()
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
ret.push(file);
|
||||
ret
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Register {
|
||||
name: char,
|
||||
values: Vec<String>,
|
||||
}
|
||||
|
||||
impl Register {
|
||||
pub const fn new(name: char) -> Self {
|
||||
Self {
|
||||
name,
|
||||
values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_values(name: char, values: Vec<String>) -> Self {
|
||||
Self { name, values }
|
||||
}
|
||||
|
||||
pub const fn name(&self) -> char {
|
||||
self.name
|
||||
}
|
||||
|
||||
pub fn read(&self) -> &[String] {
|
||||
&self.values
|
||||
}
|
||||
|
||||
pub fn write(&mut self, values: Vec<String>) {
|
||||
self.values = values;
|
||||
}
|
||||
|
||||
pub fn push(&mut self, value: String) {
|
||||
self.values.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// Currently just wraps a `HashMap` of `Register`s
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Registers {
|
||||
inner: HashMap<char, Register>,
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
pub fn get(&self, name: char) -> Option<&Register> {
|
||||
self.inner.get(&name)
|
||||
}
|
||||
|
||||
pub fn read(&self, name: char) -> Option<&[String]> {
|
||||
self.get(name).map(|reg| reg.read())
|
||||
}
|
||||
|
||||
pub fn write(&mut self, name: char, values: Vec<String>) {
|
||||
if name != '_' {
|
||||
self.inner
|
||||
.insert(name, Register::new_with_values(name, values));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, name: char, value: String) {
|
||||
if name != '_' {
|
||||
if let Some(r) = self.inner.get_mut(&name) {
|
||||
r.push(value);
|
||||
} else {
|
||||
self.write(name, vec![value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn first(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.first())
|
||||
}
|
||||
|
||||
pub fn last(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.last())
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &HashMap<char, Register> {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.inner.clear();
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, name: char) -> Option<Register> {
|
||||
self.inner.remove(&name)
|
||||
}
|
||||
}
|
37
helix-core/src/rope_reader.rs
Normal file
37
helix-core/src/rope_reader.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::io;
|
||||
|
||||
use ropey::iter::Chunks;
|
||||
use ropey::RopeSlice;
|
||||
|
||||
pub struct RopeReader<'a> {
|
||||
current_chunk: &'a [u8],
|
||||
chunks: Chunks<'a>,
|
||||
}
|
||||
|
||||
impl<'a> RopeReader<'a> {
|
||||
pub fn new(rope: RopeSlice<'a>) -> RopeReader<'a> {
|
||||
RopeReader {
|
||||
current_chunk: &[],
|
||||
chunks: rope.chunks(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for RopeReader<'_> {
|
||||
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
|
||||
let buf_len = buf.len();
|
||||
loop {
|
||||
let read_bytes = self.current_chunk.read(buf)?;
|
||||
buf = &mut buf[read_bytes..];
|
||||
if buf.is_empty() {
|
||||
return Ok(buf_len);
|
||||
}
|
||||
|
||||
if let Some(next_chunk) = self.chunks.next() {
|
||||
self.current_chunk = next_chunk.as_bytes();
|
||||
} else {
|
||||
return Ok(buf_len - buf.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,11 +7,14 @@
|
||||
ensure_grapheme_boundary_next, ensure_grapheme_boundary_prev, next_grapheme_boundary,
|
||||
prev_grapheme_boundary,
|
||||
},
|
||||
line_ending::get_line_ending,
|
||||
movement::Direction,
|
||||
Assoc, ChangeSet, RopeGraphemes, RopeSlice,
|
||||
};
|
||||
use helix_stdx::rope::{self, RopeSliceExt};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::borrow::Cow;
|
||||
use tree_sitter::Node;
|
||||
|
||||
/// A single selection range.
|
||||
///
|
||||
@ -71,6 +74,12 @@ pub fn point(head: usize) -> Self {
|
||||
Self::new(head, head)
|
||||
}
|
||||
|
||||
pub fn from_node(node: Node, text: RopeSlice, direction: Direction) -> Self {
|
||||
let from = text.byte_to_char(node.start_byte());
|
||||
let to = text.byte_to_char(node.end_byte());
|
||||
Range::new(from, to).with_direction(direction)
|
||||
}
|
||||
|
||||
/// Start of the range.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
@ -161,34 +170,35 @@ pub fn contains(&self, pos: usize) -> bool {
|
||||
self.from() <= pos && pos < self.to()
|
||||
}
|
||||
|
||||
/// Map a range through a set of changes. Returns a new range representing the same position
|
||||
/// after the changes are applied.
|
||||
pub fn map(self, changes: &ChangeSet) -> Self {
|
||||
/// Map a range through a set of changes. Returns a new range representing
|
||||
/// the same position after the changes are applied. Note that this
|
||||
/// function runs in O(N) (N is number of changes) and can therefore
|
||||
/// cause performance problems if run for a large number of ranges as the
|
||||
/// complexity is then O(MN) (for multicuror M=N usually). Instead use
|
||||
/// [Selection::map] or [ChangeSet::update_positions] instead
|
||||
pub fn map(mut self, changes: &ChangeSet) -> Self {
|
||||
use std::cmp::Ordering;
|
||||
let (anchor, head) = match self.anchor.cmp(&self.head) {
|
||||
Ordering::Equal => (
|
||||
changes.map_pos(self.anchor, Assoc::After),
|
||||
changes.map_pos(self.head, Assoc::After),
|
||||
),
|
||||
Ordering::Less => (
|
||||
changes.map_pos(self.anchor, Assoc::After),
|
||||
changes.map_pos(self.head, Assoc::Before),
|
||||
),
|
||||
Ordering::Greater => (
|
||||
changes.map_pos(self.anchor, Assoc::Before),
|
||||
changes.map_pos(self.head, Assoc::After),
|
||||
),
|
||||
};
|
||||
|
||||
// We want to return a new `Range` with `horiz == None` every time,
|
||||
// even if the anchor and head haven't changed, because we don't
|
||||
// know if the *visual* position hasn't changed due to
|
||||
// character-width or grapheme changes earlier in the text.
|
||||
Self {
|
||||
anchor,
|
||||
head,
|
||||
old_visual_position: None,
|
||||
if changes.is_empty() {
|
||||
return self;
|
||||
}
|
||||
|
||||
let positions_to_map = match self.anchor.cmp(&self.head) {
|
||||
Ordering::Equal => [
|
||||
(&mut self.anchor, Assoc::After),
|
||||
(&mut self.head, Assoc::After),
|
||||
],
|
||||
Ordering::Less => [
|
||||
(&mut self.anchor, Assoc::After),
|
||||
(&mut self.head, Assoc::Before),
|
||||
],
|
||||
Ordering::Greater => [
|
||||
(&mut self.head, Assoc::After),
|
||||
(&mut self.anchor, Assoc::Before),
|
||||
],
|
||||
};
|
||||
changes.update_positions(positions_to_map.into_iter());
|
||||
self.old_visual_position = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Extend the range to cover at least `from` `to`.
|
||||
@ -373,6 +383,12 @@ pub fn is_single_grapheme(&self, doc: RopeSlice) -> bool {
|
||||
let second = graphemes.next();
|
||||
first.is_some() && second.is_none()
|
||||
}
|
||||
|
||||
/// Converts this char range into an in order byte range, discarding
|
||||
/// direction.
|
||||
pub fn into_byte_range(&self, text: RopeSlice) -> (usize, usize) {
|
||||
(text.char_to_byte(self.from()), text.char_to_byte(self.to()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(usize, usize)> for Range {
|
||||
@ -451,17 +467,36 @@ pub fn replace(mut self, index: usize, range: Range) -> Self {
|
||||
/// Map selections over a set of changes. Useful for adjusting the selection position after
|
||||
/// applying changes to a document.
|
||||
pub fn map(self, changes: &ChangeSet) -> Self {
|
||||
self.map_no_normalize(changes).normalize()
|
||||
}
|
||||
|
||||
/// Map selections over a set of changes. Useful for adjusting the selection position after
|
||||
/// applying changes to a document. Doesn't normalize the selection
|
||||
pub fn map_no_normalize(mut self, changes: &ChangeSet) -> Self {
|
||||
if changes.is_empty() {
|
||||
return self;
|
||||
}
|
||||
|
||||
Self::new(
|
||||
self.ranges
|
||||
.into_iter()
|
||||
.map(|range| range.map(changes))
|
||||
.collect(),
|
||||
self.primary_index,
|
||||
)
|
||||
let positions_to_map = self.ranges.iter_mut().flat_map(|range| {
|
||||
use std::cmp::Ordering;
|
||||
range.old_visual_position = None;
|
||||
match range.anchor.cmp(&range.head) {
|
||||
Ordering::Equal => [
|
||||
(&mut range.anchor, Assoc::After),
|
||||
(&mut range.head, Assoc::After),
|
||||
],
|
||||
Ordering::Less => [
|
||||
(&mut range.anchor, Assoc::After),
|
||||
(&mut range.head, Assoc::Before),
|
||||
],
|
||||
Ordering::Greater => [
|
||||
(&mut range.head, Assoc::After),
|
||||
(&mut range.anchor, Assoc::Before),
|
||||
],
|
||||
}
|
||||
});
|
||||
changes.update_positions(positions_to_map);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ranges(&self) -> &[Range] {
|
||||
@ -497,6 +532,9 @@ pub fn point(pos: usize) -> Self {
|
||||
|
||||
/// Normalizes a `Selection`.
|
||||
fn normalize(mut self) -> Self {
|
||||
if self.len() < 2 {
|
||||
return self;
|
||||
}
|
||||
let mut primary = self.ranges[self.primary_index];
|
||||
self.ranges.sort_unstable_by_key(Range::from);
|
||||
|
||||
@ -561,17 +599,12 @@ pub fn merge_consecutive_ranges(mut self) -> Self {
|
||||
assert!(!ranges.is_empty());
|
||||
debug_assert!(primary_index < ranges.len());
|
||||
|
||||
let mut selection = Self {
|
||||
let selection = Self {
|
||||
ranges,
|
||||
primary_index,
|
||||
};
|
||||
|
||||
if selection.ranges.len() > 1 {
|
||||
// TODO: only normalize if needed (any ranges out of order)
|
||||
selection = selection.normalize();
|
||||
}
|
||||
|
||||
selection
|
||||
selection.normalize()
|
||||
}
|
||||
|
||||
/// Takes a closure and maps each `Range` over the closure.
|
||||
@ -612,11 +645,19 @@ pub fn cursors(self, text: RopeSlice) -> Self {
|
||||
self.transform(|range| Range::point(range.cursor(text)))
|
||||
}
|
||||
|
||||
pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
|
||||
pub fn fragments<'a>(
|
||||
&'a self,
|
||||
text: RopeSlice<'a>,
|
||||
) -> impl DoubleEndedIterator<Item = Cow<'a, str>> + ExactSizeIterator<Item = Cow<str>> + 'a
|
||||
{
|
||||
self.ranges.iter().map(move |range| range.fragment(text))
|
||||
}
|
||||
|
||||
pub fn slices<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = RopeSlice> + 'a {
|
||||
pub fn slices<'a>(
|
||||
&'a self,
|
||||
text: RopeSlice<'a>,
|
||||
) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSlice<'a>> + 'a
|
||||
{
|
||||
self.ranges.iter().map(move |range| range.slice(text))
|
||||
}
|
||||
|
||||
@ -677,17 +718,26 @@ impl IntoIterator for Selection {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Range> for Selection {
|
||||
fn from(range: Range) -> Self {
|
||||
Self {
|
||||
ranges: smallvec![range],
|
||||
primary_index: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: checkSelection -> check if valid for doc length && sorted
|
||||
|
||||
pub fn keep_or_remove_matches(
|
||||
text: RopeSlice,
|
||||
selection: &Selection,
|
||||
regex: &crate::regex::Regex,
|
||||
regex: &rope::Regex,
|
||||
remove: bool,
|
||||
) -> Option<Selection> {
|
||||
let result: SmallVec<_> = selection
|
||||
.iter()
|
||||
.filter(|range| regex.is_match(&range.fragment(text)) ^ remove)
|
||||
.filter(|range| regex.is_match(text.regex_input_at(range.from()..range.to())) ^ remove)
|
||||
.copied()
|
||||
.collect();
|
||||
|
||||
@ -698,25 +748,20 @@ pub fn keep_or_remove_matches(
|
||||
None
|
||||
}
|
||||
|
||||
// TODO: support to split on capture #N instead of whole match
|
||||
pub fn select_on_matches(
|
||||
text: RopeSlice,
|
||||
selection: &Selection,
|
||||
regex: &crate::regex::Regex,
|
||||
regex: &rope::Regex,
|
||||
) -> Option<Selection> {
|
||||
let mut result = SmallVec::with_capacity(selection.len());
|
||||
|
||||
for sel in selection {
|
||||
// TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
|
||||
let fragment = sel.fragment(text);
|
||||
|
||||
let sel_start = sel.from();
|
||||
let start_byte = text.char_to_byte(sel_start);
|
||||
|
||||
for mat in regex.find_iter(&fragment) {
|
||||
for mat in regex.find_iter(text.regex_input_at(sel.from()..sel.to())) {
|
||||
// TODO: retain range direction
|
||||
|
||||
let start = text.byte_to_char(start_byte + mat.start());
|
||||
let end = text.byte_to_char(start_byte + mat.end());
|
||||
let start = text.byte_to_char(mat.start());
|
||||
let end = text.byte_to_char(mat.end());
|
||||
|
||||
let range = Range::new(start, end);
|
||||
// Make sure the match is not right outside of the selection.
|
||||
@ -735,12 +780,7 @@ pub fn select_on_matches(
|
||||
None
|
||||
}
|
||||
|
||||
// TODO: support to split on capture #N instead of whole match
|
||||
pub fn split_on_matches(
|
||||
text: RopeSlice,
|
||||
selection: &Selection,
|
||||
regex: &crate::regex::Regex,
|
||||
) -> Selection {
|
||||
pub fn split_on_newline(text: RopeSlice, selection: &Selection) -> Selection {
|
||||
let mut result = SmallVec::with_capacity(selection.len());
|
||||
|
||||
for sel in selection {
|
||||
@ -750,21 +790,49 @@ pub fn split_on_matches(
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
|
||||
let fragment = sel.fragment(text);
|
||||
|
||||
let sel_start = sel.from();
|
||||
let sel_end = sel.to();
|
||||
|
||||
let start_byte = text.char_to_byte(sel_start);
|
||||
|
||||
let mut start = sel_start;
|
||||
|
||||
for mat in regex.find_iter(&fragment) {
|
||||
for line in sel.slice(text).lines() {
|
||||
let Some(line_ending) = get_line_ending(&line) else {
|
||||
break;
|
||||
};
|
||||
let line_end = start + line.len_chars();
|
||||
// TODO: retain range direction
|
||||
let end = text.byte_to_char(start_byte + mat.start());
|
||||
result.push(Range::new(start, line_end - line_ending.len_chars()));
|
||||
start = line_end;
|
||||
}
|
||||
|
||||
if start < sel_end {
|
||||
result.push(Range::new(start, sel_end));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure out a new primary index
|
||||
Selection::new(result, 0)
|
||||
}
|
||||
|
||||
pub fn split_on_matches(text: RopeSlice, selection: &Selection, regex: &rope::Regex) -> Selection {
|
||||
let mut result = SmallVec::with_capacity(selection.len());
|
||||
|
||||
for sel in selection {
|
||||
// Special case: zero-width selection.
|
||||
if sel.from() == sel.to() {
|
||||
result.push(*sel);
|
||||
continue;
|
||||
}
|
||||
|
||||
let sel_start = sel.from();
|
||||
let sel_end = sel.to();
|
||||
let mut start = sel_start;
|
||||
|
||||
for mat in regex.find_iter(text.regex_input_at(sel_start..sel_end)) {
|
||||
// TODO: retain range direction
|
||||
let end = text.byte_to_char(mat.start());
|
||||
result.push(Range::new(start, end));
|
||||
start = text.byte_to_char(start_byte + mat.end());
|
||||
start = text.byte_to_char(mat.end());
|
||||
}
|
||||
|
||||
if start < sel_end {
|
||||
@ -995,14 +1063,12 @@ fn test_min_width_1() {
|
||||
|
||||
#[test]
|
||||
fn test_select_on_matches() {
|
||||
use crate::regex::{Regex, RegexBuilder};
|
||||
|
||||
let r = Rope::from_str("Nobody expects the Spanish inquisition");
|
||||
let s = r.slice(..);
|
||||
|
||||
let selection = Selection::single(0, r.len_chars());
|
||||
assert_eq!(
|
||||
select_on_matches(s, &selection, &Regex::new(r"[A-Z][a-z]*").unwrap()),
|
||||
select_on_matches(s, &selection, &rope::Regex::new(r"[A-Z][a-z]*").unwrap()),
|
||||
Some(Selection::new(
|
||||
smallvec![Range::new(0, 6), Range::new(19, 26)],
|
||||
0
|
||||
@ -1012,8 +1078,14 @@ fn test_select_on_matches() {
|
||||
let r = Rope::from_str("This\nString\n\ncontains multiple\nlines");
|
||||
let s = r.slice(..);
|
||||
|
||||
let start_of_line = RegexBuilder::new(r"^").multi_line(true).build().unwrap();
|
||||
let end_of_line = RegexBuilder::new(r"$").multi_line(true).build().unwrap();
|
||||
let start_of_line = rope::RegexBuilder::new()
|
||||
.syntax(rope::Config::new().multi_line(true))
|
||||
.build(r"^")
|
||||
.unwrap();
|
||||
let end_of_line = rope::RegexBuilder::new()
|
||||
.syntax(rope::Config::new().multi_line(true))
|
||||
.build(r"$")
|
||||
.unwrap();
|
||||
|
||||
// line without ending
|
||||
assert_eq!(
|
||||
@ -1051,9 +1123,9 @@ fn test_select_on_matches() {
|
||||
select_on_matches(
|
||||
s,
|
||||
&Selection::single(0, s.len_chars()),
|
||||
&RegexBuilder::new(r"^[a-z ]*$")
|
||||
.multi_line(true)
|
||||
.build()
|
||||
&rope::RegexBuilder::new()
|
||||
.syntax(rope::Config::new().multi_line(true))
|
||||
.build(r"^[a-z ]*$")
|
||||
.unwrap()
|
||||
),
|
||||
Some(Selection::new(
|
||||
@ -1145,13 +1217,15 @@ fn test_put_cursor() {
|
||||
|
||||
#[test]
|
||||
fn test_split_on_matches() {
|
||||
use crate::regex::Regex;
|
||||
|
||||
let text = Rope::from(" abcd efg wrs xyz 123 456");
|
||||
|
||||
let selection = Selection::new(smallvec![Range::new(0, 9), Range::new(11, 20),], 0);
|
||||
|
||||
let result = split_on_matches(text.slice(..), &selection, &Regex::new(r"\s+").unwrap());
|
||||
let result = split_on_matches(
|
||||
text.slice(..),
|
||||
&selection,
|
||||
&rope::Regex::new(r"\s+").unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
result.ranges(),
|
||||
|
@ -167,6 +167,10 @@ fn find_nth_open_pair(
|
||||
mut pos: usize,
|
||||
n: usize,
|
||||
) -> Option<usize> {
|
||||
if pos >= text.len_chars() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut chars = text.chars_at(pos + 1);
|
||||
|
||||
// Adjusts pos for the first iteration, and handles the case of the
|
||||
@ -260,7 +264,8 @@ pub fn get_surround_pos(
|
||||
if change_pos.contains(&open_pos) || change_pos.contains(&close_pos) {
|
||||
return Err(Error::CursorOverlap);
|
||||
}
|
||||
change_pos.extend_from_slice(&[open_pos, close_pos]);
|
||||
// ensure the positions are always paired in the forward direction
|
||||
change_pos.extend_from_slice(&[open_pos.min(close_pos), close_pos.max(open_pos)]);
|
||||
}
|
||||
Ok(change_pos)
|
||||
}
|
||||
@ -382,6 +387,21 @@ fn test_find_nth_pairs_pos_inside_quote_ambiguous() {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_nth_closest_pairs_pos_index_range_panic() {
|
||||
#[rustfmt::skip]
|
||||
let (doc, selection, _) =
|
||||
rope_with_selections_and_expectations(
|
||||
"(a)c)",
|
||||
"^^^^^"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
find_nth_closest_pairs_pos(doc.slice(..), selection.primary(), 1),
|
||||
Err(Error::PairNotFound)
|
||||
)
|
||||
}
|
||||
|
||||
// Create a Rope and a matching Selection using a specification language.
|
||||
// ^ is a single-point selection.
|
||||
// _ is an expected index. These are returned as a Vec<usize> for use in assertions.
|
||||
|
@ -1,16 +1,20 @@
|
||||
mod tree_cursor;
|
||||
|
||||
use crate::{
|
||||
auto_pairs::AutoPairs,
|
||||
chars::char_is_line_ending,
|
||||
diagnostic::Severity,
|
||||
regex::Regex,
|
||||
transaction::{ChangeSet, Operation},
|
||||
Rope, RopeSlice, Tendril,
|
||||
RopeSlice, Tendril,
|
||||
};
|
||||
|
||||
use ahash::RandomState;
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
use bitflags::bitflags;
|
||||
use globset::GlobSet;
|
||||
use hashbrown::raw::RawTable;
|
||||
use helix_stdx::rope::{self, RopeSliceExt};
|
||||
use slotmap::{DefaultKey as LayerId, HopSlotMap};
|
||||
|
||||
use std::{
|
||||
@ -19,7 +23,7 @@
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
fmt::{self, Display},
|
||||
hash::{Hash, Hasher},
|
||||
mem::{replace, transmute},
|
||||
mem::replace,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
@ -30,6 +34,8 @@
|
||||
|
||||
use helix_loader::grammar::{get_language, load_runtime_file};
|
||||
|
||||
pub use tree_cursor::TreeCursor;
|
||||
|
||||
fn deserialize_regex<'de, D>(deserializer: D) -> Result<Option<Regex>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
@ -48,6 +54,21 @@ fn deserialize_lsp_config<'de, D>(deserializer: D) -> Result<Option<serde_json::
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn deserialize_tab_width<'de, D>(deserializer: D) -> Result<usize, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
usize::deserialize(deserializer).and_then(|n| {
|
||||
if n > 0 && n <= 16 {
|
||||
Ok(n)
|
||||
} else {
|
||||
Err(serde::de::Error::custom(
|
||||
"tab width must be a value from 1 to 16 inclusive",
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result<Option<AutoPairs>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
@ -67,12 +88,6 @@ pub struct Configuration {
|
||||
pub language_server: HashMap<String, LanguageServerConfiguration>,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
fn default() -> Self {
|
||||
crate::config::default_syntax_loader()
|
||||
}
|
||||
}
|
||||
|
||||
// largely based on tree-sitter/cli/src/loader.rs
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
|
||||
@ -86,8 +101,21 @@ pub struct LanguageConfiguration {
|
||||
pub file_types: Vec<FileType>, // filename extension or ends_with? <Gemfile, rb, etc>
|
||||
#[serde(default)]
|
||||
pub shebangs: Vec<String>, // interpreter(s) associated with language
|
||||
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
|
||||
pub comment_token: Option<String>,
|
||||
#[serde(default)]
|
||||
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing,
|
||||
deserialize_with = "from_comment_tokens",
|
||||
alias = "comment-token"
|
||||
)]
|
||||
pub comment_tokens: Option<Vec<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing,
|
||||
deserialize_with = "from_block_comment_tokens"
|
||||
)]
|
||||
pub block_comment_tokens: Option<Vec<BlockCommentToken>>,
|
||||
pub text_width: Option<usize>,
|
||||
pub soft_wrap: Option<SoftWrap>,
|
||||
|
||||
@ -139,6 +167,8 @@ pub struct LanguageConfiguration {
|
||||
/// Hardcoded LSP root directories relative to the workspace root, like `examples` or `tools/fuzz`.
|
||||
/// Falling back to the current working directory if none are configured.
|
||||
pub workspace_lsp_roots: Option<Vec<PathBuf>>,
|
||||
#[serde(default)]
|
||||
pub persistent_diagnostic_sources: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
@ -146,9 +176,11 @@ pub enum FileType {
|
||||
/// The extension of the file, either the `Path::extension` or the full
|
||||
/// filename if the file does not have an extension.
|
||||
Extension(String),
|
||||
/// The suffix of a file. This is compared to a given file's absolute
|
||||
/// path, so it can be used to detect files based on their directories.
|
||||
Suffix(String),
|
||||
/// A Unix-style path glob. This is compared to the file's absolute path, so
|
||||
/// it can be used to detect files based on their directories. If the glob
|
||||
/// is not an absolute path and does not already start with a glob pattern,
|
||||
/// a glob pattern will be prepended to it.
|
||||
Glob(globset::Glob),
|
||||
}
|
||||
|
||||
impl Serialize for FileType {
|
||||
@ -160,9 +192,9 @@ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
|
||||
match self {
|
||||
FileType::Extension(extension) => serializer.serialize_str(extension),
|
||||
FileType::Suffix(suffix) => {
|
||||
FileType::Glob(glob) => {
|
||||
let mut map = serializer.serialize_map(Some(1))?;
|
||||
map.serialize_entry("suffix", &suffix.replace(std::path::MAIN_SEPARATOR, "/"))?;
|
||||
map.serialize_entry("glob", glob.glob())?;
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
@ -195,12 +227,20 @@ fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
||||
M: serde::de::MapAccess<'de>,
|
||||
{
|
||||
match map.next_entry::<String, String>()? {
|
||||
Some((key, suffix)) if key == "suffix" => Ok(FileType::Suffix({
|
||||
// FIXME: use `suffix.replace('/', std::path::MAIN_SEPARATOR_STR)`
|
||||
// if MSRV is updated to 1.68
|
||||
let mut separator = [0; 1];
|
||||
suffix.replace('/', std::path::MAIN_SEPARATOR.encode_utf8(&mut separator))
|
||||
})),
|
||||
Some((key, mut glob)) if key == "glob" => {
|
||||
// If the glob isn't an absolute path or already starts
|
||||
// with a glob pattern, add a leading glob so we
|
||||
// properly match relative paths.
|
||||
if !glob.starts_with('/') && !glob.starts_with("*/") {
|
||||
glob.insert_str(0, "*/");
|
||||
}
|
||||
|
||||
globset::Glob::new(glob.as_str())
|
||||
.map(FileType::Glob)
|
||||
.map_err(|err| {
|
||||
serde::de::Error::custom(format!("invalid `glob` pattern: {}", err))
|
||||
})
|
||||
}
|
||||
Some((key, _value)) => Err(serde::de::Error::custom(format!(
|
||||
"unknown key in `file-types` list: {}",
|
||||
key
|
||||
@ -216,6 +256,59 @@ fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
||||
}
|
||||
}
|
||||
|
||||
fn from_comment_tokens<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum CommentTokens {
|
||||
Multiple(Vec<String>),
|
||||
Single(String),
|
||||
}
|
||||
Ok(
|
||||
Option::<CommentTokens>::deserialize(deserializer)?.map(|tokens| match tokens {
|
||||
CommentTokens::Single(val) => vec![val],
|
||||
CommentTokens::Multiple(vals) => vals,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct BlockCommentToken {
|
||||
pub start: String,
|
||||
pub end: String,
|
||||
}
|
||||
|
||||
impl Default for BlockCommentToken {
|
||||
fn default() -> Self {
|
||||
BlockCommentToken {
|
||||
start: "/*".to_string(),
|
||||
end: "*/".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_block_comment_tokens<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<Vec<BlockCommentToken>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum BlockCommentTokens {
|
||||
Multiple(Vec<BlockCommentToken>),
|
||||
Single(BlockCommentToken),
|
||||
}
|
||||
Ok(
|
||||
Option::<BlockCommentTokens>::deserialize(deserializer)?.map(|tokens| match tokens {
|
||||
BlockCommentTokens::Single(val) => vec![val],
|
||||
BlockCommentTokens::Multiple(vals) => vals,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum LanguageServerFeature {
|
||||
@ -248,7 +341,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
GotoDeclaration => "goto-declaration",
|
||||
GotoDefinition => "goto-definition",
|
||||
GotoTypeDefinition => "goto-type-definition",
|
||||
GotoReference => "goto-type-definition",
|
||||
GotoReference => "goto-reference",
|
||||
GotoImplementation => "goto-implementation",
|
||||
SignatureHelp => "signature-help",
|
||||
Hover => "hover",
|
||||
@ -343,6 +436,22 @@ fn serialize_lang_features<S>(
|
||||
serializer.end()
|
||||
}
|
||||
|
||||
fn deserialize_required_root_patterns<'de, D>(deserializer: D) -> Result<Option<GlobSet>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let patterns = Vec::<String>::deserialize(deserializer)?;
|
||||
if patterns.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut builder = globset::GlobSetBuilder::new();
|
||||
for pattern in patterns {
|
||||
let glob = globset::Glob::new(&pattern).map_err(serde::de::Error::custom)?;
|
||||
builder.add(glob);
|
||||
}
|
||||
builder.build().map(Some).map_err(serde::de::Error::custom)
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct LanguageServerConfiguration {
|
||||
@ -356,6 +465,12 @@ pub struct LanguageServerConfiguration {
|
||||
pub config: Option<serde_json::Value>,
|
||||
#[serde(default = "default_timeout")]
|
||||
pub timeout: u64,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing,
|
||||
deserialize_with = "deserialize_required_root_patterns"
|
||||
)]
|
||||
pub required_root_patterns: Option<GlobSet>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -424,10 +539,27 @@ pub struct DebuggerQuirks {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct IndentationConfiguration {
|
||||
#[serde(deserialize_with = "deserialize_tab_width")]
|
||||
pub tab_width: usize,
|
||||
pub unit: String,
|
||||
}
|
||||
|
||||
/// How the indentation for a newly inserted line should be determined.
|
||||
/// If the selected heuristic is not available (e.g. because the current
|
||||
/// language has no tree-sitter indent queries), a simpler one will be used.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum IndentationHeuristic {
|
||||
/// Just copy the indentation of the line that the cursor is currently on.
|
||||
Simple,
|
||||
/// Use tree-sitter indent queries to compute the expected absolute indentation level of the new line.
|
||||
TreeSitter,
|
||||
/// Use tree-sitter indent queries to compute the expected difference in indentation between the new line
|
||||
/// and the line before. Add this to the actual indentation level of the line before.
|
||||
#[default]
|
||||
Hybrid,
|
||||
}
|
||||
|
||||
/// Configuration for auto pairs
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case", deny_unknown_fields, untagged)]
|
||||
@ -677,7 +809,7 @@ fn load_query(&self, kind: &str) -> Option<Query> {
|
||||
if query_text.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let lang = self.highlight_config.get()?.as_ref()?.language;
|
||||
let lang = &self.highlight_config.get()?.as_ref()?.language;
|
||||
Query::new(lang, &query_text)
|
||||
.map_err(|e| {
|
||||
log::error!(
|
||||
@ -720,6 +852,47 @@ pub struct SoftWrap {
|
||||
pub wrap_at_text_width: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FileTypeGlob {
|
||||
glob: globset::Glob,
|
||||
language_id: usize,
|
||||
}
|
||||
|
||||
impl FileTypeGlob {
|
||||
fn new(glob: globset::Glob, language_id: usize) -> Self {
|
||||
Self { glob, language_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FileTypeGlobMatcher {
|
||||
matcher: globset::GlobSet,
|
||||
file_types: Vec<FileTypeGlob>,
|
||||
}
|
||||
|
||||
impl FileTypeGlobMatcher {
|
||||
fn new(file_types: Vec<FileTypeGlob>) -> Result<Self, globset::Error> {
|
||||
let mut builder = globset::GlobSetBuilder::new();
|
||||
for file_type in &file_types {
|
||||
builder.add(file_type.glob.clone());
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
matcher: builder.build()?,
|
||||
file_types,
|
||||
})
|
||||
}
|
||||
|
||||
fn language_id_for_path(&self, path: &Path) -> Option<&usize> {
|
||||
self.matcher
|
||||
.matches(path)
|
||||
.iter()
|
||||
.filter_map(|idx| self.file_types.get(*idx))
|
||||
.max_by_key(|file_type| file_type.glob.glob().len())
|
||||
.map(|file_type| &file_type.language_id)
|
||||
}
|
||||
}
|
||||
|
||||
// Expose loader as Lazy<> global since it's always static?
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -727,7 +900,7 @@ pub struct Loader {
|
||||
// highlight_names ?
|
||||
language_configs: Vec<Arc<LanguageConfiguration>>,
|
||||
language_config_ids_by_extension: HashMap<String, usize>, // Vec<usize>
|
||||
language_config_ids_by_suffix: HashMap<String, usize>,
|
||||
language_config_ids_glob_matcher: FileTypeGlobMatcher,
|
||||
language_config_ids_by_shebang: HashMap<String, usize>,
|
||||
|
||||
language_server_configs: HashMap<String, LanguageServerConfiguration>,
|
||||
@ -735,66 +908,57 @@ pub struct Loader {
|
||||
scopes: ArcSwap<Vec<String>>,
|
||||
}
|
||||
|
||||
pub type LoaderError = globset::Error;
|
||||
|
||||
impl Loader {
|
||||
pub fn new(config: Configuration) -> Self {
|
||||
let mut loader = Self {
|
||||
language_configs: Vec::new(),
|
||||
language_server_configs: config.language_server,
|
||||
language_config_ids_by_extension: HashMap::new(),
|
||||
language_config_ids_by_suffix: HashMap::new(),
|
||||
language_config_ids_by_shebang: HashMap::new(),
|
||||
scopes: ArcSwap::from_pointee(Vec::new()),
|
||||
};
|
||||
pub fn new(config: Configuration) -> Result<Self, LoaderError> {
|
||||
let mut language_configs = Vec::new();
|
||||
let mut language_config_ids_by_extension = HashMap::new();
|
||||
let mut language_config_ids_by_shebang = HashMap::new();
|
||||
let mut file_type_globs = Vec::new();
|
||||
|
||||
for config in config.language {
|
||||
// get the next id
|
||||
let language_id = loader.language_configs.len();
|
||||
let language_id = language_configs.len();
|
||||
|
||||
for file_type in &config.file_types {
|
||||
// entry().or_insert(Vec::new).push(language_id);
|
||||
match file_type {
|
||||
FileType::Extension(extension) => loader
|
||||
.language_config_ids_by_extension
|
||||
.insert(extension.clone(), language_id),
|
||||
FileType::Suffix(suffix) => loader
|
||||
.language_config_ids_by_suffix
|
||||
.insert(suffix.clone(), language_id),
|
||||
FileType::Extension(extension) => {
|
||||
language_config_ids_by_extension.insert(extension.clone(), language_id);
|
||||
}
|
||||
FileType::Glob(glob) => {
|
||||
file_type_globs.push(FileTypeGlob::new(glob.to_owned(), language_id));
|
||||
}
|
||||
};
|
||||
}
|
||||
for shebang in &config.shebangs {
|
||||
loader
|
||||
.language_config_ids_by_shebang
|
||||
.insert(shebang.clone(), language_id);
|
||||
language_config_ids_by_shebang.insert(shebang.clone(), language_id);
|
||||
}
|
||||
|
||||
loader.language_configs.push(Arc::new(config));
|
||||
language_configs.push(Arc::new(config));
|
||||
}
|
||||
|
||||
loader
|
||||
Ok(Self {
|
||||
language_configs,
|
||||
language_config_ids_by_extension,
|
||||
language_config_ids_glob_matcher: FileTypeGlobMatcher::new(file_type_globs)?,
|
||||
language_config_ids_by_shebang,
|
||||
language_server_configs: config.language_server,
|
||||
scopes: ArcSwap::from_pointee(Vec::new()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn language_config_for_file_name(&self, path: &Path) -> Option<Arc<LanguageConfiguration>> {
|
||||
// Find all the language configurations that match this file name
|
||||
// or a suffix of the file name.
|
||||
let configuration_id = path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.and_then(|file_name| self.language_config_ids_by_extension.get(file_name))
|
||||
let configuration_id = self
|
||||
.language_config_ids_glob_matcher
|
||||
.language_id_for_path(path)
|
||||
.or_else(|| {
|
||||
path.extension()
|
||||
.and_then(|extension| extension.to_str())
|
||||
.and_then(|extension| self.language_config_ids_by_extension.get(extension))
|
||||
})
|
||||
.or_else(|| {
|
||||
self.language_config_ids_by_suffix
|
||||
.iter()
|
||||
.find_map(|(file_type, id)| {
|
||||
if path.to_str()?.ends_with(file_type) {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
configuration_id.and_then(|&id| self.language_configs.get(id).cloned())
|
||||
@ -802,7 +966,10 @@ pub fn language_config_for_file_name(&self, path: &Path) -> Option<Arc<LanguageC
|
||||
// TODO: content_regex handling conflict resolution
|
||||
}
|
||||
|
||||
pub fn language_config_for_shebang(&self, source: &Rope) -> Option<Arc<LanguageConfiguration>> {
|
||||
pub fn language_config_for_shebang(
|
||||
&self,
|
||||
source: RopeSlice,
|
||||
) -> Option<Arc<LanguageConfiguration>> {
|
||||
let line = Cow::from(source.line(0));
|
||||
static SHEBANG_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(&["^", SHEBANG].concat()).unwrap());
|
||||
@ -903,7 +1070,7 @@ pub struct TsParser {
|
||||
pub struct Syntax {
|
||||
layers: HopSlotMap<LayerId, LanguageLayer>,
|
||||
root: LayerId,
|
||||
loader: Arc<Loader>,
|
||||
loader: Arc<ArcSwap<Loader>>,
|
||||
}
|
||||
|
||||
fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> {
|
||||
@ -912,9 +1079,9 @@ fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<st
|
||||
|
||||
impl Syntax {
|
||||
pub fn new(
|
||||
source: &Rope,
|
||||
source: RopeSlice,
|
||||
config: Arc<HighlightConfiguration>,
|
||||
loader: Arc<Loader>,
|
||||
loader: Arc<ArcSwap<Loader>>,
|
||||
) -> Option<Self> {
|
||||
let root_layer = LanguageLayer {
|
||||
tree: None,
|
||||
@ -927,6 +1094,7 @@ pub fn new(
|
||||
start_point: Point::new(0, 0),
|
||||
end_point: Point::new(usize::MAX, usize::MAX),
|
||||
}],
|
||||
parent: None,
|
||||
};
|
||||
|
||||
// track scope_descriptor: a Vec of scopes for item in tree
|
||||
@ -943,7 +1111,7 @@ pub fn new(
|
||||
let res = syntax.update(source, source, &ChangeSet::new(source));
|
||||
|
||||
if res.is_err() {
|
||||
log::error!("TS parser failed, disabeling TS for the current buffer: {res:?}");
|
||||
log::error!("TS parser failed, disabling TS for the current buffer: {res:?}");
|
||||
return None;
|
||||
}
|
||||
Some(syntax)
|
||||
@ -951,16 +1119,17 @@ pub fn new(
|
||||
|
||||
pub fn update(
|
||||
&mut self,
|
||||
old_source: &Rope,
|
||||
source: &Rope,
|
||||
old_source: RopeSlice,
|
||||
source: RopeSlice,
|
||||
changeset: &ChangeSet,
|
||||
) -> Result<(), Error> {
|
||||
let mut queue = VecDeque::new();
|
||||
queue.push_back(self.root);
|
||||
|
||||
let scopes = self.loader.scopes.load();
|
||||
let loader = self.loader.load();
|
||||
let scopes = loader.scopes.load();
|
||||
let injection_callback = |language: &InjectionLanguageMarker| {
|
||||
self.loader
|
||||
loader
|
||||
.language_configuration_for_injection_string(language)
|
||||
.and_then(|language_config| language_config.highlight_config(&scopes))
|
||||
};
|
||||
@ -1119,12 +1288,38 @@ fn point_sub(a: Point, b: Point) -> Point {
|
||||
layer.tree().root_node(),
|
||||
RopeProvider(source_slice),
|
||||
);
|
||||
let mut combined_injections = vec![
|
||||
(None, Vec::new(), IncludedChildren::default());
|
||||
layer.config.combined_injections_patterns.len()
|
||||
];
|
||||
let mut injections = Vec::new();
|
||||
let mut last_injection_end = 0;
|
||||
for mat in matches {
|
||||
let (injection_capture, content_node, included_children) = layer
|
||||
.config
|
||||
.injection_for_match(&layer.config.injections_query, &mat, source_slice);
|
||||
|
||||
// in case this is a combined injection save it for more processing later
|
||||
if let Some(combined_injection_idx) = layer
|
||||
.config
|
||||
.combined_injections_patterns
|
||||
.iter()
|
||||
.position(|&pattern| pattern == mat.pattern_index)
|
||||
{
|
||||
let entry = &mut combined_injections[combined_injection_idx];
|
||||
if injection_capture.is_some() {
|
||||
entry.0 = injection_capture;
|
||||
}
|
||||
if let Some(content_node) = content_node {
|
||||
if content_node.start_byte() >= last_injection_end {
|
||||
entry.1.push(content_node);
|
||||
last_injection_end = content_node.end_byte();
|
||||
}
|
||||
}
|
||||
entry.2 = included_children;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Explicitly remove this match so that none of its other captures will remain
|
||||
// in the stream of captures.
|
||||
mat.remove();
|
||||
@ -1139,49 +1334,23 @@ fn point_sub(a: Point, b: Point) -> Point {
|
||||
intersect_ranges(&layer.ranges, &[content_node], included_children);
|
||||
|
||||
if !ranges.is_empty() {
|
||||
if content_node.start_byte() < last_injection_end {
|
||||
continue;
|
||||
}
|
||||
last_injection_end = content_node.end_byte();
|
||||
injections.push((config, ranges));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process combined injections.
|
||||
if let Some(combined_injections_query) = &layer.config.combined_injections_query {
|
||||
let mut injections_by_pattern_index =
|
||||
vec![
|
||||
(None, Vec::new(), IncludedChildren::default());
|
||||
combined_injections_query.pattern_count()
|
||||
];
|
||||
let matches = cursor.matches(
|
||||
combined_injections_query,
|
||||
layer.tree().root_node(),
|
||||
RopeProvider(source_slice),
|
||||
);
|
||||
for mat in matches {
|
||||
let entry = &mut injections_by_pattern_index[mat.pattern_index];
|
||||
let (injection_capture, content_node, included_children) = layer
|
||||
.config
|
||||
.injection_for_match(combined_injections_query, &mat, source_slice);
|
||||
if injection_capture.is_some() {
|
||||
entry.0 = injection_capture;
|
||||
}
|
||||
if let Some(content_node) = content_node {
|
||||
entry.1.push(content_node);
|
||||
}
|
||||
entry.2 = included_children;
|
||||
}
|
||||
for (lang_name, content_nodes, included_children) in injections_by_pattern_index
|
||||
{
|
||||
if let (Some(lang_name), false) = (lang_name, content_nodes.is_empty()) {
|
||||
if let Some(config) = (injection_callback)(&lang_name) {
|
||||
let ranges = intersect_ranges(
|
||||
&layer.ranges,
|
||||
&content_nodes,
|
||||
included_children,
|
||||
);
|
||||
if !ranges.is_empty() {
|
||||
injections.push((config, ranges));
|
||||
}
|
||||
for (lang_name, content_nodes, included_children) in combined_injections {
|
||||
if let (Some(lang_name), false) = (lang_name, content_nodes.is_empty()) {
|
||||
if let Some(config) = (injection_callback)(&lang_name) {
|
||||
let ranges =
|
||||
intersect_ranges(&layer.ranges, &content_nodes, included_children);
|
||||
if !ranges.is_empty() {
|
||||
injections.push((config, ranges));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1196,6 +1365,7 @@ fn point_sub(a: Point, b: Point) -> Point {
|
||||
depth,
|
||||
ranges,
|
||||
flags: LayerUpdateFlags::empty(),
|
||||
parent: Some(layer_id),
|
||||
};
|
||||
|
||||
// Find an identical existing layer
|
||||
@ -1303,6 +1473,38 @@ pub fn highlight_iter<'a>(
|
||||
result
|
||||
}
|
||||
|
||||
pub fn tree_for_byte_range(&self, start: usize, end: usize) -> &Tree {
|
||||
let mut container_id = self.root;
|
||||
|
||||
for (layer_id, layer) in self.layers.iter() {
|
||||
if layer.depth > self.layers[container_id].depth
|
||||
&& layer.contains_byte_range(start, end)
|
||||
{
|
||||
container_id = layer_id;
|
||||
}
|
||||
}
|
||||
|
||||
self.layers[container_id].tree()
|
||||
}
|
||||
|
||||
pub fn named_descendant_for_byte_range(&self, start: usize, end: usize) -> Option<Node<'_>> {
|
||||
self.tree_for_byte_range(start, end)
|
||||
.root_node()
|
||||
.named_descendant_for_byte_range(start, end)
|
||||
}
|
||||
|
||||
pub fn descendant_for_byte_range(&self, start: usize, end: usize) -> Option<Node<'_>> {
|
||||
self.tree_for_byte_range(start, end)
|
||||
.root_node()
|
||||
.descendant_for_byte_range(start, end)
|
||||
}
|
||||
|
||||
pub fn walk(&self) -> TreeCursor<'_> {
|
||||
// data structure to find the smallest range that contains a point
|
||||
// when some of the ranges in the structure can overlap.
|
||||
TreeCursor::new(&self.layers, self.root)
|
||||
}
|
||||
|
||||
// Commenting
|
||||
// comment_strings_for_pos
|
||||
// is_commented
|
||||
@ -1335,6 +1537,7 @@ pub struct LanguageLayer {
|
||||
pub ranges: Vec<Range>,
|
||||
pub depth: u32,
|
||||
flags: LayerUpdateFlags,
|
||||
parent: Option<LayerId>,
|
||||
}
|
||||
|
||||
/// This PartialEq implementation only checks if that
|
||||
@ -1354,13 +1557,7 @@ fn eq(&self, other: &Self) -> bool {
|
||||
impl Hash for LanguageLayer {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.depth.hash(state);
|
||||
// The transmute is necessary here because tree_sitter::Language does not derive Hash at the moment.
|
||||
// However it does use #[repr] transparent so the transmute here is safe
|
||||
// as `Language` (which `Grammar` is an alias for) is just a newtype wrapper around a (thin) pointer.
|
||||
// This is also compatible with the PartialEq implementation of language
|
||||
// as that is just a pointer comparison.
|
||||
let language: *const () = unsafe { transmute(self.config.language) };
|
||||
language.hash(state);
|
||||
self.config.language.hash(state);
|
||||
self.ranges.hash(state);
|
||||
}
|
||||
}
|
||||
@ -1371,13 +1568,13 @@ pub fn tree(&self) -> &Tree {
|
||||
self.tree.as_ref().unwrap()
|
||||
}
|
||||
|
||||
fn parse(&mut self, parser: &mut Parser, source: &Rope) -> Result<(), Error> {
|
||||
fn parse(&mut self, parser: &mut Parser, source: RopeSlice) -> Result<(), Error> {
|
||||
parser
|
||||
.set_included_ranges(&self.ranges)
|
||||
.map_err(|_| Error::InvalidRanges)?;
|
||||
|
||||
parser
|
||||
.set_language(self.config.language)
|
||||
.set_language(&self.config.language)
|
||||
.map_err(|_| Error::InvalidLanguage)?;
|
||||
|
||||
// unsafe { syntax.parser.set_cancellation_flag(cancellation_flag) };
|
||||
@ -1386,7 +1583,7 @@ fn parse(&mut self, parser: &mut Parser, source: &Rope) -> Result<(), Error> {
|
||||
&mut |byte, _| {
|
||||
if byte <= source.len_bytes() {
|
||||
let (chunk, start_byte, _, _) = source.chunk_at_byte(byte);
|
||||
chunk[byte - start_byte..].as_bytes()
|
||||
&chunk.as_bytes()[byte - start_byte..]
|
||||
} else {
|
||||
// out of range
|
||||
&[]
|
||||
@ -1399,10 +1596,36 @@ fn parse(&mut self, parser: &mut Parser, source: &Rope) -> Result<(), Error> {
|
||||
self.tree = Some(tree);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether the layer contains the given byte range.
|
||||
///
|
||||
/// If the layer has multiple ranges (i.e. combined injections), the
|
||||
/// given range is considered contained if it is within the start and
|
||||
/// end bytes of the first and last ranges **and** if the given range
|
||||
/// starts or ends within any of the layer's ranges.
|
||||
fn contains_byte_range(&self, start: usize, end: usize) -> bool {
|
||||
let layer_start = self
|
||||
.ranges
|
||||
.first()
|
||||
.expect("ranges should not be empty")
|
||||
.start_byte;
|
||||
let layer_end = self
|
||||
.ranges
|
||||
.last()
|
||||
.expect("ranges should not be empty")
|
||||
.end_byte;
|
||||
|
||||
layer_start <= start
|
||||
&& layer_end >= end
|
||||
&& self.ranges.iter().any(|range| {
|
||||
let byte_range = range.start_byte..range.end_byte;
|
||||
byte_range.contains(&start) || byte_range.contains(&end)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn generate_edits(
|
||||
old_text: &Rope,
|
||||
old_text: RopeSlice,
|
||||
changeset: &ChangeSet,
|
||||
) -> Vec<tree_sitter::InputEdit> {
|
||||
use Operation::*;
|
||||
@ -1418,7 +1641,7 @@ pub(crate) fn generate_edits(
|
||||
|
||||
// TODO; this is a lot easier with Change instead of Operation.
|
||||
|
||||
fn point_at_pos(text: &Rope, pos: usize) -> (usize, Point) {
|
||||
fn point_at_pos(text: RopeSlice, pos: usize) -> (usize, Point) {
|
||||
let byte = text.char_to_byte(pos); // <- attempted to index past end
|
||||
let line = text.char_to_line(pos);
|
||||
let line_start_byte = text.line_to_byte(line);
|
||||
@ -1510,7 +1733,7 @@ fn traverse(point: Point, text: &Tendril) -> Point {
|
||||
use std::{iter, mem, ops, str, usize};
|
||||
use tree_sitter::{
|
||||
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
|
||||
QueryMatch, Range, TextProvider, Tree, TreeCursor,
|
||||
QueryMatch, Range, TextProvider, Tree,
|
||||
};
|
||||
|
||||
const CANCELLATION_CHECK_INTERVAL: usize = 100;
|
||||
@ -1544,7 +1767,7 @@ pub struct HighlightConfiguration {
|
||||
pub language: Grammar,
|
||||
pub query: Query,
|
||||
injections_query: Query,
|
||||
combined_injections_query: Option<Query>,
|
||||
combined_injections_patterns: Vec<usize>,
|
||||
highlights_pattern_index: usize,
|
||||
highlight_indices: ArcSwap<Vec<Option<Highlight>>>,
|
||||
non_local_variable_patterns: Vec<bool>,
|
||||
@ -1595,7 +1818,7 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
}
|
||||
|
||||
pub struct RopeProvider<'a>(pub RopeSlice<'a>);
|
||||
impl<'a> TextProvider<'a> for RopeProvider<'a> {
|
||||
impl<'a> TextProvider<&'a [u8]> for RopeProvider<'a> {
|
||||
type I = ChunksBytes<'a>;
|
||||
|
||||
fn text(&mut self, node: Node) -> Self::I {
|
||||
@ -1609,7 +1832,7 @@ fn text(&mut self, node: Node) -> Self::I {
|
||||
struct HighlightIterLayer<'a> {
|
||||
_tree: Option<Tree>,
|
||||
cursor: QueryCursor,
|
||||
captures: RefCell<iter::Peekable<QueryCaptures<'a, 'a, RopeProvider<'a>>>>,
|
||||
captures: RefCell<iter::Peekable<QueryCaptures<'a, 'a, RopeProvider<'a>, &'a [u8]>>>,
|
||||
config: &'a HighlightConfiguration,
|
||||
highlight_end_stack: Vec<usize>,
|
||||
scope_stack: Vec<LocalScope<'a>>,
|
||||
@ -1651,7 +1874,7 @@ pub fn new(
|
||||
|
||||
// Construct a single query by concatenating the three query strings, but record the
|
||||
// range of pattern indices that belong to each individual string.
|
||||
let query = Query::new(language, &query_source)?;
|
||||
let query = Query::new(&language, &query_source)?;
|
||||
let mut highlights_pattern_index = 0;
|
||||
for i in 0..(query.pattern_count()) {
|
||||
let pattern_offset = query.start_byte_for_pattern(i);
|
||||
@ -1660,26 +1883,15 @@ pub fn new(
|
||||
}
|
||||
}
|
||||
|
||||
let mut injections_query = Query::new(language, injection_query)?;
|
||||
|
||||
// Construct a separate query just for dealing with the 'combined injections'.
|
||||
// Disable the combined injection patterns in the main query.
|
||||
let mut combined_injections_query = Query::new(language, injection_query)?;
|
||||
let mut has_combined_queries = false;
|
||||
for pattern_index in 0..injections_query.pattern_count() {
|
||||
let settings = injections_query.property_settings(pattern_index);
|
||||
if settings.iter().any(|s| &*s.key == "injection.combined") {
|
||||
has_combined_queries = true;
|
||||
injections_query.disable_pattern(pattern_index);
|
||||
} else {
|
||||
combined_injections_query.disable_pattern(pattern_index);
|
||||
}
|
||||
}
|
||||
let combined_injections_query = if has_combined_queries {
|
||||
Some(combined_injections_query)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let injections_query = Query::new(&language, injection_query)?;
|
||||
let combined_injections_patterns = (0..injections_query.pattern_count())
|
||||
.filter(|&i| {
|
||||
injections_query
|
||||
.property_settings(i)
|
||||
.iter()
|
||||
.any(|s| &*s.key == "injection.combined")
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Find all of the highlighting patterns that are disabled for nodes that
|
||||
// have been identified as local variables.
|
||||
@ -1703,7 +1915,7 @@ pub fn new(
|
||||
let mut local_scope_capture_index = None;
|
||||
for (i, name) in query.capture_names().iter().enumerate() {
|
||||
let i = Some(i as u32);
|
||||
match name.as_str() {
|
||||
match *name {
|
||||
"local.definition" => local_def_capture_index = i,
|
||||
"local.definition-value" => local_def_value_capture_index = i,
|
||||
"local.reference" => local_ref_capture_index = i,
|
||||
@ -1714,7 +1926,7 @@ pub fn new(
|
||||
|
||||
for (i, name) in injections_query.capture_names().iter().enumerate() {
|
||||
let i = Some(i as u32);
|
||||
match name.as_str() {
|
||||
match *name {
|
||||
"injection.content" => injection_content_capture_index = i,
|
||||
"injection.language" => injection_language_capture_index = i,
|
||||
"injection.filename" => injection_filename_capture_index = i,
|
||||
@ -1728,7 +1940,7 @@ pub fn new(
|
||||
language,
|
||||
query,
|
||||
injections_query,
|
||||
combined_injections_query,
|
||||
combined_injections_patterns,
|
||||
highlights_pattern_index,
|
||||
highlight_indices,
|
||||
non_local_variable_patterns,
|
||||
@ -1744,7 +1956,7 @@ pub fn new(
|
||||
}
|
||||
|
||||
/// Get a slice containing all of the highlight names used in the configuration.
|
||||
pub fn names(&self) -> &[String] {
|
||||
pub fn names(&self) -> &[&str] {
|
||||
self.query.capture_names()
|
||||
}
|
||||
|
||||
@ -1771,7 +1983,6 @@ pub fn configure(&self, recognized_names: &[String]) {
|
||||
let mut best_index = None;
|
||||
let mut best_match_len = 0;
|
||||
for (i, recognized_name) in recognized_names.iter().enumerate() {
|
||||
let recognized_name = recognized_name;
|
||||
let mut len = 0;
|
||||
let mut matches = true;
|
||||
for (i, part) in recognized_name.split('.').enumerate() {
|
||||
@ -1823,11 +2034,16 @@ fn injection_pair<'a>(
|
||||
node_slice
|
||||
};
|
||||
|
||||
static SHEBANG_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(SHEBANG).unwrap());
|
||||
static SHEBANG_REGEX: Lazy<rope::Regex> =
|
||||
Lazy::new(|| rope::Regex::new(SHEBANG).unwrap());
|
||||
|
||||
injection_capture = SHEBANG_REGEX
|
||||
.captures(&Cow::from(lines))
|
||||
.map(|cap| InjectionLanguageMarker::Shebang(cap[1].to_owned()))
|
||||
.captures_iter(lines.regex_input())
|
||||
.map(|cap| {
|
||||
let cap = lines.byte_slice(cap.get_group(1).unwrap().range());
|
||||
InjectionLanguageMarker::Shebang(cap.into())
|
||||
})
|
||||
.next()
|
||||
} else if index == self.injection_content_capture_index {
|
||||
content_node = Some(capture.node);
|
||||
}
|
||||
@ -2240,6 +2456,7 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
// highlighting patterns that are disabled for local variables.
|
||||
if definition_highlight.is_some() || reference_highlight.is_some() {
|
||||
while layer.config.non_local_variable_patterns[match_.pattern_index] {
|
||||
match_.remove();
|
||||
if let Some((next_match, next_capture_index)) = captures.peek() {
|
||||
let next_capture = next_match.captures[*next_capture_index];
|
||||
if next_capture.node == capture.node {
|
||||
@ -2450,7 +2667,7 @@ pub fn pretty_print_tree<W: fmt::Write>(fmt: &mut W, node: Node) -> fmt::Result
|
||||
|
||||
fn pretty_print_tree_impl<W: fmt::Write>(
|
||||
fmt: &mut W,
|
||||
cursor: &mut TreeCursor,
|
||||
cursor: &mut tree_sitter::TreeCursor,
|
||||
depth: usize,
|
||||
) -> fmt::Result {
|
||||
let node = cursor.node();
|
||||
@ -2516,15 +2733,21 @@ fn test_textobject_queries() {
|
||||
let loader = Loader::new(Configuration {
|
||||
language: vec![],
|
||||
language_server: HashMap::new(),
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
let language = get_language("rust").unwrap();
|
||||
|
||||
let query = Query::new(language, query_str).unwrap();
|
||||
let query = Query::new(&language, query_str).unwrap();
|
||||
let textobject = TextObjectQuery { query };
|
||||
let mut cursor = QueryCursor::new();
|
||||
|
||||
let config = HighlightConfiguration::new(language, "", "", "").unwrap();
|
||||
let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
|
||||
let syntax = Syntax::new(
|
||||
source.slice(..),
|
||||
Arc::new(config),
|
||||
Arc::new(ArcSwap::from_pointee(loader)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let root = syntax.tree().root_node();
|
||||
let mut test = |capture, range| {
|
||||
@ -2578,7 +2801,8 @@ fn test_parser() {
|
||||
let loader = Loader::new(Configuration {
|
||||
language: vec![],
|
||||
language_server: HashMap::new(),
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let language = get_language("rust").unwrap();
|
||||
let config = HighlightConfiguration::new(
|
||||
@ -2598,7 +2822,12 @@ struct Stuff {}
|
||||
fn main() {}
|
||||
",
|
||||
);
|
||||
let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
|
||||
let syntax = Syntax::new(
|
||||
source.slice(..),
|
||||
Arc::new(config),
|
||||
Arc::new(ArcSwap::from_pointee(loader)),
|
||||
)
|
||||
.unwrap();
|
||||
let tree = syntax.tree();
|
||||
let root = tree.root_node();
|
||||
assert_eq!(root.kind(), "source_file");
|
||||
@ -2625,7 +2854,7 @@ fn test_input_edits() {
|
||||
&doc,
|
||||
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
|
||||
);
|
||||
let edits = generate_edits(&doc, transaction.changes());
|
||||
let edits = generate_edits(doc.slice(..), transaction.changes());
|
||||
// transaction.apply(&mut state);
|
||||
|
||||
assert_eq!(
|
||||
@ -2654,7 +2883,7 @@ fn test_input_edits() {
|
||||
let mut doc = Rope::from("fn test() {}");
|
||||
let transaction =
|
||||
Transaction::change(&doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
|
||||
let edits = generate_edits(&doc, transaction.changes());
|
||||
let edits = generate_edits(doc.slice(..), transaction.changes());
|
||||
transaction.apply(&mut doc);
|
||||
|
||||
assert_eq!(doc, "fn test(a: u32) {}");
|
||||
@ -2684,11 +2913,17 @@ fn assert_pretty_print(
|
||||
let loader = Loader::new(Configuration {
|
||||
language: vec![],
|
||||
language_server: HashMap::new(),
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
let language = get_language(language_name).unwrap();
|
||||
|
||||
let config = HighlightConfiguration::new(language, "", "", "").unwrap();
|
||||
let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
|
||||
let syntax = Syntax::new(
|
||||
source.slice(..),
|
||||
Arc::new(config),
|
||||
Arc::new(ArcSwap::from_pointee(loader)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let root = syntax
|
||||
.tree()
|
||||
@ -2742,7 +2977,7 @@ fn test_pretty_print() {
|
||||
// rule but `name` and `body` belong to an unnamed helper `_method_rest`.
|
||||
// This can cause a bug with a pretty-printing implementation that
|
||||
// uses `Node::field_name_for_child` to determine field names but is
|
||||
// fixed when using `TreeCursor::field_name`.
|
||||
// fixed when using `tree_sitter::TreeCursor::field_name`.
|
||||
let source = "def self.method_name
|
||||
true
|
||||
end";
|
||||
|
264
helix-core/src/syntax/tree_cursor.rs
Normal file
264
helix-core/src/syntax/tree_cursor.rs
Normal file
@ -0,0 +1,264 @@
|
||||
use std::{cmp::Reverse, ops::Range};
|
||||
|
||||
use super::{LanguageLayer, LayerId};
|
||||
|
||||
use slotmap::HopSlotMap;
|
||||
use tree_sitter::Node;
|
||||
|
||||
/// The byte range of an injection layer.
|
||||
///
|
||||
/// Injection ranges may overlap, but all overlapping parts are subsets of their parent ranges.
|
||||
/// This allows us to sort the ranges ahead of time in order to efficiently find a range that
|
||||
/// contains a point with maximum depth.
|
||||
#[derive(Debug)]
|
||||
struct InjectionRange {
|
||||
start: usize,
|
||||
end: usize,
|
||||
layer_id: LayerId,
|
||||
depth: u32,
|
||||
}
|
||||
|
||||
pub struct TreeCursor<'a> {
|
||||
layers: &'a HopSlotMap<LayerId, LanguageLayer>,
|
||||
root: LayerId,
|
||||
current: LayerId,
|
||||
injection_ranges: Vec<InjectionRange>,
|
||||
// TODO: Ideally this would be a `tree_sitter::TreeCursor<'a>` but
|
||||
// that returns very surprising results in testing.
|
||||
cursor: Node<'a>,
|
||||
}
|
||||
|
||||
impl<'a> TreeCursor<'a> {
|
||||
pub(super) fn new(layers: &'a HopSlotMap<LayerId, LanguageLayer>, root: LayerId) -> Self {
|
||||
let mut injection_ranges = Vec::new();
|
||||
|
||||
for (layer_id, layer) in layers.iter() {
|
||||
// Skip the root layer
|
||||
if layer.parent.is_none() {
|
||||
continue;
|
||||
}
|
||||
for byte_range in layer.ranges.iter() {
|
||||
let range = InjectionRange {
|
||||
start: byte_range.start_byte,
|
||||
end: byte_range.end_byte,
|
||||
layer_id,
|
||||
depth: layer.depth,
|
||||
};
|
||||
injection_ranges.push(range);
|
||||
}
|
||||
}
|
||||
|
||||
injection_ranges.sort_unstable_by_key(|range| (range.end, Reverse(range.depth)));
|
||||
|
||||
let cursor = layers[root].tree().root_node();
|
||||
|
||||
Self {
|
||||
layers,
|
||||
root,
|
||||
current: root,
|
||||
injection_ranges,
|
||||
cursor,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn node(&self) -> Node<'a> {
|
||||
self.cursor
|
||||
}
|
||||
|
||||
pub fn goto_parent(&mut self) -> bool {
|
||||
if let Some(parent) = self.node().parent() {
|
||||
self.cursor = parent;
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we are already on the root layer, we cannot ascend.
|
||||
if self.current == self.root {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ascend to the parent layer.
|
||||
let range = self.node().byte_range();
|
||||
let parent_id = self.layers[self.current]
|
||||
.parent
|
||||
.expect("non-root layers have a parent");
|
||||
self.current = parent_id;
|
||||
let root = self.layers[self.current].tree().root_node();
|
||||
self.cursor = root
|
||||
.descendant_for_byte_range(range.start, range.end)
|
||||
.unwrap_or(root);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub fn goto_parent_with<P>(&mut self, predicate: P) -> bool
|
||||
where
|
||||
P: Fn(&Node) -> bool,
|
||||
{
|
||||
while self.goto_parent() {
|
||||
if predicate(&self.node()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// Finds the injection layer that has exactly the same range as the given `range`.
|
||||
fn layer_id_of_byte_range(&self, search_range: Range<usize>) -> Option<LayerId> {
|
||||
let start_idx = self
|
||||
.injection_ranges
|
||||
.partition_point(|range| range.end < search_range.end);
|
||||
|
||||
self.injection_ranges[start_idx..]
|
||||
.iter()
|
||||
.take_while(|range| range.end == search_range.end)
|
||||
.find_map(|range| (range.start == search_range.start).then_some(range.layer_id))
|
||||
}
|
||||
|
||||
fn goto_first_child_impl(&mut self, named: bool) -> bool {
|
||||
// Check if the current node's range is an exact injection layer range.
|
||||
if let Some(layer_id) = self
|
||||
.layer_id_of_byte_range(self.node().byte_range())
|
||||
.filter(|&layer_id| layer_id != self.current)
|
||||
{
|
||||
// Switch to the child layer.
|
||||
self.current = layer_id;
|
||||
self.cursor = self.layers[self.current].tree().root_node();
|
||||
return true;
|
||||
}
|
||||
|
||||
let child = if named {
|
||||
self.cursor.named_child(0)
|
||||
} else {
|
||||
self.cursor.child(0)
|
||||
};
|
||||
|
||||
if let Some(child) = child {
|
||||
// Otherwise descend in the current tree.
|
||||
self.cursor = child;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn goto_first_child(&mut self) -> bool {
|
||||
self.goto_first_child_impl(false)
|
||||
}
|
||||
|
||||
pub fn goto_first_named_child(&mut self) -> bool {
|
||||
self.goto_first_child_impl(true)
|
||||
}
|
||||
|
||||
fn goto_next_sibling_impl(&mut self, named: bool) -> bool {
|
||||
let sibling = if named {
|
||||
self.cursor.next_named_sibling()
|
||||
} else {
|
||||
self.cursor.next_sibling()
|
||||
};
|
||||
|
||||
if let Some(sibling) = sibling {
|
||||
self.cursor = sibling;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn goto_next_sibling(&mut self) -> bool {
|
||||
self.goto_next_sibling_impl(false)
|
||||
}
|
||||
|
||||
pub fn goto_next_named_sibling(&mut self) -> bool {
|
||||
self.goto_next_sibling_impl(true)
|
||||
}
|
||||
|
||||
fn goto_prev_sibling_impl(&mut self, named: bool) -> bool {
|
||||
let sibling = if named {
|
||||
self.cursor.prev_named_sibling()
|
||||
} else {
|
||||
self.cursor.prev_sibling()
|
||||
};
|
||||
|
||||
if let Some(sibling) = sibling {
|
||||
self.cursor = sibling;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn goto_prev_sibling(&mut self) -> bool {
|
||||
self.goto_prev_sibling_impl(false)
|
||||
}
|
||||
|
||||
pub fn goto_prev_named_sibling(&mut self) -> bool {
|
||||
self.goto_prev_sibling_impl(true)
|
||||
}
|
||||
|
||||
/// Finds the injection layer that contains the given start-end range.
|
||||
fn layer_id_containing_byte_range(&self, start: usize, end: usize) -> LayerId {
|
||||
let start_idx = self
|
||||
.injection_ranges
|
||||
.partition_point(|range| range.end < end);
|
||||
|
||||
self.injection_ranges[start_idx..]
|
||||
.iter()
|
||||
.take_while(|range| range.start < end)
|
||||
.find_map(|range| (range.start <= start).then_some(range.layer_id))
|
||||
.unwrap_or(self.root)
|
||||
}
|
||||
|
||||
pub fn reset_to_byte_range(&mut self, start: usize, end: usize) {
|
||||
self.current = self.layer_id_containing_byte_range(start, end);
|
||||
let root = self.layers[self.current].tree().root_node();
|
||||
self.cursor = root.descendant_for_byte_range(start, end).unwrap_or(root);
|
||||
}
|
||||
|
||||
/// Returns an iterator over the children of the node the TreeCursor is on
|
||||
/// at the time this is called.
|
||||
pub fn children(&'a mut self) -> ChildIter {
|
||||
let parent = self.node();
|
||||
|
||||
ChildIter {
|
||||
cursor: self,
|
||||
parent,
|
||||
named: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over the named children of the node the TreeCursor is on
|
||||
/// at the time this is called.
|
||||
pub fn named_children(&'a mut self) -> ChildIter {
|
||||
let parent = self.node();
|
||||
|
||||
ChildIter {
|
||||
cursor: self,
|
||||
parent,
|
||||
named: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChildIter<'n> {
|
||||
cursor: &'n mut TreeCursor<'n>,
|
||||
parent: Node<'n>,
|
||||
named: bool,
|
||||
}
|
||||
|
||||
impl<'n> Iterator for ChildIter<'n> {
|
||||
type Item = Node<'n>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
// first iteration, just visit the first child
|
||||
if self.cursor.node() == self.parent {
|
||||
self.cursor
|
||||
.goto_first_child_impl(self.named)
|
||||
.then(|| self.cursor.node())
|
||||
} else {
|
||||
self.cursor
|
||||
.goto_next_sibling_impl(self.named)
|
||||
.then(|| self.cursor.node())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
use std::cell::Cell;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::syntax::Highlight;
|
||||
use crate::Tendril;
|
||||
@ -92,23 +91,23 @@ pub struct LineAnnotation {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Layer<A, M> {
|
||||
annotations: Rc<[A]>,
|
||||
struct Layer<'a, A, M> {
|
||||
annotations: &'a [A],
|
||||
current_index: Cell<usize>,
|
||||
metadata: M,
|
||||
}
|
||||
|
||||
impl<A, M: Clone> Clone for Layer<A, M> {
|
||||
impl<A, M: Clone> Clone for Layer<'_, A, M> {
|
||||
fn clone(&self) -> Self {
|
||||
Layer {
|
||||
annotations: self.annotations.clone(),
|
||||
annotations: self.annotations,
|
||||
current_index: self.current_index.clone(),
|
||||
metadata: self.metadata.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, M> Layer<A, M> {
|
||||
impl<A, M> Layer<'_, A, M> {
|
||||
pub fn reset_pos(&self, char_idx: usize, get_char_idx: impl Fn(&A) -> usize) {
|
||||
let new_index = self
|
||||
.annotations
|
||||
@ -128,8 +127,8 @@ pub fn consume(&self, char_idx: usize, get_char_idx: impl Fn(&A) -> usize) -> Op
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, M> From<(Rc<[A]>, M)> for Layer<A, M> {
|
||||
fn from((annotations, metadata): (Rc<[A]>, M)) -> Layer<A, M> {
|
||||
impl<'a, A, M> From<(&'a [A], M)> for Layer<'a, A, M> {
|
||||
fn from((annotations, metadata): (&'a [A], M)) -> Layer<A, M> {
|
||||
Layer {
|
||||
annotations,
|
||||
current_index: Cell::new(0),
|
||||
@ -147,13 +146,13 @@ fn reset_pos<A, M>(layers: &[Layer<A, M>], pos: usize, get_pos: impl Fn(&A) -> u
|
||||
/// Annotations that change that is displayed when the document is render.
|
||||
/// Also commonly called virtual text.
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct TextAnnotations {
|
||||
inline_annotations: Vec<Layer<InlineAnnotation, Option<Highlight>>>,
|
||||
overlays: Vec<Layer<Overlay, Option<Highlight>>>,
|
||||
line_annotations: Vec<Layer<LineAnnotation, ()>>,
|
||||
pub struct TextAnnotations<'a> {
|
||||
inline_annotations: Vec<Layer<'a, InlineAnnotation, Option<Highlight>>>,
|
||||
overlays: Vec<Layer<'a, Overlay, Option<Highlight>>>,
|
||||
line_annotations: Vec<Layer<'a, LineAnnotation, ()>>,
|
||||
}
|
||||
|
||||
impl TextAnnotations {
|
||||
impl<'a> TextAnnotations<'a> {
|
||||
/// Prepare the TextAnnotations for iteration starting at char_idx
|
||||
pub fn reset_pos(&self, char_idx: usize) {
|
||||
reset_pos(&self.inline_annotations, char_idx, |annot| annot.char_idx);
|
||||
@ -194,7 +193,7 @@ pub fn collect_overlay_highlights(
|
||||
/// the annotations that belong to the layers added first will be shown first.
|
||||
pub fn add_inline_annotations(
|
||||
&mut self,
|
||||
layer: Rc<[InlineAnnotation]>,
|
||||
layer: &'a [InlineAnnotation],
|
||||
highlight: Option<Highlight>,
|
||||
) -> &mut Self {
|
||||
self.inline_annotations.push((layer, highlight).into());
|
||||
@ -211,7 +210,7 @@ pub fn add_inline_annotations(
|
||||
///
|
||||
/// If multiple layers contain overlay at the same position
|
||||
/// the overlay from the layer added last will be show.
|
||||
pub fn add_overlay(&mut self, layer: Rc<[Overlay]>, highlight: Option<Highlight>) -> &mut Self {
|
||||
pub fn add_overlay(&mut self, layer: &'a [Overlay], highlight: Option<Highlight>) -> &mut Self {
|
||||
self.overlays.push((layer, highlight).into());
|
||||
self
|
||||
}
|
||||
@ -220,7 +219,7 @@ pub fn add_overlay(&mut self, layer: Rc<[Overlay]>, highlight: Option<Highlight>
|
||||
///
|
||||
/// The line annotations **must be sorted** by their `char_idx`.
|
||||
/// Multiple line annotations with the same `char_idx` **are not allowed**.
|
||||
pub fn add_line_annotation(&mut self, layer: Rc<[LineAnnotation]>) -> &mut Self {
|
||||
pub fn add_line_annotation(&mut self, layer: &'a [LineAnnotation]) -> &mut Self {
|
||||
self.line_annotations.push((layer, ()).into());
|
||||
self
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
use ropey::RopeSlice;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{Range, Rope, Selection, Tendril};
|
||||
use std::borrow::Cow;
|
||||
use crate::{chars::char_is_word, Range, Rope, Selection, Tendril};
|
||||
use std::{borrow::Cow, iter::once};
|
||||
|
||||
/// (from, to, replacement)
|
||||
pub type Change = (usize, usize, Option<Tendril>);
|
||||
@ -22,6 +23,30 @@ pub enum Operation {
|
||||
pub enum Assoc {
|
||||
Before,
|
||||
After,
|
||||
/// Acts like `After` if a word character is inserted
|
||||
/// after the position, otherwise acts like `Before`
|
||||
AfterWord,
|
||||
/// Acts like `Before` if a word character is inserted
|
||||
/// before the position, otherwise acts like `After`
|
||||
BeforeWord,
|
||||
}
|
||||
|
||||
impl Assoc {
|
||||
/// Whether to stick to gaps
|
||||
fn stay_at_gaps(self) -> bool {
|
||||
!matches!(self, Self::BeforeWord | Self::AfterWord)
|
||||
}
|
||||
|
||||
fn insert_offset(self, s: &str) -> usize {
|
||||
let chars = s.chars().count();
|
||||
match self {
|
||||
Assoc::After => chars,
|
||||
Assoc::AfterWord => s.chars().take_while(|&c| char_is_word(c)).count(),
|
||||
// return position before inserted text
|
||||
Assoc::Before => 0,
|
||||
Assoc::BeforeWord => chars - s.chars().rev().take_while(|&c| char_is_word(c)).count(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
@ -42,7 +67,7 @@ pub fn with_capacity(capacity: usize) -> Self {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new(doc: &Rope) -> Self {
|
||||
pub fn new(doc: RopeSlice) -> Self {
|
||||
let len = doc.len_chars();
|
||||
Self {
|
||||
changes: Vec::new(),
|
||||
@ -326,20 +351,75 @@ pub fn is_empty(&self) -> bool {
|
||||
self.changes.is_empty() || self.changes == [Operation::Retain(self.len)]
|
||||
}
|
||||
|
||||
/// Map a position through the changes.
|
||||
/// Map a (mostly) *sorted* list of positions through the changes.
|
||||
///
|
||||
/// `assoc` indicates which size to associate the position with. `Before` will keep the
|
||||
/// position close to the character before, and will place it before insertions over that
|
||||
/// range, or at that point. `After` will move it forward, placing it at the end of such
|
||||
/// insertions.
|
||||
pub fn map_pos(&self, pos: usize, assoc: Assoc) -> usize {
|
||||
/// This is equivalent to updating each position with `map_pos`:
|
||||
///
|
||||
/// ``` no-compile
|
||||
/// for (pos, assoc) in positions {
|
||||
/// *pos = changes.map_pos(*pos, assoc);
|
||||
/// }
|
||||
/// ```
|
||||
/// However this function is significantly faster for sorted lists running
|
||||
/// in `O(N+M)` instead of `O(NM)`. This function also handles unsorted/
|
||||
/// partially sorted lists. However, in that case worst case complexity is
|
||||
/// again `O(MN)`. For lists that are often/mostly sorted (like the end of diagnostic ranges)
|
||||
/// performance is usally close to `O(N + M)`
|
||||
pub fn update_positions<'a>(&self, positions: impl Iterator<Item = (&'a mut usize, Assoc)>) {
|
||||
use Operation::*;
|
||||
|
||||
let mut positions = positions.peekable();
|
||||
|
||||
let mut old_pos = 0;
|
||||
let mut new_pos = 0;
|
||||
let mut iter = self.changes.iter().enumerate().peekable();
|
||||
|
||||
let mut iter = self.changes.iter().peekable();
|
||||
'outer: loop {
|
||||
macro_rules! map {
|
||||
($map: expr, $i: expr) => {
|
||||
loop {
|
||||
let Some((pos, assoc)) = positions.peek_mut() else { return; };
|
||||
if **pos < old_pos {
|
||||
// Positions are not sorted, revert to the last Operation that
|
||||
// contains this position and continue iterating from there.
|
||||
// We can unwrap here since `pos` can not be negative
|
||||
// (unsigned integer) and iterating backwards to the start
|
||||
// should always move us back to the start
|
||||
for (i, change) in self.changes[..$i].iter().enumerate().rev() {
|
||||
match change {
|
||||
Retain(i) => {
|
||||
old_pos -= i;
|
||||
new_pos -= i;
|
||||
}
|
||||
Delete(i) => {
|
||||
old_pos -= i;
|
||||
}
|
||||
Insert(ins) => {
|
||||
new_pos -= ins.chars().count();
|
||||
}
|
||||
}
|
||||
if old_pos <= **pos {
|
||||
iter = self.changes[i..].iter().enumerate().peekable();
|
||||
}
|
||||
}
|
||||
debug_assert!(old_pos <= **pos, "Reverse Iter across changeset works");
|
||||
continue 'outer;
|
||||
}
|
||||
let Some(new_pos) = $map(**pos, *assoc) else { break; };
|
||||
**pos = new_pos;
|
||||
positions.next();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let Some((i, change)) = iter.next() else {
|
||||
map!(
|
||||
|pos, _| (old_pos == pos).then_some(new_pos),
|
||||
self.changes.len()
|
||||
);
|
||||
break;
|
||||
};
|
||||
|
||||
while let Some(change) = iter.next() {
|
||||
let len = match change {
|
||||
Delete(i) | Retain(i) => *i,
|
||||
Insert(_) => 0,
|
||||
@ -348,61 +428,65 @@ pub fn map_pos(&self, pos: usize, assoc: Assoc) -> usize {
|
||||
|
||||
match change {
|
||||
Retain(_) => {
|
||||
if old_end > pos {
|
||||
return new_pos + (pos - old_pos);
|
||||
}
|
||||
map!(
|
||||
|pos, _| (old_end > pos).then_some(new_pos + (pos - old_pos)),
|
||||
i
|
||||
);
|
||||
new_pos += len;
|
||||
}
|
||||
Delete(_) => {
|
||||
// in range
|
||||
if old_end > pos {
|
||||
return new_pos;
|
||||
}
|
||||
map!(|pos, _| (old_end > pos).then_some(new_pos), i);
|
||||
}
|
||||
Insert(s) => {
|
||||
let ins = s.chars().count();
|
||||
|
||||
// a subsequent delete means a replace, consume it
|
||||
if let Some(Delete(len)) = iter.peek() {
|
||||
if let Some((_, Delete(len))) = iter.peek() {
|
||||
iter.next();
|
||||
|
||||
old_end = old_pos + len;
|
||||
// in range of replaced text
|
||||
if old_end > pos {
|
||||
// at point or tracking before
|
||||
if pos == old_pos || assoc == Assoc::Before {
|
||||
return new_pos;
|
||||
} else {
|
||||
// place to end of insert
|
||||
return new_pos + ins;
|
||||
}
|
||||
}
|
||||
map!(
|
||||
|pos, assoc: Assoc| (old_end > pos).then(|| {
|
||||
// at point or tracking before
|
||||
if pos == old_pos && assoc.stay_at_gaps() {
|
||||
new_pos
|
||||
} else {
|
||||
// place to end of insert
|
||||
new_pos + assoc.insert_offset(s)
|
||||
}
|
||||
}),
|
||||
i
|
||||
);
|
||||
} else {
|
||||
// at insert point
|
||||
if old_pos == pos {
|
||||
// return position before inserted text
|
||||
if assoc == Assoc::Before {
|
||||
return new_pos;
|
||||
} else {
|
||||
// after text
|
||||
return new_pos + ins;
|
||||
}
|
||||
}
|
||||
map!(
|
||||
|pos, assoc: Assoc| (old_pos == pos).then(|| {
|
||||
// return position before inserted text
|
||||
new_pos + assoc.insert_offset(s)
|
||||
}),
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
new_pos += ins;
|
||||
new_pos += s.chars().count();
|
||||
}
|
||||
}
|
||||
old_pos = old_end;
|
||||
}
|
||||
let out_of_bounds: Vec<_> = positions.collect();
|
||||
|
||||
if pos > old_pos {
|
||||
panic!(
|
||||
"Position {} is out of range for changeset len {}!",
|
||||
pos, old_pos
|
||||
)
|
||||
}
|
||||
new_pos
|
||||
panic!("Positions {out_of_bounds:?} are out of range for changeset len {old_pos}!",)
|
||||
}
|
||||
|
||||
/// Map a position through the changes.
|
||||
///
|
||||
/// `assoc` indicates which side to associate the position with. `Before` will keep the
|
||||
/// position close to the character before, and will place it before insertions over that
|
||||
/// range, or at that point. `After` will move it forward, placing it at the end of such
|
||||
/// insertions.
|
||||
pub fn map_pos(&self, mut pos: usize, assoc: Assoc) -> usize {
|
||||
self.update_positions(once((&mut pos, assoc)));
|
||||
pos
|
||||
}
|
||||
|
||||
pub fn changes_iter(&self) -> ChangeIterator {
|
||||
@ -422,7 +506,7 @@ impl Transaction {
|
||||
/// Create a new, empty transaction.
|
||||
pub fn new(doc: &Rope) -> Self {
|
||||
Self {
|
||||
changes: ChangeSet::new(doc),
|
||||
changes: ChangeSet::new(doc.slice(..)),
|
||||
selection: None,
|
||||
}
|
||||
}
|
||||
@ -803,6 +887,62 @@ fn map_pos() {
|
||||
};
|
||||
assert_eq!(cs.map_pos(2, Assoc::Before), 2);
|
||||
assert_eq!(cs.map_pos(2, Assoc::After), 2);
|
||||
// unsorted selection
|
||||
let cs = ChangeSet {
|
||||
changes: vec![
|
||||
Insert("ab".into()),
|
||||
Delete(2),
|
||||
Insert("cd".into()),
|
||||
Delete(2),
|
||||
],
|
||||
len: 4,
|
||||
len_after: 4,
|
||||
};
|
||||
let mut positions = [4, 2];
|
||||
cs.update_positions(positions.iter_mut().map(|pos| (pos, Assoc::After)));
|
||||
assert_eq!(positions, [4, 2]);
|
||||
// stays at word boundary
|
||||
let cs = ChangeSet {
|
||||
changes: vec![
|
||||
Retain(2), // <space><space>
|
||||
Insert(" ab".into()),
|
||||
Retain(2), // cd
|
||||
Insert("de ".into()),
|
||||
],
|
||||
len: 4,
|
||||
len_after: 10,
|
||||
};
|
||||
assert_eq!(cs.map_pos(2, Assoc::BeforeWord), 3);
|
||||
assert_eq!(cs.map_pos(4, Assoc::AfterWord), 9);
|
||||
let cs = ChangeSet {
|
||||
changes: vec![
|
||||
Retain(1), // <space>
|
||||
Insert(" b".into()),
|
||||
Delete(1), // c
|
||||
Retain(1), // d
|
||||
Insert("e ".into()),
|
||||
Delete(1), // <space>
|
||||
],
|
||||
len: 5,
|
||||
len_after: 7,
|
||||
};
|
||||
assert_eq!(cs.map_pos(1, Assoc::BeforeWord), 2);
|
||||
assert_eq!(cs.map_pos(3, Assoc::AfterWord), 5);
|
||||
let cs = ChangeSet {
|
||||
changes: vec![
|
||||
Retain(1), // <space>
|
||||
Insert("a".into()),
|
||||
Delete(2), // <space>b
|
||||
Retain(1), // d
|
||||
Insert("e".into()),
|
||||
Delete(1), // f
|
||||
Retain(1), // <space>
|
||||
],
|
||||
len: 5,
|
||||
len_after: 7,
|
||||
};
|
||||
assert_eq!(cs.map_pos(2, Assoc::BeforeWord), 1);
|
||||
assert_eq!(cs.map_pos(4, Assoc::AfterWord), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -869,9 +1009,9 @@ fn optimized_composition() {
|
||||
#[test]
|
||||
fn combine_with_empty() {
|
||||
let empty = Rope::from("");
|
||||
let a = ChangeSet::new(&empty);
|
||||
let a = ChangeSet::new(empty.slice(..));
|
||||
|
||||
let mut b = ChangeSet::new(&empty);
|
||||
let mut b = ChangeSet::new(empty.slice(..));
|
||||
b.insert("a".into());
|
||||
|
||||
let changes = a.compose(b);
|
||||
@ -885,9 +1025,9 @@ fn combine_with_utf8() {
|
||||
const TEST_CASE: &str = "Hello, これはヘリックスエディターです!";
|
||||
|
||||
let empty = Rope::from("");
|
||||
let a = ChangeSet::new(&empty);
|
||||
let a = ChangeSet::new(empty.slice(..));
|
||||
|
||||
let mut b = ChangeSet::new(&empty);
|
||||
let mut b = ChangeSet::new(empty.slice(..));
|
||||
b.insert(TEST_CASE.into());
|
||||
|
||||
let changes = a.compose(b);
|
||||
|
@ -1,7 +1,9 @@
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
use textwrap::{Options, WordSplitter::NoHyphenation};
|
||||
|
||||
/// Given a slice of text, return the text re-wrapped to fit it
|
||||
/// within the given width.
|
||||
pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> {
|
||||
textwrap::refill(text, text_width).into()
|
||||
let options = Options::new(text_width).word_splitter(NoHyphenation);
|
||||
textwrap::refill(text, options).into()
|
||||
}
|
||||
|
48
helix-core/tests/data/indent/cpp.cpp
Normal file
48
helix-core/tests/data/indent/cpp.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6);
|
||||
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6) {
|
||||
auto lambda = []() {
|
||||
return 0;
|
||||
};
|
||||
auto lambda_with_a_really_long_name_that_uses_a_whole_line
|
||||
= [](int some_more_aligned_parameters,
|
||||
std::string parm2) {
|
||||
do_smth();
|
||||
};
|
||||
if (brace_on_same_line) {
|
||||
do_smth();
|
||||
} else if (brace_on_next_line)
|
||||
{
|
||||
do_smth();
|
||||
} else if (another_condition) {
|
||||
do_smth();
|
||||
}
|
||||
else {
|
||||
do_smth();
|
||||
}
|
||||
if (inline_if_statement)
|
||||
do_smth();
|
||||
if (another_inline_if_statement)
|
||||
return [](int parm1, char* parm2) {
|
||||
this_is_a_really_pointless_lambda();
|
||||
};
|
||||
|
||||
switch (var) {
|
||||
case true:
|
||||
return -1;
|
||||
case false:
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass : public MyBaseClass {
|
||||
public:
|
||||
MyClass();
|
||||
void public_fn();
|
||||
private:
|
||||
super_secret_private_fn();
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../../src/indent.rs
|
@ -11,3 +11,16 @@ indent = { tab-width = 4, unit = " " }
|
||||
[[grammar]]
|
||||
name = "rust"
|
||||
source = { git = "https://github.com/tree-sitter/tree-sitter-rust", rev = "0431a2c60828731f27491ee9fdefe25e250ce9c9" }
|
||||
|
||||
[[language]]
|
||||
name = "cpp"
|
||||
scope = "source.cpp"
|
||||
injection-regex = "cpp"
|
||||
file-types = ["cc", "hh", "c++", "cpp", "hpp", "h", "ipp", "tpp", "cxx", "hxx", "ixx", "txx", "ino", "C", "H"]
|
||||
roots = []
|
||||
comment-token = "//"
|
||||
indent = { tab-width = 2, unit = " " }
|
||||
|
||||
[[grammar]]
|
||||
name = "cpp"
|
||||
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "2d2c4aee8672af4c7c8edff68e7dd4c07e88d2b1" }
|
||||
|
@ -1,20 +1,124 @@
|
||||
use arc_swap::ArcSwap;
|
||||
use helix_core::{
|
||||
indent::{indent_level_for_line, treesitter_indent_for_pos, IndentStyle},
|
||||
syntax::Loader,
|
||||
syntax::{Configuration, Loader},
|
||||
Syntax,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use helix_stdx::rope::RopeSliceExt;
|
||||
use ropey::Rope;
|
||||
use std::{ops::Range, path::PathBuf, process::Command, sync::Arc};
|
||||
|
||||
#[test]
|
||||
fn test_treesitter_indent_rust() {
|
||||
test_treesitter_indent("rust.rs", "source.rust");
|
||||
standard_treesitter_test("rust.rs", "source.rust");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_treesitter_indent_rust_2() {
|
||||
test_treesitter_indent("indent.rs", "source.rust");
|
||||
// TODO Use commands.rs as indentation test.
|
||||
// Currently this fails because we can't align the parameters of a closure yet
|
||||
// test_treesitter_indent("commands.rs", "source.rust");
|
||||
fn test_treesitter_indent_cpp() {
|
||||
standard_treesitter_test("cpp.cpp", "source.cpp");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_treesitter_indent_rust_helix() {
|
||||
// We pin a specific git revision to prevent unrelated changes from causing the indent tests to fail.
|
||||
// Ideally, someone updates this once in a while and fixes any errors that occur.
|
||||
let rev = "af382768cdaf89ff547dbd8f644a1bddd90e7c8f";
|
||||
let files = Command::new("git")
|
||||
.args([
|
||||
"ls-tree",
|
||||
"-r",
|
||||
"--name-only",
|
||||
"--full-tree",
|
||||
rev,
|
||||
"helix-term/src",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
let files = String::from_utf8(files.stdout).unwrap();
|
||||
|
||||
let ignored_files = vec![
|
||||
// Contains many macros that tree-sitter does not parse in a meaningful way and is otherwise not very interesting
|
||||
"helix-term/src/health.rs",
|
||||
];
|
||||
|
||||
for file in files.split_whitespace() {
|
||||
if ignored_files.contains(&file) {
|
||||
continue;
|
||||
}
|
||||
let ignored_lines: Vec<Range<usize>> = match file {
|
||||
"helix-term/src/application.rs" => vec![
|
||||
// We can't handle complicated indent rules inside macros (`json!` in this case) since
|
||||
// the tree-sitter grammar only parses them as `token_tree` and `identifier` nodes.
|
||||
1045..1051,
|
||||
],
|
||||
"helix-term/src/commands.rs" => vec![
|
||||
// This is broken because of the current handling of `call_expression`
|
||||
// (i.e. having an indent query for it but outdenting again in specific cases).
|
||||
// The indent query is needed to correctly handle multi-line arguments in function calls
|
||||
// inside indented `field_expression` nodes (which occurs fairly often).
|
||||
//
|
||||
// Once we have the `@indent.always` capture type, it might be possible to just have an indent
|
||||
// capture for the `arguments` field of a call expression. That could enable us to correctly
|
||||
// handle this.
|
||||
2226..2230,
|
||||
],
|
||||
"helix-term/src/commands/dap.rs" => vec![
|
||||
// Complex `format!` macro
|
||||
46..52,
|
||||
],
|
||||
"helix-term/src/commands/lsp.rs" => vec![
|
||||
// Macro
|
||||
624..627,
|
||||
// Return type declaration of a closure. `cargo fmt` adds an additional space here,
|
||||
// which we cannot (yet) model with our indent queries.
|
||||
878..879,
|
||||
// Same as in `helix-term/src/commands.rs`
|
||||
1335..1343,
|
||||
],
|
||||
"helix-term/src/config.rs" => vec![
|
||||
// Multiline string
|
||||
146..152,
|
||||
],
|
||||
"helix-term/src/keymap.rs" => vec![
|
||||
// Complex macro (see above)
|
||||
456..470,
|
||||
// Multiline string without indent
|
||||
563..567,
|
||||
],
|
||||
"helix-term/src/main.rs" => vec![
|
||||
// Multiline string
|
||||
44..70,
|
||||
],
|
||||
"helix-term/src/ui/completion.rs" => vec![
|
||||
// Macro
|
||||
218..232,
|
||||
],
|
||||
"helix-term/src/ui/editor.rs" => vec![
|
||||
// The chained function calls here are not indented, probably because of the comment
|
||||
// in between. Since `cargo fmt` doesn't even attempt to format it, there's probably
|
||||
// no point in trying to indent this correctly.
|
||||
342..350,
|
||||
],
|
||||
"helix-term/src/ui/lsp.rs" => vec![
|
||||
// Macro
|
||||
56..61,
|
||||
],
|
||||
"helix-term/src/ui/statusline.rs" => vec![
|
||||
// Same as in `helix-term/src/commands.rs`
|
||||
436..442,
|
||||
450..456,
|
||||
],
|
||||
_ => Vec::new(),
|
||||
};
|
||||
|
||||
let git_object = rev.to_string() + ":" + file;
|
||||
let content = Command::new("git")
|
||||
.args(["cat-file", "blob", &git_object])
|
||||
.output()
|
||||
.unwrap();
|
||||
let doc = Rope::from_reader(&mut content.stdout.as_slice()).unwrap();
|
||||
test_treesitter_indent(file, doc, "source.rust", ignored_lines);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -50,20 +154,41 @@ fn test_indent_level_for_line_with_spaces_and_tabs() {
|
||||
assert_eq!(indent_level, 2)
|
||||
}
|
||||
|
||||
fn test_treesitter_indent(file_name: &str, lang_scope: &str) {
|
||||
fn indent_tests_dir() -> PathBuf {
|
||||
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
test_dir.push("tests/data/indent");
|
||||
test_dir
|
||||
}
|
||||
|
||||
let mut test_file = test_dir.clone();
|
||||
test_file.push(file_name);
|
||||
let test_file = std::fs::File::open(test_file).unwrap();
|
||||
fn indent_test_path(name: &str) -> PathBuf {
|
||||
let mut path = indent_tests_dir();
|
||||
path.push(name);
|
||||
path
|
||||
}
|
||||
|
||||
fn indent_tests_config() -> Configuration {
|
||||
let mut config_path = indent_tests_dir();
|
||||
config_path.push("languages.toml");
|
||||
let config = std::fs::read_to_string(config_path).unwrap();
|
||||
toml::from_str(&config).unwrap()
|
||||
}
|
||||
|
||||
fn standard_treesitter_test(file_name: &str, lang_scope: &str) {
|
||||
let test_path = indent_test_path(file_name);
|
||||
let test_file = std::fs::File::open(test_path).unwrap();
|
||||
let doc = ropey::Rope::from_reader(test_file).unwrap();
|
||||
test_treesitter_indent(file_name, doc, lang_scope, Vec::new())
|
||||
}
|
||||
|
||||
let mut config_file = test_dir;
|
||||
config_file.push("languages.toml");
|
||||
let config = std::fs::read_to_string(config_file).unwrap();
|
||||
let config = toml::from_str(&config).unwrap();
|
||||
let loader = Loader::new(config);
|
||||
/// Test that all the lines in the given file are indented as expected.
|
||||
/// ignored_lines is a list of (1-indexed) line ranges that are excluded from this test.
|
||||
fn test_treesitter_indent(
|
||||
test_name: &str,
|
||||
doc: Rope,
|
||||
lang_scope: &str,
|
||||
ignored_lines: Vec<std::ops::Range<usize>>,
|
||||
) {
|
||||
let loader = Loader::new(indent_tests_config()).unwrap();
|
||||
|
||||
// set runtime path so we can find the queries
|
||||
let mut runtime = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
@ -71,30 +196,40 @@ fn test_treesitter_indent(file_name: &str, lang_scope: &str) {
|
||||
std::env::set_var("HELIX_RUNTIME", runtime.to_str().unwrap());
|
||||
|
||||
let language_config = loader.language_config_for_scope(lang_scope).unwrap();
|
||||
let indent_style = IndentStyle::from_str(&language_config.indent.as_ref().unwrap().unit);
|
||||
let highlight_config = language_config.highlight_config(&[]).unwrap();
|
||||
let syntax = Syntax::new(&doc, highlight_config, std::sync::Arc::new(loader)).unwrap();
|
||||
let indent_query = language_config.indent_query().unwrap();
|
||||
let text = doc.slice(..);
|
||||
let syntax = Syntax::new(
|
||||
text,
|
||||
highlight_config,
|
||||
Arc::new(ArcSwap::from_pointee(loader)),
|
||||
)
|
||||
.unwrap();
|
||||
let indent_query = language_config.indent_query().unwrap();
|
||||
|
||||
for i in 0..doc.len_lines() {
|
||||
let line = text.line(i);
|
||||
if let Some(pos) = helix_core::find_first_non_whitespace_char(line) {
|
||||
let tab_and_indent_width: usize = 4;
|
||||
if ignored_lines.iter().any(|range| range.contains(&(i + 1))) {
|
||||
continue;
|
||||
}
|
||||
if let Some(pos) = line.first_non_whitespace_char() {
|
||||
let tab_width: usize = 4;
|
||||
let suggested_indent = treesitter_indent_for_pos(
|
||||
indent_query,
|
||||
&syntax,
|
||||
&IndentStyle::Spaces(tab_and_indent_width as u8),
|
||||
tab_and_indent_width,
|
||||
tab_and_indent_width,
|
||||
tab_width,
|
||||
indent_style.indent_width(tab_width),
|
||||
text,
|
||||
i,
|
||||
text.line_to_char(i) + pos,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.to_string(&indent_style, tab_width);
|
||||
assert!(
|
||||
line.get_slice(..pos).map_or(false, |s| s == suggested_indent),
|
||||
"Wrong indentation on line {}:\n\"{}\" (original line)\n\"{}\" (suggested indentation)\n",
|
||||
"Wrong indentation for file {:?} on line {}:\n\"{}\" (original line)\n\"{}\" (suggested indentation)\n",
|
||||
test_name,
|
||||
i+1,
|
||||
line.slice(..line.len_chars()-1),
|
||||
suggested_indent,
|
||||
|
@ -1,25 +1,27 @@
|
||||
[package]
|
||||
name = "helix-dap"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2018"
|
||||
license = "MPL-2.0"
|
||||
description = "DAP client implementation for Helix project"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-core = { path = "../helix-core" }
|
||||
|
||||
anyhow = "1.0"
|
||||
log = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "net", "sync"] }
|
||||
which = "4.4"
|
||||
|
||||
[dev-dependencies]
|
||||
fern = "0.6"
|
||||
|
@ -2,14 +2,13 @@
|
||||
requests::DisconnectArguments,
|
||||
transport::{Payload, Request, Response, Transport},
|
||||
types::*,
|
||||
Error, Result, ThreadId,
|
||||
Error, Result,
|
||||
};
|
||||
use helix_core::syntax::DebuggerQuirks;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use anyhow::anyhow;
|
||||
pub use log::{error, info};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
future::Future,
|
||||
@ -114,7 +113,7 @@ pub fn stdio(
|
||||
id: usize,
|
||||
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
||||
// Resolve path to the binary
|
||||
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
|
||||
let cmd = helix_stdx::env::which(cmd)?;
|
||||
|
||||
let process = Command::new(cmd)
|
||||
.args(args)
|
||||
|
@ -19,6 +19,8 @@ pub enum Error {
|
||||
#[error("server closed the stream")]
|
||||
StreamClosed,
|
||||
#[error(transparent)]
|
||||
ExecutableNotFound(#[from] helix_stdx::env::ExecutableNotFoundError),
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
29
helix-event/Cargo.toml
Normal file
29
helix-event/Cargo.toml
Normal file
@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "helix-event"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.8.11"
|
||||
hashbrown = "0.14.0"
|
||||
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
|
||||
# setup new events on initialization, hardware-lock-elision hugely benefits this case
|
||||
# as it essentially makes the lock entirely free as long as there is no writes
|
||||
parking_lot = { version = "0.12", features = ["hardware-lock-elision"] }
|
||||
once_cell = "1.18"
|
||||
|
||||
anyhow = "1"
|
||||
log = "0.4"
|
||||
futures-executor = "0.3.28"
|
||||
|
||||
[features]
|
||||
integration_test = []
|
19
helix-event/src/cancel.rs
Normal file
19
helix-event/src/cancel.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use std::future::Future;
|
||||
|
||||
pub use oneshot::channel as cancelation;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
pub type CancelTx = oneshot::Sender<()>;
|
||||
pub type CancelRx = oneshot::Receiver<()>;
|
||||
|
||||
pub async fn cancelable_future<T>(future: impl Future<Output = T>, cancel: CancelRx) -> Option<T> {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = cancel => {
|
||||
None
|
||||
}
|
||||
res = future => {
|
||||
Some(res)
|
||||
}
|
||||
}
|
||||
}
|
67
helix-event/src/debounce.rs
Normal file
67
helix-event/src/debounce.rs
Normal file
@ -0,0 +1,67 @@
|
||||
//! Utilities for declaring an async (usually debounced) hook
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use futures_executor::block_on;
|
||||
use tokio::sync::mpsc::{self, error::TrySendError, Sender};
|
||||
use tokio::time::Instant;
|
||||
|
||||
/// Async hooks provide a convenient framework for implementing (debounced)
|
||||
/// async event handlers. Most synchronous event hooks will likely need to
|
||||
/// debounce their events, coordinate multiple different hooks and potentially
|
||||
/// track some state. `AsyncHooks` facilitate these use cases by running as
|
||||
/// a background tokio task that waits for events (usually an enum) to be
|
||||
/// sent through a channel.
|
||||
pub trait AsyncHook: Sync + Send + 'static + Sized {
|
||||
type Event: Sync + Send + 'static;
|
||||
/// Called immediately whenever an event is received, this function can
|
||||
/// consume the event immediately or debounce it. In case of debouncing,
|
||||
/// it can either define a new debounce timeout or continue the current one
|
||||
fn handle_event(&mut self, event: Self::Event, timeout: Option<Instant>) -> Option<Instant>;
|
||||
|
||||
/// Called whenever the debounce timeline is reached
|
||||
fn finish_debounce(&mut self);
|
||||
|
||||
fn spawn(self) -> mpsc::Sender<Self::Event> {
|
||||
// the capacity doesn't matter too much here, unless the cpu is totally overwhelmed
|
||||
// the cap will never be reached since we always immediately drain the channel
|
||||
// so it should only be reached in case of total CPU overload.
|
||||
// However, a bounded channel is much more efficient so it's nice to use here
|
||||
let (tx, rx) = mpsc::channel(128);
|
||||
tokio::spawn(run(self, rx));
|
||||
tx
|
||||
}
|
||||
}
|
||||
|
||||
async fn run<Hook: AsyncHook>(mut hook: Hook, mut rx: mpsc::Receiver<Hook::Event>) {
|
||||
let mut deadline = None;
|
||||
loop {
|
||||
let event = match deadline {
|
||||
Some(deadline_) => {
|
||||
let res = tokio::time::timeout_at(deadline_, rx.recv()).await;
|
||||
match res {
|
||||
Ok(event) => event,
|
||||
Err(_) => {
|
||||
hook.finish_debounce();
|
||||
deadline = None;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
None => rx.recv().await,
|
||||
};
|
||||
let Some(event) = event else {
|
||||
break;
|
||||
};
|
||||
deadline = hook.handle_event(event, deadline);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_blocking<T>(tx: &Sender<T>, data: T) {
|
||||
// block_on has some overhead and in practice the channel should basically
|
||||
// never be full anyway so first try sending without blocking
|
||||
if let Err(TrySendError::Full(data)) = tx.try_send(data) {
|
||||
// set a timeout so that we just drop a message instead of freezing the editor in the worst case
|
||||
let _ = block_on(tx.send_timeout(data, Duration::from_millis(10)));
|
||||
}
|
||||
}
|
91
helix-event/src/hook.rs
Normal file
91
helix-event/src/hook.rs
Normal file
@ -0,0 +1,91 @@
|
||||
//! rust dynamic dispatch is extremely limited so we have to build our
|
||||
//! own vtable implementation. Otherwise implementing the event system would not be possible.
|
||||
//! A nice bonus of this approach is that we can optimize the vtable a bit more. Normally
|
||||
//! a dyn Trait fat pointer contains two pointers: A pointer to the data itself and a
|
||||
//! pointer to a global (static) vtable entry which itself contains multiple other pointers
|
||||
//! (the various functions of the trait, drop, size and align). That makes dynamic
|
||||
//! dispatch pretty slow (double pointer indirections). However, we only have a single function
|
||||
//! in the hook trait and don't need a drop implementation (event system is global anyway
|
||||
//! and never dropped) so we can just store the entire vtable inline.
|
||||
|
||||
use anyhow::Result;
|
||||
use std::ptr::{self, NonNull};
|
||||
|
||||
use crate::Event;
|
||||
|
||||
/// Opaque handle type that represents an erased type parameter.
|
||||
///
|
||||
/// If extern types were stable, this could be implemented as `extern { pub type Opaque; }` but
|
||||
/// until then we can use this.
|
||||
///
|
||||
/// Care should be taken that we don't use a concrete instance of this. It should only be used
|
||||
/// through a reference, so we can maintain something else's lifetime.
|
||||
struct Opaque(());
|
||||
|
||||
pub(crate) struct ErasedHook {
|
||||
data: NonNull<Opaque>,
|
||||
call: unsafe fn(NonNull<Opaque>, NonNull<Opaque>, NonNull<Opaque>),
|
||||
}
|
||||
|
||||
impl ErasedHook {
|
||||
pub(crate) fn new_dynamic<H: Fn() -> Result<()> + 'static + Send + Sync>(
|
||||
hook: H,
|
||||
) -> ErasedHook {
|
||||
unsafe fn call<F: Fn() -> Result<()> + 'static + Send + Sync>(
|
||||
hook: NonNull<Opaque>,
|
||||
_event: NonNull<Opaque>,
|
||||
result: NonNull<Opaque>,
|
||||
) {
|
||||
let hook: NonNull<F> = hook.cast();
|
||||
let result: NonNull<Result<()>> = result.cast();
|
||||
let hook: &F = hook.as_ref();
|
||||
let res = hook();
|
||||
ptr::write(result.as_ptr(), res)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ErasedHook {
|
||||
data: NonNull::new_unchecked(Box::into_raw(Box::new(hook)) as *mut Opaque),
|
||||
call: call::<H>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new<E: Event, F: Fn(&mut E) -> Result<()>>(hook: F) -> ErasedHook {
|
||||
unsafe fn call<E: Event, F: Fn(&mut E) -> Result<()>>(
|
||||
hook: NonNull<Opaque>,
|
||||
event: NonNull<Opaque>,
|
||||
result: NonNull<Opaque>,
|
||||
) {
|
||||
let hook: NonNull<F> = hook.cast();
|
||||
let mut event: NonNull<E> = event.cast();
|
||||
let result: NonNull<Result<()>> = result.cast();
|
||||
let hook: &F = hook.as_ref();
|
||||
let res = hook(event.as_mut());
|
||||
ptr::write(result.as_ptr(), res)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ErasedHook {
|
||||
data: NonNull::new_unchecked(Box::into_raw(Box::new(hook)) as *mut Opaque),
|
||||
call: call::<E, F>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn call<E: Event>(&self, event: &mut E) -> Result<()> {
|
||||
let mut res = Ok(());
|
||||
|
||||
unsafe {
|
||||
(self.call)(
|
||||
self.data,
|
||||
NonNull::from(event).cast(),
|
||||
NonNull::from(&mut res).cast(),
|
||||
);
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ErasedHook {}
|
||||
unsafe impl Send for ErasedHook {}
|
203
helix-event/src/lib.rs
Normal file
203
helix-event/src/lib.rs
Normal file
@ -0,0 +1,203 @@
|
||||
//! `helix-event` contains systems that allow (often async) communication between
|
||||
//! different editor components without strongly coupling them. Specifically
|
||||
//! it allows defining synchronous hooks that run when certain editor events
|
||||
//! occur.
|
||||
//!
|
||||
//! The core of the event system are hook callbacks and the [`Event`] trait. A
|
||||
//! hook is essentially just a closure `Fn(event: &mut impl Event) -> Result<()>`
|
||||
//! that gets called every time an appropriate event is dispatched. The implementation
|
||||
//! details of the [`Event`] trait are considered private. The [`events`] macro is
|
||||
//! provided which automatically declares event types. Similarly the `register_hook`
|
||||
//! macro should be used to (safely) declare event hooks.
|
||||
//!
|
||||
//! Hooks run synchronously which can be advantageous since they can modify the
|
||||
//! current editor state right away (for example to immediately hide the completion
|
||||
//! popup). However, they can not contain their own state without locking since
|
||||
//! they only receive immutable references. For handler that want to track state, do
|
||||
//! expensive background computations or debouncing an [`AsyncHook`] is preferable.
|
||||
//! Async hooks are based around a channels that receive events specific to
|
||||
//! that `AsyncHook` (usually an enum). These events can be sent by synchronous
|
||||
//! hooks. Due to some limitations around tokio channels the [`send_blocking`]
|
||||
//! function exported in this crate should be used instead of the builtin
|
||||
//! `blocking_send`.
|
||||
//!
|
||||
//! In addition to the core event system, this crate contains some message queues
|
||||
//! that allow transfer of data back to the main event loop from async hooks and
|
||||
//! hooks that may not have access to all application data (for example in helix-view).
|
||||
//! This include the ability to control rendering ([`lock_frame`], [`request_redraw`]) and
|
||||
//! display status messages ([`status`]).
|
||||
//!
|
||||
//! Hooks declared in helix-term can furthermore dispatch synchronous jobs to be run on the
|
||||
//! main loop (including access to the compositor). Ideally that queue will be moved
|
||||
//! to helix-view in the future if we manage to detach the compositor from its rendering backend.
|
||||
|
||||
use anyhow::Result;
|
||||
pub use cancel::{cancelable_future, cancelation, CancelRx, CancelTx};
|
||||
pub use debounce::{send_blocking, AsyncHook};
|
||||
pub use redraw::{lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard};
|
||||
pub use registry::Event;
|
||||
|
||||
mod cancel;
|
||||
mod debounce;
|
||||
mod hook;
|
||||
mod redraw;
|
||||
mod registry;
|
||||
#[doc(hidden)]
|
||||
pub mod runtime;
|
||||
pub mod status;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
pub fn register_event<E: Event + 'static>() {
|
||||
registry::with_mut(|registry| registry.register_event::<E>())
|
||||
}
|
||||
|
||||
/// Registers a hook that will be called when an event of type `E` is dispatched.
|
||||
/// This function should usually not be used directly, use the [`register_hook`]
|
||||
/// macro instead.
|
||||
///
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `hook` must be totally generic over all lifetime parameters of `E`. For
|
||||
/// example if `E` was a known type `Foo<'a, 'b>`, then the correct trait bound
|
||||
/// would be `F: for<'a, 'b, 'c> Fn(&'a mut Foo<'b, 'c>)`, but there is no way to
|
||||
/// express that kind of constraint for a generic type with the Rust type system
|
||||
/// as of this writing.
|
||||
pub unsafe fn register_hook_raw<E: Event>(
|
||||
hook: impl Fn(&mut E) -> Result<()> + 'static + Send + Sync,
|
||||
) {
|
||||
registry::with_mut(|registry| registry.register_hook(hook))
|
||||
}
|
||||
|
||||
/// Register a hook solely by event name
|
||||
pub fn register_dynamic_hook(
|
||||
hook: impl Fn() -> Result<()> + 'static + Send + Sync,
|
||||
id: &str,
|
||||
) -> Result<()> {
|
||||
registry::with_mut(|reg| reg.register_dynamic_hook(hook, id))
|
||||
}
|
||||
|
||||
pub fn dispatch(e: impl Event) {
|
||||
registry::with(|registry| registry.dispatch(e));
|
||||
}
|
||||
|
||||
/// Macro to declare events
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ``` no-compile
|
||||
/// events! {
|
||||
/// FileWrite(&Path)
|
||||
/// ViewScrolled{ view: View, new_pos: ViewOffset }
|
||||
/// DocumentChanged<'a> { old_doc: &'a Rope, doc: &'a mut Document, changes: &'a ChangeSet }
|
||||
/// }
|
||||
///
|
||||
/// fn init() {
|
||||
/// register_event::<FileWrite>();
|
||||
/// register_event::<ViewScrolled>();
|
||||
/// register_event::<DocumentChanged>();
|
||||
/// }
|
||||
///
|
||||
/// fn save(path: &Path, content: &str){
|
||||
/// std::fs::write(path, content);
|
||||
/// dispatch(FileWrite(path));
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! events {
|
||||
($name: ident<$($lt: lifetime),*> { $($data:ident : $data_ty:ty),* } $($rem:tt)*) => {
|
||||
pub struct $name<$($lt),*> { $(pub $data: $data_ty),* }
|
||||
unsafe impl<$($lt),*> $crate::Event for $name<$($lt),*> {
|
||||
const ID: &'static str = stringify!($name);
|
||||
const LIFETIMES: usize = $crate::events!(@sum $(1, $lt),*);
|
||||
type Static = $crate::events!(@replace_lt $name, $('static, $lt),*);
|
||||
}
|
||||
$crate::events!{ $($rem)* }
|
||||
};
|
||||
($name: ident { $($data:ident : $data_ty:ty),* } $($rem:tt)*) => {
|
||||
pub struct $name { $(pub $data: $data_ty),* }
|
||||
unsafe impl $crate::Event for $name {
|
||||
const ID: &'static str = stringify!($name);
|
||||
const LIFETIMES: usize = 0;
|
||||
type Static = Self;
|
||||
}
|
||||
$crate::events!{ $($rem)* }
|
||||
};
|
||||
() => {};
|
||||
(@replace_lt $name: ident, $($lt1: lifetime, $lt2: lifetime),* ) => {$name<$($lt1),*>};
|
||||
(@sum $($val: expr, $lt1: lifetime),* ) => {0 $(+ $val)*};
|
||||
}
|
||||
|
||||
/// Safely register statically typed event hooks
|
||||
#[macro_export]
|
||||
macro_rules! register_hook {
|
||||
// Safety: this is safe because we fully control the type of the event here and
|
||||
// ensure all lifetime arguments are fully generic and the correct number of lifetime arguments
|
||||
// is present
|
||||
(move |$event:ident: &mut $event_ty: ident<$($lt: lifetime),*>| $body: expr) => {
|
||||
let val = move |$event: &mut $event_ty<$($lt),*>| $body;
|
||||
unsafe {
|
||||
// Lifetimes are a bit of a pain. We want to allow events being
|
||||
// non-static. Lifetimes don't actually exist at runtime so its
|
||||
// fine to essentially transmute the lifetimes as long as we can
|
||||
// prove soundness. The hook must therefore accept any combination
|
||||
// of lifetimes. In other words fn(&'_ mut Event<'_, '_>) is ok
|
||||
// but examples like fn(&'_ mut Event<'_, 'static>) or fn<'a>(&'a
|
||||
// mut Event<'a, 'a>) are not. To make this safe we use a macro to
|
||||
// forbid the user from specifying lifetimes manually (all lifetimes
|
||||
// specified are always function generics and passed to the event so
|
||||
// lifetimes can't be used multiple times and using 'static causes a
|
||||
// syntax error).
|
||||
//
|
||||
// There is one soundness hole tough: Type Aliases allow
|
||||
// "accidentally" creating these problems. For example:
|
||||
//
|
||||
// type Event2 = Event<'static>.
|
||||
// type Event2<'a> = Event<'a, a>.
|
||||
//
|
||||
// These cases can be caught by counting the number of lifetimes
|
||||
// parameters at the parameter declaration site and then at the hook
|
||||
// declaration site. By asserting the number of lifetime parameters
|
||||
// are equal we can catch all bad type aliases under one assumption:
|
||||
// There are no unused lifetime parameters. Introducing a static
|
||||
// would reduce the number of arguments of the alias by one in the
|
||||
// above example Event2 has zero lifetime arguments while the original
|
||||
// event has one lifetime argument. Similar logic applies to using
|
||||
// a lifetime argument multiple times. The ASSERT below performs a
|
||||
// a compile time assertion to ensure exactly this property.
|
||||
//
|
||||
// With unused lifetime arguments it is still one way to cause unsound code:
|
||||
//
|
||||
// type Event2<'a, 'b> = Event<'a, 'a>;
|
||||
//
|
||||
// However, this case will always emit a compiler warning/cause CI
|
||||
// failures so a user would have to introduce #[allow(unused)] which
|
||||
// is easily caught in review (and a very theoretical case anyway).
|
||||
// If we want to be pedantic we can simply compile helix with
|
||||
// forbid(unused). All of this is just a safety net to prevent
|
||||
// very theoretical misuse. This won't come up in real code (and is
|
||||
// easily caught in review).
|
||||
#[allow(unused)]
|
||||
const ASSERT: () = {
|
||||
if <$event_ty as $crate::Event>::LIFETIMES != 0 + $crate::events!(@sum $(1, $lt),*){
|
||||
panic!("invalid type alias");
|
||||
}
|
||||
};
|
||||
$crate::register_hook_raw::<$crate::events!(@replace_lt $event_ty, $('static, $lt),*)>(val);
|
||||
}
|
||||
};
|
||||
(move |$event:ident: &mut $event_ty: ident| $body: expr) => {
|
||||
let val = move |$event: &mut $event_ty| $body;
|
||||
unsafe {
|
||||
#[allow(unused)]
|
||||
const ASSERT: () = {
|
||||
if <$event_ty as $crate::Event>::LIFETIMES != 0{
|
||||
panic!("invalid type alias");
|
||||
}
|
||||
};
|
||||
$crate::register_hook_raw::<$event_ty>(val);
|
||||
}
|
||||
};
|
||||
}
|
53
helix-event/src/redraw.rs
Normal file
53
helix-event/src/redraw.rs
Normal file
@ -0,0 +1,53 @@
|
||||
//! Signals that control when/if the editor redraws
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
use crate::runtime_local;
|
||||
|
||||
runtime_local! {
|
||||
/// A `Notify` instance that can be used to (asynchronously) request
|
||||
/// the editor to render a new frame.
|
||||
static REDRAW_NOTIFY: Notify = Notify::const_new();
|
||||
|
||||
/// A `RwLock` that prevents the next frame from being
|
||||
/// drawn until an exclusive (write) lock can be acquired.
|
||||
/// This allows asynchronous tasks to acquire `non-exclusive`
|
||||
/// locks (read) to prevent the next frame from being drawn
|
||||
/// until a certain computation has finished.
|
||||
static RENDER_LOCK: RwLock<()> = RwLock::new(());
|
||||
}
|
||||
|
||||
pub type RenderLockGuard = RwLockReadGuard<'static, ()>;
|
||||
|
||||
/// Requests that the editor is redrawn. The redraws are debounced (currently to
|
||||
/// 30FPS) so this can be called many times without causing a ton of frames to
|
||||
/// be rendered.
|
||||
pub fn request_redraw() {
|
||||
REDRAW_NOTIFY.notify_one();
|
||||
}
|
||||
|
||||
/// Returns a future that will yield once a redraw has been asynchronously
|
||||
/// requested using [`request_redraw`].
|
||||
pub fn redraw_requested() -> impl Future<Output = ()> {
|
||||
REDRAW_NOTIFY.notified()
|
||||
}
|
||||
|
||||
/// Wait until all locks acquired with [`lock_frame`] have been released.
|
||||
/// This function is called before rendering and is intended to allow the frame
|
||||
/// to wait for async computations that should be included in the current frame.
|
||||
pub fn start_frame() {
|
||||
drop(RENDER_LOCK.write());
|
||||
// exhaust any leftover redraw notifications
|
||||
let notify = REDRAW_NOTIFY.notified();
|
||||
tokio::pin!(notify);
|
||||
notify.enable();
|
||||
}
|
||||
|
||||
/// Acquires the render lock which will prevent the next frame from being drawn
|
||||
/// until the returned guard is dropped.
|
||||
pub fn lock_frame() -> RenderLockGuard {
|
||||
RENDER_LOCK.read()
|
||||
}
|
131
helix-event/src/registry.rs
Normal file
131
helix-event/src/registry.rs
Normal file
@ -0,0 +1,131 @@
|
||||
//! A global registry where events are registered and can be
|
||||
//! subscribed to by registering hooks. The registry identifies event
|
||||
//! types using their type name so multiple event with the same type name
|
||||
//! may not be registered (will cause a panic to ensure soundness)
|
||||
|
||||
use std::any::TypeId;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use hashbrown::hash_map::Entry;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::hook::ErasedHook;
|
||||
use crate::runtime_local;
|
||||
|
||||
pub struct Registry {
|
||||
events: HashMap<&'static str, TypeId, ahash::RandomState>,
|
||||
handlers: HashMap<&'static str, Vec<ErasedHook>, ahash::RandomState>,
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn register_event<E: Event + 'static>(&mut self) {
|
||||
let ty = TypeId::of::<E>();
|
||||
assert_eq!(ty, TypeId::of::<E::Static>());
|
||||
match self.events.entry(E::ID) {
|
||||
Entry::Occupied(entry) => {
|
||||
if entry.get() == &ty {
|
||||
// don't warn during tests to avoid log spam
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
panic!("Event {} was registered multiple times", E::ID);
|
||||
} else {
|
||||
panic!("Multiple events with ID {} were registered", E::ID);
|
||||
}
|
||||
}
|
||||
Entry::Vacant(ent) => {
|
||||
ent.insert(ty);
|
||||
self.handlers.insert(E::ID, Vec::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// `hook` must be totally generic over all lifetime parameters of `E`. For
|
||||
/// example if `E` was a known type `Foo<'a, 'b> then the correct trait bound
|
||||
/// would be `F: for<'a, 'b, 'c> Fn(&'a mut Foo<'b, 'c>)` but there is no way to
|
||||
/// express that kind of constraint for a generic type with the rust type system
|
||||
/// right now.
|
||||
pub unsafe fn register_hook<E: Event>(
|
||||
&mut self,
|
||||
hook: impl Fn(&mut E) -> Result<()> + 'static + Send + Sync,
|
||||
) {
|
||||
// ensure event type ids match so we can rely on them always matching
|
||||
let id = E::ID;
|
||||
let Some(&event_id) = self.events.get(id) else {
|
||||
panic!("Tried to register handler for unknown event {id}");
|
||||
};
|
||||
assert!(
|
||||
TypeId::of::<E::Static>() == event_id,
|
||||
"Tried to register invalid hook for event {id}"
|
||||
);
|
||||
let hook = ErasedHook::new(hook);
|
||||
self.handlers.get_mut(id).unwrap().push(hook);
|
||||
}
|
||||
|
||||
pub fn register_dynamic_hook(
|
||||
&mut self,
|
||||
hook: impl Fn() -> Result<()> + 'static + Send + Sync,
|
||||
id: &str,
|
||||
) -> Result<()> {
|
||||
// ensure event type ids match so we can rely on them always matching
|
||||
if self.events.get(id).is_none() {
|
||||
bail!("Tried to register handler for unknown event {id}");
|
||||
};
|
||||
let hook = ErasedHook::new_dynamic(hook);
|
||||
self.handlers.get_mut(id).unwrap().push(hook);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dispatch<E: Event>(&self, mut event: E) {
|
||||
let Some(hooks) = self.handlers.get(E::ID) else {
|
||||
log::error!("Dispatched unknown event {}", E::ID);
|
||||
return;
|
||||
};
|
||||
let event_id = self.events[E::ID];
|
||||
|
||||
assert_eq!(
|
||||
TypeId::of::<E::Static>(),
|
||||
event_id,
|
||||
"Tried to dispatch invalid event {}",
|
||||
E::ID
|
||||
);
|
||||
|
||||
for hook in hooks {
|
||||
// safety: event type is the same
|
||||
if let Err(err) = unsafe { hook.call(&mut event) } {
|
||||
log::error!("{} hook failed: {err:#?}", E::ID);
|
||||
crate::status::report_blocking(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtime_local! {
|
||||
static REGISTRY: RwLock<Registry> = RwLock::new(Registry {
|
||||
// hardcoded random number is good enough here we don't care about DOS resistance
|
||||
// and avoids the additional complexity of `Option<Registry>`
|
||||
events: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 9978, 38322, 3280080)),
|
||||
handlers: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 99078, 382322, 3282938)),
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn with<T>(f: impl FnOnce(&Registry) -> T) -> T {
|
||||
f(®ISTRY.read())
|
||||
}
|
||||
|
||||
pub(crate) fn with_mut<T>(f: impl FnOnce(&mut Registry) -> T) -> T {
|
||||
f(&mut REGISTRY.write())
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// The number of specified lifetimes and the static type *must* be correct.
|
||||
/// This is ensured automatically by the [`events`](crate::events)
|
||||
/// macro.
|
||||
pub unsafe trait Event: Sized {
|
||||
/// Globally unique (case sensitive) string that identifies this type.
|
||||
/// A good candidate is the events type name
|
||||
const ID: &'static str;
|
||||
const LIFETIMES: usize;
|
||||
type Static: Event + 'static;
|
||||
}
|
88
helix-event/src/runtime.rs
Normal file
88
helix-event/src/runtime.rs
Normal file
@ -0,0 +1,88 @@
|
||||
//! The event system makes use of global to decouple different systems.
|
||||
//! However, this can cause problems for the integration test system because
|
||||
//! it runs multiple helix applications in parallel. Making the globals
|
||||
//! thread-local does not work because a applications can/does have multiple
|
||||
//! runtime threads. Instead this crate implements a similar notion to a thread
|
||||
//! local but instead of being local to a single thread, the statics are local to
|
||||
//! a single tokio-runtime. The implementation requires locking so it's not exactly efficient.
|
||||
//!
|
||||
//! Therefore this function is only enabled during integration tests and behaves like
|
||||
//! a normal static otherwise. I would prefer this module to be fully private and to only
|
||||
//! export the macro but the macro still need to construct these internals so it's marked
|
||||
//! `doc(hidden)` instead
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
pub struct RuntimeLocal<T: 'static> {
|
||||
/// inner API used in the macro, not part of public API
|
||||
#[doc(hidden)]
|
||||
pub __data: T,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
impl<T> Deref for RuntimeLocal<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.__data
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
#[macro_export]
|
||||
macro_rules! runtime_local {
|
||||
($($(#[$attr:meta])* $vis: vis static $name:ident: $ty: ty = $init: expr;)*) => {
|
||||
$($(#[$attr])* $vis static $name: $crate::runtime::RuntimeLocal<$ty> = $crate::runtime::RuntimeLocal {
|
||||
__data: $init
|
||||
};)*
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
pub struct RuntimeLocal<T: 'static> {
|
||||
data:
|
||||
parking_lot::RwLock<hashbrown::HashMap<tokio::runtime::Id, &'static T, ahash::RandomState>>,
|
||||
init: fn() -> T,
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
impl<T> RuntimeLocal<T> {
|
||||
/// inner API used in the macro, not part of public API
|
||||
#[doc(hidden)]
|
||||
pub const fn __new(init: fn() -> T) -> Self {
|
||||
Self {
|
||||
data: parking_lot::RwLock::new(hashbrown::HashMap::with_hasher(
|
||||
ahash::RandomState::with_seeds(423, 9978, 38322, 3280080),
|
||||
)),
|
||||
init,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
impl<T> Deref for RuntimeLocal<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
let id = tokio::runtime::Handle::current().id();
|
||||
let guard = self.data.read();
|
||||
match guard.get(&id) {
|
||||
Some(res) => res,
|
||||
None => {
|
||||
drop(guard);
|
||||
let data = Box::leak(Box::new((self.init)()));
|
||||
let mut guard = self.data.write();
|
||||
guard.insert(id, data);
|
||||
data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
#[macro_export]
|
||||
macro_rules! runtime_local {
|
||||
($($(#[$attr:meta])* $vis: vis static $name:ident: $ty: ty = $init: expr;)*) => {
|
||||
$($(#[$attr])* $vis static $name: $crate::runtime::RuntimeLocal<$ty> = $crate::runtime::RuntimeLocal::__new(|| $init);)*
|
||||
};
|
||||
}
|
68
helix-event/src/status.rs
Normal file
68
helix-event/src/status.rs
Normal file
@ -0,0 +1,68 @@
|
||||
//! A queue of async messages/errors that will be shown in the editor
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{runtime_local, send_blocking};
|
||||
use once_cell::sync::OnceCell;
|
||||
use tokio::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
/// Describes the severity level of a [`StatusMessage`].
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)]
|
||||
pub enum Severity {
|
||||
Hint,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
}
|
||||
|
||||
pub struct StatusMessage {
|
||||
pub severity: Severity,
|
||||
pub message: Cow<'static, str>,
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for StatusMessage {
|
||||
fn from(err: anyhow::Error) -> Self {
|
||||
StatusMessage {
|
||||
severity: Severity::Error,
|
||||
message: err.to_string().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for StatusMessage {
|
||||
fn from(msg: &'static str) -> Self {
|
||||
StatusMessage {
|
||||
severity: Severity::Info,
|
||||
message: msg.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtime_local! {
|
||||
static MESSAGES: OnceCell<Sender<StatusMessage>> = OnceCell::new();
|
||||
}
|
||||
|
||||
pub async fn report(msg: impl Into<StatusMessage>) {
|
||||
// if the error channel overflows just ignore it
|
||||
let _ = MESSAGES
|
||||
.wait()
|
||||
.send_timeout(msg.into(), Duration::from_millis(10))
|
||||
.await;
|
||||
}
|
||||
|
||||
pub fn report_blocking(msg: impl Into<StatusMessage>) {
|
||||
let messages = MESSAGES.wait();
|
||||
send_blocking(messages, msg.into())
|
||||
}
|
||||
|
||||
/// Must be called once during editor startup exactly once
|
||||
/// before any of the messages in this module can be used
|
||||
///
|
||||
/// # Panics
|
||||
/// If called multiple times
|
||||
pub fn setup() -> Receiver<StatusMessage> {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(128);
|
||||
let _ = MESSAGES.set(tx);
|
||||
rx
|
||||
}
|
90
helix-event/src/test.rs
Normal file
90
helix-event/src/test.rs
Normal file
@ -0,0 +1,90 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{dispatch, events, register_dynamic_hook, register_event, register_hook};
|
||||
#[test]
|
||||
fn smoke_test() {
|
||||
events! {
|
||||
Event1 { content: String }
|
||||
Event2 { content: usize }
|
||||
}
|
||||
register_event::<Event1>();
|
||||
register_event::<Event2>();
|
||||
|
||||
// setup hooks
|
||||
let res1: Arc<Mutex<String>> = Arc::default();
|
||||
let acc = Arc::clone(&res1);
|
||||
register_hook!(move |event: &mut Event1| {
|
||||
acc.lock().push_str(&event.content);
|
||||
Ok(())
|
||||
});
|
||||
let res2: Arc<AtomicUsize> = Arc::default();
|
||||
let acc = Arc::clone(&res2);
|
||||
register_hook!(move |event: &mut Event2| {
|
||||
acc.fetch_add(event.content, Ordering::Relaxed);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
// triggers events
|
||||
let thread = std::thread::spawn(|| {
|
||||
for i in 0..1000 {
|
||||
dispatch(Event2 { content: i });
|
||||
}
|
||||
});
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
dispatch(Event1 {
|
||||
content: "foo".to_owned(),
|
||||
});
|
||||
dispatch(Event2 { content: 42 });
|
||||
dispatch(Event1 {
|
||||
content: "bar".to_owned(),
|
||||
});
|
||||
dispatch(Event1 {
|
||||
content: "hello world".to_owned(),
|
||||
});
|
||||
thread.join().unwrap();
|
||||
|
||||
// check output
|
||||
assert_eq!(&**res1.lock(), "foobarhello world");
|
||||
assert_eq!(
|
||||
res2.load(Ordering::Relaxed),
|
||||
42 + (0..1000usize).sum::<usize>()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic() {
|
||||
events! {
|
||||
Event3 {}
|
||||
Event4 { count: usize }
|
||||
};
|
||||
register_event::<Event3>();
|
||||
register_event::<Event4>();
|
||||
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let count1 = count.clone();
|
||||
let count2 = count.clone();
|
||||
register_dynamic_hook(
|
||||
move || {
|
||||
count1.fetch_add(2, Ordering::Relaxed);
|
||||
Ok(())
|
||||
},
|
||||
"Event3",
|
||||
)
|
||||
.unwrap();
|
||||
register_dynamic_hook(
|
||||
move || {
|
||||
count2.fetch_add(3, Ordering::Relaxed);
|
||||
Ok(())
|
||||
},
|
||||
"Event4",
|
||||
)
|
||||
.unwrap();
|
||||
dispatch(Event3 {});
|
||||
dispatch(Event4 { count: 0 });
|
||||
dispatch(Event3 {});
|
||||
assert_eq!(count.load(Ordering::Relaxed), 7)
|
||||
}
|
@ -1,25 +1,28 @@
|
||||
[package]
|
||||
name = "helix-loader"
|
||||
version = "0.6.0"
|
||||
description = "A post-modern text editor."
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
description = "Build bootstrapping for Helix crates"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "hx-loader"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
|
||||
anyhow = "1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.7"
|
||||
toml = "0.8"
|
||||
etcetera = "0.8"
|
||||
tree-sitter = "0.20"
|
||||
once_cell = "1.17"
|
||||
tree-sitter.workspace = true
|
||||
once_cell = "1.19"
|
||||
log = "0.4"
|
||||
|
||||
# TODO: these two should be on !wasm32 only
|
||||
@ -27,7 +30,8 @@ log = "0.4"
|
||||
# cloning/compiling tree-sitter grammars
|
||||
cc = { version = "1" }
|
||||
threadpool = { version = "1.0" }
|
||||
tempfile = "3.5.0"
|
||||
tempfile = "3.10.1"
|
||||
dunce = "1.0.4"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
libloading = "0.8"
|
||||
|
@ -2,7 +2,17 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
const VERSION: &str = include_str!("../VERSION");
|
||||
const MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
|
||||
const MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
|
||||
const PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
|
||||
|
||||
fn get_calver() -> String {
|
||||
if PATCH == "0" {
|
||||
format!("{MAJOR}.{MINOR}")
|
||||
} else {
|
||||
format!("{MAJOR}.{MINOR}.{PATCH}")
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let git_hash = Command::new("git")
|
||||
@ -12,9 +22,10 @@ fn main() {
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|x| String::from_utf8(x.stdout).ok());
|
||||
|
||||
let calver = get_calver();
|
||||
let version: Cow<_> = match &git_hash {
|
||||
Some(git_hash) => format!("{} ({})", VERSION, &git_hash[..8]).into(),
|
||||
None => VERSION.into(),
|
||||
Some(git_hash) => format!("{} ({})", calver, &git_hash[..8]).into(),
|
||||
None => calver.into(),
|
||||
};
|
||||
|
||||
println!(
|
||||
@ -22,7 +33,6 @@ fn main() {
|
||||
std::env::var("TARGET").unwrap()
|
||||
);
|
||||
|
||||
println!("cargo:rerun-if-changed=../VERSION");
|
||||
println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
|
||||
|
||||
if git_hash.is_none() {
|
||||
@ -40,7 +50,9 @@ fn main() {
|
||||
.ok()
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|x| String::from_utf8(x.stdout).ok())
|
||||
else{ return; };
|
||||
else {
|
||||
return;
|
||||
};
|
||||
// If heads starts pointing at something else (different branch)
|
||||
// we need to return
|
||||
let head = Path::new(&git_dir).join("HEAD");
|
||||
@ -55,7 +67,9 @@ fn main() {
|
||||
.ok()
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|x| String::from_utf8(x.stdout).ok())
|
||||
else{ return; };
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let head_ref = Path::new(&git_dir).join(head_ref);
|
||||
if head_ref.exists() {
|
||||
println!("cargo:rerun-if-changed={}", head_ref.display());
|
||||
|
@ -85,7 +85,14 @@ pub fn get_language(name: &str) -> Result<Language> {
|
||||
Ok(language)
|
||||
}
|
||||
|
||||
fn ensure_git_is_available() -> Result<()> {
|
||||
helix_stdx::env::which("git")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn fetch_grammars() -> Result<()> {
|
||||
ensure_git_is_available()?;
|
||||
|
||||
// We do not need to fetch local grammars.
|
||||
let mut grammars = get_grammar_configs()?;
|
||||
grammars.retain(|grammar| !matches!(grammar.source, GrammarSource::Local { .. }));
|
||||
@ -145,6 +152,8 @@ pub fn fetch_grammars() -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn build_grammars(target: Option<String>) -> Result<()> {
|
||||
ensure_git_is_available()?;
|
||||
|
||||
let grammars = get_grammar_configs()?;
|
||||
println!("Building {} grammars", grammars.len());
|
||||
let results = run_parallel(grammars, move |grammar| {
|
||||
|
@ -1,6 +1,8 @@
|
||||
pub mod config;
|
||||
pub mod grammar;
|
||||
|
||||
use helix_stdx::{env::current_working_dir, path};
|
||||
|
||||
use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -11,21 +13,20 @@
|
||||
|
||||
static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
|
||||
|
||||
static LOG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
|
||||
|
||||
pub fn initialize_config_file(specified_file: Option<PathBuf>) {
|
||||
let config_file = specified_file.unwrap_or_else(|| {
|
||||
let config_dir = config_dir();
|
||||
|
||||
if !config_dir.exists() {
|
||||
std::fs::create_dir_all(&config_dir).ok();
|
||||
}
|
||||
|
||||
config_dir.join("config.toml")
|
||||
});
|
||||
|
||||
// We should only initialize this value once.
|
||||
let config_file = specified_file.unwrap_or_else(default_config_file);
|
||||
ensure_parent_dir(&config_file);
|
||||
CONFIG_FILE.set(config_file).ok();
|
||||
}
|
||||
|
||||
pub fn initialize_log_file(specified_file: Option<PathBuf>) {
|
||||
let log_file = specified_file.unwrap_or_else(default_log_file);
|
||||
ensure_parent_dir(&log_file);
|
||||
LOG_FILE.set(log_file).ok();
|
||||
}
|
||||
|
||||
/// A list of runtime directories from highest to lowest priority
|
||||
///
|
||||
/// The priority is:
|
||||
@ -33,7 +34,8 @@ pub fn initialize_config_file(specified_file: Option<PathBuf>) {
|
||||
/// 1. sibling directory to `CARGO_MANIFEST_DIR` (if environment variable is set)
|
||||
/// 2. subdirectory of user config directory (always included)
|
||||
/// 3. `HELIX_RUNTIME` (if environment variable is set)
|
||||
/// 4. subdirectory of path to helix executable (always included)
|
||||
/// 4. `HELIX_DEFAULT_RUNTIME` (if environment variable is set *at build time*)
|
||||
/// 5. subdirectory of path to helix executable (always included)
|
||||
///
|
||||
/// Postcondition: returns at least two paths (they might not exist).
|
||||
fn prioritize_runtime_dirs() -> Vec<PathBuf> {
|
||||
@ -51,6 +53,15 @@ fn prioritize_runtime_dirs() -> Vec<PathBuf> {
|
||||
rt_dirs.push(conf_rt_dir);
|
||||
|
||||
if let Ok(dir) = std::env::var("HELIX_RUNTIME") {
|
||||
let dir = path::expand_tilde(Path::new(&dir));
|
||||
rt_dirs.push(path::normalize(dir));
|
||||
}
|
||||
|
||||
// If this variable is set during build time, it will always be included
|
||||
// in the lookup list. This allows downstream packagers to set a fallback
|
||||
// directory to a location that is conventional on their distro so that they
|
||||
// need not resort to a wrapper script or a global environment variable.
|
||||
if let Some(dir) = std::option_env!("HELIX_DEFAULT_RUNTIME") {
|
||||
rt_dirs.push(dir.into());
|
||||
}
|
||||
|
||||
@ -115,17 +126,18 @@ pub fn config_dir() -> PathBuf {
|
||||
|
||||
pub fn cache_dir() -> PathBuf {
|
||||
// TODO: allow env var override
|
||||
let strategy = choose_base_strategy().expect("Unable to find the config directory!");
|
||||
let strategy = choose_base_strategy().expect("Unable to find the cache directory!");
|
||||
let mut path = strategy.cache_dir();
|
||||
path.push("helix");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn config_file() -> PathBuf {
|
||||
CONFIG_FILE
|
||||
.get()
|
||||
.map(|path| path.to_path_buf())
|
||||
.unwrap_or_else(|| config_dir().join("config.toml"))
|
||||
CONFIG_FILE.get().map(|path| path.to_path_buf()).unwrap()
|
||||
}
|
||||
|
||||
pub fn log_file() -> PathBuf {
|
||||
LOG_FILE.get().map(|path| path.to_path_buf()).unwrap()
|
||||
}
|
||||
|
||||
pub fn workspace_config_file() -> PathBuf {
|
||||
@ -136,7 +148,7 @@ pub fn lang_config_file() -> PathBuf {
|
||||
config_dir().join("languages.toml")
|
||||
}
|
||||
|
||||
pub fn log_file() -> PathBuf {
|
||||
pub fn default_log_file() -> PathBuf {
|
||||
cache_dir().join("helix.log")
|
||||
}
|
||||
|
||||
@ -217,7 +229,7 @@ fn get_name(v: &Value) -> Option<&str> {
|
||||
/// If no workspace was found returns (CWD, true).
|
||||
/// Otherwise (workspace, false) is returned
|
||||
pub fn find_workspace() -> (PathBuf, bool) {
|
||||
let current_dir = std::env::current_dir().expect("unable to determine current directory");
|
||||
let current_dir = current_working_dir();
|
||||
for ancestor in current_dir.ancestors() {
|
||||
if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
|
||||
return (ancestor.to_owned(), false);
|
||||
@ -227,6 +239,18 @@ pub fn find_workspace() -> (PathBuf, bool) {
|
||||
(current_dir, true)
|
||||
}
|
||||
|
||||
fn default_config_file() -> PathBuf {
|
||||
config_dir().join("config.toml")
|
||||
}
|
||||
|
||||
fn ensure_parent_dir(path: &Path) {
|
||||
if let Some(parent) = path.parent() {
|
||||
if !parent.exists() {
|
||||
std::fs::create_dir_all(parent).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod merge_toml_tests {
|
||||
use std::str;
|
||||
|
@ -1,30 +1,33 @@
|
||||
[package]
|
||||
name = "helix-lsp"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
description = "LSP client implementation for Helix project"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-loader = { version = "0.6", path = "../helix-loader" }
|
||||
helix-parsec = { version = "0.6", path = "../helix-parsec" }
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-core = { path = "../helix-core" }
|
||||
helix-loader = { path = "../helix-loader" }
|
||||
helix-parsec = { path = "../helix-parsec" }
|
||||
|
||||
anyhow = "1.0"
|
||||
futures-executor = "0.3"
|
||||
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
|
||||
globset = "0.4.14"
|
||||
log = "0.4"
|
||||
lsp-types = { version = "0.94" }
|
||||
lsp-types = { version = "0.95" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1.28", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
|
||||
tokio-stream = "0.1.14"
|
||||
which = "4.4"
|
||||
tokio = { version = "1.37", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
|
||||
tokio-stream = "0.1.15"
|
||||
parking_lot = "0.12.1"
|
||||
arc-swap = "1"
|
||||
|
@ -1,26 +1,29 @@
|
||||
use crate::{
|
||||
file_operations::FileOperationsInterest,
|
||||
find_lsp_workspace, jsonrpc,
|
||||
transport::{Payload, Transport},
|
||||
Call, Error, OffsetEncoding, Result,
|
||||
};
|
||||
|
||||
use helix_core::{find_workspace, path, syntax::LanguageServerFeature, ChangeSet, Rope};
|
||||
use helix_loader::{self, VERSION_AND_GIT_HASH};
|
||||
use helix_core::{find_workspace, syntax::LanguageServerFeature, ChangeSet, Rope};
|
||||
use helix_loader::VERSION_AND_GIT_HASH;
|
||||
use helix_stdx::path;
|
||||
use lsp::{
|
||||
notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
|
||||
PositionEncodingKind, WorkspaceFolder, WorkspaceFoldersChangeEvent,
|
||||
notification::DidChangeWorkspaceFolders, CodeActionCapabilityResolveSupport,
|
||||
DidChangeWorkspaceFoldersParams, OneOf, PositionEncodingKind, SignatureHelp, Url,
|
||||
WorkspaceFolder, WorkspaceFoldersChangeEvent,
|
||||
};
|
||||
use lsp_types as lsp;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use std::future::Future;
|
||||
use std::process::Stdio;
|
||||
use std::sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::{future::Future, sync::OnceLock};
|
||||
use std::{path::Path, process::Stdio};
|
||||
use tokio::{
|
||||
io::{BufReader, BufWriter},
|
||||
process::{Child, Command},
|
||||
@ -49,6 +52,7 @@ pub struct Client {
|
||||
server_tx: UnboundedSender<Payload>,
|
||||
request_counter: AtomicU64,
|
||||
pub(crate) capabilities: OnceCell<lsp::ServerCapabilities>,
|
||||
pub(crate) file_operation_interest: OnceLock<FileOperationsInterest>,
|
||||
config: Option<Value>,
|
||||
root_path: std::path::PathBuf,
|
||||
root_uri: Option<lsp::Url>,
|
||||
@ -67,7 +71,7 @@ pub fn try_add_doc(
|
||||
may_support_workspace: bool,
|
||||
) -> bool {
|
||||
let (workspace, workspace_is_cwd) = find_workspace();
|
||||
let workspace = path::get_normalized_path(&workspace);
|
||||
let workspace = path::normalize(workspace);
|
||||
let root = find_lsp_workspace(
|
||||
doc_path
|
||||
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
||||
@ -173,15 +177,14 @@ pub fn start(
|
||||
args: &[String],
|
||||
config: Option<Value>,
|
||||
server_environment: HashMap<String, String>,
|
||||
root_markers: &[String],
|
||||
manual_roots: &[PathBuf],
|
||||
root_path: PathBuf,
|
||||
root_uri: Option<lsp::Url>,
|
||||
id: usize,
|
||||
name: String,
|
||||
req_timeout: u64,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
|
||||
// Resolve path to the binary
|
||||
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
|
||||
let cmd = helix_stdx::env::which(cmd)?;
|
||||
|
||||
let process = Command::new(cmd)
|
||||
.envs(server_environment)
|
||||
@ -202,22 +205,6 @@ pub fn start(
|
||||
|
||||
let (server_rx, server_tx, initialize_notify) =
|
||||
Transport::start(reader, writer, stderr, id, name.clone());
|
||||
let (workspace, workspace_is_cwd) = find_workspace();
|
||||
let workspace = path::get_normalized_path(&workspace);
|
||||
let root = find_lsp_workspace(
|
||||
doc_path
|
||||
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
||||
.unwrap_or("."),
|
||||
root_markers,
|
||||
manual_roots,
|
||||
&workspace,
|
||||
workspace_is_cwd,
|
||||
);
|
||||
|
||||
// `root_uri` and `workspace_folder` can be empty in case there is no workspace
|
||||
// `root_url` can not, use `workspace` as a fallback
|
||||
let root_path = root.clone().unwrap_or_else(|| workspace.clone());
|
||||
let root_uri = root.and_then(|root| lsp::Url::from_file_path(root).ok());
|
||||
|
||||
let workspace_folders = root_uri
|
||||
.clone()
|
||||
@ -231,6 +218,7 @@ pub fn start(
|
||||
server_tx,
|
||||
request_counter: AtomicU64::new(0),
|
||||
capabilities: OnceCell::new(),
|
||||
file_operation_interest: OnceLock::new(),
|
||||
config,
|
||||
req_timeout,
|
||||
root_path,
|
||||
@ -276,6 +264,11 @@ pub fn capabilities(&self) -> &lsp::ServerCapabilities {
|
||||
.expect("language server not yet initialized!")
|
||||
}
|
||||
|
||||
pub(crate) fn file_operations_intests(&self) -> &FileOperationsInterest {
|
||||
self.file_operation_interest
|
||||
.get_or_init(|| FileOperationsInterest::new(self.capabilities()))
|
||||
}
|
||||
|
||||
/// Client has to be initialized otherwise this function panics
|
||||
#[inline]
|
||||
pub fn supports_feature(&self, feature: LanguageServerFeature) -> bool {
|
||||
@ -400,12 +393,22 @@ fn call<R: lsp::request::Request>(
|
||||
&self,
|
||||
params: R::Params,
|
||||
) -> impl Future<Output = Result<Value>>
|
||||
where
|
||||
R::Params: serde::Serialize,
|
||||
{
|
||||
self.call_with_timeout::<R>(params, self.req_timeout)
|
||||
}
|
||||
|
||||
fn call_with_timeout<R: lsp::request::Request>(
|
||||
&self,
|
||||
params: R::Params,
|
||||
timeout_secs: u64,
|
||||
) -> impl Future<Output = Result<Value>>
|
||||
where
|
||||
R::Params: serde::Serialize,
|
||||
{
|
||||
let server_tx = self.server_tx.clone();
|
||||
let id = self.next_request_id();
|
||||
let timeout_secs = self.req_timeout;
|
||||
|
||||
async move {
|
||||
use std::time::Duration;
|
||||
@ -543,6 +546,15 @@ pub(crate) async fn initialize(&self, enable_snippets: bool) -> Result<lsp::Init
|
||||
normalizes_line_endings: Some(false),
|
||||
change_annotation_support: None,
|
||||
}),
|
||||
did_change_watched_files: Some(lsp::DidChangeWatchedFilesClientCapabilities {
|
||||
dynamic_registration: Some(true),
|
||||
relative_pattern_support: Some(false),
|
||||
}),
|
||||
file_operations: Some(lsp::WorkspaceFileOperationsClientCapabilities {
|
||||
will_rename: Some(true),
|
||||
did_rename: Some(true),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
text_document: Some(lsp::TextDocumentClientCapabilities {
|
||||
@ -609,10 +621,22 @@ pub(crate) async fn initialize(&self, enable_snippets: bool) -> Result<lsp::Init
|
||||
.collect(),
|
||||
},
|
||||
}),
|
||||
is_preferred_support: Some(true),
|
||||
disabled_support: Some(true),
|
||||
data_support: Some(true),
|
||||
resolve_support: Some(CodeActionCapabilityResolveSupport {
|
||||
properties: vec!["edit".to_owned(), "command".to_owned()],
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
|
||||
version_support: Some(true),
|
||||
tag_support: Some(lsp::TagSupport {
|
||||
value_set: vec![
|
||||
lsp::DiagnosticTag::UNNECESSARY,
|
||||
lsp::DiagnosticTag::DEPRECATED,
|
||||
],
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
inlay_hint: Some(lsp::InlayHintClientCapabilities {
|
||||
@ -641,6 +665,7 @@ pub(crate) async fn initialize(&self, enable_snippets: bool) -> Result<lsp::Init
|
||||
version: Some(String::from(VERSION_AND_GIT_HASH)),
|
||||
}),
|
||||
locale: None, // TODO
|
||||
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
|
||||
};
|
||||
|
||||
self.request::<lsp::request::Initialize>(params).await
|
||||
@ -689,6 +714,66 @@ pub fn did_change_workspace(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn will_rename(
|
||||
&self,
|
||||
old_path: &Path,
|
||||
new_path: &Path,
|
||||
is_dir: bool,
|
||||
) -> Option<impl Future<Output = Result<lsp::WorkspaceEdit>>> {
|
||||
let capabilities = self.file_operations_intests();
|
||||
if !capabilities.will_rename.has_interest(old_path, is_dir) {
|
||||
return None;
|
||||
}
|
||||
let url_from_path = |path| {
|
||||
let url = if is_dir {
|
||||
Url::from_directory_path(path)
|
||||
} else {
|
||||
Url::from_file_path(path)
|
||||
};
|
||||
Some(url.ok()?.to_string())
|
||||
};
|
||||
let files = vec![lsp::FileRename {
|
||||
old_uri: url_from_path(old_path)?,
|
||||
new_uri: url_from_path(new_path)?,
|
||||
}];
|
||||
let request = self.call_with_timeout::<lsp::request::WillRenameFiles>(
|
||||
lsp::RenameFilesParams { files },
|
||||
5,
|
||||
);
|
||||
|
||||
Some(async move {
|
||||
let json = request.await?;
|
||||
let response: Option<lsp::WorkspaceEdit> = serde_json::from_value(json)?;
|
||||
Ok(response.unwrap_or_default())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn did_rename(
|
||||
&self,
|
||||
old_path: &Path,
|
||||
new_path: &Path,
|
||||
is_dir: bool,
|
||||
) -> Option<impl Future<Output = std::result::Result<(), Error>>> {
|
||||
let capabilities = self.file_operations_intests();
|
||||
if !capabilities.did_rename.has_interest(new_path, is_dir) {
|
||||
return None;
|
||||
}
|
||||
let url_from_path = |path| {
|
||||
let url = if is_dir {
|
||||
Url::from_directory_path(path)
|
||||
} else {
|
||||
Url::from_file_path(path)
|
||||
};
|
||||
Some(url.ok()?.to_string())
|
||||
};
|
||||
|
||||
let files = vec![lsp::FileRename {
|
||||
old_uri: url_from_path(old_path)?,
|
||||
new_uri: url_from_path(new_path)?,
|
||||
}];
|
||||
Some(self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files }))
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
// Text document
|
||||
// -------------------------------------------------------------------------------------------
|
||||
@ -884,20 +969,19 @@ pub fn text_document_did_save(
|
||||
) -> Option<impl Future<Output = Result<()>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
let include_text = match &capabilities.text_document_sync {
|
||||
Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
|
||||
save: Some(options),
|
||||
let include_text = match &capabilities.text_document_sync.as_ref()? {
|
||||
lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
|
||||
save: options,
|
||||
..
|
||||
})) => match options {
|
||||
}) => match options.as_ref()? {
|
||||
lsp::TextDocumentSyncSaveOptions::Supported(true) => false,
|
||||
lsp::TextDocumentSyncSaveOptions::SaveOptions(lsp_types::SaveOptions {
|
||||
include_text,
|
||||
}) => include_text.unwrap_or(false),
|
||||
// Supported(false)
|
||||
_ => return None,
|
||||
lsp::TextDocumentSyncSaveOptions::Supported(false) => return None,
|
||||
},
|
||||
// unsupported
|
||||
_ => return None,
|
||||
// see: https://github.com/microsoft/language-server-protocol/issues/288
|
||||
lsp::TextDocumentSyncCapability::Kind(..) => false,
|
||||
};
|
||||
|
||||
Some(self.notify::<lsp::notification::DidSaveTextDocument>(
|
||||
@ -913,6 +997,7 @@ pub fn completion(
|
||||
text_document: lsp::TextDocumentIdentifier,
|
||||
position: lsp::Position,
|
||||
work_done_token: Option<lsp::ProgressToken>,
|
||||
context: lsp::CompletionContext,
|
||||
) -> Option<impl Future<Output = Result<Value>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
@ -924,13 +1009,12 @@ pub fn completion(
|
||||
text_document,
|
||||
position,
|
||||
},
|
||||
context: Some(context),
|
||||
// TODO: support these tokens by async receiving and updating the choice list
|
||||
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
|
||||
partial_result_params: lsp::PartialResultParams {
|
||||
partial_result_token: None,
|
||||
},
|
||||
context: None,
|
||||
// lsp::CompletionContext { trigger_kind: , trigger_character: Some(), }
|
||||
};
|
||||
|
||||
Some(self.call::<lsp::request::Completion>(params))
|
||||
@ -939,7 +1023,7 @@ pub fn completion(
|
||||
pub fn resolve_completion_item(
|
||||
&self,
|
||||
completion_item: lsp::CompletionItem,
|
||||
) -> Option<impl Future<Output = Result<Value>>> {
|
||||
) -> Option<impl Future<Output = Result<lsp::CompletionItem>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
// Return early if the server does not support resolving completion items.
|
||||
@ -951,7 +1035,26 @@ pub fn resolve_completion_item(
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
Some(self.call::<lsp::request::ResolveCompletionItem>(completion_item))
|
||||
let res = self.call::<lsp::request::ResolveCompletionItem>(completion_item);
|
||||
Some(async move { Ok(serde_json::from_value(res.await?)?) })
|
||||
}
|
||||
|
||||
pub fn resolve_code_action(
|
||||
&self,
|
||||
code_action: lsp::CodeAction,
|
||||
) -> Option<impl Future<Output = Result<Value>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
// Return early if the server does not support resolving code actions.
|
||||
match capabilities.code_action_provider {
|
||||
Some(lsp::CodeActionProviderCapability::Options(lsp::CodeActionOptions {
|
||||
resolve_provider: Some(true),
|
||||
..
|
||||
})) => (),
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
Some(self.call::<lsp::request::CodeActionResolveRequest>(code_action))
|
||||
}
|
||||
|
||||
pub fn text_document_signature_help(
|
||||
@ -959,7 +1062,7 @@ pub fn text_document_signature_help(
|
||||
text_document: lsp::TextDocumentIdentifier,
|
||||
position: lsp::Position,
|
||||
work_done_token: Option<lsp::ProgressToken>,
|
||||
) -> Option<impl Future<Output = Result<Value>>> {
|
||||
) -> Option<impl Future<Output = Result<Option<SignatureHelp>>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
// Return early if the server does not support signature help.
|
||||
@ -975,7 +1078,8 @@ pub fn text_document_signature_help(
|
||||
// lsp::SignatureHelpContext
|
||||
};
|
||||
|
||||
Some(self.call::<lsp::request::SignatureHelpRequest>(params))
|
||||
let res = self.call::<lsp::request::SignatureHelpRequest>(params);
|
||||
Some(async move { Ok(serde_json::from_value(res.await?)?) })
|
||||
}
|
||||
|
||||
pub fn text_document_range_inlay_hints(
|
||||
@ -1428,4 +1532,13 @@ pub fn command(&self, command: lsp::Command) -> Option<impl Future<Output = Resu
|
||||
|
||||
Some(self.call::<lsp::request::ExecuteCommand>(params))
|
||||
}
|
||||
|
||||
pub fn did_change_watched_files(
|
||||
&self,
|
||||
changes: Vec<lsp::FileEvent>,
|
||||
) -> impl Future<Output = std::result::Result<(), Error>> {
|
||||
self.notify::<lsp::notification::DidChangeWatchedFiles>(lsp::DidChangeWatchedFilesParams {
|
||||
changes,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
193
helix-lsp/src/file_event.rs
Normal file
193
helix-lsp/src/file_event.rs
Normal file
@ -0,0 +1,193 @@
|
||||
use std::{collections::HashMap, path::PathBuf, sync::Weak};
|
||||
|
||||
use globset::{GlobBuilder, GlobSetBuilder};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{lsp, Client};
|
||||
|
||||
enum Event {
|
||||
FileChanged {
|
||||
path: PathBuf,
|
||||
},
|
||||
Register {
|
||||
client_id: usize,
|
||||
client: Weak<Client>,
|
||||
registration_id: String,
|
||||
options: lsp::DidChangeWatchedFilesRegistrationOptions,
|
||||
},
|
||||
Unregister {
|
||||
client_id: usize,
|
||||
registration_id: String,
|
||||
},
|
||||
RemoveClient {
|
||||
client_id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ClientState {
|
||||
client: Weak<Client>,
|
||||
registered: HashMap<String, globset::GlobSet>,
|
||||
}
|
||||
|
||||
/// The Handler uses a dedicated tokio task to respond to file change events by
|
||||
/// forwarding changes to LSPs that have registered for notifications with a
|
||||
/// matching glob.
|
||||
///
|
||||
/// When an LSP registers for the DidChangeWatchedFiles notification, the
|
||||
/// Handler is notified by sending the registration details in addition to a
|
||||
/// weak reference to the LSP client. This is done so that the Handler can have
|
||||
/// access to the client without preventing the client from being dropped if it
|
||||
/// is closed and the Handler isn't properly notified.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Handler {
|
||||
tx: mpsc::UnboundedSender<Event>,
|
||||
}
|
||||
|
||||
impl Default for Handler {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn new() -> Self {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
tokio::spawn(Self::run(rx));
|
||||
Self { tx }
|
||||
}
|
||||
|
||||
pub fn register(
|
||||
&self,
|
||||
client_id: usize,
|
||||
client: Weak<Client>,
|
||||
registration_id: String,
|
||||
options: lsp::DidChangeWatchedFilesRegistrationOptions,
|
||||
) {
|
||||
let _ = self.tx.send(Event::Register {
|
||||
client_id,
|
||||
client,
|
||||
registration_id,
|
||||
options,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn unregister(&self, client_id: usize, registration_id: String) {
|
||||
let _ = self.tx.send(Event::Unregister {
|
||||
client_id,
|
||||
registration_id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn file_changed(&self, path: PathBuf) {
|
||||
let _ = self.tx.send(Event::FileChanged { path });
|
||||
}
|
||||
|
||||
pub fn remove_client(&self, client_id: usize) {
|
||||
let _ = self.tx.send(Event::RemoveClient { client_id });
|
||||
}
|
||||
|
||||
async fn run(mut rx: mpsc::UnboundedReceiver<Event>) {
|
||||
let mut state: HashMap<usize, ClientState> = HashMap::new();
|
||||
while let Some(event) = rx.recv().await {
|
||||
match event {
|
||||
Event::FileChanged { path } => {
|
||||
log::debug!("Received file event for {:?}", &path);
|
||||
|
||||
state.retain(|id, client_state| {
|
||||
if !client_state
|
||||
.registered
|
||||
.values()
|
||||
.any(|glob| glob.is_match(&path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
let Some(client) = client_state.client.upgrade() else {
|
||||
log::warn!("LSP client was dropped: {id}");
|
||||
return false;
|
||||
};
|
||||
let Ok(uri) = lsp::Url::from_file_path(&path) else {
|
||||
return true;
|
||||
};
|
||||
log::debug!(
|
||||
"Sending didChangeWatchedFiles notification to client '{}'",
|
||||
client.name()
|
||||
);
|
||||
if let Err(err) = crate::block_on(client
|
||||
.did_change_watched_files(vec![lsp::FileEvent {
|
||||
uri,
|
||||
// We currently always send the CHANGED state
|
||||
// since we don't actually have more context at
|
||||
// the moment.
|
||||
typ: lsp::FileChangeType::CHANGED,
|
||||
}]))
|
||||
{
|
||||
log::warn!("Failed to send didChangeWatchedFiles notification to client: {err}");
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
Event::Register {
|
||||
client_id,
|
||||
client,
|
||||
registration_id,
|
||||
options: ops,
|
||||
} => {
|
||||
log::debug!(
|
||||
"Registering didChangeWatchedFiles for client '{}' with id '{}'",
|
||||
client_id,
|
||||
registration_id
|
||||
);
|
||||
|
||||
let entry = state.entry(client_id).or_insert_with(ClientState::default);
|
||||
entry.client = client;
|
||||
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
for watcher in ops.watchers {
|
||||
if let lsp::GlobPattern::String(pattern) = watcher.glob_pattern {
|
||||
if let Ok(glob) = GlobBuilder::new(&pattern).build() {
|
||||
builder.add(glob);
|
||||
}
|
||||
}
|
||||
}
|
||||
match builder.build() {
|
||||
Ok(globset) => {
|
||||
entry.registered.insert(registration_id, globset);
|
||||
}
|
||||
Err(err) => {
|
||||
// Remove any old state for that registration id and
|
||||
// remove the entire client if it's now empty.
|
||||
entry.registered.remove(®istration_id);
|
||||
if entry.registered.is_empty() {
|
||||
state.remove(&client_id);
|
||||
}
|
||||
log::warn!(
|
||||
"Unable to build globset for LSP didChangeWatchedFiles {err}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Unregister {
|
||||
client_id,
|
||||
registration_id,
|
||||
} => {
|
||||
log::debug!(
|
||||
"Unregistering didChangeWatchedFiles with id '{}' for client '{}'",
|
||||
registration_id,
|
||||
client_id
|
||||
);
|
||||
if let Some(client_state) = state.get_mut(&client_id) {
|
||||
client_state.registered.remove(®istration_id);
|
||||
if client_state.registered.is_empty() {
|
||||
state.remove(&client_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::RemoveClient { client_id } => {
|
||||
log::debug!("Removing LSP client: {client_id}");
|
||||
state.remove(&client_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
105
helix-lsp/src/file_operations.rs
Normal file
105
helix-lsp/src/file_operations.rs
Normal file
@ -0,0 +1,105 @@
|
||||
use std::path::Path;
|
||||
|
||||
use globset::{GlobBuilder, GlobSet};
|
||||
|
||||
use crate::lsp;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct FileOperationFilter {
|
||||
dir_globs: GlobSet,
|
||||
file_globs: GlobSet,
|
||||
}
|
||||
|
||||
impl FileOperationFilter {
|
||||
fn new(capability: Option<&lsp::FileOperationRegistrationOptions>) -> FileOperationFilter {
|
||||
let Some(cap) = capability else {
|
||||
return FileOperationFilter::default();
|
||||
};
|
||||
let mut dir_globs = GlobSet::builder();
|
||||
let mut file_globs = GlobSet::builder();
|
||||
for filter in &cap.filters {
|
||||
// TODO: support other url schemes
|
||||
let is_non_file_schema = filter
|
||||
.scheme
|
||||
.as_ref()
|
||||
.is_some_and(|schema| schema != "file");
|
||||
if is_non_file_schema {
|
||||
continue;
|
||||
}
|
||||
let ignore_case = filter
|
||||
.pattern
|
||||
.options
|
||||
.as_ref()
|
||||
.and_then(|opts| opts.ignore_case)
|
||||
.unwrap_or(false);
|
||||
let mut glob_builder = GlobBuilder::new(&filter.pattern.glob);
|
||||
glob_builder.case_insensitive(!ignore_case);
|
||||
let glob = match glob_builder.build() {
|
||||
Ok(glob) => glob,
|
||||
Err(err) => {
|
||||
log::error!("invalid glob send by LS: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
match filter.pattern.matches {
|
||||
Some(lsp::FileOperationPatternKind::File) => {
|
||||
file_globs.add(glob);
|
||||
}
|
||||
Some(lsp::FileOperationPatternKind::Folder) => {
|
||||
dir_globs.add(glob);
|
||||
}
|
||||
None => {
|
||||
file_globs.add(glob.clone());
|
||||
dir_globs.add(glob);
|
||||
}
|
||||
};
|
||||
}
|
||||
let file_globs = file_globs.build().unwrap_or_else(|err| {
|
||||
log::error!("invalid globs send by LS: {err}");
|
||||
GlobSet::empty()
|
||||
});
|
||||
let dir_globs = dir_globs.build().unwrap_or_else(|err| {
|
||||
log::error!("invalid globs send by LS: {err}");
|
||||
GlobSet::empty()
|
||||
});
|
||||
FileOperationFilter {
|
||||
dir_globs,
|
||||
file_globs,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn has_interest(&self, path: &Path, is_dir: bool) -> bool {
|
||||
if is_dir {
|
||||
self.dir_globs.is_match(path)
|
||||
} else {
|
||||
self.file_globs.is_match(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct FileOperationsInterest {
|
||||
// TODO: support other notifications
|
||||
// did_create: FileOperationFilter,
|
||||
// will_create: FileOperationFilter,
|
||||
pub did_rename: FileOperationFilter,
|
||||
pub will_rename: FileOperationFilter,
|
||||
// did_delete: FileOperationFilter,
|
||||
// will_delete: FileOperationFilter,
|
||||
}
|
||||
|
||||
impl FileOperationsInterest {
|
||||
pub fn new(capabilities: &lsp::ServerCapabilities) -> FileOperationsInterest {
|
||||
let capabilities = capabilities
|
||||
.workspace
|
||||
.as_ref()
|
||||
.and_then(|capabilities| capabilities.file_operations.as_ref());
|
||||
let Some(capabilities) = capabilities else {
|
||||
return FileOperationsInterest::default();
|
||||
};
|
||||
FileOperationsInterest {
|
||||
did_rename: FileOperationFilter::new(capabilities.did_rename.as_ref()),
|
||||
will_rename: FileOperationFilter::new(capabilities.will_rename.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
mod client;
|
||||
pub mod file_event;
|
||||
mod file_operations;
|
||||
pub mod jsonrpc;
|
||||
pub mod snippet;
|
||||
mod transport;
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
pub use client::Client;
|
||||
pub use futures_executor::block_on;
|
||||
pub use jsonrpc::Call;
|
||||
@ -10,10 +13,10 @@
|
||||
pub use lsp_types as lsp;
|
||||
|
||||
use futures_util::stream::select_all::SelectAll;
|
||||
use helix_core::{
|
||||
path,
|
||||
syntax::{LanguageConfiguration, LanguageServerConfiguration, LanguageServerFeatures},
|
||||
use helix_core::syntax::{
|
||||
LanguageConfiguration, LanguageServerConfiguration, LanguageServerFeatures,
|
||||
};
|
||||
use helix_stdx::path;
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
|
||||
use std::{
|
||||
@ -43,6 +46,8 @@ pub enum Error {
|
||||
#[error("Unhandled")]
|
||||
Unhandled,
|
||||
#[error(transparent)]
|
||||
ExecutableNotFound(#[from] helix_stdx::env::ExecutableNotFoundError),
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
@ -279,7 +284,8 @@ fn find_completion_range(text: RopeSlice, replace_mode: bool, cursor: usize) ->
|
||||
.chars_at(cursor)
|
||||
.skip(1)
|
||||
.take_while(|ch| chars::char_is_word(*ch))
|
||||
.count();
|
||||
.count()
|
||||
+ 1;
|
||||
}
|
||||
(start, end)
|
||||
}
|
||||
@ -377,7 +383,7 @@ pub fn generate_transaction_from_snippet(
|
||||
.expect("transaction must be valid for primary selection");
|
||||
let removed_text = text.slice(removed_start..removed_end);
|
||||
|
||||
let (transaction, selection) = Transaction::change_by_selection_ignore_overlapping(
|
||||
let (transaction, mut selection) = Transaction::change_by_selection_ignore_overlapping(
|
||||
doc,
|
||||
selection,
|
||||
|range| {
|
||||
@ -420,6 +426,11 @@ pub fn generate_transaction_from_snippet(
|
||||
return transaction;
|
||||
}
|
||||
|
||||
// Don't normalize to avoid merging/reording selections which would
|
||||
// break the association between tabstops and selections. Most ranges
|
||||
// will be replaced by tabstops anyways and the final selection will be
|
||||
// normalized anyways
|
||||
selection = selection.map_no_normalize(changes);
|
||||
let mut mapped_selection = SmallVec::with_capacity(selection.len());
|
||||
let mut mapped_primary_idx = 0;
|
||||
let primary_range = selection.primary();
|
||||
@ -428,9 +439,8 @@ pub fn generate_transaction_from_snippet(
|
||||
mapped_primary_idx = mapped_selection.len()
|
||||
}
|
||||
|
||||
let range = range.map(changes);
|
||||
let tabstops = tabstops.first().filter(|tabstops| !tabstops.is_empty());
|
||||
let Some(tabstops) = tabstops else{
|
||||
let Some(tabstops) = tabstops else {
|
||||
// no tabstop normal mapping
|
||||
mapped_selection.push(range);
|
||||
continue;
|
||||
@ -440,36 +450,36 @@ pub fn generate_transaction_from_snippet(
|
||||
// the tabstop closest to the range simply replaces `head` while anchor remains in place
|
||||
// the remaining tabstops receive their own single-width cursor
|
||||
if range.head < range.anchor {
|
||||
let first_tabstop = tabstop_anchor + tabstops[0].1;
|
||||
let last_idx = tabstops.len() - 1;
|
||||
let last_tabstop = tabstop_anchor + tabstops[last_idx].0;
|
||||
|
||||
// if selection is forward but was moved to the right it is
|
||||
// contained entirely in the replacement text, just do a point
|
||||
// selection (fallback below)
|
||||
if range.anchor >= first_tabstop {
|
||||
let range = Range::new(range.anchor, first_tabstop);
|
||||
if range.anchor > last_tabstop {
|
||||
let range = Range::new(range.anchor, last_tabstop);
|
||||
mapped_selection.push(range);
|
||||
let rem_tabstops = tabstops[1..]
|
||||
let rem_tabstops = tabstops[..last_idx]
|
||||
.iter()
|
||||
.map(|tabstop| Range::point(tabstop_anchor + tabstop.1));
|
||||
.map(|tabstop| Range::point(tabstop_anchor + tabstop.0));
|
||||
mapped_selection.extend(rem_tabstops);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
let last_idx = tabstops.len() - 1;
|
||||
let last_tabstop = tabstop_anchor + tabstops[last_idx].1;
|
||||
let first_tabstop = tabstop_anchor + tabstops[0].0;
|
||||
|
||||
// if selection is forward but was moved to the right it is
|
||||
// contained entirely in the replacement text, just do a point
|
||||
// selection (fallback below)
|
||||
if range.anchor <= last_tabstop {
|
||||
if range.anchor < first_tabstop {
|
||||
// we can't properly compute the the next grapheme
|
||||
// here because the transaction hasn't been applied yet
|
||||
// that is not a problem because the range gets grapheme aligned anyway
|
||||
// tough so just adding one will always cause head to be grapheme
|
||||
// aligned correctly when applied to the document
|
||||
let range = Range::new(range.anchor, last_tabstop + 1);
|
||||
let range = Range::new(range.anchor, first_tabstop + 1);
|
||||
mapped_selection.push(range);
|
||||
let rem_tabstops = tabstops[..last_idx]
|
||||
let rem_tabstops = tabstops[1..]
|
||||
.iter()
|
||||
.map(|tabstop| Range::point(tabstop_anchor + tabstop.0));
|
||||
mapped_selection.extend(rem_tabstops);
|
||||
@ -530,6 +540,16 @@ pub fn generate_transaction_from_edits(
|
||||
} else {
|
||||
return (0, 0, None);
|
||||
};
|
||||
|
||||
if start > end {
|
||||
log::error!(
|
||||
"Invalid LSP text edit start {:?} > end {:?}, discarding",
|
||||
start,
|
||||
end
|
||||
);
|
||||
return (0, 0, None);
|
||||
}
|
||||
|
||||
(start, end, replacement)
|
||||
}),
|
||||
)
|
||||
@ -543,6 +563,8 @@ pub enum MethodCall {
|
||||
WorkspaceFolders,
|
||||
WorkspaceConfiguration(lsp::ConfigurationParams),
|
||||
RegisterCapability(lsp::RegistrationParams),
|
||||
UnregisterCapability(lsp::UnregistrationParams),
|
||||
ShowDocument(lsp::ShowDocumentParams),
|
||||
}
|
||||
|
||||
impl MethodCall {
|
||||
@ -566,6 +588,14 @@ pub fn parse(method: &str, params: jsonrpc::Params) -> Result<MethodCall> {
|
||||
let params: lsp::RegistrationParams = params.parse()?;
|
||||
Self::RegisterCapability(params)
|
||||
}
|
||||
lsp::request::UnregisterCapability::METHOD => {
|
||||
let params: lsp::UnregistrationParams = params.parse()?;
|
||||
Self::UnregisterCapability(params)
|
||||
}
|
||||
lsp::request::ShowDocument::METHOD => {
|
||||
let params: lsp::ShowDocumentParams = params.parse()?;
|
||||
Self::ShowDocument(params)
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unhandled);
|
||||
}
|
||||
@ -622,18 +652,20 @@ pub fn parse(method: &str, params: jsonrpc::Params) -> Result<Notification> {
|
||||
#[derive(Debug)]
|
||||
pub struct Registry {
|
||||
inner: HashMap<LanguageServerName, Vec<Arc<Client>>>,
|
||||
syn_loader: Arc<helix_core::syntax::Loader>,
|
||||
syn_loader: Arc<ArcSwap<helix_core::syntax::Loader>>,
|
||||
counter: usize,
|
||||
pub incoming: SelectAll<UnboundedReceiverStream<(usize, Call)>>,
|
||||
pub file_event_handler: file_event::Handler,
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn new(syn_loader: Arc<helix_core::syntax::Loader>) -> Self {
|
||||
pub fn new(syn_loader: Arc<ArcSwap<helix_core::syntax::Loader>>) -> Self {
|
||||
Self {
|
||||
inner: HashMap::new(),
|
||||
syn_loader,
|
||||
counter: 0,
|
||||
incoming: SelectAll::new(),
|
||||
file_event_handler: file_event::Handler::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -646,6 +678,7 @@ pub fn get_by_id(&self, id: usize) -> Option<&Client> {
|
||||
}
|
||||
|
||||
pub fn remove_by_id(&mut self, id: usize) {
|
||||
self.file_event_handler.remove_client(id);
|
||||
self.inner.retain(|_, language_servers| {
|
||||
language_servers.retain(|ls| id != ls.id());
|
||||
!language_servers.is_empty()
|
||||
@ -659,15 +692,15 @@ fn start_client(
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
root_dirs: &[PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Result<Arc<Client>> {
|
||||
let config = self
|
||||
.syn_loader
|
||||
) -> Result<Option<Arc<Client>>> {
|
||||
let syn_loader = self.syn_loader.load();
|
||||
let config = syn_loader
|
||||
.language_server_configs()
|
||||
.get(&name)
|
||||
.ok_or_else(|| anyhow::anyhow!("Language server '{name}' not defined"))?;
|
||||
let id = self.counter;
|
||||
self.counter += 1;
|
||||
let NewClient(client, incoming) = start_client(
|
||||
if let Some(NewClient(client, incoming)) = start_client(
|
||||
id,
|
||||
name,
|
||||
ls_config,
|
||||
@ -675,9 +708,12 @@ fn start_client(
|
||||
doc_path,
|
||||
root_dirs,
|
||||
enable_snippets,
|
||||
)?;
|
||||
self.incoming.push(UnboundedReceiverStream::new(incoming));
|
||||
Ok(client)
|
||||
)? {
|
||||
self.incoming.push(UnboundedReceiverStream::new(incoming));
|
||||
Ok(Some(client))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// If this method is called, all documents that have a reference to language servers used by the language config have to refresh their language servers,
|
||||
@ -702,8 +738,8 @@ pub fn restart(
|
||||
root_dirs,
|
||||
enable_snippets,
|
||||
) {
|
||||
Ok(client) => client,
|
||||
error => return Some(error),
|
||||
Ok(client) => client?,
|
||||
Err(error) => return Some(Err(error)),
|
||||
};
|
||||
let old_clients = self
|
||||
.inner
|
||||
@ -711,6 +747,7 @@ pub fn restart(
|
||||
.unwrap();
|
||||
|
||||
for old_client in old_clients {
|
||||
self.file_event_handler.remove_client(old_client.id());
|
||||
tokio::spawn(async move {
|
||||
let _ = old_client.force_shutdown().await;
|
||||
});
|
||||
@ -727,6 +764,7 @@ pub fn restart(
|
||||
pub fn stop(&mut self, name: &str) {
|
||||
if let Some(clients) = self.inner.remove(name) {
|
||||
for client in clients {
|
||||
self.file_event_handler.remove_client(client.id());
|
||||
tokio::spawn(async move {
|
||||
let _ = client.force_shutdown().await;
|
||||
});
|
||||
@ -734,36 +772,41 @@ pub fn stop(&mut self, name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(
|
||||
&mut self,
|
||||
language_config: &LanguageConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
root_dirs: &[PathBuf],
|
||||
pub fn get<'a>(
|
||||
&'a mut self,
|
||||
language_config: &'a LanguageConfiguration,
|
||||
doc_path: Option<&'a std::path::PathBuf>,
|
||||
root_dirs: &'a [PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Result<HashMap<LanguageServerName, Arc<Client>>> {
|
||||
language_config
|
||||
.language_servers
|
||||
.iter()
|
||||
.map(|LanguageServerFeatures { name, .. }| {
|
||||
) -> impl Iterator<Item = (LanguageServerName, Result<Arc<Client>>)> + 'a {
|
||||
language_config.language_servers.iter().filter_map(
|
||||
move |LanguageServerFeatures { name, .. }| {
|
||||
if let Some(clients) = self.inner.get(name) {
|
||||
if let Some((_, client)) = clients.iter().enumerate().find(|(i, client)| {
|
||||
client.try_add_doc(&language_config.roots, root_dirs, doc_path, *i == 0)
|
||||
}) {
|
||||
return Ok((name.to_owned(), client.clone()));
|
||||
return Some((name.to_owned(), Ok(client.clone())));
|
||||
}
|
||||
}
|
||||
let client = self.start_client(
|
||||
match self.start_client(
|
||||
name.clone(),
|
||||
language_config,
|
||||
doc_path,
|
||||
root_dirs,
|
||||
enable_snippets,
|
||||
)?;
|
||||
let clients = self.inner.entry(name.clone()).or_default();
|
||||
clients.push(client.clone());
|
||||
Ok((name.clone(), client))
|
||||
})
|
||||
.collect()
|
||||
) {
|
||||
Ok(client) => {
|
||||
let client = client?;
|
||||
self.inner
|
||||
.entry(name.to_owned())
|
||||
.or_default()
|
||||
.push(client.clone());
|
||||
Some((name.clone(), Ok(client)))
|
||||
}
|
||||
Err(err) => Some((name.to_owned(), Err(err))),
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn iter_clients(&self) -> impl Iterator<Item = &Arc<Client>> {
|
||||
@ -861,18 +904,45 @@ fn start_client(
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
root_dirs: &[PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Result<NewClient> {
|
||||
) -> Result<Option<NewClient>> {
|
||||
let (workspace, workspace_is_cwd) = helix_loader::find_workspace();
|
||||
let workspace = path::normalize(workspace);
|
||||
let root = find_lsp_workspace(
|
||||
doc_path
|
||||
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
||||
.unwrap_or("."),
|
||||
&config.roots,
|
||||
config.workspace_lsp_roots.as_deref().unwrap_or(root_dirs),
|
||||
&workspace,
|
||||
workspace_is_cwd,
|
||||
);
|
||||
|
||||
// `root_uri` and `workspace_folder` can be empty in case there is no workspace
|
||||
// `root_url` can not, use `workspace` as a fallback
|
||||
let root_path = root.clone().unwrap_or_else(|| workspace.clone());
|
||||
let root_uri = root.and_then(|root| lsp::Url::from_file_path(root).ok());
|
||||
|
||||
if let Some(globset) = &ls_config.required_root_patterns {
|
||||
if !root_path
|
||||
.read_dir()?
|
||||
.flatten()
|
||||
.map(|entry| entry.file_name())
|
||||
.any(|entry| globset.is_match(entry))
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
let (client, incoming, initialize_notify) = Client::start(
|
||||
&ls_config.command,
|
||||
&ls_config.args,
|
||||
ls_config.config.clone(),
|
||||
ls_config.environment.clone(),
|
||||
&config.roots,
|
||||
config.workspace_lsp_roots.as_deref().unwrap_or(root_dirs),
|
||||
root_path,
|
||||
root_uri,
|
||||
id,
|
||||
name,
|
||||
ls_config.timeout,
|
||||
doc_path,
|
||||
)?;
|
||||
|
||||
let client = Arc::new(client);
|
||||
@ -896,15 +966,22 @@ fn start_client(
|
||||
}
|
||||
|
||||
// next up, notify<initialized>
|
||||
_client
|
||||
let notification_result = _client
|
||||
.notify::<lsp::notification::Initialized>(lsp::InitializedParams {})
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
if let Err(e) = notification_result {
|
||||
log::error!(
|
||||
"failed to notify language server of its initialization: {}",
|
||||
e
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
initialize_notify.notify_one();
|
||||
});
|
||||
|
||||
Ok(NewClient(client, incoming))
|
||||
Ok(Some(NewClient(client, incoming)))
|
||||
}
|
||||
|
||||
/// Find an LSP workspace of a file using the following mechanism:
|
||||
@ -927,10 +1004,10 @@ pub fn find_lsp_workspace(
|
||||
let mut file = if file.is_absolute() {
|
||||
file.to_path_buf()
|
||||
} else {
|
||||
let current_dir = std::env::current_dir().expect("unable to determine current directory");
|
||||
let current_dir = helix_stdx::env::current_working_dir();
|
||||
current_dir.join(file)
|
||||
};
|
||||
file = path::get_normalized_path(&file);
|
||||
file = path::normalize(&file);
|
||||
|
||||
if !file.starts_with(workspace) {
|
||||
return None;
|
||||
@ -947,7 +1024,7 @@ pub fn find_lsp_workspace(
|
||||
|
||||
if root_dirs
|
||||
.iter()
|
||||
.any(|root_dir| path::get_normalized_path(&workspace.join(root_dir)) == ancestor)
|
||||
.any(|root_dir| path::normalize(workspace.join(root_dir)) == ancestor)
|
||||
{
|
||||
// if the worskapce is the cwd do not search any higher for workspaces
|
||||
// but specify
|
||||
|
@ -270,7 +270,14 @@ async fn recv(
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(Error::StreamClosed) => {
|
||||
Err(err) => {
|
||||
if !matches!(err, Error::StreamClosed) {
|
||||
error!(
|
||||
"Exiting {} after unexpected error: {err:?}",
|
||||
&transport.name
|
||||
);
|
||||
}
|
||||
|
||||
// Close any outstanding requests.
|
||||
for (id, tx) in transport.pending_requests.lock().await.drain() {
|
||||
match tx.send(Err(Error::StreamClosed)).await {
|
||||
@ -300,10 +307,6 @@ async fn recv(
|
||||
}
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
error!("{} err: <- {err:?}", transport.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -353,6 +356,11 @@ fn is_initialize(payload: &Payload) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_shutdown(payload: &Payload) -> bool {
|
||||
use lsp_types::request::{Request, Shutdown};
|
||||
matches!(payload, Payload::Request { value: jsonrpc::MethodCall { method, .. }, .. } if method == Shutdown::METHOD)
|
||||
}
|
||||
|
||||
// TODO: events that use capabilities need to do the right thing
|
||||
|
||||
loop {
|
||||
@ -391,7 +399,10 @@ fn is_initialize(payload: &Payload) -> bool {
|
||||
}
|
||||
msg = client_rx.recv() => {
|
||||
if let Some(msg) = msg {
|
||||
if is_pending && !is_initialize(&msg) {
|
||||
if is_pending && is_shutdown(&msg) {
|
||||
log::info!("Language server not initialized, shutting down");
|
||||
break;
|
||||
} else if is_pending && !is_initialize(&msg) {
|
||||
// ignore notifications
|
||||
if let Payload::Notification(_) = msg {
|
||||
continue;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user