mirror of
https://github.com/helix-editor/helix.git
synced 2025-10-06 16:33:17 +02:00
Compare commits
572 Commits
config_ref
...
helix_synt
Author | SHA1 | Date | |
---|---|---|---|
|
ae0d4189e1 | ||
|
f7686d7af2 | ||
|
29ffc20290 | ||
|
1bd36f528a | ||
|
0cd8817d06 | ||
|
782a34941e | ||
|
37397ecc6d | ||
|
c4b7b08809 | ||
|
08ee8b9443 | ||
|
9de5f5cefa | ||
|
6345b78409 | ||
|
a7777b3c11 | ||
|
009bbdaf8d | ||
|
8555248b01 | ||
|
3906f6605f | ||
|
f4a433f855 | ||
|
408282097f | ||
|
6ccbfe9bdf | ||
|
6492f17e7d | ||
|
7b1131adf6 | ||
|
1d023b05ac | ||
|
5622db6798 | ||
|
9e31ba5475 | ||
|
11f809c177 | ||
|
2c9f5b3efb | ||
|
53ac833efb | ||
|
385b398808 | ||
|
c4c17c693d | ||
|
f40fca88e0 | ||
|
dae3841a75 | ||
|
702a96d417 | ||
|
7f77d95c79 | ||
|
1bad3b0dd4 | ||
|
079f544260 | ||
|
b2cc7d8fea | ||
|
c9b484097b | ||
|
e6bf97b843 | ||
|
44d2fc2ab3 | ||
|
35f1c2a55f | ||
|
928e3f0d85 | ||
|
ec0bdb3976 | ||
|
b0f3fe7556 | ||
|
fd7b1a3e37 | ||
|
a75b1cf51e | ||
|
501af93c92 | ||
|
2d1ac0f699 | ||
|
8229a40da8 | ||
|
9d75385062 | ||
|
649bd4501e | ||
|
86982ab33c | ||
|
15a26b87c9 | ||
|
bfb7023656 | ||
|
86e4b51416 | ||
|
71df2428ee | ||
|
348c0ebeb4 | ||
|
6997ee9151 | ||
|
0c8d51ee36 | ||
|
8b7c33d00d | ||
|
1fb99ec3b2 | ||
|
06d8fee048 | ||
|
fc97ecc3e3 | ||
|
3524060ee8 | ||
|
64f8660d3e | ||
|
ed761fbe7c | ||
|
0c6ffe192b | ||
|
9c4c66d417 | ||
|
21fd654cc6 | ||
|
c6dbb9c270 | ||
|
dca952c03a | ||
|
b4811f7d2e | ||
|
0e46f56f30 | ||
|
6ed0d0cd39 | ||
|
b05ed9bf85 | ||
|
a982e5ce26 | ||
|
b894cf087b | ||
|
3706c0dc85 | ||
|
3b5f2e66fc | ||
|
44e113cb76 | ||
|
b55cb3aa11 | ||
|
9b7dffbd61 | ||
|
0edf60964d | ||
|
94a9c81eb0 | ||
|
d70f58da10 | ||
|
668f1239a9 | ||
|
69acf66cd8 | ||
|
afe9049a0e | ||
|
bc73dd19d3 | ||
|
dbacaaddca | ||
|
43cc30d225 | ||
|
8eda96de6d | ||
|
9c479e6d2d | ||
|
62655e97f1 | ||
|
9123d3fbb8 | ||
|
8a549b767b | ||
|
a64dbf825f | ||
|
265608a3d8 | ||
|
a1cda3c19e | ||
|
03813bbc2e | ||
|
aa1630a41a | ||
|
44504b720b | ||
|
80e0e98e45 | ||
|
3a03109a99 | ||
|
886d307b9e | ||
|
6f1437e9f3 | ||
|
c39cde8fc2 | ||
|
31bcde360c | ||
|
a801044152 | ||
|
6dbab51f4a | ||
|
972265640d | ||
|
179673568d | ||
|
730e684d1d | ||
|
f1c9580e4b | ||
|
4dbb4eeba1 | ||
|
41dec92b0f | ||
|
a789f72a88 | ||
|
5b9f5f9fdb | ||
|
dfcd814389 | ||
|
e94735bbd3 | ||
|
8444f52e9a | ||
|
ff6aca12b7 | ||
|
2301430e37 | ||
|
889bbefeb3 | ||
|
e76020ddb9 | ||
|
380c7adcc0 | ||
|
855568fa34 | ||
|
5fea7cd0cc | ||
|
00e9e5eade | ||
|
f4a61006bf | ||
|
f656b4f3a7 | ||
|
5c11af1479 | ||
|
9dd51e75e0 | ||
|
3cf2a91a25 | ||
|
2bc0d036e7 | ||
|
81d4cbc66e | ||
|
5e3de68591 | ||
|
5b8b2f4b9b | ||
|
0432d9cf14 | ||
|
beb5afcbef | ||
|
e16a4f8a2c | ||
|
b437b8b0ee | ||
|
295a9a95ce | ||
|
a959c0ef9b | ||
|
f86f350d5d | ||
|
6876f923d5 | ||
|
50b13d1aea | ||
|
7d1e5f18a2 | ||
|
61818996c6 | ||
|
7e13213e74 | ||
|
cfca30887c | ||
|
31273c69e0 | ||
|
752ed8eb15 | ||
|
d8701bfd1e | ||
|
eeb8782c54 | ||
|
724a96abc8 | ||
|
ec224798e7 | ||
|
8db93013fb | ||
|
e2594b64c0 | ||
|
93e8c16614 | ||
|
2d6d876a23 | ||
|
a1d7997fe3 | ||
|
bc03b6b5fe | ||
|
615d34a237 | ||
|
f1461b49fa | ||
|
918dd3fa37 | ||
|
5ee7411450 | ||
|
31248d4e2f | ||
|
109f53fb60 | ||
|
839ec4ad39 | ||
|
81dc8e8d6b | ||
|
50c90cb47c | ||
|
22960e0d70 | ||
|
89a9f2be78 | ||
|
e18b772654 | ||
|
38ee845b05 | ||
|
b834806dbc | ||
|
d140072fdc | ||
|
26d9610e78 | ||
|
efae85ec20 | ||
|
35b6aef5fb | ||
|
345e687573 | ||
|
4b8bcd2773 | ||
|
af4ff80524 | ||
|
211f368064 | ||
|
18d5cacea6 | ||
|
94405f3d07 | ||
|
98b4df23a3 | ||
|
2209effb02 | ||
|
34291f0f3b | ||
|
4e16956007 | ||
|
bb57686854 | ||
|
ccb0c40b5e | ||
|
785d09e38f | ||
|
6fdc1d6a95 | ||
|
c0aadfd4ce | ||
|
368b29ca72 | ||
|
be8dc22272 | ||
|
a5a9827f32 | ||
|
88da9e857c | ||
|
4713eb06b1 | ||
|
6bdc6f460e | ||
|
97f683b336 | ||
|
8924691c5d | ||
|
f06a166962 | ||
|
1d23796ad1 | ||
|
30baff907d | ||
|
521accaf00 | ||
|
ab203b5f53 | ||
|
1cce693bef | ||
|
43dff1c772 | ||
|
36ee9ba7d6 | ||
|
69e08d9e91 | ||
|
7775b35cba | ||
|
50470f755f | ||
|
68765f51c9 | ||
|
8e161723ee | ||
|
8256ca7bc3 | ||
|
70459b2b66 | ||
|
0546273570 | ||
|
1245760595 | ||
|
9df1266376 | ||
|
081f7d0bd8 | ||
|
6d363a978d | ||
|
c9ae694aff | ||
|
009a5498ca | ||
|
4fc0a4dafc | ||
|
34c7eb4bd4 | ||
|
73d26d0d97 | ||
|
b974716b92 | ||
|
f601b7c278 | ||
|
c5e257b81c | ||
|
b8ddb2f114 | ||
|
c99c333337 | ||
|
fa67c5c474 | ||
|
87c4161732 | ||
|
cf9b88f9bd | ||
|
07cb24abdd | ||
|
cf99615b43 | ||
|
55346f32b5 | ||
|
cf259e37c8 | ||
|
ae85f5ff71 | ||
|
c499f9aa55 | ||
|
be8afe1bfe | ||
|
ea2a4858b7 | ||
|
92338bc207 | ||
|
d180395461 | ||
|
1e7c01d75b | ||
|
6f5ea6be58 | ||
|
0da809c981 | ||
|
e663dafcd8 | ||
|
e69292e5eb | ||
|
97afd67fca | ||
|
3f2de21342 | ||
|
d3bfa3e063 | ||
|
1ba5763a0c | ||
|
a2ee2e66f2 | ||
|
f240d896a4 | ||
|
d053886fe3 | ||
|
5f44890176 | ||
|
962c714185 | ||
|
3e2b85c61b | ||
|
1539312558 | ||
|
5fece0054d | ||
|
88f2931153 | ||
|
f16380d418 | ||
|
fa79ce59a0 | ||
|
f773972241 | ||
|
84cc42e5ee | ||
|
e54e3f07cb | ||
|
e0ec34421b | ||
|
226b2755fb | ||
|
54844241ce | ||
|
96f7d73f3d | ||
|
190fbf66d4 | ||
|
cc8290f393 | ||
|
e63ed0579d | ||
|
545ff1aac6 | ||
|
bb0bfa23f3 | ||
|
b24c465a08 | ||
|
4b236f30db | ||
|
8635913f0e | ||
|
d56f3fb755 | ||
|
88d455afeb | ||
|
a224ee5079 | ||
|
1abb64e48d | ||
|
47ef9f0ca2 | ||
|
2f4572d91e | ||
|
0c3bc46ac4 | ||
|
957d030be9 | ||
|
0da5865695 | ||
|
9a80f7203d | ||
|
f5991657f4 | ||
|
2533b08f64 | ||
|
8b7cbf5280 | ||
|
25d8e9445c | ||
|
825ae74b9e | ||
|
96220cb632 | ||
|
3d6f34c270 | ||
|
2cadec0b11 | ||
|
64c1de1988 | ||
|
787a237f8b | ||
|
381976a04c | ||
|
527cbe656c | ||
|
7ec509e2f9 | ||
|
c69ad7b3bf | ||
|
f21efc7a2f | ||
|
cb286b7a5d | ||
|
a6c6fa4c8e | ||
|
cef839e477 | ||
|
1e50fb8b55 | ||
|
07e21a10f0 | ||
|
a0d6566140 | ||
|
3205bc4132 | ||
|
d4b467090b | ||
|
1d1087822a | ||
|
614a744d24 | ||
|
2d9e336f64 | ||
|
47995bfb0c | ||
|
7bce9530d3 | ||
|
da2dec174a | ||
|
628dcd5c56 | ||
|
2178adfe93 | ||
|
54fab657be | ||
|
8f65bfe089 | ||
|
b46064b8c4 | ||
|
3001f22b31 | ||
|
66b9ff1d2a | ||
|
69e07ab61e | ||
|
68b21578ac | ||
|
b1222f0664 | ||
|
6dd46bfe1c | ||
|
d5c2973cd1 | ||
|
be307a4204 | ||
|
c9e34c556b | ||
|
f5d95de227 | ||
|
c099dde2a7 | ||
|
9ceeea5a83 | ||
|
fdcd461e65 | ||
|
459eb9a4c1 | ||
|
961025433d | ||
|
51739f1290 | ||
|
5ba36fe9b3 | ||
|
7f5fd63835 | ||
|
52a0734120 | ||
|
b8e79c0ef5 | ||
|
bcf7b26393 | ||
|
427dd2f383 | ||
|
d9de809a57 | ||
|
1d1806c85a | ||
|
4b4947639a | ||
|
5b8bfc5476 | ||
|
485c5cf0b8 | ||
|
0b6dea6dc2 | ||
|
6a22d7d1ca | ||
|
4d2282cbcc | ||
|
3d4889ce9a | ||
|
0f5430ab9e | ||
|
e91ec8e880 | ||
|
6ed93b6e49 | ||
|
6607938bf8 | ||
|
13533cb99c | ||
|
df8352ec05 | ||
|
ef797acf0d | ||
|
7ef583bea7 | ||
|
326c078356 | ||
|
8dc50bded9 | ||
|
58022586a0 | ||
|
2e4653ea31 | ||
|
94d210c9bf | ||
|
4ffe993533 | ||
|
38af99f05f | ||
|
476e6baf8f | ||
|
d99b6177c2 | ||
|
eead105f94 | ||
|
64389f97fe | ||
|
f7913c1a3b | ||
|
8457652da1 | ||
|
0301d01e78 | ||
|
3890376a23 | ||
|
e36774c2c8 | ||
|
9ec0271873 | ||
|
61f7d9ce2f | ||
|
761df60077 | ||
|
6fea7876a4 | ||
|
9282f1b8e5 | ||
|
b961acf746 | ||
|
0c51ab16d0 | ||
|
6c4d986c1b | ||
|
b44b627b14 | ||
|
e01a558294 | ||
|
3915b04bd9 | ||
|
2d15acdf60 | ||
|
ab61874efb | ||
|
2e2a1d6f61 | ||
|
2d589e74f0 | ||
|
c145999bff | ||
|
3bd493299f | ||
|
0dc67ff885 | ||
|
e3c6c82828 | ||
|
fd89c3c833 | ||
|
301dfb07cc | ||
|
e27b04735c | ||
|
cb01e52cd8 | ||
|
b93fae9c8b | ||
|
4e5f19df53 | ||
|
7a473c7494 | ||
|
ea0b244644 | ||
|
7d8c86e403 | ||
|
3f98891e79 | ||
|
cc43e3521e | ||
|
9267343830 | ||
|
5bd007266a | ||
|
d769fadde0 | ||
|
f04dafa2e2 | ||
|
5ca6a448e9 | ||
|
1d6db30acf | ||
|
062fb819a2 | ||
|
44db25939c | ||
|
d0bb774471 | ||
|
e51a1e4e2a | ||
|
1143f47954 | ||
|
f03b91d1b7 | ||
|
083a9e775d | ||
|
00653c772e | ||
|
26b3dc29be | ||
|
f46a09ab4f | ||
|
358ac6bc1f | ||
|
1a82aeeae9 | ||
|
ea95c68775 | ||
|
d0f8261141 | ||
|
b43d9aa306 | ||
|
cd02976fa3 | ||
|
c68ec92c5e | ||
|
a876148585 | ||
|
928bf80d9a | ||
|
8141a4a1ab | ||
|
dfa5382c51 | ||
|
6db666fce1 | ||
|
ec9efdef3b | ||
|
38484f33e5 | ||
|
03623f2f40 | ||
|
7100ed4efc | ||
|
b7b6f30084 | ||
|
98ebeeebd8 | ||
|
eca537615a | ||
|
cad0209e20 | ||
|
d2aacb3e36 | ||
|
27335476ed | ||
|
990378a46b | ||
|
cdef4f8a70 | ||
|
787cc36092 | ||
|
ebf155d635 | ||
|
2dc9ce68ec | ||
|
c72426cc87 | ||
|
b950dea003 | ||
|
9ab3f9d01a | ||
|
6432669822 | ||
|
78c34194b5 | ||
|
3e963b3c1b | ||
|
6ffe09e873 | ||
|
76e512f944 | ||
|
59369d99e2 | ||
|
4df08ddbe0 | ||
|
c59f29921d | ||
|
fe869e5dc7 | ||
|
7934ac7714 | ||
|
36ad70e4c7 | ||
|
c55bf72d25 | ||
|
caad87e999 | ||
|
fd7b722dfb | ||
|
661e123152 | ||
|
c111e28a6f | ||
|
d232e7a985 | ||
|
0516337abb | ||
|
bb1e2ddcd8 | ||
|
78ed3aded3 | ||
|
0eec518ff6 | ||
|
45ee568b98 | ||
|
d7c7589fd5 | ||
|
ad7b7bc804 | ||
|
6a90166d0a | ||
|
ac8d1f62a1 | ||
|
d9f7aaacaf | ||
|
7d8ce1a400 | ||
|
204c3707b0 | ||
|
13b9885084 | ||
|
786b5c533e | ||
|
581a1ebf5d | ||
|
d570c29ce3 | ||
|
d137a08231 | ||
|
f8e2d822ba | ||
|
a1272bdb17 | ||
|
bbcc89241f | ||
|
630d91168a | ||
|
72c508de24 | ||
|
c64a0e615b | ||
|
28a39e6efc | ||
|
a37af2dcbf | ||
|
1d87c6a999 | ||
|
0975d9c5e7 | ||
|
5c567f31e2 | ||
|
6e3ed7f0fa | ||
|
75d61d8149 | ||
|
d1054de3ce | ||
|
3f380722fb | ||
|
d545452819 | ||
|
81ae768a4e | ||
|
70cea93bff | ||
|
aa4241c973 | ||
|
5ec9565ddb | ||
|
dd59602809 | ||
|
dbac78bb3c | ||
|
cf4492174d | ||
|
87a720c3a1 | ||
|
f5b67d9acb | ||
|
4ab7029535 | ||
|
eb3c4e9f00 | ||
|
fe44391016 | ||
|
ee68fd09ac | ||
|
0328fa4d02 | ||
|
035b8eabdb | ||
|
8b6565c839 | ||
|
5e0b3cc28b | ||
|
9978d421fe | ||
|
f0be0c6d4a | ||
|
1616021a5a | ||
|
0d09fb4f55 | ||
|
2661e05b34 | ||
|
d8b8d2fda6 | ||
|
cda8ea991e | ||
|
83f09ecbff | ||
|
cb25d13028 | ||
|
6d724a8f33 | ||
|
6bfe1ddc53 | ||
|
b606c05246 | ||
|
299bcce481 | ||
|
2058b3732c | ||
|
7caae13465 | ||
|
cbd8602018 | ||
|
4168864572 | ||
|
ae8042bb83 | ||
|
e85507ccac | ||
|
960cda60ab | ||
|
8e592a151f | ||
|
13ed4f6c47 | ||
|
7d7ace551c | ||
|
9ed3dc52e0 | ||
|
52a43bcdfc | ||
|
f5f08becef | ||
|
9c56afeff3 | ||
|
1bc7aac780 | ||
|
1f916e65cf | ||
|
af8e524a7d | ||
|
c60ba4ba04 | ||
|
6754acd83f | ||
|
dcdecaab22 | ||
|
f41727cc9c | ||
|
6339a8c95a | ||
|
44cb8e5475 | ||
|
eef46b1aed | ||
|
bd9eef1f90 | ||
|
0e7f5d604e | ||
|
fa1d8dfabc | ||
|
2d8d16ff5e | ||
|
8a00620a71 | ||
|
6ce57b7924 | ||
|
eca3ccff76 | ||
|
3011df4f35 | ||
|
445f7a273a | ||
|
2fb7e50b54 | ||
|
3f88a3f4e6 | ||
|
a0b02106c3 | ||
|
054ce3961a |
@@ -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"
|
||||
|
||||
|
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: "/"
|
||||
|
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -12,6 +12,7 @@ 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@v4
|
||||
@@ -31,6 +32,7 @@ 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
|
||||
@@ -46,7 +48,7 @@ jobs:
|
||||
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') }}
|
||||
@@ -65,6 +67,7 @@ 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@v4
|
||||
@@ -92,6 +95,7 @@ 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@v4
|
||||
|
4
.github/workflows/cachix.yml
vendored
4
.github/workflows/cachix.yml
vendored
@@ -14,10 +14,10 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install nix
|
||||
uses: cachix/install-nix-action@v24
|
||||
uses: cachix/install-nix-action@V27
|
||||
|
||||
- name: Authenticate with Cachix
|
||||
uses: cachix/cachix-action@v13
|
||||
uses: cachix/cachix-action@v15
|
||||
with:
|
||||
name: helix
|
||||
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||
|
6
.github/workflows/gh-pages.yml
vendored
6
.github/workflows/gh-pages.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
- 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'
|
||||
@@ -27,14 +27,14 @@ jobs:
|
||||
echo "OUTDIR=$OUTDIR" >> $GITHUB_ENV
|
||||
|
||||
- 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@v3
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
||||
|
2
.ignore
2
.ignore
@@ -1,2 +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
|
457
CHANGELOG.md
457
CHANGELOG.md
@@ -1,3 +1,460 @@
|
||||
# 24.07 (2024-07-14)
|
||||
|
||||
Thanks to all of the contributors! This release has changes from 160 contributors.
|
||||
|
||||
Breaking changes:
|
||||
|
||||
Features:
|
||||
|
||||
- Add a textobject for entries/elements of list-like things ([#8150](https://github.com/helix-editor/helix/pull/8150))
|
||||
- Add a picker showing files changed in VCS ([#5645](https://github.com/helix-editor/helix/pull/5645))
|
||||
- Use a temporary file for writes ([#9236](https://github.com/helix-editor/helix/pull/9236), [#10339](https://github.com/helix-editor/helix/pull/10339), [#10790](https://github.com/helix-editor/helix/pull/10790))
|
||||
- Allow cycling through LSP signature-help signatures with `A-n`/`A-p` ([#9974](https://github.com/helix-editor/helix/pull/9974), [#10654](https://github.com/helix-editor/helix/pull/10654), [#10655](https://github.com/helix-editor/helix/pull/10655))
|
||||
- Use tree-sitter when finding matching brackets and closest pairs ([#8294](https://github.com/helix-editor/helix/pull/8294), [#10613](https://github.com/helix-editor/helix/pull/10613), [#10777](https://github.com/helix-editor/helix/pull/10777))
|
||||
- Auto-save all buffers after a delay ([#10899](https://github.com/helix-editor/helix/pull/10899), [#11047](https://github.com/helix-editor/helix/pull/11047))
|
||||
|
||||
Commands:
|
||||
|
||||
- `select_all_siblings` (`A-a`) - select all siblings of each selection ([87c4161](https://github.com/helix-editor/helix/commit/87c4161))
|
||||
- `select_all_children` (`A-i`) - select all children of each selection ([fa67c5c](https://github.com/helix-editor/helix/commit/fa67c5c))
|
||||
- `:read` - insert the contents of the given file at each selection ([#10447](https://github.com/helix-editor/helix/pull/10447))
|
||||
|
||||
Usability improvements:
|
||||
|
||||
- Support scrolling popup contents using the mouse ([#10053](https://github.com/helix-editor/helix/pull/10053))
|
||||
- Sort the jumplist picker so that most recent items come first ([#10095](https://github.com/helix-editor/helix/pull/10095))
|
||||
- Improve `goto_file`'s (`gf`) automatic path detection strategy ([#9065](https://github.com/helix-editor/helix/pull/9065))
|
||||
- Respect language server definition order in code action menu ([#9590](https://github.com/helix-editor/helix/pull/9590))
|
||||
- Allow using a count with `goto_next_buffer` (`gn`) and `goto_previous_buffer` (`gp`) ([#10463](https://github.com/helix-editor/helix/pull/10463))
|
||||
- Improve the positioning of popups ([#10257](https://github.com/helix-editor/helix/pull/10257), [#10573](https://github.com/helix-editor/helix/pull/10573))
|
||||
- Reset all changes overlapped by selections in `:reset-diff-change` ([#10728](https://github.com/helix-editor/helix/pull/10728))
|
||||
- Await pending writes in the `suspend` command (`C-z`) ([#10797](https://github.com/helix-editor/helix/pull/10797))
|
||||
- Remove special handling of line ending characters in `replace` (`r`) ([#10786](https://github.com/helix-editor/helix/pull/10786))
|
||||
- Use the selected register as a history register for `rename_symbol` (`<space>r`) ([#10932](https://github.com/helix-editor/helix/pull/10932))
|
||||
- Use the configured insert-mode cursor for prompt entry ([#10945](https://github.com/helix-editor/helix/pull/10945))
|
||||
- Add tilted quotes to the matching brackets list ([#10971](https://github.com/helix-editor/helix/pull/10971))
|
||||
- Prevent improper files like `/dev/urandom` from being used as file arguments ([#10733](https://github.com/helix-editor/helix/pull/10733))
|
||||
- Allow multiple language servers to provide `:lsp-workspace-command`s ([#10176](https://github.com/helix-editor/helix/pull/10176), [#11105](https://github.com/helix-editor/helix/pull/11105))
|
||||
- Trim output of commands executed through `:pipe` ([#10952](https://github.com/helix-editor/helix/pull/10952))
|
||||
|
||||
Fixes:
|
||||
|
||||
- Use `lldb-dap` instead of `lldb-vscode` in default DAP configuration ([#10091](https://github.com/helix-editor/helix/pull/10091))
|
||||
- Fix creation of uneven splits when closing windows ([#10004](https://github.com/helix-editor/helix/pull/10004))
|
||||
- Avoid setting a register in `delete_selection_noyank`, fixing the command's use in command sequences ([#10050](https://github.com/helix-editor/helix/pull/10050), [#10148](https://github.com/helix-editor/helix/pull/10148))
|
||||
- Fix jump alphabet config resetting when using `:config-reload` ([#10156](https://github.com/helix-editor/helix/pull/10156))
|
||||
- Overlay LSP unnecessary/deprecated diagnostic tag highlights onto regular diagnostic highlights ([#10084](https://github.com/helix-editor/helix/pull/10084))
|
||||
- Fix crash on LSP text edits with invalid ranges ([#9649](https://github.com/helix-editor/helix/pull/9649))
|
||||
- Handle partial failure when sending multiple LSP `textDocument/didSave` notifications ([#10168](https://github.com/helix-editor/helix/pull/10168))
|
||||
- Fix off-by-one error for completion-replace option ([#10279](https://github.com/helix-editor/helix/pull/10279))
|
||||
- Fix mouse right-click selection behavior ([#10067](https://github.com/helix-editor/helix/pull/10067))
|
||||
- Fix scrolling to the end within a popup ([#10181](https://github.com/helix-editor/helix/pull/10181))
|
||||
- Fix jump label highlight locations when jumping in non-ascii text ([#10317](https://github.com/helix-editor/helix/pull/10317))
|
||||
- Fix crashes from tree-sitter query captures that return non-grapheme aligned ranges ([#10310](https://github.com/helix-editor/helix/pull/10310))
|
||||
- Include VCS change in `mi`/`ma` textobject infobox ([#10496](https://github.com/helix-editor/helix/pull/10496))
|
||||
- Override crossterm's support for `NO_COLOR` ([#10514](https://github.com/helix-editor/helix/pull/10514))
|
||||
- Respect mode when starting a search ([#10505](https://github.com/helix-editor/helix/pull/10505))
|
||||
- Simplify first-in-line computation for indent queries ([#10527](https://github.com/helix-editor/helix/pull/10527))
|
||||
- Ignore .svn version controlled files in file pickers ([#10536](https://github.com/helix-editor/helix/pull/10536))
|
||||
- Fix overloading language servers with `completionItem/resolve` requests ([38ee845](https://github.com/helix-editor/helix/commit/38ee845), [#10873](https://github.com/helix-editor/helix/pull/10873))
|
||||
- Specify direction for `select_next_sibling` / `select_prev_sibling` ([#10542](https://github.com/helix-editor/helix/pull/10542))
|
||||
- Fix restarting language servers ([#10614](https://github.com/helix-editor/helix/pull/10614))
|
||||
- Don't stop at the first URL in `goto_file` ([#10622](https://github.com/helix-editor/helix/pull/10622))
|
||||
- Fix overflows in window size calculations for small terminals ([#10620](https://github.com/helix-editor/helix/pull/10620))
|
||||
- Allow missing or empty completion lists in DAP ([#10332](https://github.com/helix-editor/helix/pull/10332))
|
||||
- Revert statusline refactor that could cause the statusline to blank out on files with long paths ([#10642](https://github.com/helix-editor/helix/pull/10642))
|
||||
- Synchronize files after writing ([#10735](https://github.com/helix-editor/helix/pull/10735))
|
||||
- Avoid `cnorm` for cursor-type detection in certain terminals ([#10769](https://github.com/helix-editor/helix/pull/10769))
|
||||
- Reset inlay hints when stopping or restarting a language server ([#10741](https://github.com/helix-editor/helix/pull/10741))
|
||||
- Fix logic for updating `--version` when development VCS HEAD changes ([#10896](https://github.com/helix-editor/helix/pull/10896))
|
||||
- Set a max value for the count ([#10930](https://github.com/helix-editor/helix/pull/10930))
|
||||
- Deserialize number IDs in DAP module types ([#10943](https://github.com/helix-editor/helix/pull/10943))
|
||||
- Fix the behavior of `jump_backwords` when the jumplist is at capacity ([#10968](https://github.com/helix-editor/helix/pull/10968))
|
||||
- Fix injection layer heritage tracking for reused tree-sitter injection layers ([#1098](https://github.com/helix-editor/helix/pull/1098))
|
||||
- Fix pluralization of "buffers" in the statusline for `:q`, `:q!`, `:wq` ([#11018](https://github.com/helix-editor/helix/pull/11018))
|
||||
- Declare LSP formatting client capabilities ([#11064](https://github.com/helix-editor/helix/pull/11064))
|
||||
- Commit uncommitted changes before attempting undo/earlier ([#11090](https://github.com/helix-editor/helix/pull/11090))
|
||||
- Expand tilde for selected paths in `goto_file` ([#10964](https://github.com/helix-editor/helix/pull/10964))
|
||||
- Commit undo checkpoints before `:write[-all]`, fixing the modification indicator ([#11062](https://github.com/helix-editor/helix/pull/11062))
|
||||
|
||||
Themes:
|
||||
|
||||
- Add jump label styles to `nightfox` ([#10052](https://github.com/helix-editor/helix/pull/10052))
|
||||
- Add jump label styles to Solarized themes ([#10056](https://github.com/helix-editor/helix/pull/10056))
|
||||
- Add jump label styles to `cyan_light` ([#10058](https://github.com/helix-editor/helix/pull/10058))
|
||||
- Add jump label styles to `onelight` ([#10061](https://github.com/helix-editor/helix/pull/10061))
|
||||
- Add `flexoki-dark` and `flexoki-light` ([#10002](https://github.com/helix-editor/helix/pull/10002))
|
||||
- Add default theme keys for LSP diagnostics tags to existing themes ([#10064](https://github.com/helix-editor/helix/pull/10064))
|
||||
- Add jump label styles to base16 themes ([#10076](https://github.com/helix-editor/helix/pull/10076))
|
||||
- Dim primary selection in `kanagawa` ([#10094](https://github.com/helix-editor/helix/pull/10094), [#10500](https://github.com/helix-editor/helix/pull/10500))
|
||||
- Add jump label styles to tokyonight themes ([#10106](https://github.com/helix-editor/helix/pull/10106))
|
||||
- Add jump label styles to papercolor themes ([#10104](https://github.com/helix-editor/helix/pull/10104))
|
||||
- Add jump label styles to Darcula themes ([#10116](https://github.com/helix-editor/helix/pull/10116))
|
||||
- Add jump label styles to `autumn` ([#10134](https://github.com/helix-editor/helix/pull/10134))
|
||||
- Add jump label styles to Ayu themes ([#10133](https://github.com/helix-editor/helix/pull/10133))
|
||||
- Add jump label styles to `dark_high_contrast` ([#10133](https://github.com/helix-editor/helix/pull/10133))
|
||||
- Update material themes ([#10290](https://github.com/helix-editor/helix/pull/10290))
|
||||
- Add jump label styles to `varua` ([#10299](https://github.com/helix-editor/helix/pull/10299))
|
||||
- Add ruler style to `adwaita-dark` ([#10260](https://github.com/helix-editor/helix/pull/10260))
|
||||
- Remove `ui.highlight` effects from `solarized_dark` ([#10261](https://github.com/helix-editor/helix/pull/10261))
|
||||
- Fix statusline color in material themes ([#10308](https://github.com/helix-editor/helix/pull/10308))
|
||||
- Brighten `nord` selection highlight ([#10307](https://github.com/helix-editor/helix/pull/10307))
|
||||
- Add inlay-hint styles to monokai themes ([#10334](https://github.com/helix-editor/helix/pull/10334))
|
||||
- Add bufferline and cursorline colors to `vim_dark_high_contrast` ([#10444](https://github.com/helix-editor/helix/pull/10444))
|
||||
- Switch themes with foreground rulers to background ([#10309](https://github.com/helix-editor/helix/pull/10309))
|
||||
- Fix statusline colors for `everblush` ([#10394](https://github.com/helix-editor/helix/pull/10394))
|
||||
- Use `yellow1` for `gruvbox` warning diagnostics ([#10506](https://github.com/helix-editor/helix/pull/10506))
|
||||
- Add jump label styles to Modus themes ([#10538](https://github.com/helix-editor/helix/pull/10538))
|
||||
- Refactor `dark_plus` and switch maintainers ([#10543](https://github.com/helix-editor/helix/pull/10543), [#10574](https://github.com/helix-editor/helix/pull/10574))
|
||||
- Add debug highlights to `dark_plus` ([#10593](https://github.com/helix-editor/helix/pull/10593))
|
||||
- Fix per-mode cursor colors in the default theme ([#10608](https://github.com/helix-editor/helix/pull/10608))
|
||||
- Add `tag` and `attribute` highlights to `dark_high_contrast` ([#10705](https://github.com/helix-editor/helix/pull/10705))
|
||||
- Improve readability of virtual text with `noctis` theme ([#10910](https://github.com/helix-editor/helix/pull/10910))
|
||||
- Sync `catppuccin` themes with upstream ([#10954](https://github.com/helix-editor/helix/pull/10954))
|
||||
- Improve jump colors for `github_dark` themes ([#10946](https://github.com/helix-editor/helix/pull/10946))
|
||||
- Add modeline and default virtual highlights to `base16_default` ([#10858](https://github.com/helix-editor/helix/pull/10858))
|
||||
- Add `iroaseta` ([#10381](https://github.com/helix-editor/helix/pull/10381))
|
||||
- Refactor `gruvbox` ([#10773](https://github.com/helix-editor/helix/pull/10773), [#11071](https://github.com/helix-editor/helix/pull/11071))
|
||||
- Add cursorcolumn and cursorline to `base16_transparent` ([#11099](https://github.com/helix-editor/helix/pull/11099))
|
||||
- Update cursorline color for `fleet_dark` ([#11046](https://github.com/helix-editor/helix/pull/11046))
|
||||
- Add `kanagawa-dragon` ([#10172](https://github.com/helix-editor/helix/pull/10172))
|
||||
|
||||
New languages:
|
||||
|
||||
- BitBake ([#10010](https://github.com/helix-editor/helix/pull/10010))
|
||||
- Earthfile ([#10111](https://github.com/helix-editor/helix/pull/10111), [#10489](https://github.com/helix-editor/helix/pull/10489), [#10779](https://github.com/helix-editor/helix/pull/10779))
|
||||
- TCL ([#9837](https://github.com/helix-editor/helix/pull/9837))
|
||||
- ADL ([#10029](https://github.com/helix-editor/helix/pull/10029))
|
||||
- LDIF ([#10330](https://github.com/helix-editor/helix/pull/10330))
|
||||
- XTC ([#10448](https://github.com/helix-editor/helix/pull/10448))
|
||||
- Move ([f06a166](https://github.com/helix-editor/helix/commit/f06a166))
|
||||
- Pest ([#10616](https://github.com/helix-editor/helix/pull/10616))
|
||||
- GJS/GTS ([#9940](https://github.com/helix-editor/helix/pull/9940))
|
||||
- Inko ([#10656](https://github.com/helix-editor/helix/pull/10656))
|
||||
- Mojo ([#10743](https://github.com/helix-editor/helix/pull/10743))
|
||||
- Elisp ([#10644](https://github.com/helix-editor/helix/pull/10644))
|
||||
|
||||
Updated languages and queries:
|
||||
|
||||
- Recognize `mkdn` files as markdown ([#10065](https://github.com/helix-editor/helix/pull/10065))
|
||||
- Add comment injections for Gleam ([#10062](https://github.com/helix-editor/helix/pull/10062))
|
||||
- Recognize BuildKite commands in YAML injections ([#10090](https://github.com/helix-editor/helix/pull/10090))
|
||||
- Add F# block comment token configuration ([#10108](https://github.com/helix-editor/helix/pull/10108))
|
||||
- Update tree-sitter-templ and queries ([#10114](https://github.com/helix-editor/helix/pull/10114))
|
||||
- Recognize `Tiltfile` as Starlark ([#10072](https://github.com/helix-editor/helix/pull/10072))
|
||||
- Remove `todo.txt` from files recognized as todotxt ([5fece00](https://github.com/helix-editor/helix/commit/5fece00))
|
||||
- Highlight `type` keyword in Python from PEP695 ([#10165](https://github.com/helix-editor/helix/pull/10165))
|
||||
- Update tree-sitter-koka, add language server config ([#10119](https://github.com/helix-editor/helix/pull/10119))
|
||||
- Recognize node and Python history files ([#10120](https://github.com/helix-editor/helix/pull/10120))
|
||||
- Recognize more shell files as bash ([#10120](https://github.com/helix-editor/helix/pull/10120))
|
||||
- Recognize the bun shebang as typescript ([#10120](https://github.com/helix-editor/helix/pull/10120))
|
||||
- Add a configuration for the angular language server ([#10166](https://github.com/helix-editor/helix/pull/10166))
|
||||
- Add textobject queries for Solidity ([#10318](https://github.com/helix-editor/helix/pull/10318))
|
||||
- Recognize `meson.options` as Meson ([#10323](https://github.com/helix-editor/helix/pull/10323))
|
||||
- Improve Solidity highlighting ([4fc0a4d](https://github.com/helix-editor/helix/commit/4fc0a4d))
|
||||
- Recognize `_.tpl` files as Helm ([#10344](https://github.com/helix-editor/helix/pull/10344))
|
||||
- Update tree-sitter-ld and highlights ([#10379](https://github.com/helix-editor/helix/pull/10379))
|
||||
- Add `lldb-dap` configuration for Odin ([#10175](https://github.com/helix-editor/helix/pull/10175))
|
||||
- Update tree-sitter-rust ([#10365](https://github.com/helix-editor/helix/pull/10365))
|
||||
- Update tree-sitter-typst ([#10321](https://github.com/helix-editor/helix/pull/10321))
|
||||
- Recognize `hyprpaper.conf`, `hypridle.conf` and `hyprlock.conf` as Hyprlang ([#10383](https://github.com/helix-editor/helix/pull/10383))
|
||||
- Improve HTML highlighting ([#10503](https://github.com/helix-editor/helix/pull/10503))
|
||||
- Add `rust-script` and `cargo` as shebangs for Rust ([#10484](https://github.com/helix-editor/helix/pull/10484))
|
||||
- Fix precedence of tag highlights in Svelte ([#10487](https://github.com/helix-editor/helix/pull/10487))
|
||||
- Update tree-sitter-bash ([#10526](https://github.com/helix-editor/helix/pull/10526))
|
||||
- Recognize `*.ignore` files as ignore ([#10579](https://github.com/helix-editor/helix/pull/10579))
|
||||
- Add configuration to enable inlay hints in metals ([#10597](https://github.com/helix-editor/helix/pull/10597))
|
||||
- Enable highlighting private members in ECMA languages ([#10554](https://github.com/helix-editor/helix/pull/10554))
|
||||
- Add comment injection to typst queries ([#10628](https://github.com/helix-editor/helix/pull/10628))
|
||||
- Add textobject queries for Hurl ([#10594](https://github.com/helix-editor/helix/pull/10594))
|
||||
- Add `try` keyword to Rust ([#10641](https://github.com/helix-editor/helix/pull/10641))
|
||||
- Add `is not` and `not in` to Python highlights ([#10647](https://github.com/helix-editor/helix/pull/10647))
|
||||
- Remove ' and ⟨⟩ from Lean autopair configuration ([#10688](https://github.com/helix-editor/helix/pull/10688))
|
||||
- Match TOML/YAML highlights for JSON keys ([#10676](https://github.com/helix-editor/helix/pull/10676))
|
||||
- Recognize WORKSPACE files as Starlark ([#10713](https://github.com/helix-editor/helix/pull/10713))
|
||||
- Switch Odin tree-sitter grammar and highlights ([#10698](https://github.com/helix-editor/helix/pull/10698))
|
||||
- Update `tree-sitter-slint` ([#10749](https://github.com/helix-editor/helix/pull/10749))
|
||||
- Add missing operators for Solidity highlights ([#10735](https://github.com/helix-editor/helix/pull/10735))
|
||||
- Update `tree-sitter-inko` ([#10805](https://github.com/helix-editor/helix/pull/10805))
|
||||
- Add `py`, `hs`, `rs` and `typ` injection regexes ([#10785](https://github.com/helix-editor/helix/pull/10785))
|
||||
- Update Swift grammar and queries ([#10802](https://github.com/helix-editor/helix/pull/10802))
|
||||
- Update Cairo grammar and queries ([#10919](https://github.com/helix-editor/helix/pull/10919), [#11067](https://github.com/helix-editor/helix/pull/11067))
|
||||
- Update Rust grammar ([#10973](https://github.com/helix-editor/helix/pull/10973))
|
||||
- Add block comment tokens for typst ([#10955](https://github.com/helix-editor/helix/pull/10955))
|
||||
- Recognize `jsonl` as JSON ([#11004](https://github.com/helix-editor/helix/pull/11004))
|
||||
- Add rulers and text-width at 100 columns for Lean language ([#10969](https://github.com/helix-editor/helix/pull/10969))
|
||||
- Improve VDHL highlights ([#10845](https://github.com/helix-editor/helix/pull/10845))
|
||||
- Recognize `hsc` as Haskell ([#11074](https://github.com/helix-editor/helix/pull/11074))
|
||||
- Fix heredoc and `$'<ansi_string>'` highlights in Bash ([#11118](https://github.com/helix-editor/helix/pull/11118))
|
||||
- Add LSP configuration for `basedpyright` ([#11121](https://github.com/helix-editor/helix/pull/11121))
|
||||
- Recognize `npmrc` and `.nmprc` files as INI ([#11131](https://github.com/helix-editor/helix/pull/11131))
|
||||
- Recognize `~/.config/git/ignore` as git-ignore ([#11131](https://github.com/helix-editor/helix/pull/11131))
|
||||
- Recognize `pdm.lock` and `uv.lock` as TOML ([#11131](https://github.com/helix-editor/helix/pull/11131))
|
||||
- Recognize `.yml` as well as `.yaml` for Helm chart templates ([#11135](https://github.com/helix-editor/helix/pull/11135))
|
||||
- Add regex injections for Bash ([#11112](https://github.com/helix-editor/helix/pull/11112))
|
||||
- Update tree-sitter-todo ([#11097](https://github.com/helix-editor/helix/pull/11097))
|
||||
|
||||
Packaging:
|
||||
|
||||
- Make `Helix.appdata.xml` spec-compliant ([#10051](https://github.com/helix-editor/helix/pull/10051))
|
||||
- Expose all flake outputs through flake-compat ([#10673](https://github.com/helix-editor/helix/pull/10673))
|
||||
- Bump the MSRV to 1.74.0 ([#10714](https://github.com/helix-editor/helix/pull/10714))
|
||||
- Improve FiSH completions ([#10853](https://github.com/helix-editor/helix/pull/10853))
|
||||
- Improve ZSH completions ([#10853](https://github.com/helix-editor/helix/pull/10853))
|
||||
|
||||
# 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.
|
||||
|
889
Cargo.lock
generated
889
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
@@ -2,7 +2,6 @@
|
||||
resolver = "2"
|
||||
members = [
|
||||
"helix-core",
|
||||
"helix-config",
|
||||
"helix-view",
|
||||
"helix-term",
|
||||
"helix-tui",
|
||||
@@ -12,6 +11,8 @@ members = [
|
||||
"helix-loader",
|
||||
"helix-vcs",
|
||||
"helix-parsec",
|
||||
"helix-stdx",
|
||||
"helix-syntax",
|
||||
"xtask",
|
||||
]
|
||||
|
||||
@@ -37,11 +38,13 @@ package.helix-tui.opt-level = 2
|
||||
package.helix-term.opt-level = 2
|
||||
|
||||
[workspace.dependencies]
|
||||
tree-sitter = { version = "0.20", git = "https://github.com/tree-sitter/tree-sitter", rev = "ab09ae20d640711174b8da8a654f6b3dec93da1a" }
|
||||
nucleo = "0.2.0"
|
||||
tree-sitter = { version = "0.22" }
|
||||
nucleo = "0.5.0"
|
||||
slotmap = "1.0.7"
|
||||
thiserror = "1.0"
|
||||
|
||||
[workspace.package]
|
||||
version = "23.10.0"
|
||||
version = "24.7.0"
|
||||
edition = "2021"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
categories = ["editor"]
|
||||
|
@@ -47,7 +47,7 @@ Note: Only certain languages have indentation definitions at the moment. Check
|
||||
|
||||
[Installation documentation](https://docs.helix-editor.com/install.html).
|
||||
|
||||
[](https://repology.org/project/helix/versions)
|
||||
[](https://repology.org/project/helix/versions)
|
||||
|
||||
# Contributing
|
||||
|
||||
|
@@ -28,6 +28,11 @@
|
||||
"label" = "magenta"
|
||||
"namespace" = "magenta"
|
||||
"ui.help" = { fg = "white", bg = "black" }
|
||||
"ui.statusline.insert" = { fg = "black", bg = "green" }
|
||||
"ui.statusline.select" = { fg = "black", bg = "blue" }
|
||||
"ui.virtual" = { fg = "gray", modifiers = ["italic"] }
|
||||
"ui.virtual.jump-label" = { fg = "blue", modifiers = ["bold", "underlined"] }
|
||||
"ui.virtual.ruler" = { bg = "black" }
|
||||
|
||||
"markup.heading" = "blue"
|
||||
"markup.list" = "red"
|
||||
|
@@ -3,12 +3,19 @@
|
||||
[Helix](./title-page.md)
|
||||
|
||||
- [Installation](./install.md)
|
||||
- [Package Managers](./package-managers.md)
|
||||
- [Building from source](./building-from-source.md)
|
||||
- [Usage](./usage.md)
|
||||
- [Registers](./registers.md)
|
||||
- [Surround](./surround.md)
|
||||
- [Textobjects](./textobjects.md)
|
||||
- [Syntax aware motions](./syntax-aware-motions.md)
|
||||
- [Keymap](./keymap.md)
|
||||
- [Commands](./commands.md)
|
||||
- [Language support](./lang-support.md)
|
||||
- [Migrating from Vim](./from-vim.md)
|
||||
- [Configuration](./configuration.md)
|
||||
- [Editor](./editor.md)
|
||||
- [Themes](./themes.md)
|
||||
- [Key remapping](./remapping.md)
|
||||
- [Languages](./languages.md)
|
||||
|
164
book/src/building-from-source.md
Normal file
164
book/src/building-from-source.md
Normal file
@@ -0,0 +1,164 @@
|
||||
## Building from source
|
||||
|
||||
- [Configuring Helix's runtime files](#configuring-helixs-runtime-files)
|
||||
- [Linux and macOS](#linux-and-macos)
|
||||
- [Windows](#windows)
|
||||
- [Multiple runtime directories](#multiple-runtime-directories)
|
||||
- [Note to packagers](#note-to-packagers)
|
||||
- [Validating the installation](#validating-the-installation)
|
||||
- [Configure the desktop shortcut](#configure-the-desktop-shortcut)
|
||||
|
||||
Requirements:
|
||||
|
||||
Clone the Helix GitHub repository into a directory of your choice. The
|
||||
examples in this documentation assume installation into either `~/src/` on
|
||||
Linux and macOS, or `%userprofile%\src\` on Windows.
|
||||
|
||||
- The [Rust toolchain](https://www.rust-lang.org/tools/install)
|
||||
- The [Git version control system](https://git-scm.com/)
|
||||
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
|
||||
If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
|
||||
|
||||
```sh
|
||||
RUSTFLAGS="-C target-feature=-crt-static"
|
||||
```
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
|
||||
2. Compile from source:
|
||||
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
|
||||
> 💡 If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD`
|
||||
|
||||
> 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
|
||||
> grammars with `hx --grammar fetch` and compile them with
|
||||
> `hx --grammar build`. This will install them in
|
||||
> the `runtime` directory within the user's helix config directory (more
|
||||
> [details below](#multiple-runtime-directories)).
|
||||
|
||||
### Configuring Helix's runtime files
|
||||
|
||||
#### Linux and macOS
|
||||
|
||||
The **runtime** directory is one below the Helix source, so either export a
|
||||
`HELIX_RUNTIME` environment variable to point to that directory and add it to
|
||||
your `~/.bashrc` or equivalent:
|
||||
|
||||
```sh
|
||||
export HELIX_RUNTIME=~/src/helix/runtime
|
||||
```
|
||||
|
||||
Or, create a symbolic link:
|
||||
|
||||
```sh
|
||||
ln -Ts $PWD/runtime ~/.config/helix/runtime
|
||||
```
|
||||
|
||||
If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again.
|
||||
|
||||
#### Windows
|
||||
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
|
||||
`Edit environment variables for your account`) or use the `setx` command in
|
||||
Cmd:
|
||||
|
||||
```sh
|
||||
setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime"
|
||||
```
|
||||
|
||||
> 💡 `%userprofile%` resolves to your user directory like
|
||||
> `C:\Users\Your-Name\` for example.
|
||||
|
||||
Or, create a symlink in `%appdata%\helix\` that links to the source code directory:
|
||||
|
||||
| Method | Command |
|
||||
| ---------- | -------------------------------------------------------------------------------------- |
|
||||
| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` |
|
||||
| Cmd | `cd %appdata%\helix` <br/> `mklink /D runtime "%userprofile%\src\helix\runtime"` |
|
||||
|
||||
> 💡 On Windows, creating a symbolic link may require running PowerShell or
|
||||
> Cmd as an administrator.
|
||||
|
||||
#### Multiple runtime directories
|
||||
|
||||
When Helix finds multiple runtime directories it will search through them for files in the
|
||||
following order:
|
||||
|
||||
1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
|
||||
developing and testing helix only).
|
||||
2. `runtime/` subdirectory of OS-dependent helix user config directory.
|
||||
3. `$HELIX_RUNTIME`
|
||||
4. Distribution-specific fallback directory (set at compile time—not run time—
|
||||
with the `HELIX_DEFAULT_RUNTIME` environment variable)
|
||||
5. `runtime/` subdirectory of path to Helix executable.
|
||||
|
||||
This order also sets the priority for selecting which file will be used if multiple runtime
|
||||
directories have files with the same name.
|
||||
|
||||
#### Note to packagers
|
||||
|
||||
If you are making a package of Helix for end users, to provide a good out of
|
||||
the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment
|
||||
variable at build time (before invoking `cargo build`) to a directory which
|
||||
will store the final runtime files after installation. For example, say you want
|
||||
to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build
|
||||
script could follow are:
|
||||
|
||||
1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime`
|
||||
1. `cargo build --profile opt --locked --path helix-term`
|
||||
1. `cp -r runtime $BUILD_DIR/usr/lib/helix/`
|
||||
1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx`
|
||||
|
||||
This way the resulting `hx` binary will always look for its runtime directory in
|
||||
`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix`
|
||||
or `HELIX_RUNTIME`.
|
||||
|
||||
### Validating the installation
|
||||
|
||||
To make sure everything is set up as expected you should run the Helix health
|
||||
check:
|
||||
|
||||
```sh
|
||||
hx --health
|
||||
```
|
||||
|
||||
For more information on the health check results refer to
|
||||
[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
|
||||
### Configure the desktop shortcut
|
||||
|
||||
If your desktop environment supports the
|
||||
[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html)
|
||||
you can configure Helix to show up in the application menu by copying the
|
||||
provided `.desktop` and icon files to their correct folders:
|
||||
|
||||
```sh
|
||||
cp contrib/Helix.desktop ~/.local/share/applications
|
||||
cp contrib/helix.png ~/.icons # or ~/.local/share/icons
|
||||
```
|
||||
It is recommended to convert the links in the `.desktop` file to absolute paths to avoid potential problems:
|
||||
|
||||
```sh
|
||||
sed -i -e "s|Exec=hx %F|Exec=$(readlink -f ~/.cargo/bin/hx) %F|g" \
|
||||
-e "s|Icon=helix|Icon=$(readlink -f ~/.icons/helix.png)|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
||||
|
||||
To use another terminal than the system default, you can modify the `.desktop`
|
||||
file. For example, to use `kitty`:
|
||||
|
||||
```sh
|
||||
sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
|
||||
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
@@ -33,344 +33,3 @@ signal to the Helix process on Unix operating systems, such as by using the comm
|
||||
Finally, you can have a `config.toml` local to a project by putting it under a `.helix` directory in your repository.
|
||||
Its settings will be merged with the configuration directory `config.toml` and the built-in configuration.
|
||||
|
||||
## Editor
|
||||
|
||||
### `[editor]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
| `scrolloff` | Number of lines of padding around the edge of the screen when scrolling | `5` |
|
||||
| `mouse` | Enable mouse mode | `true` |
|
||||
| `middle-click-paste` | Middle click paste support | `true` |
|
||||
| `scroll-lines` | Number of lines to scroll per scroll wheel step | `3` |
|
||||
| `shell` | Shell to use when running external commands | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
|
||||
| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `absolute` |
|
||||
| `cursorline` | Highlight all lines with a cursor | `false` |
|
||||
| `cursorcolumn` | Highlight all columns with a cursor | `false` |
|
||||
| `gutters` | Gutters to display: Available are `diagnostics` and `diff` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` |
|
||||
| `auto-completion` | Enable automatic pop up of auto-completion | `true` |
|
||||
| `auto-format` | Enable automatic formatting on save | `true` |
|
||||
| `auto-save` | Enable automatic saving on the focus moving away from Helix. Requires [focus event support](https://github.com/helix-editor/helix/wiki/Terminal-Support) from your terminal | `false` |
|
||||
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant | `250` |
|
||||
| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` |
|
||||
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
|
||||
| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` |
|
||||
| `auto-info` | Whether to display info boxes | `true` |
|
||||
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` |
|
||||
| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
|
||||
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` |
|
||||
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
|
||||
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
|
||||
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |
|
||||
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` |
|
||||
| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` |
|
||||
| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` |
|
||||
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` |
|
||||
| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid`
|
||||
|
||||
### `[editor.statusline]` Section
|
||||
|
||||
Allows configuring the statusline at the bottom of the editor.
|
||||
|
||||
The configuration distinguishes between three areas of the status line:
|
||||
|
||||
`[ ... ... LEFT ... ... | ... ... ... ... CENTER ... ... ... ... | ... ... RIGHT ... ... ]`
|
||||
|
||||
Statusline elements can be defined as follows:
|
||||
|
||||
```toml
|
||||
[editor.statusline]
|
||||
left = ["mode", "spinner"]
|
||||
center = ["file-name"]
|
||||
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
|
||||
separator = "│"
|
||||
mode.normal = "NORMAL"
|
||||
mode.insert = "INSERT"
|
||||
mode.select = "SELECT"
|
||||
```
|
||||
The `[editor.statusline]` key takes the following sub-keys:
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` |
|
||||
| `center` | A list of elements aligned to the middle of the statusline | `[]` |
|
||||
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` |
|
||||
| `separator` | The character used to separate elements in the statusline | `"│"` |
|
||||
| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
|
||||
| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` |
|
||||
| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` |
|
||||
|
||||
The following statusline elements can be configured:
|
||||
|
||||
| Key | Description |
|
||||
| ------ | ----------- |
|
||||
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
|
||||
| `spinner` | A progress spinner indicating LSP activity |
|
||||
| `file-name` | The path/name of the opened file |
|
||||
| `file-base-name` | The basename of the opened file |
|
||||
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
|
||||
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
|
||||
| `file-line-ending` | The file line endings (CRLF or LF) |
|
||||
| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written |
|
||||
| `total-line-numbers` | The total line numbers of the opened file |
|
||||
| `file-type` | The type of the opened file |
|
||||
| `diagnostics` | The number of warnings and/or errors |
|
||||
| `workspace-diagnostics` | The number of warnings and/or errors on workspace |
|
||||
| `selections` | The number of active selections |
|
||||
| `primary-selection-length` | The number of characters currently in primary selection |
|
||||
| `position` | The cursor position |
|
||||
| `position-percentage` | The cursor position as a percentage of the total number of lines |
|
||||
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
|
||||
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
|
||||
| `version-control` | The current branch name or detached commit hash of the opened workspace |
|
||||
| `register` | The current selected register |
|
||||
|
||||
### `[editor.lsp]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | ----------- | ------- |
|
||||
| `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` |
|
||||
| `display-messages` | Display LSP progress messages below statusline[^1] | `false` |
|
||||
| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` |
|
||||
| `display-inlay-hints` | Display inlay hints[^2] | `false` |
|
||||
| `display-signature-help-docs` | Display docs under signature help popup | `true` |
|
||||
| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
|
||||
| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` |
|
||||
|
||||
[^1]: By default, a progress spinner is shown in the statusline beside the file path.
|
||||
|
||||
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix. Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances. Please report any bugs you see so we can fix them!
|
||||
|
||||
### `[editor.cursor-shape]` Section
|
||||
|
||||
Defines the shape of cursor in each mode.
|
||||
Valid values for these options are `block`, `bar`, `underline`, or `hidden`.
|
||||
|
||||
> 💡 Due to limitations of the terminal environment, only the primary cursor can
|
||||
> change shape.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | ----------- | ------- |
|
||||
| `normal` | Cursor shape in [normal mode][normal mode] | `block` |
|
||||
| `insert` | Cursor shape in [insert mode][insert mode] | `block` |
|
||||
| `select` | Cursor shape in [select mode][select mode] | `block` |
|
||||
|
||||
[normal mode]: ./keymap.md#normal-mode
|
||||
[insert mode]: ./keymap.md#insert-mode
|
||||
[select mode]: ./keymap.md#select--extend-mode
|
||||
|
||||
### `[editor.file-picker]` Section
|
||||
|
||||
Set options for file picker and global search. Ignoring a file means it is
|
||||
not visible in the Helix file picker and global search.
|
||||
|
||||
All git related options are only enabled in a git repository.
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
|`hidden` | Enables ignoring hidden files | `true`
|
||||
|`follow-symlinks` | Follow symlinks instead of ignoring them | `true`
|
||||
|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | `true`
|
||||
|`parents` | Enables reading ignore files from parent directories | `true`
|
||||
|`ignore` | Enables reading `.ignore` files | `true`
|
||||
|`git-ignore` | Enables reading `.gitignore` files | `true`
|
||||
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true`
|
||||
|`git-exclude` | Enables reading `.git/info/exclude` files | `true`
|
||||
|`max-depth` | Set with an integer value for maximum depth to recurse | Defaults to `None`.
|
||||
|
||||
Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files.
|
||||
|
||||
Additionally, you can use Helix-specific ignore files by creating a local `.helix/ignore` file in the current workspace or a global `ignore` file located in your Helix config directory:
|
||||
- Linux and Mac: `~/.config/helix/ignore`
|
||||
- Windows: `%AppData%\helix\ignore`
|
||||
|
||||
Example:
|
||||
|
||||
```ini
|
||||
# unignore in file picker and global search
|
||||
!.github/
|
||||
!.gitignore
|
||||
!.gitattributes
|
||||
```
|
||||
|
||||
### `[editor.auto-pairs]` Section
|
||||
|
||||
Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a
|
||||
simple boolean value, or a specific mapping of pairs of single characters.
|
||||
|
||||
To disable auto-pairs altogether, set `auto-pairs` to `false`:
|
||||
|
||||
```toml
|
||||
[editor]
|
||||
auto-pairs = false # defaults to `true`
|
||||
```
|
||||
|
||||
The default pairs are <code>(){}[]''""``</code>, but these can be customized by
|
||||
setting `auto-pairs` to a TOML table:
|
||||
|
||||
```toml
|
||||
[editor.auto-pairs]
|
||||
'(' = ')'
|
||||
'{' = '}'
|
||||
'[' = ']'
|
||||
'"' = '"'
|
||||
'`' = '`'
|
||||
'<' = '>'
|
||||
```
|
||||
|
||||
Additionally, this setting can be used in a language config. Unless
|
||||
the editor setting is `false`, this will override the editor config in
|
||||
documents with this language.
|
||||
|
||||
Example `languages.toml` that adds <> and removes ''
|
||||
|
||||
```toml
|
||||
[[language]]
|
||||
name = "rust"
|
||||
|
||||
[language.auto-pairs]
|
||||
'(' = ')'
|
||||
'{' = '}'
|
||||
'[' = ']'
|
||||
'"' = '"'
|
||||
'`' = '`'
|
||||
'<' = '>'
|
||||
```
|
||||
|
||||
### `[editor.search]` Section
|
||||
|
||||
Search specific options.
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
| `smart-case` | Enable smart case regex searching (case-insensitive unless pattern contains upper case characters) | `true` |
|
||||
| `wrap-around`| Whether the search should wrap after depleting the matches | `true` |
|
||||
|
||||
### `[editor.whitespace]` Section
|
||||
|
||||
Options for rendering whitespace with visible characters. Use `:set whitespace.render all` to temporarily enable visible whitespace.
|
||||
|
||||
| Key | Description | Default |
|
||||
|-----|-------------|---------|
|
||||
| `render` | Whether to render whitespace. May either be `"all"` or `"none"`, or a table with sub-keys `space`, `nbsp`, `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 |
|
||||
|
||||
Example
|
||||
|
||||
```toml
|
||||
[editor.whitespace]
|
||||
render = "all"
|
||||
# or control each character
|
||||
[editor.whitespace.render]
|
||||
space = "all"
|
||||
tab = "all"
|
||||
newline = "none"
|
||||
|
||||
[editor.whitespace.characters]
|
||||
space = "·"
|
||||
nbsp = "⍽"
|
||||
tab = "→"
|
||||
newline = "⏎"
|
||||
tabpad = "·" # Tabs will look like "→···" (depending on tab width)
|
||||
```
|
||||
|
||||
### `[editor.indent-guides]` Section
|
||||
|
||||
Options for rendering vertical indent guides.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `render` | Whether to render indent guides | `false` |
|
||||
| `character` | Literal character to use for rendering the indent guide | `│` |
|
||||
| `skip-levels` | Number of indent levels to skip | `0` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.indent-guides]
|
||||
render = true
|
||||
character = "╎" # Some characters that work well: "▏", "┆", "┊", "⸽"
|
||||
skip-levels = 1
|
||||
```
|
||||
|
||||
### `[editor.gutters]` Section
|
||||
|
||||
For simplicity, `editor.gutters` accepts an array of gutter types, which will
|
||||
use default settings for all gutter components.
|
||||
|
||||
```toml
|
||||
[editor]
|
||||
gutters = ["diff", "diagnostics", "line-numbers", "spacer"]
|
||||
```
|
||||
|
||||
To customize the behavior of gutters, the `[editor.gutters]` section must
|
||||
be used. This section contains top level settings, as well as settings for
|
||||
specific gutter components as subsections.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `layout` | A vector of gutters to display | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.gutters]
|
||||
layout = ["diff", "diagnostics", "line-numbers", "spacer"]
|
||||
```
|
||||
|
||||
#### `[editor.gutters.line-numbers]` Section
|
||||
|
||||
Options for the line number gutter
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `min-width` | The minimum number of characters to use | `3` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.gutters.line-numbers]
|
||||
min-width = 1
|
||||
```
|
||||
|
||||
#### `[editor.gutters.diagnostics]` Section
|
||||
|
||||
Currently unused
|
||||
|
||||
#### `[editor.gutters.diff]` Section
|
||||
|
||||
Currently unused
|
||||
|
||||
#### `[editor.gutters.spacer]` Section
|
||||
|
||||
Currently unused
|
||||
|
||||
### `[editor.soft-wrap]` Section
|
||||
|
||||
Options for soft wrapping lines that exceed the view width:
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `enable` | Whether soft wrapping is enabled. | `false` |
|
||||
| `max-wrap` | Maximum free space left at the end of the line. | `20` |
|
||||
| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` |
|
||||
| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `↪ ` |
|
||||
| `wrap-at-text-width` | Soft wrap at `text-width` instead of using the full viewport size. | `false` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.soft-wrap]
|
||||
enable = true
|
||||
max-wrap = 25 # increase value to reduce forced mid-word wrapping
|
||||
max-indent-retain = 0
|
||||
wrap-indicator = "" # set wrap-indicator to "" to hide it
|
||||
```
|
||||
|
||||
### `[editor.smart-tab]` Section
|
||||
|
||||
|
||||
| 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` |
|
||||
|
395
book/src/editor.md
Normal file
395
book/src/editor.md
Normal file
@@ -0,0 +1,395 @@
|
||||
## Editor
|
||||
|
||||
- [`[editor]` Section](#editor-section)
|
||||
- [`[editor.statusline]` Section](#editorstatusline-section)
|
||||
- [`[editor.lsp]` Section](#editorlsp-section)
|
||||
- [`[editor.cursor-shape]` Section](#editorcursor-shape-section)
|
||||
- [`[editor.file-picker]` Section](#editorfile-picker-section)
|
||||
- [`[editor.auto-pairs]` Section](#editorauto-pairs-section)
|
||||
- [`[editor.search]` Section](#editorsearch-section)
|
||||
- [`[editor.whitespace]` Section](#editorwhitespace-section)
|
||||
- [`[editor.indent-guides]` Section](#editorindent-guides-section)
|
||||
- [`[editor.gutters]` Section](#editorgutters-section)
|
||||
- [`[editor.gutters.line-numbers]` Section](#editorguttersline-numbers-section)
|
||||
- [`[editor.gutters.diagnostics]` Section](#editorguttersdiagnostics-section)
|
||||
- [`[editor.gutters.diff]` Section](#editorguttersdiff-section)
|
||||
- [`[editor.gutters.spacer]` Section](#editorguttersspacer-section)
|
||||
- [`[editor.soft-wrap]` Section](#editorsoft-wrap-section)
|
||||
- [`[editor.smart-tab]` Section](#editorsmart-tab-section)
|
||||
|
||||
### `[editor]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
| `scrolloff` | Number of lines of padding around the edge of the screen when scrolling | `5` |
|
||||
| `mouse` | Enable mouse mode | `true` |
|
||||
| `middle-click-paste` | Middle click paste support | `true` |
|
||||
| `scroll-lines` | Number of lines to scroll per scroll wheel step | `3` |
|
||||
| `shell` | Shell to use when running external commands | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
|
||||
| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `absolute` |
|
||||
| `cursorline` | Highlight all lines with a cursor | `false` |
|
||||
| `cursorcolumn` | Highlight all columns with a cursor | `false` |
|
||||
| `gutters` | Gutters to display: Available are `diagnostics` and `diff` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` |
|
||||
| `auto-completion` | Enable automatic pop up of auto-completion | `true` |
|
||||
| `auto-format` | Enable automatic formatting on save | `true` |
|
||||
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. | `250` |
|
||||
| `completion-timeout` | Time in milliseconds after typing a word character before completions are shown, set to 5 for instant. | `250` |
|
||||
| `preview-completion-insert` | Whether to apply completion item instantly when selected | `true` |
|
||||
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
|
||||
| `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` |
|
||||
| `auto-info` | Whether to display info boxes | `true` |
|
||||
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` |
|
||||
| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
|
||||
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` |
|
||||
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
|
||||
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
|
||||
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |
|
||||
| `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` |
|
||||
| `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` |
|
||||
| `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` |
|
||||
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` |
|
||||
| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid`
|
||||
| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"`
|
||||
|
||||
### `[editor.statusline]` Section
|
||||
|
||||
Allows configuring the statusline at the bottom of the editor.
|
||||
|
||||
The configuration distinguishes between three areas of the status line:
|
||||
|
||||
`[ ... ... LEFT ... ... | ... ... ... CENTER ... ... ... | ... ... RIGHT ... ... ]`
|
||||
|
||||
Statusline elements can be defined as follows:
|
||||
|
||||
```toml
|
||||
[editor.statusline]
|
||||
left = ["mode", "spinner"]
|
||||
center = ["file-name"]
|
||||
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
|
||||
separator = "│"
|
||||
mode.normal = "NORMAL"
|
||||
mode.insert = "INSERT"
|
||||
mode.select = "SELECT"
|
||||
```
|
||||
The `[editor.statusline]` key takes the following sub-keys:
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` |
|
||||
| `center` | A list of elements aligned to the middle of the statusline | `[]` |
|
||||
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` |
|
||||
| `separator` | The character used to separate elements in the statusline | `"│"` |
|
||||
| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
|
||||
| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` |
|
||||
| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` |
|
||||
|
||||
The following statusline elements can be configured:
|
||||
|
||||
| Key | Description |
|
||||
| ------ | ----------- |
|
||||
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
|
||||
| `spinner` | A progress spinner indicating LSP activity |
|
||||
| `file-name` | The path/name of the opened file |
|
||||
| `file-absolute-path` | The absolute path/name of the opened file |
|
||||
| `file-base-name` | The basename of the opened file |
|
||||
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
|
||||
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
|
||||
| `file-line-ending` | The file line endings (CRLF or LF) |
|
||||
| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written |
|
||||
| `total-line-numbers` | The total line numbers of the opened file |
|
||||
| `file-type` | The type of the opened file |
|
||||
| `diagnostics` | The number of warnings and/or errors |
|
||||
| `workspace-diagnostics` | The number of warnings and/or errors on workspace |
|
||||
| `selections` | The number of active selections |
|
||||
| `primary-selection-length` | The number of characters currently in primary selection |
|
||||
| `position` | The cursor position |
|
||||
| `position-percentage` | The cursor position as a percentage of the total number of lines |
|
||||
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
|
||||
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
|
||||
| `version-control` | The current branch name or detached commit hash of the opened workspace |
|
||||
| `register` | The current selected register |
|
||||
|
||||
### `[editor.lsp]` Section
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | ----------- | ------- |
|
||||
| `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` |
|
||||
| `display-messages` | Display LSP progress messages below statusline[^1] | `false` |
|
||||
| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` |
|
||||
| `display-inlay-hints` | Display inlay hints[^2] | `false` |
|
||||
| `display-signature-help-docs` | Display docs under signature help popup | `true` |
|
||||
| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
|
||||
| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` |
|
||||
|
||||
[^1]: By default, a progress spinner is shown in the statusline beside the file path.
|
||||
|
||||
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix. Inlay hints in Helix are still being improved on and may be a little bit laggy/janky under some circumstances. Please report any bugs you see so we can fix them!
|
||||
|
||||
### `[editor.cursor-shape]` Section
|
||||
|
||||
Defines the shape of cursor in each mode.
|
||||
Valid values for these options are `block`, `bar`, `underline`, or `hidden`.
|
||||
|
||||
> 💡 Due to limitations of the terminal environment, only the primary cursor can
|
||||
> change shape.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | ----------- | ------- |
|
||||
| `normal` | Cursor shape in [normal mode][normal mode] | `block` |
|
||||
| `insert` | Cursor shape in [insert mode][insert mode] | `block` |
|
||||
| `select` | Cursor shape in [select mode][select mode] | `block` |
|
||||
|
||||
[normal mode]: ./keymap.md#normal-mode
|
||||
[insert mode]: ./keymap.md#insert-mode
|
||||
[select mode]: ./keymap.md#select--extend-mode
|
||||
|
||||
### `[editor.file-picker]` Section
|
||||
|
||||
Set options for file picker and global search. Ignoring a file means it is
|
||||
not visible in the Helix file picker and global search.
|
||||
|
||||
All git related options are only enabled in a git repository.
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
|`hidden` | Enables ignoring hidden files | `true`
|
||||
|`follow-symlinks` | Follow symlinks instead of ignoring them | `true`
|
||||
|`deduplicate-links` | Ignore symlinks that point at files already shown in the picker | `true`
|
||||
|`parents` | Enables reading ignore files from parent directories | `true`
|
||||
|`ignore` | Enables reading `.ignore` files | `true`
|
||||
|`git-ignore` | Enables reading `.gitignore` files | `true`
|
||||
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true`
|
||||
|`git-exclude` | Enables reading `.git/info/exclude` files | `true`
|
||||
|`max-depth` | Set with an integer value for maximum depth to recurse | Unset by default
|
||||
|
||||
Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files.
|
||||
|
||||
Additionally, you can use Helix-specific ignore files by creating a local `.helix/ignore` file in the current workspace or a global `ignore` file located in your Helix config directory:
|
||||
- Linux and Mac: `~/.config/helix/ignore`
|
||||
- Windows: `%AppData%\helix\ignore`
|
||||
|
||||
Example:
|
||||
|
||||
```ini
|
||||
# unignore in file picker and global search
|
||||
!.github/
|
||||
!.gitignore
|
||||
!.gitattributes
|
||||
```
|
||||
|
||||
### `[editor.auto-pairs]` Section
|
||||
|
||||
Enables automatic insertion of pairs to parentheses, brackets, etc. Can be a
|
||||
simple boolean value, or a specific mapping of pairs of single characters.
|
||||
|
||||
To disable auto-pairs altogether, set `auto-pairs` to `false`:
|
||||
|
||||
```toml
|
||||
[editor]
|
||||
auto-pairs = false # defaults to `true`
|
||||
```
|
||||
|
||||
The default pairs are <code>(){}[]''""``</code>, but these can be customized by
|
||||
setting `auto-pairs` to a TOML table:
|
||||
|
||||
```toml
|
||||
[editor.auto-pairs]
|
||||
'(' = ')'
|
||||
'{' = '}'
|
||||
'[' = ']'
|
||||
'"' = '"'
|
||||
'`' = '`'
|
||||
'<' = '>'
|
||||
```
|
||||
|
||||
Additionally, this setting can be used in a language config. Unless
|
||||
the editor setting is `false`, this will override the editor config in
|
||||
documents with this language.
|
||||
|
||||
Example `languages.toml` that adds `<>` and removes `''`
|
||||
|
||||
```toml
|
||||
[[language]]
|
||||
name = "rust"
|
||||
|
||||
[language.auto-pairs]
|
||||
'(' = ')'
|
||||
'{' = '}'
|
||||
'[' = ']'
|
||||
'"' = '"'
|
||||
'`' = '`'
|
||||
'<' = '>'
|
||||
```
|
||||
|
||||
### `[editor.auto-save]` Section
|
||||
|
||||
Control auto save behavior.
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
| `focus-lost` | 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` |
|
||||
| `after-delay.enable` | Enable automatic saving after `auto-save.after-delay.timeout` milliseconds have passed since last edit. | `false` |
|
||||
| `after-delay.timeout` | Time in milliseconds since last edit before auto save timer triggers. | `3000` |
|
||||
|
||||
### `[editor.search]` Section
|
||||
|
||||
Search specific options.
|
||||
|
||||
| Key | Description | Default |
|
||||
|--|--|---------|
|
||||
| `smart-case` | Enable smart case regex searching (case-insensitive unless pattern contains upper case characters) | `true` |
|
||||
| `wrap-around`| Whether the search should wrap after depleting the matches | `true` |
|
||||
|
||||
### `[editor.whitespace]` Section
|
||||
|
||||
Options for rendering whitespace with visible characters. Use `:set whitespace.render all` to temporarily enable visible whitespace.
|
||||
|
||||
| Key | Description | Default |
|
||||
|-----|-------------|---------|
|
||||
| `render` | Whether to render whitespace. May either be `all` or `none`, or a table with sub-keys `space`, `nbsp`, `nnbsp`, `tab`, and `newline` | `none` |
|
||||
| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `nnbsp`, `newline` or `tabpad` | See example below |
|
||||
|
||||
Example
|
||||
|
||||
```toml
|
||||
[editor.whitespace]
|
||||
render = "all"
|
||||
# or control each character
|
||||
[editor.whitespace.render]
|
||||
space = "all"
|
||||
tab = "all"
|
||||
nbsp = "none"
|
||||
nnbsp = "none"
|
||||
newline = "none"
|
||||
|
||||
[editor.whitespace.characters]
|
||||
space = "·"
|
||||
nbsp = "⍽"
|
||||
nnbsp = "␣"
|
||||
tab = "→"
|
||||
newline = "⏎"
|
||||
tabpad = "·" # Tabs will look like "→···" (depending on tab width)
|
||||
```
|
||||
|
||||
### `[editor.indent-guides]` Section
|
||||
|
||||
Options for rendering vertical indent guides.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `render` | Whether to render indent guides | `false` |
|
||||
| `character` | Literal character to use for rendering the indent guide | `│` |
|
||||
| `skip-levels` | Number of indent levels to skip | `0` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.indent-guides]
|
||||
render = true
|
||||
character = "╎" # Some characters that work well: "▏", "┆", "┊", "⸽"
|
||||
skip-levels = 1
|
||||
```
|
||||
|
||||
### `[editor.gutters]` Section
|
||||
|
||||
For simplicity, `editor.gutters` accepts an array of gutter types, which will
|
||||
use default settings for all gutter components.
|
||||
|
||||
```toml
|
||||
[editor]
|
||||
gutters = ["diff", "diagnostics", "line-numbers", "spacer"]
|
||||
```
|
||||
|
||||
To customize the behavior of gutters, the `[editor.gutters]` section must
|
||||
be used. This section contains top level settings, as well as settings for
|
||||
specific gutter components as subsections.
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `layout` | A vector of gutters to display | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.gutters]
|
||||
layout = ["diff", "diagnostics", "line-numbers", "spacer"]
|
||||
```
|
||||
|
||||
#### `[editor.gutters.line-numbers]` Section
|
||||
|
||||
Options for the line number gutter
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `min-width` | The minimum number of characters to use | `3` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.gutters.line-numbers]
|
||||
min-width = 1
|
||||
```
|
||||
|
||||
#### `[editor.gutters.diagnostics]` Section
|
||||
|
||||
Currently unused
|
||||
|
||||
#### `[editor.gutters.diff]` Section
|
||||
|
||||
The `diff` gutter option displays colored bars indicating whether a `git` diff represents that a line was added, removed or changed.
|
||||
These colors are controlled by the theme attributes `diff.plus`, `diff.minus` and `diff.delta`.
|
||||
|
||||
Other diff providers will eventually be supported by a future plugin system.
|
||||
|
||||
There are currently no options for this section.
|
||||
|
||||
#### `[editor.gutters.spacer]` Section
|
||||
|
||||
Currently unused
|
||||
|
||||
### `[editor.soft-wrap]` Section
|
||||
|
||||
Options for soft wrapping lines that exceed the view width:
|
||||
|
||||
| Key | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `enable` | Whether soft wrapping is enabled. | `false` |
|
||||
| `max-wrap` | Maximum free space left at the end of the line. | `20` |
|
||||
| `max-indent-retain` | Maximum indentation to carry over when soft wrapping a line. | `40` |
|
||||
| `wrap-indicator` | Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap` | `↪ ` |
|
||||
| `wrap-at-text-width` | Soft wrap at `text-width` instead of using the full viewport size. | `false` |
|
||||
|
||||
Example:
|
||||
|
||||
```toml
|
||||
[editor.soft-wrap]
|
||||
enable = true
|
||||
max-wrap = 25 # increase value to reduce forced mid-word wrapping
|
||||
max-indent-retain = 0
|
||||
wrap-indicator = "" # set wrap-indicator to "" to hide it
|
||||
```
|
||||
|
||||
### `[editor.smart-tab]` Section
|
||||
|
||||
Options for navigating and editing using tab key.
|
||||
|
||||
| Key | Description | Default |
|
||||
|------------|-------------|---------|
|
||||
| `enable` | If set to true, then when the cursor is in a position with non-whitespace to its left, instead of inserting a tab, it will run `move_parent_node_end`. If there is only whitespace to the left, then it inserts a tab as normal. With the default bindings, to explicitly insert a tab character, press Shift-tab. | `true` |
|
||||
| `supersede-menu` | Normally, when a menu is on screen, such as when auto complete is triggered, the tab key is bound to cycling through the items. This means when menus are on screen, one cannot use the tab key to trigger the `smart-tab` command. If this option is set to true, the `smart-tab` command always takes precedence, which means one cannot use the tab key to cycle through menu items. One of the other bindings must be used instead, such as arrow keys or `C-n`/`C-p`. | `false` |
|
||||
|
||||
|
||||
Due to lack of support for S-tab in some terminals, the default keybindings don't fully embrace smart-tab editing experience. If you enjoy smart-tab navigation and a terminal that supports the [Enhanced Keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol), consider setting extra keybindings:
|
||||
|
||||
```
|
||||
[keys.normal]
|
||||
tab = "move_parent_node_end"
|
||||
S-tab = "move_parent_node_start"
|
||||
|
||||
[keys.insert]
|
||||
S-tab = "move_parent_node_start"
|
||||
|
||||
[keys.select]
|
||||
tab = "extend_parent_node_end"
|
||||
S-tab = "extend_parent_node_start"
|
||||
```
|
@@ -1,5 +1,7 @@
|
||||
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| ada | ✓ | ✓ | | `ada_language_server`, `ada_language_server` |
|
||||
| adl | ✓ | ✓ | ✓ | |
|
||||
| agda | ✓ | | | |
|
||||
| astro | ✓ | | | |
|
||||
| awk | ✓ | ✓ | | `awk-language-server` |
|
||||
@@ -8,12 +10,15 @@
|
||||
| beancount | ✓ | | | |
|
||||
| bibtex | ✓ | | | `texlab` |
|
||||
| bicep | ✓ | | | `bicep-langserver` |
|
||||
| bitbake | ✓ | | | `bitbake-language-server` |
|
||||
| blade | ✓ | | | |
|
||||
| blueprint | ✓ | | | `blueprint-compiler` |
|
||||
| c | ✓ | ✓ | ✓ | `clangd` |
|
||||
| c-sharp | ✓ | ✓ | | `OmniSharp` |
|
||||
| cabal | | | | `haskell-language-server-wrapper` |
|
||||
| cairo | ✓ | ✓ | ✓ | `cairo-language-server` |
|
||||
| capnp | ✓ | | ✓ | |
|
||||
| cel | ✓ | | | |
|
||||
| clojure | ✓ | | | `clojure-lsp` |
|
||||
| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
|
||||
| comment | ✓ | | | |
|
||||
@@ -21,20 +26,23 @@
|
||||
| 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 | ✓ | | | |
|
||||
| elisp | ✓ | | | |
|
||||
| elixir | ✓ | ✓ | ✓ | `elixir-ls` |
|
||||
| elm | ✓ | ✓ | | `elm-language-server` |
|
||||
| elvish | ✓ | | | `elvish` |
|
||||
@@ -42,6 +50,7 @@
|
||||
| erb | ✓ | | | |
|
||||
| erlang | ✓ | ✓ | | `erlang_ls` |
|
||||
| esdl | ✓ | | | |
|
||||
| fidl | ✓ | | | |
|
||||
| fish | ✓ | ✓ | ✓ | |
|
||||
| forth | ✓ | | | `forth-lsp` |
|
||||
| fortran | ✓ | | ✓ | `fortls` |
|
||||
@@ -54,7 +63,9 @@
|
||||
| git-config | ✓ | | | |
|
||||
| git-ignore | ✓ | | | |
|
||||
| git-rebase | ✓ | | | |
|
||||
| gjs | ✓ | ✓ | ✓ | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` |
|
||||
| gleam | ✓ | ✓ | | `gleam` |
|
||||
| glimmer | ✓ | | | `ember-language-server` |
|
||||
| glsl | ✓ | ✓ | ✓ | |
|
||||
| gn | ✓ | | | |
|
||||
| go | ✓ | ✓ | ✓ | `gopls`, `golangci-lint-langserver` |
|
||||
@@ -62,33 +73,43 @@
|
||||
| gomod | ✓ | | | `gopls` |
|
||||
| gotmpl | ✓ | | | `gopls` |
|
||||
| gowork | ✓ | | | `gopls` |
|
||||
| graphql | ✓ | | | `graphql-lsp` |
|
||||
| graphql | ✓ | ✓ | | `graphql-lsp` |
|
||||
| groovy | ✓ | | | |
|
||||
| gts | ✓ | ✓ | ✓ | `typescript-language-server`, `vscode-eslint-language-server`, `ember-language-server` |
|
||||
| hare | ✓ | | | |
|
||||
| haskell | ✓ | ✓ | | `haskell-language-server-wrapper` |
|
||||
| haskell-persistent | ✓ | | | |
|
||||
| hcl | ✓ | | ✓ | `terraform-ls` |
|
||||
| hcl | ✓ | ✓ | ✓ | `terraform-ls` |
|
||||
| heex | ✓ | ✓ | | `elixir-ls` |
|
||||
| helm | ✓ | | | `helm_ls` |
|
||||
| hocon | ✓ | | ✓ | |
|
||||
| hoon | ✓ | | | |
|
||||
| hosts | ✓ | | | |
|
||||
| html | ✓ | | | `vscode-html-language-server` |
|
||||
| hurl | ✓ | | ✓ | |
|
||||
| hurl | ✓ | ✓ | ✓ | |
|
||||
| hyprlang | ✓ | | ✓ | |
|
||||
| idris | | | | `idris2-lsp` |
|
||||
| iex | ✓ | | | |
|
||||
| ini | ✓ | | | |
|
||||
| inko | ✓ | ✓ | ✓ | |
|
||||
| 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 | ✓ | ✓ | ✓ | |
|
||||
| koka | ✓ | | ✓ | `koka` |
|
||||
| kotlin | ✓ | | | `kotlin-language-server` |
|
||||
| latex | ✓ | ✓ | | `texlab` |
|
||||
| ld | ✓ | | ✓ | |
|
||||
| ldif | ✓ | | | |
|
||||
| lean | ✓ | | | `lean` |
|
||||
| ledger | ✓ | | | |
|
||||
| llvm | ✓ | ✓ | ✓ | |
|
||||
@@ -97,24 +118,27 @@
|
||||
| log | ✓ | | | |
|
||||
| lpf | ✓ | | | |
|
||||
| lua | ✓ | ✓ | ✓ | `lua-language-server` |
|
||||
| make | ✓ | | | |
|
||||
| make | ✓ | | ✓ | |
|
||||
| markdoc | ✓ | | | `markdoc-ls` |
|
||||
| markdown | ✓ | | | `marksman` |
|
||||
| markdown | ✓ | | | `marksman`, `markdown-oxide` |
|
||||
| markdown.inline | ✓ | | | |
|
||||
| matlab | ✓ | ✓ | ✓ | |
|
||||
| mermaid | ✓ | | | |
|
||||
| meson | ✓ | | ✓ | |
|
||||
| mint | | | | `mint` |
|
||||
| mojo | ✓ | ✓ | ✓ | `mojo-lsp-server` |
|
||||
| move | ✓ | | | |
|
||||
| msbuild | ✓ | | ✓ | |
|
||||
| nasm | ✓ | ✓ | | |
|
||||
| nickel | ✓ | | ✓ | `nls` |
|
||||
| nim | ✓ | ✓ | ✓ | `nimlangserver` |
|
||||
| nix | ✓ | | | `nil` |
|
||||
| nix | ✓ | ✓ | | `nil` |
|
||||
| nu | ✓ | | | `nu` |
|
||||
| nunjucks | ✓ | | | |
|
||||
| ocaml | ✓ | | ✓ | `ocamllsp` |
|
||||
| ocaml-interface | ✓ | | | `ocamllsp` |
|
||||
| odin | ✓ | | ✓ | `ols` |
|
||||
| ohm | ✓ | ✓ | ✓ | |
|
||||
| opencl | ✓ | ✓ | ✓ | `clangd` |
|
||||
| openscad | ✓ | | | `openscad-lsp` |
|
||||
| org | ✓ | | | |
|
||||
@@ -122,10 +146,15 @@
|
||||
| passwd | ✓ | | | |
|
||||
| pem | ✓ | | | |
|
||||
| perl | ✓ | ✓ | ✓ | `perlnavigator` |
|
||||
| pest | ✓ | ✓ | ✓ | `pest-language-server` |
|
||||
| php | ✓ | ✓ | ✓ | `intelephense` |
|
||||
| php-only | ✓ | | | |
|
||||
| pkgbuild | ✓ | ✓ | ✓ | `pkgbuild-language-server`, `bash-language-server` |
|
||||
| pkl | ✓ | | ✓ | |
|
||||
| po | ✓ | ✓ | | |
|
||||
| pod | ✓ | | | |
|
||||
| ponylang | ✓ | ✓ | ✓ | |
|
||||
| powershell | ✓ | | | |
|
||||
| prisma | ✓ | | | `prisma-language-server` |
|
||||
| prolog | | | | `swipl` |
|
||||
| protobuf | ✓ | ✓ | ✓ | `bufls`, `pb` |
|
||||
@@ -148,35 +177,39 @@
|
||||
| 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 | ✓ | ✓ | | |
|
||||
| strace | ✓ | | | |
|
||||
| supercollider | ✓ | | | |
|
||||
| svelte | ✓ | | ✓ | `svelteserver` |
|
||||
| sway | ✓ | ✓ | ✓ | `forc` |
|
||||
| swift | ✓ | | | `sourcekit-lsp` |
|
||||
| swift | ✓ | ✓ | | `sourcekit-lsp` |
|
||||
| t32 | ✓ | | | |
|
||||
| tablegen | ✓ | ✓ | ✓ | |
|
||||
| tact | ✓ | ✓ | ✓ | |
|
||||
| task | ✓ | | | |
|
||||
| tcl | ✓ | | ✓ | |
|
||||
| templ | ✓ | | | `templ` |
|
||||
| tfvars | ✓ | | ✓ | `terraform-ls` |
|
||||
| todotxt | ✓ | | | |
|
||||
| toml | ✓ | | | `taplo` |
|
||||
| toml | ✓ | ✓ | | `taplo` |
|
||||
| tsq | ✓ | | | |
|
||||
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| twig | ✓ | | | |
|
||||
| typescript | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||
| typst | ✓ | | | `typst-lsp` |
|
||||
| typst | ✓ | | | `tinymist`, `typst-lsp` |
|
||||
| ungrammar | ✓ | | | |
|
||||
| unison | ✓ | | | |
|
||||
| unison | ✓ | | ✓ | |
|
||||
| uxntal | ✓ | | | |
|
||||
| v | ✓ | ✓ | ✓ | `v-analyzer` |
|
||||
| vala | ✓ | | | `vala-language-server` |
|
||||
| vala | ✓ | ✓ | | `vala-language-server` |
|
||||
| verilog | ✓ | ✓ | | `svlangserver` |
|
||||
| vhdl | ✓ | | | `vhdl_ls` |
|
||||
| vhs | ✓ | | | |
|
||||
@@ -189,6 +222,7 @@
|
||||
| wren | ✓ | ✓ | ✓ | |
|
||||
| xit | ✓ | | | |
|
||||
| xml | ✓ | | ✓ | |
|
||||
| xtc | ✓ | | | |
|
||||
| yaml | ✓ | | ✓ | `yaml-language-server`, `ansible-language-server` |
|
||||
| yuck | ✓ | | | |
|
||||
| zig | ✓ | ✓ | ✓ | `zls` |
|
||||
|
@@ -86,3 +86,5 @@
|
||||
| `: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 |
|
||||
| `:read`, `:r` | Load a file into buffer |
|
||||
|
@@ -16,7 +16,7 @@ below.
|
||||
|
||||
> 💡 If you are adding a new Language Server configuration, make sure to update
|
||||
> the
|
||||
> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers)
|
||||
> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/Language-Server-Configurations)
|
||||
> with the installation instructions.
|
||||
|
||||
## Grammar configuration
|
||||
|
@@ -315,6 +315,10 @@ The first argument (a capture) must/must not be equal to the second argument
|
||||
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?`:
|
||||
@@ -366,4 +370,4 @@ 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.)
|
||||
written explicitly for demonstration.)
|
||||
|
@@ -54,4 +54,7 @@ The first argument (a capture) must be equal to the second argument
|
||||
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 @@ The following [captures][tree-sitter-captures] are recognized:
|
||||
| `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 @@ doesn't make sense in a navigation context.
|
||||
|
||||
[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=
|
||||
|
@@ -1,38 +1,10 @@
|
||||
# Installing Helix
|
||||
|
||||
<!--toc:start-->
|
||||
- [Pre-built binaries](#pre-built-binaries)
|
||||
- [Linux, macOS, Windows and OpenBSD packaging status](#linux-macos-windows-and-openbsd-packaging-status)
|
||||
- [Linux](#linux)
|
||||
- [Ubuntu](#ubuntu)
|
||||
- [Fedora/RHEL](#fedorarhel)
|
||||
- [Arch Linux extra](#arch-linux-extra)
|
||||
- [NixOS](#nixos)
|
||||
- [Flatpak](#flatpak)
|
||||
- [Snap](#snap)
|
||||
- [AppImage](#appimage)
|
||||
- [macOS](#macos)
|
||||
- [Homebrew Core](#homebrew-core)
|
||||
- [MacPorts](#macports)
|
||||
- [Windows](#windows)
|
||||
- [Winget](#winget)
|
||||
- [Scoop](#scoop)
|
||||
- [Chocolatey](#chocolatey)
|
||||
- [MSYS2](#msys2)
|
||||
- [Building from source](#building-from-source)
|
||||
- [Configuring Helix's runtime files](#configuring-helixs-runtime-files)
|
||||
- [Linux and macOS](#linux-and-macos)
|
||||
- [Windows](#windows)
|
||||
- [Multiple runtime directories](#multiple-runtime-directories)
|
||||
- [Validating the installation](#validating-the-installation)
|
||||
- [Configure the desktop shortcut](#configure-the-desktop-shortcut)
|
||||
<!--toc:end-->
|
||||
|
||||
To install Helix, follow the instructions specific to your operating system.
|
||||
Note that:
|
||||
|
||||
- To get the latest nightly version of Helix, you need to
|
||||
[build from source](#building-from-source).
|
||||
[build from source](./building-from-source.md).
|
||||
|
||||
- To take full advantage of Helix, install the language servers for your
|
||||
preferred programming languages. See the
|
||||
@@ -41,282 +13,7 @@ Note that:
|
||||
|
||||
## Pre-built binaries
|
||||
|
||||
Download pre-built binaries from the
|
||||
[GitHub Releases page](https://github.com/helix-editor/helix/releases). Add the binary to your system's `$PATH` to use it from the command
|
||||
line.
|
||||
Download pre-built binaries from the [GitHub Releases page](https://github.com/helix-editor/helix/releases).
|
||||
Add the `hx` binary to your system's `$PATH` to use it from the command line, and copy the `runtime` directory into the config directory (for example `~/.config/helix/runtime` on Linux/macOS).
|
||||
The runtime location can be overriden via the HELIX_RUNTIME environment variable.
|
||||
|
||||
## Linux, macOS, Windows and OpenBSD packaging status
|
||||
|
||||
[](https://repology.org/project/helix/versions)
|
||||
|
||||
## Linux
|
||||
|
||||
The following third party repositories are available:
|
||||
|
||||
### Ubuntu
|
||||
|
||||
Add the `PPA` for Helix:
|
||||
|
||||
```sh
|
||||
sudo add-apt-repository ppa:maveonair/helix-editor
|
||||
sudo apt update
|
||||
sudo apt install helix
|
||||
```
|
||||
|
||||
### Fedora/RHEL
|
||||
|
||||
```sh
|
||||
sudo dnf install helix
|
||||
```
|
||||
|
||||
### Arch Linux extra
|
||||
|
||||
Releases are available in the `extra` repository:
|
||||
|
||||
```sh
|
||||
sudo pacman -S helix
|
||||
```
|
||||
Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available
|
||||
in the AUR, which builds the master branch.
|
||||
|
||||
### NixOS
|
||||
|
||||
Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute,
|
||||
the unstable channel usually carries the latest release.
|
||||
|
||||
Helix is also available as a [flake](https://nixos.wiki/wiki/Flakes) in the project
|
||||
root. Use `nix develop` to spin up a reproducible development shell. Outputs are
|
||||
cached for each push to master using [Cachix](https://www.cachix.org/). The
|
||||
flake is configured to automatically make use of this cache assuming the user
|
||||
accepts the new settings on first use.
|
||||
|
||||
If you are using a version of Nix without flakes enabled,
|
||||
[install Cachix CLI](https://docs.cachix.org/installation) and use
|
||||
`cachix use helix` to configure Nix to use cached outputs when possible.
|
||||
|
||||
### Flatpak
|
||||
|
||||
Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix):
|
||||
|
||||
```sh
|
||||
flatpak install flathub com.helix_editor.Helix
|
||||
flatpak run com.helix_editor.Helix
|
||||
```
|
||||
|
||||
### Snap
|
||||
|
||||
Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with:
|
||||
|
||||
```sh
|
||||
snap install --classic helix
|
||||
```
|
||||
|
||||
This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`.
|
||||
|
||||
### AppImage
|
||||
|
||||
Install Helix using the Linux [AppImage](https://appimage.org/) format.
|
||||
Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page.
|
||||
|
||||
```sh
|
||||
chmod +x helix-*.AppImage # change permission for executable mode
|
||||
./helix-*.AppImage # run helix
|
||||
```
|
||||
|
||||
## macOS
|
||||
|
||||
### Homebrew Core
|
||||
|
||||
```sh
|
||||
brew install helix
|
||||
```
|
||||
|
||||
### MacPorts
|
||||
|
||||
```sh
|
||||
port install helix
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
or [MSYS2](https://msys2.org/).
|
||||
|
||||
### Winget
|
||||
Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer.
|
||||
You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version.
|
||||
|
||||
```sh
|
||||
winget install Helix.Helix
|
||||
```
|
||||
|
||||
### Scoop
|
||||
|
||||
```sh
|
||||
scoop install helix
|
||||
```
|
||||
|
||||
### Chocolatey
|
||||
|
||||
```sh
|
||||
choco install helix
|
||||
```
|
||||
|
||||
### MSYS2
|
||||
|
||||
For 64-bit Windows 8.1 or above:
|
||||
|
||||
```sh
|
||||
pacman -S mingw-w64-ucrt-x86_64-helix
|
||||
```
|
||||
|
||||
## Building from source
|
||||
|
||||
Requirements:
|
||||
|
||||
Clone the Helix GitHub repository into a directory of your choice. The
|
||||
examples in this documentation assume installation into either `~/src/` on
|
||||
Linux and macOS, or `%userprofile%\src\` on Windows.
|
||||
|
||||
- The [Rust toolchain](https://www.rust-lang.org/tools/install)
|
||||
- The [Git version control system](https://git-scm.com/)
|
||||
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
|
||||
If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
|
||||
|
||||
```sh
|
||||
RUSTFLAGS="-C target-feature=-crt-static"
|
||||
```
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
|
||||
2. Compile from source:
|
||||
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
|
||||
> 💡 If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD`
|
||||
|
||||
> 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
|
||||
> grammars with `hx --grammar fetch` and compile them with
|
||||
> `hx --grammar build`. This will install them in
|
||||
> the `runtime` directory within the user's helix config directory (more
|
||||
> [details below](#multiple-runtime-directories)).
|
||||
|
||||
### Configuring Helix's runtime files
|
||||
|
||||
#### Linux and macOS
|
||||
|
||||
The **runtime** directory is one below the Helix source, so either set a
|
||||
`HELIX_RUNTIME` environment variable to point to that directory and add it to
|
||||
your `~/.bashrc` or equivalent:
|
||||
|
||||
```sh
|
||||
HELIX_RUNTIME=~/src/helix/runtime
|
||||
```
|
||||
|
||||
Or, create a symbolic link:
|
||||
|
||||
```sh
|
||||
ln -Ts $PWD/runtime ~/.config/helix/runtime
|
||||
```
|
||||
|
||||
If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again.
|
||||
|
||||
#### Windows
|
||||
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
|
||||
`Edit environment variables for your account`) or use the `setx` command in
|
||||
Cmd:
|
||||
|
||||
```sh
|
||||
setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime"
|
||||
```
|
||||
|
||||
> 💡 `%userprofile%` resolves to your user directory like
|
||||
> `C:\Users\Your-Name\` for example.
|
||||
|
||||
Or, create a symlink in `%appdata%\helix\` that links to the source code directory:
|
||||
|
||||
| Method | Command |
|
||||
| ---------- | -------------------------------------------------------------------------------------- |
|
||||
| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` |
|
||||
| Cmd | `cd %appdata%\helix` <br/> `mklink /D runtime "%userprofile%\src\helix\runtime"` |
|
||||
|
||||
> 💡 On Windows, creating a symbolic link may require running PowerShell or
|
||||
> Cmd as an administrator.
|
||||
|
||||
#### Multiple runtime directories
|
||||
|
||||
When Helix finds multiple runtime directories it will search through them for files in the
|
||||
following order:
|
||||
|
||||
1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
|
||||
developing and testing helix only).
|
||||
2. `runtime/` subdirectory of OS-dependent helix user config directory.
|
||||
3. `$HELIX_RUNTIME`
|
||||
4. Distribution-specific fallback directory (set at compile time—not run time—
|
||||
with the `HELIX_DEFAULT_RUNTIME` environment variable)
|
||||
5. `runtime/` subdirectory of path to Helix executable.
|
||||
|
||||
This order also sets the priority for selecting which file will be used if multiple runtime
|
||||
directories have files with the same name.
|
||||
|
||||
#### Note to packagers
|
||||
|
||||
If you are making a package of Helix for end users, to provide a good out of
|
||||
the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment
|
||||
variable at build time (before invoking `cargo build`) to a directory which
|
||||
will store the final runtime files after installation. For example, say you want
|
||||
to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build
|
||||
script could follow are:
|
||||
|
||||
1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime`
|
||||
1. `cargo build --profile opt --locked --path helix-term`
|
||||
1. `cp -r runtime $BUILD_DIR/usr/lib/helix/`
|
||||
1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx`
|
||||
|
||||
This way the resulting `hx` binary will always look for its runtime directory in
|
||||
`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix`
|
||||
or `HELIX_RUNTIME`.
|
||||
|
||||
### Validating the installation
|
||||
|
||||
To make sure everything is set up as expected you should run the Helix health
|
||||
check:
|
||||
|
||||
```sh
|
||||
hx --health
|
||||
```
|
||||
|
||||
For more information on the health check results refer to
|
||||
[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
|
||||
### Configure the desktop shortcut
|
||||
|
||||
If your desktop environment supports the
|
||||
[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html)
|
||||
you can configure Helix to show up in the application menu by copying the
|
||||
provided `.desktop` and icon files to their correct folders:
|
||||
|
||||
```sh
|
||||
cp contrib/Helix.desktop ~/.local/share/applications
|
||||
cp contrib/helix.png ~/.icons # or ~/.local/share/icons
|
||||
```
|
||||
|
||||
To use another terminal than the system default, you can modify the `.desktop`
|
||||
file. For example, to use `kitty`:
|
||||
|
||||
```sh
|
||||
sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
|
||||
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Keymap
|
||||
## Keymap
|
||||
|
||||
- [Normal mode](#normal-mode)
|
||||
- [Movement](#movement)
|
||||
@@ -13,6 +13,8 @@
|
||||
- [Window mode](#window-mode)
|
||||
- [Space mode](#space-mode)
|
||||
- [Popup](#popup)
|
||||
- [Completion Menu](#completion-menu)
|
||||
- [Signature-help Popup](#signature-help-popup)
|
||||
- [Unimpaired](#unimpaired)
|
||||
- [Insert mode](#insert-mode)
|
||||
- [Select / extend mode](#select--extend-mode)
|
||||
@@ -23,6 +25,8 @@
|
||||
|
||||
> 💡 Mappings marked (**TS**) require a tree-sitter grammar for the file type.
|
||||
|
||||
> ⚠️ Some terminals' default key mappings conflict with Helix's. If any of the mappings described on this page do not work as expected, check your terminal's mappings to ensure they do not conflict. See the [wiki](https://github.com/helix-editor/helix/wiki/Terminal-Support) for known conflicts.
|
||||
|
||||
## 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.
|
||||
@@ -48,13 +52,13 @@ Normal mode is the default mode when you launch helix. You can return to it from
|
||||
| `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` |
|
||||
@@ -85,7 +89,7 @@ Normal mode is the default mode when you launch helix. You can return to it from
|
||||
| `"` `<reg>` | Select a register to yank to or paste from | `select_register` |
|
||||
| `>` | Indent selection | `indent` |
|
||||
| `<` | Unindent selection | `unindent` |
|
||||
| `=` | Format selection (currently nonfunctional/disabled) (**LSP**) | `format_selections` |
|
||||
| `=` | Format selection (**LSP**) | `format_selections` |
|
||||
| `d` | Delete selection | `delete_selection` |
|
||||
| `Alt-d` | Delete selection, without yanking | `delete_selection_noyank` |
|
||||
| `c` | Change selection (delete and enter insert mode) | `change_selection` |
|
||||
@@ -182,18 +186,18 @@ normal mode) is persistent and can be exited using the escape key. This is
|
||||
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
|
||||
|
||||
@@ -223,13 +227,13 @@ Jumps to various locations.
|
||||
| `.` | 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
|
||||
|
||||
Accessed by typing `m` in [normal mode](#normal-mode).
|
||||
|
||||
See the relevant section in [Usage](./usage.md) for an explanation about
|
||||
[surround](./usage.md#surround) and [textobject](./usage.md#navigating-using-tree-sitter-textobjects) usage.
|
||||
Please refer to the relevant sections for detailed explanations about [surround](./surround.md) and [textobjects](./textobjects.md).
|
||||
|
||||
| Key | Description | Command |
|
||||
| ----- | ----------- | ------- |
|
||||
@@ -278,7 +282,8 @@ This layer is a kludge of mappings, mostly pickers.
|
||||
| `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` |
|
||||
@@ -289,6 +294,9 @@ This layer is a kludge of mappings, mostly pickers.
|
||||
| `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` | Yank selections to clipboard | `yank_to_clipboard` |
|
||||
@@ -301,13 +309,31 @@ This layer is a kludge of mappings, mostly pickers.
|
||||
|
||||
##### Popup
|
||||
|
||||
Displays documentation for item under cursor.
|
||||
Displays documentation for item under cursor. Remapping currently not supported.
|
||||
|
||||
| Key | Description |
|
||||
| ---- | ----------- |
|
||||
| `Ctrl-u` | Scroll up |
|
||||
| `Ctrl-d` | Scroll down |
|
||||
|
||||
##### Completion Menu
|
||||
|
||||
Displays documentation for the selected completion item. Remapping currently not supported.
|
||||
|
||||
| Key | Description |
|
||||
| ---- | ----------- |
|
||||
| `Shift-Tab`, `Ctrl-p`, `Up` | Previous entry |
|
||||
| `Tab`, `Ctrl-n`, `Down` | Next entry |
|
||||
|
||||
##### Signature-help Popup
|
||||
|
||||
Displays the signature of the selected completion item. Remapping currently not supported.
|
||||
|
||||
| Key | Description |
|
||||
| ---- | ----------- |
|
||||
| `Alt-p` | Previous signature |
|
||||
| `Alt-n` | Next signature |
|
||||
|
||||
#### Unimpaired
|
||||
|
||||
These mappings are in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired).
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# Language Support
|
||||
|
||||
The following languages and Language Servers are supported. To use
|
||||
Language Server features, you must first [install][lsp-install-wiki] the
|
||||
Language Server features, you must first [configure][lsp-config-wiki] the
|
||||
appropriate Language Server.
|
||||
|
||||
You can check the language support in your installed helix version with `hx --health`.
|
||||
@@ -11,6 +11,6 @@ Languages][adding-languages] guide for more language configuration information.
|
||||
|
||||
{{#include ./generated/lang-support.md}}
|
||||
|
||||
[lsp-install-wiki]: https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers
|
||||
[lsp-config-wiki]: https://github.com/helix-editor/helix/wiki/Language-Server-Configurations
|
||||
[lang-config]: ./languages.md
|
||||
[adding-languages]: ./guides/adding_languages.md
|
||||
|
@@ -42,7 +42,7 @@ name = "mylang"
|
||||
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,7 +61,8 @@ These configuration keys are available:
|
||||
| `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`) |
|
||||
@@ -78,24 +79,26 @@ from the above section. `file-types` is a list of strings or tables, for
|
||||
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
|
||||
|
||||
@@ -120,13 +123,14 @@ languages = { typescript = [ { formatCommand ="prettier --stdin-filepath ${INPUT
|
||||
|
||||
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://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting).
|
||||
@@ -146,6 +150,8 @@ They have to be defined in the `[language-server]` table as described in the pre
|
||||
|
||||
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.
|
||||
|
||||
|
150
book/src/package-managers.md
Normal file
150
book/src/package-managers.md
Normal file
@@ -0,0 +1,150 @@
|
||||
## Package managers
|
||||
|
||||
- [Linux](#linux)
|
||||
- [Ubuntu](#ubuntu)
|
||||
- [Fedora/RHEL](#fedorarhel)
|
||||
- [Arch Linux extra](#arch-linux-extra)
|
||||
- [NixOS](#nixos)
|
||||
- [Flatpak](#flatpak)
|
||||
- [Snap](#snap)
|
||||
- [AppImage](#appimage)
|
||||
- [macOS](#macos)
|
||||
- [Homebrew Core](#homebrew-core)
|
||||
- [MacPorts](#macports)
|
||||
- [Windows](#windows)
|
||||
- [Winget](#winget)
|
||||
- [Scoop](#scoop)
|
||||
- [Chocolatey](#chocolatey)
|
||||
- [MSYS2](#msys2)
|
||||
|
||||
[](https://repology.org/project/helix/versions)
|
||||
|
||||
## Linux
|
||||
|
||||
The following third party repositories are available:
|
||||
|
||||
### Ubuntu
|
||||
|
||||
Add the `PPA` for Helix:
|
||||
|
||||
```sh
|
||||
sudo add-apt-repository ppa:maveonair/helix-editor
|
||||
sudo apt update
|
||||
sudo apt install helix
|
||||
```
|
||||
|
||||
### Fedora/RHEL
|
||||
|
||||
```sh
|
||||
sudo dnf install helix
|
||||
```
|
||||
|
||||
### Arch Linux extra
|
||||
|
||||
Releases are available in the `extra` repository:
|
||||
|
||||
```sh
|
||||
sudo pacman -S helix
|
||||
```
|
||||
|
||||
> 💡 When installed from the `extra` repository, run Helix with `helix` instead of `hx`.
|
||||
>
|
||||
> For example:
|
||||
> ```sh
|
||||
> helix --health
|
||||
> ```
|
||||
> to check health
|
||||
|
||||
Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available
|
||||
in the AUR, which builds the master branch.
|
||||
|
||||
### NixOS
|
||||
|
||||
Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute,
|
||||
the unstable channel usually carries the latest release.
|
||||
|
||||
Helix is also available as a [flake](https://wiki.nixos.org/wiki/Flakes) in the project
|
||||
root. Use `nix develop` to spin up a reproducible development shell. Outputs are
|
||||
cached for each push to master using [Cachix](https://www.cachix.org/). The
|
||||
flake is configured to automatically make use of this cache assuming the user
|
||||
accepts the new settings on first use.
|
||||
|
||||
If you are using a version of Nix without flakes enabled,
|
||||
[install Cachix CLI](https://docs.cachix.org/installation) and use
|
||||
`cachix use helix` to configure Nix to use cached outputs when possible.
|
||||
|
||||
### Flatpak
|
||||
|
||||
Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix):
|
||||
|
||||
```sh
|
||||
flatpak install flathub com.helix_editor.Helix
|
||||
flatpak run com.helix_editor.Helix
|
||||
```
|
||||
|
||||
### Snap
|
||||
|
||||
Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with:
|
||||
|
||||
```sh
|
||||
snap install --classic helix
|
||||
```
|
||||
|
||||
This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`.
|
||||
|
||||
### AppImage
|
||||
|
||||
Install Helix using the Linux [AppImage](https://appimage.org/) format.
|
||||
Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page.
|
||||
|
||||
```sh
|
||||
chmod +x helix-*.AppImage # change permission for executable mode
|
||||
./helix-*.AppImage # run helix
|
||||
```
|
||||
|
||||
## macOS
|
||||
|
||||
### Homebrew Core
|
||||
|
||||
```sh
|
||||
brew install helix
|
||||
```
|
||||
|
||||
### MacPorts
|
||||
|
||||
```sh
|
||||
port install helix
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
or [MSYS2](https://msys2.org/).
|
||||
|
||||
### Winget
|
||||
Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer.
|
||||
You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version.
|
||||
|
||||
```sh
|
||||
winget install Helix.Helix
|
||||
```
|
||||
|
||||
### Scoop
|
||||
|
||||
```sh
|
||||
scoop install helix
|
||||
```
|
||||
|
||||
### Chocolatey
|
||||
|
||||
```sh
|
||||
choco install helix
|
||||
```
|
||||
|
||||
### MSYS2
|
||||
|
||||
For 64-bit Windows 8.1 or above:
|
||||
|
||||
```sh
|
||||
pacman -S mingw-w64-ucrt-x86_64-helix
|
||||
```
|
54
book/src/registers.md
Normal file
54
book/src/registers.md
Normal file
@@ -0,0 +1,54 @@
|
||||
## Registers
|
||||
|
||||
- [User-defined registers](#user-defined-registers)
|
||||
- [Default registers](#default-registers)
|
||||
- [Special registers](#special-registers)
|
||||
|
||||
In Helix, registers are storage locations for text and other data, such as the
|
||||
result of a search. Registers can be used to cut, copy, and paste text, similar
|
||||
to the clipboard in other text editors. Usage is similar to Vim, with `"` being
|
||||
used to select a register.
|
||||
|
||||
### User-defined registers
|
||||
|
||||
Helix allows you to create your own named registers for storing text, for
|
||||
example:
|
||||
|
||||
- `"ay` - Yank the current selection to register `a`.
|
||||
- `"op` - Paste the text in register `o` after the selection.
|
||||
|
||||
If a register is selected before invoking a change or delete command, the selection will be stored in the register and the action will be carried out:
|
||||
|
||||
- `"hc` - Store the selection in register `h` and then change it (delete and enter insert mode).
|
||||
- `"md` - Store the selection in register `m` and delete it.
|
||||
|
||||
### Default registers
|
||||
|
||||
Commands that use registers, like yank (`y`), use a default register if none is specified.
|
||||
These registers are used as defaults:
|
||||
|
||||
| Register character | Contains |
|
||||
| --- | --- |
|
||||
| `/` | Last search |
|
||||
| `:` | Last executed command |
|
||||
| `"` | Last yanked text |
|
||||
| `@` | Last recorded macro |
|
||||
|
||||
### Special registers
|
||||
|
||||
Some registers have special behavior when read from and written to.
|
||||
|
||||
| Register character | When read | When written |
|
||||
| --- | --- | --- |
|
||||
| `_` | No values are returned | All values are discarded |
|
||||
| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable |
|
||||
| `.` | Contents of the current selections | This register is not writable |
|
||||
| `%` | Name of the current file | This register is not writable |
|
||||
| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard |
|
||||
| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard |
|
||||
|
||||
When yanking multiple selections to the clipboard registers, the selections
|
||||
are joined with newlines. Pasting from these registers will paste multiple
|
||||
selections if the clipboard was last yanked to by the Helix session. Otherwise
|
||||
the clipboard contents are pasted as one selection.
|
||||
|
24
book/src/surround.md
Normal file
24
book/src/surround.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## Surround
|
||||
|
||||
Helix includes built-in functionality similar to [vim-surround](https://github.com/tpope/vim-surround).
|
||||
The keymappings have been inspired from [vim-sandwich](https://github.com/machakann/vim-sandwich):
|
||||
|
||||

|
||||
|
||||
| Key Sequence | Action |
|
||||
| --------------------------------- | --------------------------------------- |
|
||||
| `ms<char>` (after selecting text) | Add surround characters to selection |
|
||||
| `mr<char_to_replace><new_char>` | Replace the closest surround characters |
|
||||
| `md<char_to_delete>` | Delete the closest surround characters |
|
||||
|
||||
You can use counts to act on outer pairs.
|
||||
|
||||
Surround can also act on multiple selections. For example, to change every occurrence of `(use)` to `[use]`:
|
||||
|
||||
1. `%` to select the whole file
|
||||
2. `s` to split the selections on a search term
|
||||
3. Input `use` and hit Enter
|
||||
4. `mr([` to replace the parentheses with square brackets
|
||||
|
||||
Multiple characters are currently not supported, but planned for future release.
|
||||
|
66
book/src/syntax-aware-motions.md
Normal file
66
book/src/syntax-aware-motions.md
Normal file
@@ -0,0 +1,66 @@
|
||||
## Moving the selection with syntax-aware motions
|
||||
|
||||
`Alt-p`, `Alt-o`, `Alt-i`, and `Alt-n` (or `Alt` and arrow keys) allow you to move the
|
||||
selection according to its location in the syntax tree. For example, many languages have the
|
||||
following syntax for function calls:
|
||||
|
||||
```js
|
||||
func(arg1, arg2, arg3);
|
||||
```
|
||||
|
||||
A function call might be parsed by tree-sitter into a tree like the following.
|
||||
|
||||
```tsq
|
||||
(call
|
||||
function: (identifier) ; func
|
||||
arguments:
|
||||
(arguments ; (arg1, arg2, arg3)
|
||||
(identifier) ; arg1
|
||||
(identifier) ; arg2
|
||||
(identifier))) ; arg3
|
||||
```
|
||||
|
||||
Use `:tree-sitter-subtree` to view the syntax tree of the primary selection. In
|
||||
a more intuitive tree format:
|
||||
|
||||
```
|
||||
┌────┐
|
||||
│call│
|
||||
┌─────┴────┴─────┐
|
||||
│ │
|
||||
┌─────▼────┐ ┌────▼────┐
|
||||
│identifier│ │arguments│
|
||||
│ "func" │ ┌────┴───┬─────┴───┐
|
||||
└──────────┘ │ │ │
|
||||
│ │ │
|
||||
┌─────────▼┐ ┌────▼─────┐ ┌▼─────────┐
|
||||
│identifier│ │identifier│ │identifier│
|
||||
│ "arg1" │ │ "arg2" │ │ "arg3" │
|
||||
└──────────┘ └──────────┘ └──────────┘
|
||||
```
|
||||
|
||||
If you have a selection that wraps `arg1` (see the tree above), and you use
|
||||
`Alt-n`, it will select the next sibling in the syntax tree: `arg2`.
|
||||
|
||||
```js
|
||||
// before
|
||||
func([arg1], arg2, arg3)
|
||||
// after
|
||||
func(arg1, [arg2], arg3);
|
||||
```
|
||||
|
||||
Similarly, `Alt-o` will expand the selection to the parent node, in this case, the
|
||||
arguments node.
|
||||
|
||||
```js
|
||||
func[(arg1, arg2, arg3)];
|
||||
```
|
||||
|
||||
There is also some nuanced behavior that prevents you from getting stuck on a
|
||||
node with no sibling. When using `Alt-p` with a selection on `arg1`, the previous
|
||||
child node will be selected. In the event that `arg1` does not have a previous
|
||||
sibling, the selection will move up the syntax tree and select the previous
|
||||
element. As a result, using `Alt-p` with a selection on `arg1` will move the
|
||||
selection to the "func" `identifier`.
|
||||
|
||||
[lang-support]: ./lang-support.md
|
47
book/src/textobjects.md
Normal file
47
book/src/textobjects.md
Normal file
@@ -0,0 +1,47 @@
|
||||
## Selecting and manipulating text with textobjects
|
||||
|
||||
In Helix, textobjects are a way to select, manipulate and operate on a piece of
|
||||
text in a structured way. They allow you to refer to blocks of text based on
|
||||
their structure or purpose, such as a word, sentence, paragraph, or even a
|
||||
function or block of code.
|
||||
|
||||

|
||||

|
||||
|
||||
- `ma` - Select around the object (`va` in Vim, `<alt-a>` in Kakoune)
|
||||
- `mi` - Select inside the object (`vi` in Vim, `<alt-i>` in Kakoune)
|
||||
|
||||
| Key after `mi` or `ma` | Textobject selected |
|
||||
| --- | --- |
|
||||
| `w` | Word |
|
||||
| `W` | WORD |
|
||||
| `p` | Paragraph |
|
||||
| `(`, `[`, `'`, etc. | Specified surround pairs |
|
||||
| `m` | The closest surround pair |
|
||||
| `f` | Function |
|
||||
| `t` | Type (or Class) |
|
||||
| `a` | Argument/parameter |
|
||||
| `c` | Comment |
|
||||
| `T` | Test |
|
||||
| `g` | Change |
|
||||
|
||||
> 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current
|
||||
document and a special tree-sitter query file to work properly. [Only
|
||||
some grammars](./lang-support.md) currently have the query file implemented.
|
||||
Contributions are welcome!
|
||||
|
||||
## Navigating using tree-sitter textobjects
|
||||
|
||||
Navigating between functions, classes, parameters, and other elements is
|
||||
possible using tree-sitter and textobject queries. For
|
||||
example to move to the next function use `]f`, to move to previous
|
||||
type use `[t`, and so on.
|
||||
|
||||

|
||||
|
||||
For the full reference see the [unimpaired](./keymap.html#unimpaired) section of the key bind
|
||||
documentation.
|
||||
|
||||
> 💡 This feature relies on tree-sitter textobjects
|
||||
> and requires the corresponding query file to work properly.
|
||||
|
@@ -36,13 +36,6 @@ For inspiration, you can find the default `theme.toml`
|
||||
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
|
||||
|
||||
@@ -186,6 +179,7 @@ We use a similar set of scopes as
|
||||
- `parameter` - Function parameters
|
||||
- `other`
|
||||
- `member` - Fields of composite data types (e.g. structs, unions)
|
||||
- `private` - Private fields that use a unique syntax (currently just ECMAScript-based languages)
|
||||
|
||||
- `label`
|
||||
|
||||
@@ -213,6 +207,7 @@ We use a similar set of scopes as
|
||||
- `function`
|
||||
- `builtin`
|
||||
- `method`
|
||||
- `private` - Private methods that use a unique syntax (currently just ECMAScript-based languages)
|
||||
- `macro`
|
||||
- `special` (preprocessor in C)
|
||||
|
||||
@@ -251,6 +246,7 @@ We use a similar set of scopes as
|
||||
- `gutter` - gutter indicator
|
||||
- `delta` - modifications
|
||||
- `moved` - renamed or moved files/changes
|
||||
- `conflict` - merge conflicts
|
||||
- `gutter` - gutter indicator
|
||||
|
||||
#### Interface
|
||||
@@ -301,6 +297,8 @@ These scopes are used for theming the editor interface:
|
||||
| `ui.bufferline.background` | Style for bufferline background |
|
||||
| `ui.popup` | Documentation popups (e.g. Space + k) |
|
||||
| `ui.popup.info` | Prompt for multiple key options |
|
||||
| `ui.picker.header` | Column names in pickers with multiple columns |
|
||||
| `ui.picker.header.active` | The column name in pickers with multiple columns where the cursor is entering into. |
|
||||
| `ui.window` | Borderlines separating splits |
|
||||
| `ui.help` | Description box for commands |
|
||||
| `ui.text` | Default text style, command prompts, popup text, etc. |
|
||||
@@ -314,6 +312,7 @@ These scopes are used for theming the editor 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 |
|
||||
@@ -333,5 +332,7 @@ These scopes are used for theming the editor 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
|
||||
|
@@ -1,15 +1,5 @@
|
||||
# Using Helix
|
||||
|
||||
<!--toc:start-->
|
||||
- [Registers](#registers)
|
||||
- [User-defined registers](#user-defined-registers)
|
||||
- [Special registers](#special-registers)
|
||||
- [Surround](#surround)
|
||||
- [Selecting and manipulating text with textobjects](#selecting-and-manipulating-text-with-textobjects)
|
||||
- [Navigating using tree-sitter textobjects](#navigating-using-tree-sitter-textobjects)
|
||||
- [Moving the selection with syntax-aware motions](#moving-the-selection-with-syntax-aware-motions)
|
||||
<!--toc:end-->
|
||||
|
||||
For a full interactive introduction to Helix, refer to the
|
||||
[tutor](https://github.com/helix-editor/helix/blob/master/runtime/tutor) which
|
||||
can be accessed via the command `hx --tutor` or `:tutor`.
|
||||
@@ -17,192 +7,3 @@ can be accessed via the command `hx --tutor` or `:tutor`.
|
||||
> 💡 Currently, not all functionality is fully documented, please refer to the
|
||||
> [key mappings](./keymap.md) list.
|
||||
|
||||
## Registers
|
||||
|
||||
In Helix, registers are storage locations for text and other data, such as the
|
||||
result of a search. Registers can be used to cut, copy, and paste text, similar
|
||||
to the clipboard in other text editors. Usage is similar to Vim, with `"` being
|
||||
used to select a register.
|
||||
|
||||
### User-defined registers
|
||||
|
||||
Helix allows you to create your own named registers for storing text, for
|
||||
example:
|
||||
|
||||
- `"ay` - Yank the current selection to register `a`.
|
||||
- `"op` - Paste the text in register `o` after the selection.
|
||||
|
||||
If a register is selected before invoking a change or delete command, the selection will be stored in the register and the action will be carried out:
|
||||
|
||||
- `"hc` - Store the selection in register `h` and then change it (delete and enter insert mode).
|
||||
- `"md` - Store the selection in register `m` and delete it.
|
||||
|
||||
### Default registers
|
||||
|
||||
Commands that use registers, like yank (`y`), use a default register if none is specified.
|
||||
These registers are used as defaults:
|
||||
|
||||
| Register character | Contains |
|
||||
| --- | --- |
|
||||
| `/` | Last search |
|
||||
| `:` | Last executed command |
|
||||
| `"` | Last yanked text |
|
||||
| `@` | Last recorded macro |
|
||||
|
||||
### Special registers
|
||||
|
||||
Some registers have special behavior when read from and written to.
|
||||
|
||||
| Register character | When read | When written |
|
||||
| --- | --- | --- |
|
||||
| `_` | No values are returned | All values are discarded |
|
||||
| `#` | Selection indices (first selection is `1`, second is `2`, etc.) | This register is not writable |
|
||||
| `.` | Contents of the current selections | This register is not writable |
|
||||
| `%` | Name of the current file | This register is not writable |
|
||||
| `+` | Reads from the system clipboard | Joins and yanks to the system clipboard |
|
||||
| `*` | Reads from the primary clipboard | Joins and yanks to the primary clipboard |
|
||||
|
||||
When yanking multiple selections to the clipboard registers, the selections
|
||||
are joined with newlines. Pasting from these registers will paste multiple
|
||||
selections if the clipboard was last yanked to by the Helix session. Otherwise
|
||||
the clipboard contents are pasted as one selection.
|
||||
|
||||
## Surround
|
||||
|
||||
Helix includes built-in functionality similar to [vim-surround](https://github.com/tpope/vim-surround).
|
||||
The keymappings have been inspired from [vim-sandwich](https://github.com/machakann/vim-sandwich):
|
||||
|
||||

|
||||
|
||||
| Key Sequence | Action |
|
||||
| --------------------------------- | --------------------------------------- |
|
||||
| `ms<char>` (after selecting text) | Add surround characters to selection |
|
||||
| `mr<char_to_replace><new_char>` | Replace the closest surround characters |
|
||||
| `md<char_to_delete>` | Delete the closest surround characters |
|
||||
|
||||
You can use counts to act on outer pairs.
|
||||
|
||||
Surround can also act on multiple selections. For example, to change every occurrence of `(use)` to `[use]`:
|
||||
|
||||
1. `%` to select the whole file
|
||||
2. `s` to split the selections on a search term
|
||||
3. Input `use` and hit Enter
|
||||
4. `mr([` to replace the parentheses with square brackets
|
||||
|
||||
Multiple characters are currently not supported, but planned for future release.
|
||||
|
||||
## Selecting and manipulating text with textobjects
|
||||
|
||||
In Helix, textobjects are a way to select, manipulate and operate on a piece of
|
||||
text in a structured way. They allow you to refer to blocks of text based on
|
||||
their structure or purpose, such as a word, sentence, paragraph, or even a
|
||||
function or block of code.
|
||||
|
||||

|
||||

|
||||
|
||||
- `ma` - Select around the object (`va` in Vim, `<alt-a>` in Kakoune)
|
||||
- `mi` - Select inside the object (`vi` in Vim, `<alt-i>` in Kakoune)
|
||||
|
||||
| Key after `mi` or `ma` | Textobject selected |
|
||||
| --- | --- |
|
||||
| `w` | Word |
|
||||
| `W` | WORD |
|
||||
| `p` | Paragraph |
|
||||
| `(`, `[`, `'`, etc. | Specified surround pairs |
|
||||
| `m` | The closest surround pair |
|
||||
| `f` | Function |
|
||||
| `t` | Type (or Class) |
|
||||
| `a` | Argument/parameter |
|
||||
| `c` | Comment |
|
||||
| `T` | Test |
|
||||
| `g` | Change |
|
||||
|
||||
> 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current
|
||||
document and a special tree-sitter query file to work properly. [Only
|
||||
some grammars][lang-support] currently have the query file implemented.
|
||||
Contributions are welcome!
|
||||
|
||||
## Navigating using tree-sitter textobjects
|
||||
|
||||
Navigating between functions, classes, parameters, and other elements is
|
||||
possible using tree-sitter and textobject queries. For
|
||||
example to move to the next function use `]f`, to move to previous
|
||||
type use `[t`, and so on.
|
||||
|
||||
![Tree-sitter-nav-demo][tree-sitter-nav-demo]
|
||||
|
||||
For the full reference see the [unimpaired][unimpaired-keybinds] section of the key bind
|
||||
documentation.
|
||||
|
||||
> 💡 This feature relies on tree-sitter textobjects
|
||||
> and requires the corresponding query file to work properly.
|
||||
|
||||
## Moving the selection with syntax-aware motions
|
||||
|
||||
`Alt-p`, `Alt-o`, `Alt-i`, and `Alt-n` (or `Alt` and arrow keys) allow you to move the
|
||||
selection according to its location in the syntax tree. For example, many languages have the
|
||||
following syntax for function calls:
|
||||
|
||||
```js
|
||||
func(arg1, arg2, arg3);
|
||||
```
|
||||
|
||||
A function call might be parsed by tree-sitter into a tree like the following.
|
||||
|
||||
```tsq
|
||||
(call
|
||||
function: (identifier) ; func
|
||||
arguments:
|
||||
(arguments ; (arg1, arg2, arg3)
|
||||
(identifier) ; arg1
|
||||
(identifier) ; arg2
|
||||
(identifier))) ; arg3
|
||||
```
|
||||
|
||||
Use `:tree-sitter-subtree` to view the syntax tree of the primary selection. In
|
||||
a more intuitive tree format:
|
||||
|
||||
```
|
||||
┌────┐
|
||||
│call│
|
||||
┌─────┴────┴─────┐
|
||||
│ │
|
||||
┌─────▼────┐ ┌────▼────┐
|
||||
│identifier│ │arguments│
|
||||
│ "func" │ ┌────┴───┬─────┴───┐
|
||||
└──────────┘ │ │ │
|
||||
│ │ │
|
||||
┌─────────▼┐ ┌────▼─────┐ ┌▼─────────┐
|
||||
│identifier│ │identifier│ │identifier│
|
||||
│ "arg1" │ │ "arg2" │ │ "arg3" │
|
||||
└──────────┘ └──────────┘ └──────────┘
|
||||
```
|
||||
|
||||
If you have a selection that wraps `arg1` (see the tree above), and you use
|
||||
`Alt-n`, it will select the next sibling in the syntax tree: `arg2`.
|
||||
|
||||
```js
|
||||
// before
|
||||
func([arg1], arg2, arg3)
|
||||
// after
|
||||
func(arg1, [arg2], arg3);
|
||||
```
|
||||
|
||||
Similarly, `Alt-o` will expand the selection to the parent node, in this case, the
|
||||
arguments node.
|
||||
|
||||
```js
|
||||
func[(arg1, arg2, arg3)];
|
||||
```
|
||||
|
||||
There is also some nuanced behavior that prevents you from getting stuck on a
|
||||
node with no sibling. When using `Alt-p` with a selection on `arg1`, the previous
|
||||
child node will be selected. In the event that `arg1` does not have a previous
|
||||
sibling, the selection will move up the syntax tree and select the previous
|
||||
element. As a result, using `Alt-p` with a selection on `arg1` will move the
|
||||
selection to the "func" `identifier`.
|
||||
|
||||
[lang-support]: ./lang-support.md
|
||||
[unimpaired-keybinds]: ./keymap.md#unimpaired
|
||||
[tree-sitter-nav-demo]: https://user-images.githubusercontent.com/23398472/152332550-7dfff043-36a2-4aec-b8f2-77c13eb56d6f.gif
|
||||
|
@@ -6,27 +6,26 @@
|
||||
<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>
|
||||
<ul>
|
||||
<li>Vim-like modal editing</li>
|
||||
<li>Multiple selections</li>
|
||||
<li>Built-in language server support</li>
|
||||
<li>Smart, incremental syntax highlighting and code editing via tree-sitter</li>
|
||||
</ul>
|
||||
</description>
|
||||
<description xml:lang="ar">
|
||||
<p>
|
||||
<p xml:lang="ar">
|
||||
مُحَرِّرُ نُصُوصٍ يَعمَلُ فِي الطَّرَفِيَّة، مُستَلهَمٌ مِن Kakoune وَ Neovim وَمَكتُوبٌ بِلُغَةِ رَست البَرمَجِيَّة.
|
||||
</p>
|
||||
<ul>
|
||||
<li>تَحرِيرٌ وَضعِيٌّ شَبيهٌ بِـVim</li>
|
||||
<li>تَحدِيدَاتٌ لِلنَّصِ مُتَعَدِّدَة</li>
|
||||
<li>دَعْمٌ مُدمَجٌ لِخَوادِمِ اللُّغَات</li>
|
||||
<li>تَحرِيرُ التَّعلِيمَاتِ البَّرمَجِيَّةِ مَعَ تَمييزٍ لِلتَّركِيبِ النَّحُويِّ بِواسِطَةِ tree-sitter</li>
|
||||
<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>
|
||||
|
||||
@@ -48,6 +47,12 @@
|
||||
<content_rating type="oars-1.1" />
|
||||
|
||||
<releases>
|
||||
<release version="24.07" date="2024-07-14">
|
||||
<url>https://github.com/helix-editor/helix/releases/tag/24.07</url>
|
||||
</release>
|
||||
<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>
|
||||
@@ -71,9 +76,9 @@
|
||||
</release>
|
||||
</releases>
|
||||
|
||||
<requires>
|
||||
<recommends>
|
||||
<control>keyboard</control>
|
||||
</requires>
|
||||
</recommends>
|
||||
|
||||
<categories>
|
||||
<category>Utility</category>
|
||||
|
@@ -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
|
||||
|
@@ -1,15 +1,18 @@
|
||||
#!/usr/bin/env fish
|
||||
# Fish completion script for Helix editor
|
||||
|
||||
set -l langs (hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g')
|
||||
|
||||
complete -c hx -s h -l help -d "Prints help information"
|
||||
complete -c hx -l tutor -d "Loads the tutorial"
|
||||
complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup"
|
||||
complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
|
||||
complete -c hx -l health -xa "(__hx_langs_ops)" -d "Checks for errors"
|
||||
complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetch or build tree-sitter grammars"
|
||||
complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
|
||||
complete -c hx -s V -l version -d "Prints version information"
|
||||
complete -c hx -l vsplit -d "Splits all given files vertically into different windows"
|
||||
complete -c hx -l hsplit -d "Splits all given files horizontally into different windows"
|
||||
complete -c hx -s c -l config -r -d "Specifies a file to use for completion"
|
||||
complete -c hx -l log -r -d "Specifies a file to write log data into"
|
||||
complete -c hx -l vsplit -d "Splits all given files vertically"
|
||||
complete -c hx -l hsplit -d "Splits all given files horizontally"
|
||||
complete -c hx -s c -l config -r -d "Specifies a file to use for config"
|
||||
complete -c hx -l log -r -d "Specifies a file to use for logging"
|
||||
complete -c hx -s w -l working-dir -d "Specify initial working directory" -xa "(__fish_complete_directories)"
|
||||
|
||||
function __hx_langs_ops
|
||||
hx --health languages | tail -n '+2' | string replace -fr '^(\S+) .*' '$1'
|
||||
end
|
||||
|
@@ -14,16 +14,18 @@ _hx() {
|
||||
"--health[Checks for errors in editor setup]:language:->health" \
|
||||
"-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
|
||||
"--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
|
||||
"--vsplit[Splits all given files vertically into different windows]" \
|
||||
"--hsplit[Splits all given files horizontally into different windows]" \
|
||||
"--vsplit[Splits all given files vertically]" \
|
||||
"--hsplit[Splits all given files horizontally]" \
|
||||
"-c[Specifies a file to use for configuration]" \
|
||||
"--config[Specifies a file to use for configuration]" \
|
||||
"--log[Specifies a file to write log data into]" \
|
||||
"-w[Specify initial working directory]" \
|
||||
"--working-dir[Specify initial working directory]" \
|
||||
"--log[Specifies a file to use for logging]" \
|
||||
"*:file:_files"
|
||||
|
||||
case "$state" in
|
||||
health)
|
||||
local languages=($(hx --health |tail -n '+7' |awk '{print $1}' |sed 's/\x1b\[[0-9;]*m//g'))
|
||||
local languages=($(hx --health | tail -n '+11' | awk '{print $1}' | sed 's/\x1b\[[0-9;]*m//g;s/[✘✓]//g'))
|
||||
_values 'language' $languages
|
||||
;;
|
||||
grammar)
|
||||
@@ -31,4 +33,3 @@ _hx() {
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
BIN
contrib/helix-256p.ico
Normal file
BIN
contrib/helix-256p.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 KiB |
@@ -5,4 +5,4 @@ let
|
||||
sha256 = "sha256:1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7";
|
||||
};
|
||||
in
|
||||
(import compat {src = ./.;}).defaultNix.default
|
||||
(import compat {src = ./.;}).defaultNix
|
||||
|
@@ -31,7 +31,7 @@ being published.
|
||||
* Post to reddit
|
||||
* [Example post](https://www.reddit.com/r/rust/comments/uzp5ze/helix_editor_2205_released/)
|
||||
|
||||
[homebrew formula]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/helix.rb
|
||||
[homebrew formula]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/h/helix.rb
|
||||
|
||||
## Changelog Curation
|
||||
|
||||
|
24
flake.lock
generated
24
flake.lock
generated
@@ -7,11 +7,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701025348,
|
||||
"narHash": "sha256-42GHmYH+GF7VjwGSt+fVT1CQuNpGanJbNgVHTAZppUM=",
|
||||
"lastModified": 1709610799,
|
||||
"narHash": "sha256-5jfLQx0U9hXbi2skYMGodDJkIgffrjIOgMRjZqms2QE=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "42afaeb1a0325194a7cdb526332d2cb92fddd07b",
|
||||
"rev": "81c393c776d5379c030607866afef6406ca1be57",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -25,11 +25,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"lastModified": 1709126324,
|
||||
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -40,11 +40,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1700794826,
|
||||
"narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=",
|
||||
"lastModified": 1709479366,
|
||||
"narHash": "sha256-n6F0n8UV6lnTZbYPl1A9q1BS0p4hduAv1mGAP17CVd0=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8",
|
||||
"rev": "b8697e57f10292a6165a20f03d2f42920dfaf973",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -72,11 +72,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701137803,
|
||||
"narHash": "sha256-0LcPAdql5IhQSUXJx3Zna0dYTgdIoYO7zUrsKgiBd04=",
|
||||
"lastModified": 1709604635,
|
||||
"narHash": "sha256-le4fwmWmjGRYWwkho0Gr7mnnZndOOe4XGbLw68OvF40=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "9dd940c967502f844eacea52a61e9596268d4f70",
|
||||
"rev": "e86c0fb5d3a22a5f30d7f64ecad88643fe26449d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@@ -114,10 +114,7 @@
|
||||
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";
|
||||
rustFlagsEnv = pkgs.lib.optionalString stdenv.isLinux "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment";
|
||||
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;
|
||||
@@ -183,7 +180,7 @@
|
||||
shellHook = ''
|
||||
export HELIX_RUNTIME="$PWD/runtime"
|
||||
export RUST_BACKTRACE="1"
|
||||
export RUSTFLAGS="${rustFlagsEnv}"
|
||||
export RUSTFLAGS="''${RUSTFLAGS:-""} ${rustFlagsEnv}"
|
||||
'';
|
||||
};
|
||||
})
|
||||
|
12
grammars.nix
12
grammars.nix
@@ -28,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 {
|
||||
|
@@ -1,28 +0,0 @@
|
||||
[package]
|
||||
name = "helix-config"
|
||||
description = "Helix editor core editing primitives"
|
||||
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
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.8.6"
|
||||
hashbrown = { version = "0.14.3", features = ["raw"] }
|
||||
parking_lot = "0.12"
|
||||
anyhow = "1.0.79"
|
||||
indexmap = { version = "2.1.0", features = ["serde"] }
|
||||
serde = { version = "1.0" }
|
||||
serde_json = "1.0"
|
||||
globset = "0.4.14"
|
||||
regex = "1.10.2"
|
||||
regex-syntax = "0.8.2"
|
||||
which = "5.0.0"
|
||||
|
||||
regex-syntax = "0.8.2"
|
||||
which = "5.0.0"
|
@@ -1,76 +0,0 @@
|
||||
/// this is a reimplementation of dynamic dispatch that only stores the
|
||||
/// information we need and stores everythin inline. Values that are smaller or
|
||||
/// the same size as a slice (2 usize) are also stored inline. This avoids
|
||||
/// significant overallocation when setting lots of simple config
|
||||
/// options (integers, strings, lists, enums)
|
||||
use std::any::{Any, TypeId};
|
||||
use std::mem::{align_of, size_of, MaybeUninit};
|
||||
|
||||
pub struct ConfigData {
|
||||
data: MaybeUninit<[usize; 2]>,
|
||||
ty: TypeId,
|
||||
drop_fn: unsafe fn(MaybeUninit<[usize; 2]>),
|
||||
}
|
||||
|
||||
const fn store_inline<T>() -> bool {
|
||||
size_of::<T>() <= size_of::<[usize; 2]>() && align_of::<T>() <= align_of::<[usize; 2]>()
|
||||
}
|
||||
|
||||
impl ConfigData {
|
||||
unsafe fn drop_impl<T: Any>(mut data: MaybeUninit<[usize; 2]>) {
|
||||
if store_inline::<T>() {
|
||||
data.as_mut_ptr().cast::<T>().drop_in_place();
|
||||
} else {
|
||||
let ptr = data.as_mut_ptr().cast::<*mut T>().read();
|
||||
drop(Box::from_raw(ptr));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get<T: Any>(&self) -> &T {
|
||||
assert_eq!(TypeId::of::<T>(), self.ty);
|
||||
unsafe {
|
||||
if store_inline::<T>() {
|
||||
return &*self.data.as_ptr().cast();
|
||||
}
|
||||
let data: *const T = self.data.as_ptr().cast::<*const T>().read();
|
||||
&*data
|
||||
}
|
||||
}
|
||||
pub fn new<T: Any>(val: T) -> Self {
|
||||
let mut data = MaybeUninit::uninit();
|
||||
if store_inline::<T>() {
|
||||
let data: *mut T = data.as_mut_ptr() as _;
|
||||
unsafe {
|
||||
data.write(val);
|
||||
}
|
||||
} else {
|
||||
assert!(store_inline::<*const T>());
|
||||
let data: *mut *const T = data.as_mut_ptr() as _;
|
||||
unsafe {
|
||||
data.write(Box::into_raw(Box::new(val)));
|
||||
}
|
||||
};
|
||||
Self {
|
||||
data,
|
||||
ty: TypeId::of::<T>(),
|
||||
drop_fn: ConfigData::drop_impl::<T>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ConfigData {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
(self.drop_fn)(self.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ConfigData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ConfigData").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for ConfigData {}
|
||||
unsafe impl Sync for ConfigData {}
|
@@ -1,42 +0,0 @@
|
||||
use crate::any::ConfigData;
|
||||
use crate::validator::Ty;
|
||||
use crate::Value;
|
||||
|
||||
pub trait IntoTy: Clone {
|
||||
type Ty: Ty;
|
||||
fn into_ty(self) -> Self::Ty;
|
||||
}
|
||||
|
||||
impl<T: Ty> IntoTy for T {
|
||||
type Ty = Self;
|
||||
|
||||
fn into_ty(self) -> Self::Ty {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl<T: IntoTy> IntoTy for &[T] {
|
||||
type Ty = Box<[T::Ty]>;
|
||||
|
||||
fn into_ty(self) -> Self::Ty {
|
||||
self.iter().cloned().map(T::into_ty).collect()
|
||||
}
|
||||
}
|
||||
impl<T: IntoTy, const N: usize> IntoTy for &[T; N] {
|
||||
type Ty = Box<[T::Ty]>;
|
||||
|
||||
fn into_ty(self) -> Self::Ty {
|
||||
self.iter().cloned().map(T::into_ty).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoTy for &str {
|
||||
type Ty = Box<str>;
|
||||
|
||||
fn into_ty(self) -> Self::Ty {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn ty_into_value<T: Ty>(val: &ConfigData) -> Value {
|
||||
T::to_value(val.get())
|
||||
}
|
@@ -1,113 +0,0 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::*;
|
||||
|
||||
mod language;
|
||||
mod lsp;
|
||||
mod ui;
|
||||
|
||||
pub use lsp::init_language_server_config;
|
||||
|
||||
options! {
|
||||
use ui::*;
|
||||
use lsp::*;
|
||||
use language::*;
|
||||
|
||||
struct WrapConfig {
|
||||
/// Soft wrap lines that exceed viewport width.
|
||||
enable: bool = false,
|
||||
/// Maximum free space left at the end of the line.
|
||||
/// Automatically limited to a quarter of the viewport.
|
||||
max_wrap: u16 = 20,
|
||||
/// Maximum indentation to carry over when soft wrapping a line.
|
||||
/// Automatically limited to a quarter of the viewport.
|
||||
max_indent_retain: u16 = 40,
|
||||
/// Text inserted before soft wrapped lines, highlighted with `ui.virtual.wrap`.
|
||||
wrap_indicator: String = "↪",
|
||||
/// Soft wrap at `text-width` instead of using the full viewport size.
|
||||
wrap_at_text_width: bool = false,
|
||||
/// Maximum line length. Used for the `:reflow` command and
|
||||
/// soft-wrapping if `soft-wrap.wrap-at-text-width` is set
|
||||
text_width: usize = 80,
|
||||
}
|
||||
|
||||
struct MouseConfig {
|
||||
/// Enable mouse mode
|
||||
#[read = copy]
|
||||
mouse: bool = true,
|
||||
/// Number of lines to scroll per scroll wheel step.
|
||||
#[read = copy]
|
||||
scroll_lines: usize = 3,
|
||||
/// Middle click paste support
|
||||
#[read = copy]
|
||||
middle_click_paste: bool = true,
|
||||
}
|
||||
struct SmartTabConfig {
|
||||
/// 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.
|
||||
#[name = "smart-tab.enable"]
|
||||
#[read = copy]
|
||||
enable: bool = true,
|
||||
/// 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`.
|
||||
#[name = "smart-tab.supersede-menu"]
|
||||
#[read = copy]
|
||||
supersede_menu: bool = false,
|
||||
}
|
||||
|
||||
struct SearchConfig {
|
||||
/// Enable smart case regex searching (case-insensitive unless pattern
|
||||
/// contains upper case characters)
|
||||
#[name = "search.smart-case"]
|
||||
#[read = copy]
|
||||
smart_case: bool = true,
|
||||
/// Whether the search should wrap after depleting the matches
|
||||
#[name = "search.wrap-round"]
|
||||
#[read = copy]
|
||||
wrap_round: bool = true,
|
||||
}
|
||||
|
||||
struct MiscConfig {
|
||||
/// Number of lines of padding around the edge of the screen when scrolling.
|
||||
#[read = copy]
|
||||
scrolloff: usize = 5,
|
||||
/// Shell to use when running external commands
|
||||
#[read = deref]
|
||||
shell: List<String> = if cfg!(windows) {
|
||||
&["cmd", "/C"]
|
||||
} else {
|
||||
&["sh", "-c"]
|
||||
},
|
||||
/// 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
|
||||
#[read = copy]
|
||||
auto_save: bool = false,
|
||||
/// Whether to automatically insert a trailing line-ending on write
|
||||
/// if missing
|
||||
#[read = copy]
|
||||
insert_final_newline: bool = true,
|
||||
/// Time in milliseconds since last keypress before idle timers trigger.
|
||||
/// Used for autocompletion, set to 0 for instant
|
||||
#[read = copy]
|
||||
idle_timeout: Duration = Duration::from_millis(250),
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for Duration {
|
||||
fn from_value(val: Value) -> anyhow::Result<Self> {
|
||||
let val: usize = val.typed()?;
|
||||
Ok(Duration::from_millis(val as _))
|
||||
}
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Int(self.as_millis().try_into().unwrap())
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
use crate::*;
|
||||
|
||||
options! {
|
||||
struct LanguageConfig {
|
||||
/// regex pattern that will be tested against a language name in order to determine whether this language should be used for a potential [language injection][treesitter-language-injection] site.
|
||||
#[validator = regex_str_validator()]
|
||||
injection_regex: Option<String> = None,
|
||||
/// The interpreters from the shebang line, for example `["sh", "bash"]`
|
||||
#[read = deref]
|
||||
shebangs: List<String> = List::default(),
|
||||
/// The token to use as a comment-token
|
||||
#[read = deref]
|
||||
comment_token: String = "//",
|
||||
/// The tree-sitter grammar to use (defaults to the language name)
|
||||
grammar: Option<String> = None,
|
||||
}
|
||||
|
||||
struct FormatterConfiguration {
|
||||
#[read = copy]
|
||||
auto_format: bool = true,
|
||||
#[name = "formatter.command"]
|
||||
formatter_command: Option<String> = None,
|
||||
#[name = "formatter.args"]
|
||||
#[read = deref]
|
||||
formatter_args: List<String> = List::default(),
|
||||
}
|
||||
}
|
@@ -1,266 +0,0 @@
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// Describes the severity level of a [`Diagnostic`].
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize)]
|
||||
pub enum Severity {
|
||||
Hint,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl Ty for Severity {
|
||||
fn from_value(val: Value) -> anyhow::Result<Self> {
|
||||
let val: String = val.typed()?;
|
||||
match &*val {
|
||||
"hint" => Ok(Severity::Hint),
|
||||
"info" => Ok(Severity::Info),
|
||||
"warning" => Ok(Severity::Warning),
|
||||
"error" => Ok(Severity::Error),
|
||||
_ => bail!("expected one of 'hint', 'info', 'warning' or 'error' (got {val:?})"),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
match self {
|
||||
Severity::Hint => "hint".into(),
|
||||
Severity::Info => "info".into(),
|
||||
Severity::Warning => "warning".into(),
|
||||
Severity::Error => "error".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move to stdx
|
||||
/// Helper macro that automatically generates an array
|
||||
/// that contains all variants of an enum
|
||||
macro_rules! variant_list {
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
$vis: vis enum $name: ident {
|
||||
$($(#[$inner: meta])* $variant: ident $(= $_: literal)?),*$(,)?
|
||||
}
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
$vis enum $name {
|
||||
$($(#[$inner])* $variant),*
|
||||
}
|
||||
impl $name {
|
||||
$vis const ALL: &[$name] = &[$(Self::$variant),*];
|
||||
}
|
||||
}
|
||||
}
|
||||
variant_list! {
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum LanguageServerFeature {
|
||||
Format,
|
||||
GotoDeclaration,
|
||||
GotoDefinition,
|
||||
GotoTypeDefinition,
|
||||
GotoReference,
|
||||
GotoImplementation,
|
||||
// Goto, use bitflags, combining previous Goto members?
|
||||
SignatureHelp,
|
||||
Hover,
|
||||
DocumentHighlight,
|
||||
Completion,
|
||||
CodeAction,
|
||||
WorkspaceCommand,
|
||||
DocumentSymbols,
|
||||
WorkspaceSymbols,
|
||||
// Symbols, use bitflags, see above?
|
||||
Diagnostics,
|
||||
RenameSymbol,
|
||||
InlayHints,
|
||||
}
|
||||
}
|
||||
|
||||
impl LanguageServerFeature {
|
||||
fn to_str(self) -> &'static str {
|
||||
use LanguageServerFeature::*;
|
||||
|
||||
match self {
|
||||
Format => "format",
|
||||
GotoDeclaration => "goto-declaration",
|
||||
GotoDefinition => "goto-definition",
|
||||
GotoTypeDefinition => "goto-type-definition",
|
||||
GotoReference => "goto-reference",
|
||||
GotoImplementation => "goto-implementation",
|
||||
SignatureHelp => "signature-help",
|
||||
Hover => "hover",
|
||||
DocumentHighlight => "document-highlight",
|
||||
Completion => "completion",
|
||||
CodeAction => "code-action",
|
||||
WorkspaceCommand => "workspace-command",
|
||||
DocumentSymbols => "document-symbols",
|
||||
WorkspaceSymbols => "workspace-symbols",
|
||||
Diagnostics => "diagnostics",
|
||||
RenameSymbol => "rename-symbol",
|
||||
InlayHints => "inlay-hints",
|
||||
}
|
||||
}
|
||||
fn description(self) -> &'static str {
|
||||
use LanguageServerFeature::*;
|
||||
|
||||
match self {
|
||||
Format => "Use this language server for autoformatting.",
|
||||
GotoDeclaration => "Use this language server for the goto_declaration command.",
|
||||
GotoDefinition => "Use this language server for the goto_definition command.",
|
||||
GotoTypeDefinition => "Use this language server for the goto_type_definition command.",
|
||||
GotoReference => "Use this language server for the goto_reference command.",
|
||||
GotoImplementation => "Use this language server for the goto_implementation command.",
|
||||
SignatureHelp => "Use this language server to display signature help.",
|
||||
Hover => "Use this language server to display hover information.",
|
||||
DocumentHighlight => {
|
||||
"Use this language server for the select_references_to_symbol_under_cursor command."
|
||||
}
|
||||
Completion => "Request completion items from this language server.",
|
||||
CodeAction => "Use this language server for the code_action command.",
|
||||
WorkspaceCommand => "Use this language server for :lsp-workspace-command.",
|
||||
DocumentSymbols => "Use this language server for the symbol_picker command.",
|
||||
WorkspaceSymbols => "Use this language server for the workspace_symbol_picker command.",
|
||||
Diagnostics => "Display diagnostics emitted by this language server.",
|
||||
RenameSymbol => "Use this language server for the rename_symbol command.",
|
||||
InlayHints => "Display inlay hints form this language server.",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LanguageServerFeature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let feature = self.to_str();
|
||||
write!(f, "{feature}",)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for LanguageServerFeature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for LanguageServerFeature {
|
||||
fn from_value(val: Value) -> anyhow::Result<Self> {
|
||||
let val: String = val.typed()?;
|
||||
use LanguageServerFeature::*;
|
||||
|
||||
match &*val {
|
||||
"format" => Ok(Format),
|
||||
"goto-declaration" => Ok(GotoDeclaration),
|
||||
"goto-definition" => Ok(GotoDefinition),
|
||||
"goto-type-definition" => Ok(GotoTypeDefinition),
|
||||
"goto-reference" => Ok(GotoReference),
|
||||
"goto-implementation" => Ok(GotoImplementation),
|
||||
"signature-help" => Ok(SignatureHelp),
|
||||
"hover" => Ok(Hover),
|
||||
"document-highlight" => Ok(DocumentHighlight),
|
||||
"completion" => Ok(Completion),
|
||||
"code-action" => Ok(CodeAction),
|
||||
"workspace-command" => Ok(WorkspaceCommand),
|
||||
"document-symbols" => Ok(DocumentSymbols),
|
||||
"workspace-symbols" => Ok(WorkspaceSymbols),
|
||||
"diagnostics" => Ok(Diagnostics),
|
||||
"rename-symbol" => Ok(RenameSymbol),
|
||||
"inlay-hints" => Ok(InlayHints),
|
||||
_ => bail!("invalid language server feature {val}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::String(self.to_str().into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_language_server_config(registry: &mut OptionRegistry, languag_server: &str) {
|
||||
registry.register(
|
||||
&format!("language-servers.{languag_server}.active"),
|
||||
"Wether this language servers is used for a buffer",
|
||||
false,
|
||||
);
|
||||
for &feature in LanguageServerFeature::ALL {
|
||||
registry.register(
|
||||
&format!("language-servers.{languag_server}.{feature}"),
|
||||
feature.description(),
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
options! {
|
||||
struct LspConfig {
|
||||
/// Enables LSP integration. Setting to false will completely disable language servers.
|
||||
#[name = "lsp.enable"]
|
||||
#[read = copy]
|
||||
enable: bool = true,
|
||||
/// Enables LSP integration. Setting to false will completely disable language servers.
|
||||
#[name = "lsp.display-messages"]
|
||||
#[read = copy]
|
||||
display_messages: bool = false,
|
||||
/// Enable automatic popup of signature help (parameter hints)
|
||||
#[name = "lsp.auto-signature-help"]
|
||||
#[read = copy]
|
||||
auto_signature_help: bool = true,
|
||||
/// Enable automatic popup of signature help (parameter hints)
|
||||
#[name = "lsp.display-inlay-hints"]
|
||||
#[read = copy]
|
||||
display_inlay_hints: bool = false,
|
||||
/// Display docs under signature help popup
|
||||
#[name = "lsp.display-signature-help-docs"]
|
||||
#[read = copy]
|
||||
display_signature_help_docs: bool = true,
|
||||
/// Enables snippet completions. Requires a server restart
|
||||
/// (`:lsp-restart`) to take effect after `:config-reload`/`:set`.
|
||||
#[name = "lsp.snippets"]
|
||||
#[read = copy]
|
||||
snippets: bool = true,
|
||||
/// Include declaration in the goto references popup.
|
||||
#[name = "lsp.goto-reference-include-declaration"]
|
||||
#[read = copy]
|
||||
goto_reference_include_declaration: bool = true,
|
||||
// TODO(breaing): prefix all options below with `lsp.`
|
||||
/// The language-id for language servers, checkout the
|
||||
/// table at [TextDocumentItem](https://microsoft.github.io/
|
||||
/// language-server-protocol/specifications/lsp/3.17/specification/
|
||||
/// #textDocumentItem) for the right id
|
||||
#[name = "languague-id"]
|
||||
language_server_id: Option<String> = None,
|
||||
// TODO(breaking): rename to root-markers to differentiate from workspace-roots
|
||||
// TODO: also makes this setteble on the language server
|
||||
/// A set of marker files to look for when trying to find the workspace
|
||||
/// root. For example `Cargo.lock`, `yarn.lock`
|
||||
roots: List<String> = List::default(),
|
||||
// TODO: also makes this setteble on the language server
|
||||
/// Directories relative to the workspace root that are treated as LSP
|
||||
/// roots. The search for root markers (starting at the path of the
|
||||
/// file) will stop at these paths.
|
||||
#[name = "workspace-lsp-roots"]
|
||||
workspace_roots: List<String> = List::default(),
|
||||
/// An array of LSP diagnostic sources assumed unchanged when the
|
||||
/// language server resends the same set of diagnostics. Helix can track
|
||||
/// the position for these diagnostics internally instead. Useful for
|
||||
/// diagnostics that are recomputed on save.
|
||||
persistent_diagnostic_sources: List<String> = List::default(),
|
||||
/// Minimal severity of diagnostic for it to be displayed. (Allowed
|
||||
/// values: `error`, `warning`, `info`, `hint`)
|
||||
diagnostic_severity: Severity = Severity::Hint,
|
||||
}
|
||||
|
||||
struct CompletionConfig {
|
||||
/// Automatic auto-completion, automatically pop up without user trigger.
|
||||
#[read = copy]
|
||||
auto_completion: bool = true,
|
||||
/// Whether to apply completion item instantly when selected
|
||||
#[read = copy]
|
||||
preview_completion_insert: bool = true,
|
||||
/// Whether to apply completion item instantly when selected
|
||||
#[read = copy]
|
||||
completion_replace: bool = false,
|
||||
/// Whether to apply completion item instantly when selected
|
||||
#[read = copy]
|
||||
completion_trigger_len: u8 = 2,
|
||||
}
|
||||
}
|
@@ -1,291 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum StatusLineElement {
|
||||
/// The editor mode (Normal, Insert, Visual/Selection)
|
||||
Mode,
|
||||
/// The LSP activity spinner
|
||||
Spinner,
|
||||
/// The file basename (the leaf of the open file's path)
|
||||
FileBaseName,
|
||||
/// The relative file path
|
||||
FileName,
|
||||
// The file modification indicator
|
||||
FileModificationIndicator,
|
||||
/// An indicator that shows `"[readonly]"` when a file cannot be written
|
||||
ReadOnlyIndicator,
|
||||
/// The file encoding
|
||||
FileEncoding,
|
||||
/// The file line endings (CRLF or LF)
|
||||
FileLineEnding,
|
||||
/// The file type (language ID or "text")
|
||||
FileType,
|
||||
/// A summary of the number of errors and warnings
|
||||
Diagnostics,
|
||||
/// A summary of the number of errors and warnings on file and workspace
|
||||
WorkspaceDiagnostics,
|
||||
/// The number of selections (cursors)
|
||||
Selections,
|
||||
/// The number of characters currently in primary selection
|
||||
PrimarySelectionLength,
|
||||
/// The cursor position
|
||||
Position,
|
||||
/// The separator string
|
||||
Separator,
|
||||
/// The cursor position as a percent of the total file
|
||||
PositionPercentage,
|
||||
/// The total line numbers of the current file
|
||||
TotalLineNumbers,
|
||||
/// A single space
|
||||
Spacer,
|
||||
/// Current version control information
|
||||
VersionControl,
|
||||
/// Indicator for selected register
|
||||
Register,
|
||||
}
|
||||
|
||||
config_serde_adapter!(StatusLineElement);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
/// UNSTABLE
|
||||
pub enum CursorKind {
|
||||
/// █
|
||||
Block,
|
||||
/// |
|
||||
Bar,
|
||||
/// _
|
||||
Underline,
|
||||
/// Hidden cursor, can set cursor position with this to let IME have correct cursor position.
|
||||
Hidden,
|
||||
}
|
||||
|
||||
impl Default for CursorKind {
|
||||
fn default() -> Self {
|
||||
Self::Block
|
||||
}
|
||||
}
|
||||
|
||||
config_serde_adapter!(CursorKind);
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum WhitespaceRenderValue {
|
||||
None,
|
||||
// TODO
|
||||
// Selection,
|
||||
All,
|
||||
}
|
||||
|
||||
config_serde_adapter!(WhitespaceRenderValue);
|
||||
|
||||
/// bufferline render modes
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum BufferLine {
|
||||
/// Don't render bufferline
|
||||
Never,
|
||||
/// Always render
|
||||
Always,
|
||||
/// Only if multiple buffers are open
|
||||
Multiple,
|
||||
}
|
||||
|
||||
config_serde_adapter!(BufferLine);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PopupBorderConfig {
|
||||
None,
|
||||
All,
|
||||
Popup,
|
||||
Menu,
|
||||
}
|
||||
|
||||
config_serde_adapter!(PopupBorderConfig);
|
||||
|
||||
options! {
|
||||
struct UiConfig {
|
||||
/// Whether to display info boxes
|
||||
#[read = copy]
|
||||
auto_info: bool = true,
|
||||
/// Renders a line at the top of the editor displaying open buffers.
|
||||
/// Can be `always`, `never` or `multiple` (only shown if more than one
|
||||
/// buffer is in use)
|
||||
#[read = copy]
|
||||
bufferline: BufferLine = BufferLine::Never,
|
||||
/// Highlight all lines with a cursor
|
||||
#[read = copy]
|
||||
cursorline: bool = false,
|
||||
/// Highlight all columns with a cursor
|
||||
#[read = copy]
|
||||
cursorcolumn: bool = false,
|
||||
/// List of column positions at which to display the rulers.
|
||||
#[read = deref]
|
||||
rulers: List<u16> = List::default(),
|
||||
/// Whether to color the mode indicator with different colors depending on the mode itself
|
||||
#[read = copy]
|
||||
popup_border: bool = false,
|
||||
/// Whether to color the mode indicator with different colors depending on the mode itself
|
||||
#[read = copy]
|
||||
color_modes: bool = false,
|
||||
}
|
||||
|
||||
struct WhiteSpaceRenderConfig {
|
||||
#[name = "whitespace.characters.space"]
|
||||
#[read = copy]
|
||||
space_char: char = '·', // U+00B7
|
||||
#[name = "whitespace.characters.nbsp"]
|
||||
#[read = copy]
|
||||
nbsp_char: char = '⍽', // U+237D
|
||||
#[name = "whitespace.characters.tab"]
|
||||
#[read = copy]
|
||||
tab_char: char = '→', // U+2192
|
||||
#[name = "whitespace.characters.tabpad"]
|
||||
#[read = copy]
|
||||
tabpad_char: char = '⏎', // U+23CE
|
||||
#[name = "whitespace.characters.newline"]
|
||||
#[read = copy]
|
||||
newline_char: char = ' ',
|
||||
#[name = "whitespace.render.default"]
|
||||
#[read = copy]
|
||||
render: WhitespaceRenderValue = WhitespaceRenderValue::None,
|
||||
#[name = "whitespace.render.space"]
|
||||
#[read = copy]
|
||||
render_space: Option<WhitespaceRenderValue> = None,
|
||||
#[name = "whitespace.render.nbsp"]
|
||||
#[read = copy]
|
||||
render_nbsp: Option<WhitespaceRenderValue> = None,
|
||||
#[name = "whitespace.render.tab"]
|
||||
#[read = copy]
|
||||
render_tab: Option<WhitespaceRenderValue> = None,
|
||||
#[name = "whitespace.render.newline"]
|
||||
#[read = copy]
|
||||
render_newline: Option<WhitespaceRenderValue> = None,
|
||||
}
|
||||
|
||||
struct TerminfoConfig {
|
||||
/// Set to `true` to override automatic detection of terminal truecolor
|
||||
/// support in the event of a false negative
|
||||
#[name = "true-color"]
|
||||
#[read = copy]
|
||||
force_true_color: bool = false,
|
||||
/// Set to `true` to override automatic detection of terminal undercurl
|
||||
/// support in the event of a false negative
|
||||
#[name = "undercurl"]
|
||||
#[read = copy]
|
||||
force_undercurl: bool = false,
|
||||
}
|
||||
|
||||
struct IndentGuidesConfig {
|
||||
/// Whether to render indent guides
|
||||
#[read = copy]
|
||||
render: bool = false,
|
||||
/// Character to use for rendering indent guides
|
||||
#[read = copy]
|
||||
character: char = '│',
|
||||
/// Number of indent levels to skip
|
||||
#[read = copy]
|
||||
skip_levels: u8 = 0,
|
||||
}
|
||||
|
||||
struct CursorShapeConfig {
|
||||
/// Cursor shape in normal mode
|
||||
#[name = "cursor-shape.normal"]
|
||||
#[read = copy]
|
||||
normal_mode_cursor: CursorKind = CursorKind::Block,
|
||||
/// Cursor shape in select mode
|
||||
#[name = "cursor-shape.select"]
|
||||
#[read = copy]
|
||||
select_mode_cursor: CursorKind = CursorKind::Block,
|
||||
/// Cursor shape in insert mode
|
||||
#[name = "cursor-shape.insert"]
|
||||
#[read = copy]
|
||||
insert_mode_cursor: CursorKind = CursorKind::Block,
|
||||
}
|
||||
|
||||
struct FilePickerConfig {
|
||||
/// Whether to exclude hidden files from any file pickers.
|
||||
#[name = "file-picker.hidden"]
|
||||
#[read = copy]
|
||||
hidden: bool = true,
|
||||
/// Follow symlinks instead of ignoring them
|
||||
#[name = "file-picker.follow-symlinks"]
|
||||
#[read = copy]
|
||||
follow_symlinks: bool = true,
|
||||
/// Ignore symlinks that point at files already shown in the picker
|
||||
#[name = "file-picker.deduplicate-links"]
|
||||
#[read = copy]
|
||||
deduplicate_links: bool = true,
|
||||
/// Enables reading ignore files from parent directories.
|
||||
#[name = "file-picker.parents"]
|
||||
#[read = copy]
|
||||
parents: bool = true,
|
||||
/// Enables reading `.ignore` files.
|
||||
#[name = "file-picker.ignore"]
|
||||
#[read = copy]
|
||||
ignore: bool = true,
|
||||
/// Enables reading `.gitignore` files.
|
||||
#[name = "file-picker.git-ignore"]
|
||||
#[read = copy]
|
||||
git_ignore: bool = true,
|
||||
/// Enables reading global .gitignore, whose path is specified in git's config: `core.excludefile` option.
|
||||
#[name = "file-picker.git-global"]
|
||||
#[read = copy]
|
||||
git_global: bool = true,
|
||||
/// Enables reading `.git/info/exclude` files.
|
||||
#[name = "file-picker.git-exclude"]
|
||||
#[read = copy]
|
||||
git_exclude: bool = true,
|
||||
/// Maximum Depth to recurse directories in file picker and global search.
|
||||
#[name = "file-picker.max-depth"]
|
||||
#[read = copy]
|
||||
max_depth: Option<usize> = None,
|
||||
}
|
||||
|
||||
struct StatusLineConfig{
|
||||
/// A list of elements aligned to the left of the statusline
|
||||
#[name = "statusline.left"]
|
||||
#[read = deref]
|
||||
left: List<StatusLineElement> = &[
|
||||
StatusLineElement::Mode,
|
||||
StatusLineElement::Spinner,
|
||||
StatusLineElement::FileName,
|
||||
StatusLineElement::ReadOnlyIndicator,
|
||||
StatusLineElement::FileModificationIndicator,
|
||||
],
|
||||
/// A list of elements aligned to the middle of the statusline
|
||||
#[name = "statusline.center"]
|
||||
#[read = deref]
|
||||
center: List<StatusLineElement> = List::default(),
|
||||
/// A list of elements aligned to the right of the statusline
|
||||
#[name = "statusline.right"]
|
||||
#[read = deref]
|
||||
right: List<StatusLineElement> = &[
|
||||
StatusLineElement::Diagnostics,
|
||||
StatusLineElement::Selections,
|
||||
StatusLineElement::Register,
|
||||
StatusLineElement::Position,
|
||||
StatusLineElement::FileEncoding,
|
||||
],
|
||||
/// The character used to separate elements in the statusline
|
||||
#[name = "statusline.seperator"]
|
||||
#[read = deref]
|
||||
seperator: String = "│",
|
||||
/// The text shown in the `mode` element for normal mode
|
||||
#[name = "statusline.mode.normal"]
|
||||
#[read = deref]
|
||||
mode_indicator_normal: String = "NOR",
|
||||
/// The text shown in the `mode` element for insert mode
|
||||
#[name = "statusline.mode.insert"]
|
||||
#[read = deref]
|
||||
mode_indicator_insert: String = "INS",
|
||||
/// The text shown in the `mode` element for select mode
|
||||
#[name = "statusline.mode.select"]
|
||||
#[read = deref]
|
||||
mode_indicator_select: String = "SEL",
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
// TOOD: move to stdx
|
||||
|
||||
pub fn binary_exists(binary_name: &str) -> bool {
|
||||
which::which(binary_name).is_ok()
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn env_var_is_set(env_var_name: &str) -> bool {
|
||||
std::env::var_os(env_var_name).is_some()
|
||||
}
|
@@ -1,246 +0,0 @@
|
||||
use std::any::Any;
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::bail;
|
||||
use hashbrown::hash_map::Entry;
|
||||
use hashbrown::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
|
||||
|
||||
use any::ConfigData;
|
||||
use convert::ty_into_value;
|
||||
pub use convert::IntoTy;
|
||||
pub use definition::{init_config, init_language_server_config};
|
||||
pub use toml::read_toml_config;
|
||||
use validator::StaticValidator;
|
||||
pub use validator::{regex_str_validator, ty_validator, IntegerRangeValidator, Ty, Validator};
|
||||
pub use value::{from_value, to_value, Value};
|
||||
|
||||
mod any;
|
||||
mod convert;
|
||||
mod definition;
|
||||
pub mod env;
|
||||
mod macros;
|
||||
mod toml;
|
||||
mod validator;
|
||||
mod value;
|
||||
|
||||
pub type Guard<'a, T> = MappedRwLockReadGuard<'a, T>;
|
||||
pub type Map<T> = IndexMap<Box<str>, T, ahash::RandomState>;
|
||||
pub type String = Box<str>;
|
||||
pub type List<T> = Box<[T]>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OptionInfo {
|
||||
pub name: Arc<str>,
|
||||
pub description: Box<str>,
|
||||
pub validator: Box<dyn Validator>,
|
||||
pub into_value: fn(&ConfigData) -> Value,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OptionManager {
|
||||
vals: RwLock<HashMap<Arc<str>, ConfigData>>,
|
||||
parent: Option<Arc<OptionManager>>,
|
||||
}
|
||||
|
||||
impl OptionManager {
|
||||
pub fn get<T: Any>(&self, option: &str) -> Guard<'_, T> {
|
||||
Guard::map(self.get_data(option), ConfigData::get)
|
||||
}
|
||||
|
||||
pub fn get_data(&self, option: &str) -> Guard<'_, ConfigData> {
|
||||
let mut current_scope = self;
|
||||
loop {
|
||||
let lock = current_scope.vals.read();
|
||||
if let Ok(res) = RwLockReadGuard::try_map(lock, |options| options.get(option)) {
|
||||
return res;
|
||||
}
|
||||
let Some(new_scope) = current_scope.parent.as_deref() else{
|
||||
unreachable!("option must be atleast defined in the global scope")
|
||||
};
|
||||
current_scope = new_scope;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_deref<T: Deref + Any>(&self, option: &str) -> Guard<'_, T::Target> {
|
||||
Guard::map(self.get::<T>(option), T::deref)
|
||||
}
|
||||
|
||||
pub fn get_folded<T: Any, R>(
|
||||
&self,
|
||||
option: &str,
|
||||
init: R,
|
||||
mut fold: impl FnMut(&T, R) -> R,
|
||||
) -> R {
|
||||
let mut res = init;
|
||||
let mut current_scope = self;
|
||||
loop {
|
||||
let options = current_scope.vals.read();
|
||||
if let Some(option) = options.get(option).map(|val| val.get()) {
|
||||
res = fold(option, res);
|
||||
}
|
||||
let Some(new_scope) = current_scope.parent.as_deref() else{
|
||||
break
|
||||
};
|
||||
current_scope = new_scope;
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
pub fn get_value(
|
||||
&self,
|
||||
option: impl Into<Arc<str>>,
|
||||
registry: &OptionRegistry,
|
||||
) -> anyhow::Result<Value> {
|
||||
let option: Arc<str> = option.into();
|
||||
let Some(opt) = registry.get(&option) else { bail!("unknown option {option:?}") };
|
||||
let data = self.get_data(&option);
|
||||
let val = (opt.into_value)(&data);
|
||||
Ok(val)
|
||||
}
|
||||
|
||||
pub fn create_scope(self: &Arc<OptionManager>) -> OptionManager {
|
||||
OptionManager {
|
||||
vals: RwLock::default(),
|
||||
parent: Some(self.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_parent_scope(&mut self, parent: Arc<OptionManager>) {
|
||||
self.parent = Some(parent)
|
||||
}
|
||||
|
||||
pub fn set_unchecked(&self, option: Arc<str>, val: ConfigData) {
|
||||
self.vals.write().insert(option, val);
|
||||
}
|
||||
|
||||
pub fn append(
|
||||
&self,
|
||||
option: impl Into<Arc<str>>,
|
||||
val: impl Into<Value>,
|
||||
registry: &OptionRegistry,
|
||||
max_depth: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
let val = val.into();
|
||||
let option: Arc<str> = option.into();
|
||||
let Some(opt) = registry.get(&option) else { bail!("unknown option {option:?}") };
|
||||
let old_data = self.get_data(&option);
|
||||
let mut old = (opt.into_value)(&old_data);
|
||||
old.append(val, max_depth);
|
||||
let val = opt.validator.validate(old)?;
|
||||
self.set_unchecked(option, val);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the value of a config option. Returns an error if this config
|
||||
/// option doesn't exist or the provided value is not valid.
|
||||
pub fn set(
|
||||
&self,
|
||||
option: impl Into<Arc<str>>,
|
||||
val: impl Into<Value>,
|
||||
registry: &OptionRegistry,
|
||||
) -> anyhow::Result<()> {
|
||||
let option: Arc<str> = option.into();
|
||||
let val = val.into();
|
||||
let Some(opt) = registry.get(&option) else { bail!("unknown option {option:?}") };
|
||||
let val = opt.validator.validate(val)?;
|
||||
self.set_unchecked(option, val);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// unsets an options so that its value will be read from
|
||||
/// the parent scope instead
|
||||
pub fn unset(&self, option: &str) {
|
||||
self.vals.write().remove(option);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OptionRegistry {
|
||||
options: HashMap<Arc<str>, OptionInfo>,
|
||||
defaults: Arc<OptionManager>,
|
||||
}
|
||||
|
||||
impl OptionRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
options: HashMap::with_capacity(1024),
|
||||
defaults: Arc::new(OptionManager {
|
||||
vals: RwLock::new(HashMap::with_capacity(1024)),
|
||||
parent: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register<T: IntoTy>(&mut self, name: &str, description: &str, default: T) {
|
||||
self.register_with_validator(
|
||||
name,
|
||||
description,
|
||||
default,
|
||||
StaticValidator::<T::Ty> { ty: PhantomData },
|
||||
);
|
||||
}
|
||||
|
||||
pub fn register_with_validator<T: IntoTy>(
|
||||
&mut self,
|
||||
name: &str,
|
||||
description: &str,
|
||||
default: T,
|
||||
validator: impl Validator,
|
||||
) {
|
||||
let mut name: Arc<str> = name.into();
|
||||
// convert from snake case to kebab case in place without an additional
|
||||
// allocation this is save since we only replace ascii with ascii in
|
||||
// place std really ougth to have a function for this :/
|
||||
// TODO: move to stdx as extension trait
|
||||
for byte in unsafe { Arc::get_mut(&mut name).unwrap().as_bytes_mut() } {
|
||||
if *byte == b'-' {
|
||||
*byte = b'_';
|
||||
}
|
||||
}
|
||||
let default = default.into_ty();
|
||||
match self.options.entry(name.clone()) {
|
||||
Entry::Vacant(e) => {
|
||||
// make sure the validator is correct
|
||||
if cfg!(debug_assertions) {
|
||||
validator.validate(T::Ty::to_value(&default)).unwrap();
|
||||
}
|
||||
let opt = OptionInfo {
|
||||
name: name.clone(),
|
||||
description: description.into(),
|
||||
validator: Box::new(validator),
|
||||
into_value: ty_into_value::<T::Ty>,
|
||||
};
|
||||
e.insert(opt);
|
||||
}
|
||||
Entry::Occupied(ent) => {
|
||||
ent.get()
|
||||
.validator
|
||||
.validate(T::Ty::to_value(&default))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
self.defaults.set_unchecked(name, ConfigData::new(default));
|
||||
}
|
||||
|
||||
pub fn global_scope(&self) -> Arc<OptionManager> {
|
||||
self.defaults.clone()
|
||||
}
|
||||
|
||||
pub fn get(&self, name: &str) -> Option<&OptionInfo> {
|
||||
self.options.get(name)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for OptionRegistry {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
@@ -1,130 +0,0 @@
|
||||
/// This macro allows specifiying a trait of related config
|
||||
/// options with a struct like syntax. From that information
|
||||
/// two things are generated:
|
||||
///
|
||||
/// * A `init_config` function that registers the config options with the
|
||||
/// `OptionRegistry` registry.
|
||||
/// * A **trait** definition with an accessor for every config option that is
|
||||
/// implemented for `OptionManager`.
|
||||
///
|
||||
/// The accessors on the trait allow convenient statically typed access to
|
||||
/// config fields. The accessors return `Guard<T>` (which allows derferecning to
|
||||
/// &T). Any type that implements copy can be returned as a copy instead by
|
||||
/// specifying `#[read = copy]`. Collections like `List<T>` and `String` are not
|
||||
/// copy However, they usually implement deref (to &[T] and &str respectively).
|
||||
/// Working with the dereferneced &str/&[T] is more convenient then &String and &List<T>. The
|
||||
/// accessor will return these if `#[read = deref]` is specified.
|
||||
///
|
||||
/// The doc comments will be retained for the accessors and also stored in the
|
||||
/// option registrry for dispaly in the UI and documentation.
|
||||
///
|
||||
/// The name of a config option can be changed with #[name = "<name>"],
|
||||
/// otherwise the name of the field is used directly. The OptionRegistry
|
||||
/// automatically converts all names to kebab-case so a name attribute is only
|
||||
/// required if the name is supposed to be significantly altered.
|
||||
///
|
||||
/// In some cases more complex validation may be necssary. In that case the
|
||||
/// valiidtator can be provided with an exprission that implements the `Validator`
|
||||
/// trait: `#[validator = create_validator()]`.
|
||||
#[macro_export]
|
||||
macro_rules! options {
|
||||
(
|
||||
$(use $use: ident::*;)*
|
||||
$($(#[$($meta: tt)*])* struct $ident: ident {
|
||||
$(
|
||||
$(#[doc = $option_desc: literal])*
|
||||
$(#[name = $option_name: literal])?
|
||||
$(#[validator = $option_validator: expr])?
|
||||
$(#[read = $($extra: tt)*])?
|
||||
$option: ident: $ty: ty = $default: expr
|
||||
),+$(,)?
|
||||
})+
|
||||
) => {
|
||||
$(pub use $use::*;)*
|
||||
$($(#[$($meta)*])* pub trait $ident {
|
||||
$(
|
||||
$(#[doc = $option_desc])*
|
||||
fn $option(&self) -> $crate::options!(@ret_ty $($($extra)*)? $ty);
|
||||
)+
|
||||
})+
|
||||
pub fn init_config(registry: &mut $crate::OptionRegistry) {
|
||||
$($use::init_config(registry);)*
|
||||
$($(
|
||||
let name = $crate::options!(@name $option $($option_name)?);
|
||||
let docs = concat!("" $(,$option_desc,)" "*);
|
||||
$crate::options!(@register registry name docs $default, $ty $(,$option_validator)?);
|
||||
)+)+
|
||||
}
|
||||
$(impl $ident for $crate::OptionManager {
|
||||
$(
|
||||
$(#[doc = $option_desc])*
|
||||
fn $option(&self) -> $crate::options!(@ret_ty $($($extra)*)? $ty) {
|
||||
let name = $crate::options!(@name $option $($option_name)?);
|
||||
$crate::options!(@get $($($extra)*)? self, $ty, name)
|
||||
}
|
||||
)+
|
||||
})+
|
||||
};
|
||||
(@register $registry: ident $name: ident $desc: ident $default: expr, $ty:ty) => {{
|
||||
use $crate::IntoTy;
|
||||
let val: $ty = $default.into_ty();
|
||||
$registry.register($name, $desc, val);
|
||||
}};
|
||||
(@register $registry: ident $name: ident $desc: ident $default: expr, $ty:ty, $validator: expr) => {{
|
||||
use $crate::IntoTy;
|
||||
let val: $ty = $default.into_ty();
|
||||
$registry.register_with_validator($name, $desc, val, $validator);
|
||||
}};
|
||||
(@name $ident: ident) => {
|
||||
::std::stringify!($ident)
|
||||
};
|
||||
(@name $ident: ident $name: literal) => {
|
||||
$name
|
||||
};
|
||||
(@ret_ty copy $ty: ty) => {
|
||||
$ty
|
||||
};
|
||||
(@ret_ty map($fn: expr, $ret_ty: ty) $ty: ty) => {
|
||||
$ret_ty
|
||||
};
|
||||
(@ret_ty fold($init: expr, $fn: expr, $ret_ty: ty) $ty: ty) => {
|
||||
$ret_ty
|
||||
};
|
||||
(@ret_ty deref $ty: ty) => {
|
||||
$crate::Guard<'_, <$ty as ::std::ops::Deref>::Target>
|
||||
};
|
||||
(@ret_ty $ty: ty) => {
|
||||
$crate::Guard<'_, $ty>
|
||||
};
|
||||
(@get map($fn: expr, $ret_ty: ty) $config: ident, $ty: ty, $name: ident) => {
|
||||
let val = $config.get::<$ty>($name);
|
||||
$fn(val)
|
||||
};
|
||||
(@get fold($init: expr, $fn: expr, $ret_ty: ty) $config: ident, $ty: ty, $name: ident) => {
|
||||
$config.get_folded::<$ty, $ret_ty>($name, $init, $fn)
|
||||
};
|
||||
(@get copy $config: ident, $ty: ty, $name: ident) => {
|
||||
*$config.get::<$ty>($name)
|
||||
};
|
||||
(@get deref $config: ident, $ty: ty, $name: ident) => {
|
||||
$config.get_deref::<$ty>($name)
|
||||
};
|
||||
(@get $config: ident, $ty: ty, $name: ident) => {
|
||||
$config.get::<$ty>($name)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! config_serde_adapter {
|
||||
($ty: ident) => {
|
||||
impl $crate::Ty for $ty {
|
||||
fn to_value(&self) -> $crate::Value {
|
||||
$crate::to_value(self).unwrap()
|
||||
}
|
||||
fn from_value(val: $crate::Value) -> ::anyhow::Result<Self> {
|
||||
let val = $crate::from_value(val)?;
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config_serde_adapter;
|
||||
use crate::OptionRegistry;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum LineNumber {
|
||||
/// Show absolute line number
|
||||
#[serde(alias = "abs")]
|
||||
Absolute,
|
||||
/// If focused and in normal/select mode, show relative line number to the primary cursor.
|
||||
/// If unfocused or in insert mode, show absolute line number.
|
||||
#[serde(alias = "rel")]
|
||||
Relative,
|
||||
}
|
||||
|
||||
config_serde_adapter!(LineNumber);
|
||||
|
||||
fn setup_registry() -> OptionRegistry {
|
||||
let mut registry = OptionRegistry::new();
|
||||
registry.register(
|
||||
"scrolloff",
|
||||
"Number of lines of padding around the edge of the screen when scrolling",
|
||||
5usize,
|
||||
);
|
||||
registry.register(
|
||||
"shell",
|
||||
"Shell to use when running external commands",
|
||||
&["sh", "-c"],
|
||||
);
|
||||
registry.register("mouse", "Enable mouse mode", true);
|
||||
registry.register(
|
||||
"line-number",
|
||||
"Line number display: `absolute` simply shows each line's number, while \
|
||||
`relative` shows the distance from the current line. When unfocused or in \
|
||||
insert mode, `relative` will still show absolute line numbers",
|
||||
LineNumber::Absolute,
|
||||
);
|
||||
registry
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_values() {
|
||||
let registry = setup_registry();
|
||||
let global_scope = registry.global_scope();
|
||||
let scrolloff: usize = *global_scope.get("scrolloff");
|
||||
let shell_ = global_scope.get_deref::<Box<[_]>>("shell");
|
||||
let shell: &[Box<str>] = &shell_;
|
||||
let mouse: bool = *global_scope.get("mouse");
|
||||
let line_number: LineNumber = *global_scope.get("line-number");
|
||||
assert_eq!(scrolloff, 5);
|
||||
assert!(shell.iter().map(Box::deref).eq(["sh", "-c"]));
|
||||
assert!(mouse);
|
||||
assert_eq!(line_number, LineNumber::Absolute);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scope_overwrite() {
|
||||
let registry = setup_registry();
|
||||
let global_scope = registry.global_scope();
|
||||
let scope_1 = Arc::new(global_scope.create_scope());
|
||||
let scope_2 = Arc::new(global_scope.create_scope());
|
||||
let mut scope_3 = scope_1.create_scope();
|
||||
scope_1.set("line-number", "rel", ®istry).unwrap();
|
||||
let line_number: LineNumber = *scope_3.get("line-number");
|
||||
assert_eq!(line_number, LineNumber::Relative);
|
||||
scope_3.set_parent_scope(scope_2.clone());
|
||||
let line_number: LineNumber = *scope_3.get("line-number");
|
||||
assert_eq!(line_number, LineNumber::Absolute);
|
||||
scope_2.set("line-number", "rel", ®istry).unwrap();
|
||||
let line_number: LineNumber = *scope_3.get("line-number");
|
||||
assert_eq!(line_number, LineNumber::Relative);
|
||||
scope_2.set("line-number", "abs", ®istry).unwrap();
|
||||
let line_number: LineNumber = *scope_3.get("line-number");
|
||||
assert_eq!(line_number, LineNumber::Absolute);
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
use crate::{Map, OptionManager, OptionRegistry, Value};
|
||||
|
||||
/// Inserts the config declaration from a map deserialized from toml into
|
||||
/// options manager. Returns an error if any of theu config options are
|
||||
/// invalid The convresion may not be exactly one-to-one to retain backwards
|
||||
/// compatibility
|
||||
pub fn read_toml_config(
|
||||
config_entries: Map<Value>,
|
||||
options: &OptionManager,
|
||||
registry: &OptionRegistry,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut buf = String::new();
|
||||
for (key, val) in config_entries {
|
||||
if matches!(val, Value::Map(_)) {
|
||||
buf.push_str(&key);
|
||||
visit(&mut buf, val, options, registry)?;
|
||||
buf.clear();
|
||||
} else {
|
||||
visit(&mut key.to_string(), val, options, registry)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit(
|
||||
path: &mut String,
|
||||
val: Value,
|
||||
options: &OptionManager,
|
||||
registry: &OptionRegistry,
|
||||
) -> anyhow::Result<()> {
|
||||
match &**path {
|
||||
// don't descend
|
||||
"auto-format" => {
|
||||
// treat as unset
|
||||
if Value::Bool(true) == val {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
"auto-pairs" => return options.set("auto-pairs", val, registry),
|
||||
"enviorment" => return options.set("enviorment", val, registry),
|
||||
"config" => return options.set("config", val, registry),
|
||||
"gutters" if matches!(val, Value::List(_)) => {
|
||||
return options.set("gutters.layout", val, registry);
|
||||
}
|
||||
"gutters" if matches!(val, Value::List(_)) => {
|
||||
return options.set("gutters.layout", val, registry);
|
||||
}
|
||||
"whitespace.render" if matches!(val, Value::String(_)) => {
|
||||
return options.set("whitespace.render.default", val, registry);
|
||||
}
|
||||
"language-servers" => {
|
||||
// merge list/map of language servers but if "only" and "except" are specified overwrite
|
||||
return options.append("language-servers", val, registry, 0);
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
if let Value::Map(val) = val {
|
||||
let old_path_len = path.len();
|
||||
for (key, val) in val.into_iter() {
|
||||
path.push('.');
|
||||
path.push_str(&key);
|
||||
visit(path, val, options, registry)?;
|
||||
path.truncate(old_path_len);
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
options.set(&**path, val, registry)
|
||||
}
|
||||
}
|
@@ -1,296 +0,0 @@
|
||||
use std::any::{type_name, Any};
|
||||
use std::error::Error;
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use anyhow::{bail, ensure, Result};
|
||||
|
||||
use crate::any::ConfigData;
|
||||
use crate::Value;
|
||||
|
||||
pub trait Validator: 'static + Debug {
|
||||
fn validate(&self, val: Value) -> Result<ConfigData>;
|
||||
}
|
||||
|
||||
pub trait Ty: Sized + Clone + 'static {
|
||||
fn from_value(val: Value) -> Result<Self>;
|
||||
fn to_value(&self) -> Value;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct IntegerRangeValidator<T> {
|
||||
pub min: isize,
|
||||
pub max: isize,
|
||||
ty: PhantomData<T>,
|
||||
}
|
||||
impl<E, T> IntegerRangeValidator<T>
|
||||
where
|
||||
E: Debug,
|
||||
T: TryInto<isize, Error = E>,
|
||||
{
|
||||
pub fn new(min: T, max: T) -> Self {
|
||||
Self {
|
||||
min: min.try_into().unwrap(),
|
||||
max: max.try_into().unwrap(),
|
||||
ty: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for IntegerRangeValidator<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("IntegerRangeValidator")
|
||||
.field("min", &self.min)
|
||||
.field("max", &self.max)
|
||||
.field("ty", &type_name::<T>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, T> IntegerRangeValidator<T>
|
||||
where
|
||||
E: Error + Sync + Send + 'static,
|
||||
T: Any + TryFrom<isize, Error = E>,
|
||||
{
|
||||
pub fn validate(&self, val: Value) -> Result<T> {
|
||||
let IntegerRangeValidator { min, max, .. } = *self;
|
||||
let Value::Int(val) = val else {
|
||||
bail!("expected an integer")
|
||||
};
|
||||
ensure!(
|
||||
min <= val && val <= max,
|
||||
"expected an integer between {min} and {max} (got {val})",
|
||||
);
|
||||
Ok(T::try_from(val)?)
|
||||
}
|
||||
}
|
||||
impl<E, T> Validator for IntegerRangeValidator<T>
|
||||
where
|
||||
E: Error + Sync + Send + 'static,
|
||||
T: Any + TryFrom<isize, Error = E>,
|
||||
{
|
||||
fn validate(&self, val: Value) -> Result<ConfigData> {
|
||||
Ok(ConfigData::new(self.validate(val)))
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! integer_tys {
|
||||
($($ty: ident),*) => {
|
||||
$(
|
||||
impl Ty for $ty {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Int((*self).try_into().unwrap())
|
||||
}
|
||||
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
IntegerRangeValidator::new($ty::MIN, $ty::MAX).validate(val)
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
integer_tys! {
|
||||
i8, i16, i32, isize,
|
||||
u8, u16, u32
|
||||
}
|
||||
|
||||
impl Ty for usize {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Int((*self).try_into().unwrap())
|
||||
}
|
||||
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
IntegerRangeValidator::new(0usize, isize::MAX as usize).validate(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for u64 {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Int((*self).try_into().unwrap())
|
||||
}
|
||||
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
IntegerRangeValidator::new(0u64, isize::MAX as u64).validate(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for bool {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Bool(*self)
|
||||
}
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::Bool(val) = val else {
|
||||
bail!("expected a boolean")
|
||||
};
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for Box<str> {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::String(self.clone().into_string())
|
||||
}
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::String(val) = val else {
|
||||
bail!("expected a string")
|
||||
};
|
||||
Ok(val.into_boxed_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for char {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::String(self.to_string())
|
||||
}
|
||||
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::String(val) = val else {
|
||||
bail!("expected a string")
|
||||
};
|
||||
ensure!(
|
||||
val.chars().count() == 1,
|
||||
"expecet a single character (got {val:?})"
|
||||
);
|
||||
Ok(val.chars().next().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for std::string::String {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::String(self.clone())
|
||||
}
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::String(val) = val else {
|
||||
bail!("expected a string")
|
||||
};
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ty> Ty for Option<T> {
|
||||
fn to_value(&self) -> Value {
|
||||
match self {
|
||||
Some(_) => todo!(),
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
if val == Value::Null {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(T::from_value(val)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ty> Ty for Box<T> {
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
Ok(Box::new(T::from_value(val)?))
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
T::to_value(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ty> Ty for indexmap::IndexMap<Box<str>, T, ahash::RandomState> {
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::Map(map) = val else {
|
||||
bail!("expected a map");
|
||||
};
|
||||
map.into_iter()
|
||||
.map(|(k, v)| Ok((k, T::from_value(v)?)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
let map = self
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.to_value()))
|
||||
.collect();
|
||||
Value::Map(Box::new(map))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ty> Ty for Box<[T]> {
|
||||
fn to_value(&self) -> Value {
|
||||
Value::List(self.iter().map(T::to_value).collect())
|
||||
}
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
let Value::List(val) = val else {
|
||||
bail!("expected a list")
|
||||
};
|
||||
val.iter().cloned().map(T::from_value).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for serde_json::Value {
|
||||
fn from_value(val: Value) -> Result<Self> {
|
||||
Ok(val.into())
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct StaticValidator<T: Ty> {
|
||||
pub(super) ty: PhantomData<fn(&T)>,
|
||||
}
|
||||
|
||||
impl<T: Ty> Debug for StaticValidator<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("StaticValidator")
|
||||
.field("ty", &type_name::<T>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ty> Validator for StaticValidator<T> {
|
||||
fn validate(&self, val: Value) -> Result<ConfigData> {
|
||||
let val = <T as Ty>::from_value(val)?;
|
||||
Ok(ConfigData::new(val))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TyValidator<F, T: Ty> {
|
||||
pub(super) ty: PhantomData<fn(&T)>,
|
||||
f: F,
|
||||
}
|
||||
|
||||
impl<T: Ty, F> Debug for TyValidator<F, T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("TyValidator")
|
||||
.field("ty", &type_name::<T>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F> Validator for TyValidator<F, T>
|
||||
where
|
||||
T: Ty,
|
||||
F: Fn(&T) -> anyhow::Result<()> + 'static,
|
||||
{
|
||||
fn validate(&self, val: Value) -> Result<ConfigData> {
|
||||
let val = <T as Ty>::from_value(val)?;
|
||||
(self.f)(&val)?;
|
||||
Ok(ConfigData::new(val))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty_validator<T, F>(f: F) -> impl Validator
|
||||
where
|
||||
T: Ty,
|
||||
F: Fn(&T) -> anyhow::Result<()> + 'static,
|
||||
{
|
||||
TyValidator { ty: PhantomData, f }
|
||||
}
|
||||
|
||||
pub fn regex_str_validator() -> impl Validator {
|
||||
ty_validator(|val: &crate::String| {
|
||||
regex_syntax::parse(val)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
@@ -1,448 +0,0 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::ser::{Error as _, Impossible};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Error, Result};
|
||||
|
||||
use crate::Ty;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Value {
|
||||
List(Vec<Value>),
|
||||
Map(Box<IndexMap<Box<str>, Value, ahash::RandomState>>),
|
||||
Int(isize),
|
||||
Float(f64),
|
||||
Bool(bool),
|
||||
String(String),
|
||||
Null,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
pub fn typed<T: Ty>(self) -> anyhow::Result<T> {
|
||||
T::from_value(self)
|
||||
}
|
||||
|
||||
pub fn append(&mut self, val: Value, depth: usize) {
|
||||
match (self, val) {
|
||||
(Value::List(dst), Value::List(ref mut val)) => dst.append(val),
|
||||
(Value::Map(dst), Value::Map(val)) if depth == 0 || dst.is_empty() => {
|
||||
dst.extend(val.into_iter())
|
||||
}
|
||||
(Value::Map(dst), Value::Map(val)) => {
|
||||
dst.reserve(val.len());
|
||||
for (k, v) in val.into_iter() {
|
||||
// we don't use the entry api because we want
|
||||
// to maintain thhe ordering
|
||||
let merged = match dst.shift_remove(&k) {
|
||||
Some(mut old) => {
|
||||
old.append(v, depth - 1);
|
||||
old
|
||||
}
|
||||
None => v,
|
||||
};
|
||||
dst.insert(k, merged);
|
||||
}
|
||||
}
|
||||
(dst, val) => *dst = val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Value {
|
||||
fn from(value: &str) -> Self {
|
||||
Value::String(value.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! from_int {
|
||||
($($ty: ident),*) => {
|
||||
$(
|
||||
impl From<$ty> for Value {
|
||||
fn from(value: $ty) -> Self {
|
||||
Value::Int(value.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
impl From<serde_json::Value> for Value {
|
||||
fn from(value: serde_json::Value) -> Self {
|
||||
to_value(value).unwrap()
|
||||
}
|
||||
}
|
||||
impl From<&serde_json::Value> for Value {
|
||||
fn from(value: &serde_json::Value) -> Self {
|
||||
to_value(value).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for serde_json::Value {
|
||||
fn from(value: Value) -> Self {
|
||||
serde_json::to_value(value).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
from_int!(isize, usize, u32, i32, i16, u16, i8, u8);
|
||||
|
||||
pub fn to_value<T>(value: T) -> Result<Value>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
value.serialize(Serializer)
|
||||
}
|
||||
|
||||
pub fn from_value<T>(value: Value) -> Result<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
// roundtripping trough json is very inefficient *and incorrect* (captures
|
||||
// json semantics that don't apply to us)
|
||||
// TODO: implement a custom deserializer just like serde_json does
|
||||
serde_json::from_value(value.into())
|
||||
}
|
||||
|
||||
// We only use our own error type; no need for From conversions provided by the
|
||||
// standard library's try! macro. This reduces lines of LLVM IR by 4%.
|
||||
macro_rules! tri {
|
||||
($e:expr $(,)?) => {
|
||||
match $e {
|
||||
core::result::Result::Ok(val) => val,
|
||||
core::result::Result::Err(err) => return core::result::Result::Err(err),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Serializer whose output is a `Value`.
|
||||
///
|
||||
/// This is the serializer that backs [`serde_json::to_value`][crate::to_value].
|
||||
/// Unlike the main serde_json serializer which goes from some serializable
|
||||
/// value of type `T` to JSON text, this one goes from `T` to
|
||||
/// `serde_json::Value`.
|
||||
///
|
||||
/// The `to_value` function is implementable as:
|
||||
///
|
||||
/// ```
|
||||
/// use serde::Serialize;
|
||||
/// use serde_json::{Error, Value};
|
||||
///
|
||||
/// pub fn to_value<T>(input: T) -> Result<Value, Error>
|
||||
/// where
|
||||
/// T: Serialize,
|
||||
/// {
|
||||
/// input.serialize(serde_json::value::Serializer)
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Serializer;
|
||||
|
||||
impl serde::Serializer for Serializer {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
type SerializeSeq = SerializeVec;
|
||||
type SerializeTuple = SerializeVec;
|
||||
type SerializeTupleStruct = SerializeVec;
|
||||
type SerializeTupleVariant = Impossible<Value, Error>;
|
||||
type SerializeMap = SerializeMap;
|
||||
type SerializeStruct = SerializeMap;
|
||||
type SerializeStructVariant = Impossible<Value, Error>;
|
||||
|
||||
#[inline]
|
||||
fn serialize_bool(self, value: bool) -> Result<Value> {
|
||||
Ok(Value::Bool(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_i8(self, value: i8) -> Result<Value> {
|
||||
self.serialize_i64(value as i64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_i16(self, value: i16) -> Result<Value> {
|
||||
self.serialize_i64(value as i64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_i32(self, value: i32) -> Result<Value> {
|
||||
self.serialize_i64(value as i64)
|
||||
}
|
||||
|
||||
fn serialize_i64(self, value: i64) -> Result<Value> {
|
||||
Ok(Value::Int(value.try_into().unwrap()))
|
||||
}
|
||||
|
||||
fn serialize_i128(self, _value: i128) -> Result<Value> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_u8(self, value: u8) -> Result<Value> {
|
||||
self.serialize_u64(value as u64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_u16(self, value: u16) -> Result<Value> {
|
||||
self.serialize_u64(value as u64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_u32(self, value: u32) -> Result<Value> {
|
||||
self.serialize_u64(value as u64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_u64(self, value: u64) -> Result<Value> {
|
||||
Ok(Value::Int(value.try_into().unwrap()))
|
||||
}
|
||||
|
||||
fn serialize_u128(self, _value: u128) -> Result<Value> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_f32(self, float: f32) -> Result<Value> {
|
||||
Ok(Value::Float(float as f64))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_f64(self, float: f64) -> Result<Value> {
|
||||
Ok(Value::Float(float))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_char(self, value: char) -> Result<Value> {
|
||||
let mut s = String::new();
|
||||
s.push(value);
|
||||
Ok(Value::String(s))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_str(self, value: &str) -> Result<Value> {
|
||||
Ok(Value::String(value.into()))
|
||||
}
|
||||
|
||||
fn serialize_bytes(self, value: &[u8]) -> Result<Value> {
|
||||
let vec = value.iter().map(|&b| Value::Int(b.into())).collect();
|
||||
Ok(Value::List(vec))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_unit(self) -> Result<Value> {
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_unit_struct(self, _name: &'static str) -> Result<Value> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_unit_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
variant: &'static str,
|
||||
) -> Result<Value> {
|
||||
self.serialize_str(variant)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_newtype_struct<T>(self, _name: &'static str, _value: &T) -> Result<Value>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_value: &T,
|
||||
) -> Result<Value>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_none(self) -> Result<Value> {
|
||||
self.serialize_unit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Value>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq> {
|
||||
Ok(SerializeVec {
|
||||
vec: Vec::with_capacity(len.unwrap_or(0)),
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple> {
|
||||
self.serialize_seq(Some(len))
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
self,
|
||||
_name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct> {
|
||||
self.serialize_seq(Some(len))
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap> {
|
||||
Ok(SerializeMap {
|
||||
map: IndexMap::default(),
|
||||
next_key: None,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_struct(self, _name: &'static str, _len: usize) -> Result<Self::SerializeStruct> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeStructVariant> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn collect_str<T>(self, value: &T) -> Result<Value>
|
||||
where
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
Ok(Value::String(value.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SerializeVec {
|
||||
vec: Vec<Value>,
|
||||
}
|
||||
|
||||
impl serde::ser::SerializeSeq for SerializeVec {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.vec.push(tri!(to_value(value)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Value> {
|
||||
Ok(Value::List(self.vec))
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::ser::SerializeTuple for SerializeVec {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
serde::ser::SerializeSeq::serialize_element(self, value)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Value> {
|
||||
serde::ser::SerializeSeq::end(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::ser::SerializeTupleStruct for SerializeVec {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
serde::ser::SerializeSeq::serialize_element(self, value)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Value> {
|
||||
serde::ser::SerializeSeq::end(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SerializeMap {
|
||||
map: IndexMap<Box<str>, Value, ahash::RandomState>,
|
||||
next_key: Option<Box<str>>,
|
||||
}
|
||||
|
||||
impl serde::ser::SerializeMap for SerializeMap {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let key = to_value(key)?;
|
||||
let Value::String(val) = key else {
|
||||
return Err(Error::custom("only string keys are supported"));
|
||||
};
|
||||
self.next_key = Some(val.into_boxed_str());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let key = self.next_key.take();
|
||||
// Panic because this indicates a bug in the program rather than an
|
||||
// expected failure.
|
||||
let key = key.expect("serialize_value called before serialize_key");
|
||||
self.map.insert(key, tri!(to_value(value)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Value> {
|
||||
Ok(Value::Map(Box::new(self.map)))
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::ser::SerializeStruct for SerializeMap {
|
||||
type Ok = Value;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
serde::ser::SerializeMap::serialize_entry(self, key, value)
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Value> {
|
||||
serde::ser::SerializeMap::end(self)
|
||||
}
|
||||
}
|
@@ -16,45 +16,45 @@ unicode-lines = ["ropey/unicode_lines"]
|
||||
integration = []
|
||||
|
||||
[dependencies]
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-syntax = { path = "../helix-syntax" }
|
||||
helix-loader = { path = "../helix-loader" }
|
||||
helix-config = { path = "../helix-config" }
|
||||
|
||||
ropey = { version = "1.6.1", default-features = false, features = ["simd"] }
|
||||
smallvec = "1.11"
|
||||
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"
|
||||
slotmap.workspace = true
|
||||
tree-sitter.workspace = true
|
||||
once_cell = "1.19"
|
||||
arc-swap = "1"
|
||||
regex = "1"
|
||||
bitflags = "2.4"
|
||||
ahash = "0.8.6"
|
||||
hashbrown = { version = "0.14.3", features = ["raw"] }
|
||||
bitflags = "2.6"
|
||||
ahash = "0.8.11"
|
||||
hashbrown = { version = "0.14.5", features = ["raw"] }
|
||||
dunce = "1.0"
|
||||
url = "2.5.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"
|
||||
imara-diff = "0.1.6"
|
||||
|
||||
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"
|
||||
anyhow = "1.0.79"
|
||||
indexmap = { version = "2.1.0", features = ["serde"] }
|
||||
globset = "0.4.14"
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = { version = "1", default-features = false }
|
||||
indoc = "2.0.4"
|
||||
indoc = "2.0.5"
|
||||
|
@@ -2,10 +2,8 @@
|
||||
//! this module provides the functionality to insert the paired closing character.
|
||||
|
||||
use crate::{graphemes, movement::Direction, Range, Rope, Selection, Tendril, Transaction};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::{bail, ensure};
|
||||
use helix_config::options;
|
||||
use indexmap::IndexMap;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
// Heavily based on https://github.com/codemirror/closebrackets/
|
||||
@@ -21,7 +19,7 @@ pub const DEFAULT_PAIRS: &[(char, char)] = &[
|
||||
/// The type that represents the collection of auto pairs,
|
||||
/// keyed by both opener and closer.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AutoPairs(IndexMap<char, Pair, ahash::RandomState>);
|
||||
pub struct AutoPairs(HashMap<char, Pair>);
|
||||
|
||||
/// Represents the config for a particular pairing.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -77,15 +75,15 @@ impl From<(&char, &char)> for Pair {
|
||||
|
||||
impl AutoPairs {
|
||||
/// Make a new AutoPairs set with the given pairs and default conditions.
|
||||
pub fn new<'a, V: 'a, A>(pairs: V) -> anyhow::Result<Self>
|
||||
pub fn new<'a, V: 'a, A>(pairs: V) -> Self
|
||||
where
|
||||
V: IntoIterator<Item = anyhow::Result<A>>,
|
||||
V: IntoIterator<Item = A>,
|
||||
A: Into<Pair>,
|
||||
{
|
||||
let mut auto_pairs = IndexMap::default();
|
||||
let mut auto_pairs = HashMap::new();
|
||||
|
||||
for pair in pairs.into_iter() {
|
||||
let auto_pair = pair?.into();
|
||||
let auto_pair = pair.into();
|
||||
|
||||
auto_pairs.insert(auto_pair.open, auto_pair);
|
||||
|
||||
@@ -94,7 +92,7 @@ impl AutoPairs {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self(auto_pairs))
|
||||
Self(auto_pairs)
|
||||
}
|
||||
|
||||
pub fn get(&self, ch: char) -> Option<&Pair> {
|
||||
@@ -104,7 +102,7 @@ impl AutoPairs {
|
||||
|
||||
impl Default for AutoPairs {
|
||||
fn default() -> Self {
|
||||
AutoPairs::new(DEFAULT_PAIRS.iter().map(Ok)).unwrap()
|
||||
AutoPairs::new(DEFAULT_PAIRS.iter())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,43 +371,3 @@ fn handle_same(doc: &Rope, selection: &Selection, pair: &Pair) -> Transaction {
|
||||
log::debug!("auto pair transaction: {:#?}", t);
|
||||
t
|
||||
}
|
||||
|
||||
options! {
|
||||
struct AutopairConfig {
|
||||
/// Mapping of character pairs like `{ '(' = ')', '`' = '`' }` that are
|
||||
/// automatically closed by the editor when typed.
|
||||
auto_pairs: AutoPairs = AutoPairs::default(),
|
||||
}
|
||||
}
|
||||
|
||||
impl helix_config::Ty for AutoPairs {
|
||||
fn from_value(val: helix_config::Value) -> anyhow::Result<Self> {
|
||||
let map = match val {
|
||||
helix_config::Value::Map(map) => map,
|
||||
helix_config::Value::Bool(false) => return Ok(Self(IndexMap::default())),
|
||||
_ => bail!("expect 'false' or a map of pairs"),
|
||||
};
|
||||
let pairs = map.into_iter().map(|(open, close)| {
|
||||
let open = helix_config::Value::String(open.into_string());
|
||||
Ok(Pair {
|
||||
open: open.typed()?,
|
||||
close: close.typed()?,
|
||||
})
|
||||
});
|
||||
AutoPairs::new(pairs)
|
||||
}
|
||||
|
||||
fn to_value(&self) -> helix_config::Value {
|
||||
let map = self
|
||||
.0
|
||||
.values()
|
||||
.map(|pair| {
|
||||
(
|
||||
pair.open.to_string().into(),
|
||||
helix_config::Value::String(pair.close.into()),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
helix_config::Value::Map(Box::new(map))
|
||||
}
|
||||
}
|
||||
|
@@ -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 @@ mod test {
|
||||
|
||||
// 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, "");
|
||||
}
|
||||
}
|
||||
|
45
helix-core/src/config.rs
Normal file
45
helix-core/src/config.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
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 deserialize built-in languages.toml")
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
//! LSP diagnostic utility types.
|
||||
use std::fmt;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Describes the severity level of a [`Diagnostic`].
|
||||
@@ -47,8 +49,25 @@ pub struct Diagnostic {
|
||||
pub message: String,
|
||||
pub severity: Option<Severity>,
|
||||
pub code: Option<NumberOrString>,
|
||||
pub language_server_id: usize,
|
||||
pub provider: DiagnosticProvider,
|
||||
pub tags: Vec<DiagnosticTag>,
|
||||
pub source: Option<String>,
|
||||
pub data: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
// TODO turn this into an enum + feature flag when lsp becomes optional
|
||||
pub type DiagnosticProvider = LanguageServerId;
|
||||
|
||||
// while I would prefer having this in helix-lsp that necessitates a bunch of
|
||||
// conversions I would rather not add. I think its fine since this just a very
|
||||
// trivial newtype wrapper and we would need something similar once we define
|
||||
// completions in core
|
||||
slotmap::new_key_type! {
|
||||
pub struct LanguageServerId;
|
||||
}
|
||||
|
||||
impl fmt::Display for LanguageServerId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self.0)
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ impl Default for TextFormat {
|
||||
#[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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use std::ops::DerefMut;
|
||||
|
||||
use nucleo::pattern::{Atom, AtomKind, CaseMatching};
|
||||
use nucleo::pattern::{Atom, AtomKind, CaseMatching, Normalization};
|
||||
use nucleo::Config;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
@@ -38,6 +38,12 @@ pub fn fuzzy_match<T: AsRef<str>>(
|
||||
if path {
|
||||
matcher.config.set_match_paths();
|
||||
}
|
||||
let pattern = Atom::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy, false);
|
||||
let pattern = Atom::new(
|
||||
pattern,
|
||||
CaseMatching::Smart,
|
||||
Normalization::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 @@ impl<'a> Iterator for RopeGraphemes<'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> {
|
||||
|
@@ -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,
|
||||
|
@@ -1,36 +1,16 @@
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use anyhow::{anyhow, bail};
|
||||
use helix_config::{config_serde_adapter, options, IntegerRangeValidator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use helix_stdx::rope::RopeSliceExt;
|
||||
use tree_sitter::{Query, QueryCursor, QueryPredicateArg};
|
||||
|
||||
use crate::{
|
||||
chars::{char_is_line_ending, char_is_whitespace},
|
||||
find_first_non_whitespace_char,
|
||||
graphemes::{grapheme_width, tab_width_at},
|
||||
syntax::{LanguageConfiguration, RopeProvider, Syntax},
|
||||
syntax::{IndentationHeuristic, LanguageConfiguration, RopeProvider, Syntax},
|
||||
tree_sitter::Node,
|
||||
Position, Rope, RopeGraphemes, RopeSlice,
|
||||
};
|
||||
|
||||
/// 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, Copy, 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,
|
||||
}
|
||||
config_serde_adapter!(IndentationHeuristic);
|
||||
|
||||
/// Enum representing indentation style.
|
||||
///
|
||||
/// Only values 1-8 are valid for the `Spaces` variant.
|
||||
@@ -40,50 +20,6 @@ pub enum IndentStyle {
|
||||
Spaces(u8),
|
||||
}
|
||||
|
||||
options! {
|
||||
struct IndentationConfig {
|
||||
/// The number columns that a tabs are aligned to.
|
||||
#[name = "ident.tab_width"]
|
||||
#[read = copy]
|
||||
tab_width: usize = 4,
|
||||
/// Indentation inserted/removed into the document when indenting/dedenting.
|
||||
/// This can be set to an integer representing N spaces or "tab" for tabs.
|
||||
#[name = "ident.unit"]
|
||||
#[read = copy]
|
||||
indent_style: IndentStyle = IndentStyle::Tabs,
|
||||
/// 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`).
|
||||
#[read = copy]
|
||||
indent_heuristic: IndentationHeuristic = IndentationHeuristic::Hybrid
|
||||
}
|
||||
}
|
||||
|
||||
impl helix_config::Ty for IndentStyle {
|
||||
fn from_value(val: helix_config::Value) -> anyhow::Result<Self> {
|
||||
match val {
|
||||
helix_config::Value::String(s) if s == "t" || s == "tab" => Ok(IndentStyle::Tabs),
|
||||
helix_config::Value::Int(_) => {
|
||||
let spaces = IntegerRangeValidator::new(0, MAX_INDENT)
|
||||
.validate(val)
|
||||
.map_err(|err| anyhow!("invalid number of spaces! {err}"))?;
|
||||
Ok(IndentStyle::Spaces(spaces))
|
||||
}
|
||||
_ => bail!("expected an integer (spaces) or 'tab'"),
|
||||
}
|
||||
}
|
||||
fn to_value(&self) -> helix_config::Value {
|
||||
match *self {
|
||||
IndentStyle::Tabs => helix_config::Value::String("tab".into()),
|
||||
IndentStyle::Spaces(spaces) => helix_config::Value::Int(spaces as _),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 16 spaces
|
||||
const INDENTS: &str = " ";
|
||||
pub const MAX_INDENT: u8 = 16;
|
||||
@@ -311,41 +247,18 @@ fn add_indent_level(
|
||||
}
|
||||
}
|
||||
|
||||
/// Computes for node and all ancestors whether they are the first node on their line.
|
||||
/// The first entry in the return value represents the root node, the last one the node itself
|
||||
fn get_first_in_line(mut node: Node, new_line_byte_pos: Option<usize>) -> Vec<bool> {
|
||||
let mut first_in_line = Vec::new();
|
||||
loop {
|
||||
if let Some(prev) = node.prev_sibling() {
|
||||
// If we insert a new line, the first node at/after the cursor is considered to be the first in its line
|
||||
let first = prev.end_position().row != node.start_position().row
|
||||
|| new_line_byte_pos.map_or(false, |byte_pos| {
|
||||
node.start_byte() >= byte_pos && prev.start_byte() < byte_pos
|
||||
});
|
||||
first_in_line.push(Some(first));
|
||||
} else {
|
||||
// Nodes that have no previous siblings are first in their line if and only if their parent is
|
||||
// (which we don't know yet)
|
||||
first_in_line.push(None);
|
||||
}
|
||||
if let Some(parent) = node.parent() {
|
||||
node = parent;
|
||||
} else {
|
||||
break;
|
||||
/// Return true if only whitespace comes before the node on its line.
|
||||
/// If given, new_line_byte_pos is treated the same way as any existing newline.
|
||||
fn is_first_in_line(node: Node, text: RopeSlice, new_line_byte_pos: Option<usize>) -> bool {
|
||||
let mut line_start_byte_pos = text.line_to_byte(node.start_position().row);
|
||||
if let Some(pos) = new_line_byte_pos {
|
||||
if line_start_byte_pos < pos && pos <= node.start_byte() {
|
||||
line_start_byte_pos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
let mut result = Vec::with_capacity(first_in_line.len());
|
||||
let mut parent_is_first = true; // The root node is by definition the first node in its line
|
||||
for first in first_in_line.into_iter().rev() {
|
||||
if let Some(first) = first {
|
||||
result.push(first);
|
||||
parent_is_first = first;
|
||||
} else {
|
||||
result.push(parent_is_first);
|
||||
}
|
||||
}
|
||||
result
|
||||
text.byte_slice(line_start_byte_pos..node.start_byte())
|
||||
.chars()
|
||||
.all(|c| c.is_whitespace())
|
||||
}
|
||||
|
||||
/// The total indent for some line of code.
|
||||
@@ -615,7 +528,7 @@ fn query_indents<'a>(
|
||||
// The row/column position of the optional anchor in this query
|
||||
let mut anchor: Option<tree_sitter::Node> = None;
|
||||
for capture in m.captures {
|
||||
let capture_name = query.capture_names()[capture.index as usize].as_str();
|
||||
let capture_name = query.capture_names()[capture.index as usize];
|
||||
let capture_type = match capture_name {
|
||||
"indent" => IndentCaptureType::Indent,
|
||||
"indent.always" => IndentCaptureType::IndentAlways,
|
||||
@@ -825,18 +738,9 @@ fn init_indent_query<'a, 'b>(
|
||||
.map(|prec| prec.byte_range().end - 1..byte_pos + 1)
|
||||
.unwrap_or(byte_pos..byte_pos + 1);
|
||||
|
||||
crate::syntax::PARSER.with(|ts_parser| {
|
||||
let mut ts_parser = ts_parser.borrow_mut();
|
||||
let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
|
||||
let query_result = query_indents(
|
||||
query,
|
||||
syntax,
|
||||
&mut cursor,
|
||||
text,
|
||||
query_range,
|
||||
new_line_byte_pos,
|
||||
);
|
||||
ts_parser.cursors.push(cursor);
|
||||
crate::syntax::with_cursor(|cursor| {
|
||||
let query_result =
|
||||
query_indents(query, syntax, cursor, text, query_range, new_line_byte_pos);
|
||||
(query_result, deepest_preceding)
|
||||
})
|
||||
};
|
||||
@@ -916,7 +820,6 @@ pub fn treesitter_indent_for_pos<'a>(
|
||||
byte_pos,
|
||||
new_line_byte_pos,
|
||||
)?;
|
||||
let mut first_in_line = get_first_in_line(node, new_line.then_some(byte_pos));
|
||||
|
||||
let mut result = Indentation::default();
|
||||
// We always keep track of all the indent changes on one line, in order to only indent once
|
||||
@@ -925,9 +828,7 @@ pub fn treesitter_indent_for_pos<'a>(
|
||||
let mut indent_for_line_below = Indentation::default();
|
||||
|
||||
loop {
|
||||
// This can safely be unwrapped because `first_in_line` contains
|
||||
// one entry for each ancestor of the node (which is what we iterate over)
|
||||
let is_first = *first_in_line.last().unwrap();
|
||||
let is_first = is_first_in_line(node, text, new_line_byte_pos);
|
||||
|
||||
// Apply all indent definitions for this node.
|
||||
// Since we only iterate over each node once, we can remove the
|
||||
@@ -970,7 +871,6 @@ pub fn treesitter_indent_for_pos<'a>(
|
||||
}
|
||||
|
||||
node = parent;
|
||||
first_in_line.pop();
|
||||
} else {
|
||||
// Only add the indentation for the line below if that line
|
||||
// is not after the line that the indentation is calculated for.
|
||||
@@ -1034,7 +934,7 @@ pub fn indent_for_newline(
|
||||
let mut num_attempts = 0;
|
||||
for line_idx in (0..=line_before).rev() {
|
||||
let line = text.line(line_idx);
|
||||
let first_non_whitespace_char = match find_first_non_whitespace_char(line) {
|
||||
let first_non_whitespace_char = match line.first_non_whitespace_char() {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
continue;
|
||||
|
@@ -3,6 +3,7 @@ pub use encoding_rs as encoding;
|
||||
pub mod auto_pairs;
|
||||
pub mod chars;
|
||||
pub mod comment;
|
||||
pub mod config;
|
||||
pub mod diagnostic;
|
||||
pub mod diff;
|
||||
pub mod doc_formatter;
|
||||
@@ -16,7 +17,6 @@ pub mod macros;
|
||||
pub mod match_brackets;
|
||||
pub mod movement;
|
||||
pub mod object;
|
||||
pub mod path;
|
||||
mod position;
|
||||
pub mod search;
|
||||
pub mod selection;
|
||||
@@ -27,6 +27,7 @@ pub mod test;
|
||||
pub mod text_annotations;
|
||||
pub mod textobject;
|
||||
mod transaction;
|
||||
pub mod uri;
|
||||
pub mod wrap;
|
||||
|
||||
pub mod unicode {
|
||||
@@ -35,12 +36,8 @@ pub mod unicode {
|
||||
pub use unicode_width as width;
|
||||
}
|
||||
|
||||
use helix_config::OptionRegistry;
|
||||
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;
|
||||
@@ -71,8 +68,4 @@ pub use diagnostic::Diagnostic;
|
||||
pub use line_ending::{LineEnding, NATIVE_LINE_ENDING};
|
||||
pub use transaction::{Assoc, Change, ChangeSet, Deletion, Operation, Transaction};
|
||||
|
||||
pub fn init_config(registry: &mut OptionRegistry) {
|
||||
line_ending::init_config(registry);
|
||||
auto_pairs::init_config(registry);
|
||||
indent::init_config(registry);
|
||||
}
|
||||
pub use uri::Uri;
|
||||
|
@@ -1,6 +1,3 @@
|
||||
use anyhow::bail;
|
||||
use helix_config::{options, Ty};
|
||||
|
||||
use crate::{Rope, RopeSlice};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -8,61 +5,6 @@ pub const NATIVE_LINE_ENDING: LineEnding = LineEnding::Crlf;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub const NATIVE_LINE_ENDING: LineEnding = LineEnding::LF;
|
||||
|
||||
options! {
|
||||
struct LineEndingConfig {
|
||||
/// The line ending to use for new documents. Can be `lf` or `crlf`. If
|
||||
/// helix was compiled with the `unicode-lines` feature then `vt`, `ff`,
|
||||
/// `cr`, `nel`, `ls` or `ps` are also allowed.
|
||||
#[read = copy]
|
||||
default_line_ending: LineEnding = NATIVE_LINE_ENDING,
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty for LineEnding {
|
||||
fn from_value(val: helix_config::Value) -> anyhow::Result<Self> {
|
||||
let val: String = val.typed()?;
|
||||
match &*val {
|
||||
"crlf" => Ok(LineEnding::Crlf),
|
||||
"lf" => Ok(LineEnding::LF),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"vt" => Ok(LineEnding::VT),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"ff" => Ok(LineEnding::FF),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"cr" => Ok(LineEnding::CR),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"nel" => Ok(LineEnding::Nel),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"ls" => Ok(LineEnding::LS),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
"ps" => Ok(LineEnding::PS),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
_ => bail!("expecte one of 'lf', 'crlf', 'vt', 'ff', 'cr', 'nel', 'ls' or 'ps'"),
|
||||
#[cfg(not(feature = "unicode-lines"))]
|
||||
_ => bail!("expecte one of 'lf' or 'crlf'"),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_value(&self) -> helix_config::Value {
|
||||
match self {
|
||||
LineEnding::Crlf => "crlf".into(),
|
||||
LineEnding::LF => "lf".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
VT => "vt".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
FF => "ff".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
CR => "cr".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
Nel => "nel".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
LS => "ls".into(),
|
||||
#[cfg(feature = "unicode-lines")]
|
||||
PS => "ps".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents one of the valid Unicode line endings.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub enum LineEnding {
|
||||
|
@@ -9,16 +9,34 @@ use crate::Syntax;
|
||||
const MAX_PLAINTEXT_SCAN: usize = 10000;
|
||||
const MATCH_LIMIT: usize = 16;
|
||||
|
||||
// Limit matching pairs to only ( ) { } [ ] < > ' ' " "
|
||||
const PAIRS: &[(char, char)] = &[
|
||||
pub const BRACKETS: [(char, char); 9] = [
|
||||
('(', ')'),
|
||||
('{', '}'),
|
||||
('[', ']'),
|
||||
('<', '>'),
|
||||
('\'', '\''),
|
||||
('\"', '\"'),
|
||||
('‘', '’'),
|
||||
('“', '”'),
|
||||
('«', '»'),
|
||||
('「', '」'),
|
||||
('(', ')'),
|
||||
];
|
||||
|
||||
// The difference between BRACKETS and PAIRS is that we can find matching
|
||||
// BRACKETS in a plain text file, but we can't do the same for PAIRs.
|
||||
// PAIRS also contains all BRACKETS.
|
||||
pub const PAIRS: [(char, char); BRACKETS.len() + 3] = {
|
||||
let mut pairs = [(' ', ' '); BRACKETS.len() + 3];
|
||||
let mut idx = 0;
|
||||
while idx < BRACKETS.len() {
|
||||
pairs[idx] = BRACKETS[idx];
|
||||
idx += 1;
|
||||
}
|
||||
pairs[idx] = ('"', '"');
|
||||
pairs[idx + 1] = ('\'', '\'');
|
||||
pairs[idx + 2] = ('`', '`');
|
||||
pairs
|
||||
};
|
||||
|
||||
/// Returns the position of the matching bracket under cursor.
|
||||
///
|
||||
/// If the cursor is on the opening bracket, the position of
|
||||
@@ -30,7 +48,7 @@ const PAIRS: &[(char, char)] = &[
|
||||
/// If no matching bracket is found, `None` is returned.
|
||||
#[must_use]
|
||||
pub fn find_matching_bracket(syntax: &Syntax, doc: RopeSlice, pos: usize) -> Option<usize> {
|
||||
if pos >= doc.len_chars() || !is_valid_bracket(doc.char(pos)) {
|
||||
if pos >= doc.len_chars() || !is_valid_pair(doc.char(pos)) {
|
||||
return None;
|
||||
}
|
||||
find_pair(syntax, doc, pos, false)
|
||||
@@ -57,68 +75,72 @@ fn find_pair(
|
||||
pos_: usize,
|
||||
traverse_parents: bool,
|
||||
) -> Option<usize> {
|
||||
let tree = syntax.tree();
|
||||
let pos = doc.char_to_byte(pos_);
|
||||
|
||||
let mut node = tree.root_node().descendant_for_byte_range(pos, pos)?;
|
||||
let root = syntax.tree_for_byte_range(pos, pos).root_node();
|
||||
let mut node = root.descendant_for_byte_range(pos, pos)?;
|
||||
|
||||
loop {
|
||||
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 node.is_named() && node.child_count() >= 2 {
|
||||
let open = node.child(0).unwrap();
|
||||
let close = node.child(node.child_count() - 1).unwrap();
|
||||
|
||||
if is_valid_pair(doc, start_char, end_char) {
|
||||
if end_byte == pos {
|
||||
return Some(start_char);
|
||||
}
|
||||
if let (Some((start_pos, open)), Some((end_pos, close))) =
|
||||
(as_char(doc, &open), as_char(doc, &close))
|
||||
{
|
||||
if PAIRS.contains(&(open, close)) {
|
||||
if end_pos == pos_ {
|
||||
return Some(start_pos);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// 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_pos == pos_ {
|
||||
return Some(end_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
if let Some((start_char, end_char)) = as_close_pair(doc, &node) {
|
||||
if let Some(pair_start) =
|
||||
find_pair_end(doc, node.prev_sibling(), start_char, end_char, Backward)
|
||||
{
|
||||
return Some(pair_start);
|
||||
}
|
||||
}
|
||||
if let Some((start_char, end_char)) = as_open_pair(doc, &node) {
|
||||
if let Some(pair_end) =
|
||||
find_pair_end(doc, node.next_sibling(), start_char, end_char, Forward)
|
||||
{
|
||||
return Some(pair_end);
|
||||
}
|
||||
}
|
||||
|
||||
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 traverse_parents {
|
||||
for sibling in
|
||||
iter::successors(node.next_sibling(), |node| node.next_sibling()).take(MATCH_LIMIT)
|
||||
{
|
||||
let Some((start_char, end_char)) = as_close_pair(doc, &sibling) else {
|
||||
continue;
|
||||
};
|
||||
if find_pair_end(doc, sibling.prev_sibling(), start_char, end_char, Backward)
|
||||
.is_some()
|
||||
{
|
||||
return doc.try_byte_to_char(sibling.start_byte()).ok();
|
||||
}
|
||||
}
|
||||
if node.is_named() {
|
||||
break;
|
||||
}
|
||||
} else 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 = tree.root_node().named_descendant_for_byte_range(pos, pos)?;
|
||||
let node = root.named_descendant_for_byte_range(pos, pos + 1)?;
|
||||
if node.child_count() != 0 {
|
||||
return None;
|
||||
}
|
||||
@@ -140,14 +162,22 @@ fn find_pair(
|
||||
/// If no matching bracket is found, `None` is returned.
|
||||
#[must_use]
|
||||
pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> {
|
||||
let bracket = doc.get_char(cursor_pos)?;
|
||||
let matching_bracket = {
|
||||
let pair = get_pair(bracket);
|
||||
if pair.0 == bracket {
|
||||
pair.1
|
||||
} else {
|
||||
pair.0
|
||||
}
|
||||
};
|
||||
// Don't do anything when the cursor is not on top of a bracket.
|
||||
let bracket = doc.char(cursor_pos);
|
||||
if !is_valid_bracket(bracket) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Determine the direction of the matching.
|
||||
let is_fwd = is_forward_bracket(bracket);
|
||||
let is_fwd = is_open_bracket(bracket);
|
||||
let chars_iter = if is_fwd {
|
||||
doc.chars_at(cursor_pos + 1)
|
||||
} else {
|
||||
@@ -159,19 +189,7 @@ pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Opt
|
||||
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
|
||||
},
|
||||
) {
|
||||
} else if candidate == matching_bracket {
|
||||
// Return when all pending brackets have been closed.
|
||||
if open_cnt == 1 {
|
||||
return Some(if is_fwd {
|
||||
@@ -187,37 +205,55 @@ pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Opt
|
||||
None
|
||||
}
|
||||
|
||||
fn is_valid_bracket(c: char) -> bool {
|
||||
PAIRS.iter().any(|(l, r)| *l == c || *r == c)
|
||||
/// Returns the open and closing chars pair. If not found in
|
||||
/// [`BRACKETS`] returns (ch, ch).
|
||||
///
|
||||
/// ```
|
||||
/// use helix_core::match_brackets::get_pair;
|
||||
///
|
||||
/// assert_eq!(get_pair('['), ('[', ']'));
|
||||
/// assert_eq!(get_pair('}'), ('{', '}'));
|
||||
/// assert_eq!(get_pair('"'), ('"', '"'));
|
||||
/// ```
|
||||
pub fn get_pair(ch: char) -> (char, char) {
|
||||
PAIRS
|
||||
.iter()
|
||||
.find(|(open, close)| *open == ch || *close == ch)
|
||||
.copied()
|
||||
.unwrap_or((ch, ch))
|
||||
}
|
||||
|
||||
fn is_forward_bracket(c: char) -> bool {
|
||||
PAIRS.iter().any(|(l, _)| *l == c)
|
||||
pub fn is_open_bracket(ch: char) -> bool {
|
||||
BRACKETS.iter().any(|(l, _)| *l == ch)
|
||||
}
|
||||
|
||||
fn is_valid_pair(doc: RopeSlice, start_char: usize, end_char: usize) -> bool {
|
||||
PAIRS.contains(&(doc.char(start_char), doc.char(end_char)))
|
||||
pub fn is_close_bracket(ch: char) -> bool {
|
||||
BRACKETS.iter().any(|(_, r)| *r == ch)
|
||||
}
|
||||
|
||||
fn surrounding_bytes(doc: RopeSlice, node: &Node) -> Option<(usize, usize)> {
|
||||
let len = doc.len_bytes();
|
||||
pub fn is_valid_bracket(ch: char) -> bool {
|
||||
BRACKETS.iter().any(|(l, r)| *l == ch || *r == ch)
|
||||
}
|
||||
|
||||
let start_byte = node.start_byte();
|
||||
let end_byte = node.end_byte().saturating_sub(1);
|
||||
pub fn is_open_pair(ch: char) -> bool {
|
||||
PAIRS.iter().any(|(l, _)| *l == ch)
|
||||
}
|
||||
|
||||
if start_byte >= len || end_byte >= len {
|
||||
return None;
|
||||
}
|
||||
pub fn is_close_pair(ch: char) -> bool {
|
||||
PAIRS.iter().any(|(_, r)| *r == ch)
|
||||
}
|
||||
|
||||
Some((start_byte, end_byte))
|
||||
pub fn is_valid_pair(ch: char) -> bool {
|
||||
PAIRS.iter().any(|(l, r)| *l == ch || *r == ch)
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
/// and close char contained in this node
|
||||
fn as_close_pair(doc: RopeSlice, node: &Node) -> Option<(char, char)> {
|
||||
let close = as_char(doc, node)?.1;
|
||||
PAIRS
|
||||
.iter()
|
||||
.find_map(|&(open, close_)| (close_ == close).then_some(open))
|
||||
.find_map(|&(open, close_)| (close_ == close).then_some((close, open)))
|
||||
}
|
||||
|
||||
/// Checks if `node` or its siblings (at most MATCH_LIMIT nodes) is the specified closing char
|
||||
@@ -228,6 +264,7 @@ fn as_close_pair(doc: RopeSlice, node: &Node) -> Option<char> {
|
||||
fn find_pair_end(
|
||||
doc: RopeSlice,
|
||||
node: Option<Node>,
|
||||
start_char: char,
|
||||
end_char: char,
|
||||
direction: Direction,
|
||||
) -> Option<usize> {
|
||||
@@ -235,20 +272,30 @@ fn find_pair_end(
|
||||
Forward => Node::next_sibling,
|
||||
Backward => Node::prev_sibling,
|
||||
};
|
||||
let mut depth = 0;
|
||||
iter::successors(node, advance)
|
||||
.take(MATCH_LIMIT)
|
||||
.find_map(|node| {
|
||||
let (pos, c) = as_char(doc, &node)?;
|
||||
(end_char == c).then_some(pos)
|
||||
if c == end_char {
|
||||
if depth == 0 {
|
||||
return Some(pos);
|
||||
}
|
||||
depth -= 1;
|
||||
} else if c == start_char {
|
||||
depth += 1;
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
/// Tests if this node is a pair open char and returns the expected close char
|
||||
/// and open char contained in this node
|
||||
fn as_open_pair(doc: RopeSlice, node: &Node) -> Option<(char, char)> {
|
||||
let open = as_char(doc, node)?.1;
|
||||
PAIRS
|
||||
.iter()
|
||||
.find_map(|&(open_, close)| (open_ == open).then_some(close))
|
||||
.find_map(|&(open_, close)| (open_ == open).then_some((open, close)))
|
||||
}
|
||||
|
||||
/// If node is a single char return it (and its char position)
|
||||
@@ -265,6 +312,12 @@ fn as_char(doc: RopeSlice, node: &Node) -> Option<(usize, char)> {
|
||||
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| {
|
||||
|
@@ -573,16 +573,11 @@ pub fn move_parent_node_end(
|
||||
dir: Direction,
|
||||
movement: Movement,
|
||||
) -> Selection {
|
||||
let tree = syntax.tree();
|
||||
|
||||
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 tree
|
||||
.root_node()
|
||||
.named_descendant_for_byte_range(start_from, start_to)
|
||||
{
|
||||
let mut node = match syntax.named_descendant_for_byte_range(start_from, start_to) {
|
||||
Some(node) => node,
|
||||
None => {
|
||||
log::debug!(
|
||||
|
@@ -1,76 +1,137 @@
|
||||
use crate::{Range, RopeSlice, Selection, Syntax};
|
||||
use tree_sitter::Node;
|
||||
use crate::{movement::Direction, 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();
|
||||
},
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
},
|
||||
Some(Direction::Forward),
|
||||
)
|
||||
}
|
||||
|
||||
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_sibling<F>(
|
||||
syntax: &Syntax,
|
||||
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;
|
||||
}
|
||||
}
|
||||
},
|
||||
Some(Direction::Backward),
|
||||
)
|
||||
}
|
||||
|
||||
fn select_node_impl<F>(
|
||||
syntax: &Syntax,
|
||||
text: RopeSlice,
|
||||
selection: Selection,
|
||||
select_fn: F,
|
||||
motion: F,
|
||||
direction: Option<Direction>,
|
||||
) -> 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(direction.unwrap_or_else(|| range.direction()))
|
||||
})
|
||||
}
|
||||
|
@@ -1,162 +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) -> PathBuf {
|
||||
let path = expand_tilde(path);
|
||||
let path = if path.is_relative() {
|
||||
helix_loader::current_working_dir().join(path)
|
||||
} else {
|
||||
path
|
||||
};
|
||||
|
||||
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 = get_normalized_path(&helix_loader::current_working_dir());
|
||||
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 = helix_loader::current_working_dir();
|
||||
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
|
||||
}
|
@@ -7,11 +7,14 @@ use crate::{
|
||||
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 std::{borrow::Cow, iter, slice};
|
||||
use tree_sitter::Node;
|
||||
|
||||
/// A single selection range.
|
||||
///
|
||||
@@ -71,6 +74,12 @@ impl Range {
|
||||
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]
|
||||
@@ -113,7 +122,7 @@ impl Range {
|
||||
}
|
||||
|
||||
/// `Direction::Backward` when head < anchor.
|
||||
/// `Direction::Backward` otherwise.
|
||||
/// `Direction::Forward` otherwise.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn direction(&self) -> Direction {
|
||||
@@ -166,7 +175,7 @@ impl Range {
|
||||
/// 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
|
||||
/// [Selection::map] or [ChangeSet::update_positions].
|
||||
pub fn map(mut self, changes: &ChangeSet) -> Self {
|
||||
use std::cmp::Ordering;
|
||||
if changes.is_empty() {
|
||||
@@ -374,6 +383,12 @@ impl Range {
|
||||
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 {
|
||||
@@ -488,6 +503,16 @@ impl Selection {
|
||||
&self.ranges
|
||||
}
|
||||
|
||||
/// Returns an iterator over the line ranges of each range in the selection.
|
||||
///
|
||||
/// Adjacent and overlapping line ranges of the [Range]s in the selection are merged.
|
||||
pub fn line_ranges<'a>(&'a self, text: RopeSlice<'a>) -> LineRangeIter<'a> {
|
||||
LineRangeIter {
|
||||
ranges: self.ranges.iter().peekable(),
|
||||
text,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn primary_index(&self) -> usize {
|
||||
self.primary_index
|
||||
}
|
||||
@@ -516,6 +541,8 @@ impl Selection {
|
||||
}
|
||||
|
||||
/// Normalizes a `Selection`.
|
||||
///
|
||||
/// Ranges are sorted by [Range::from], with overlapping ranges merged.
|
||||
fn normalize(mut self) -> Self {
|
||||
if self.len() < 2 {
|
||||
return self;
|
||||
@@ -703,17 +730,53 @@ impl IntoIterator for Selection {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Range> for Selection {
|
||||
fn from(range: Range) -> Self {
|
||||
Self {
|
||||
ranges: smallvec![range],
|
||||
primary_index: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LineRangeIter<'a> {
|
||||
ranges: iter::Peekable<slice::Iter<'a, Range>>,
|
||||
text: RopeSlice<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for LineRangeIter<'a> {
|
||||
type Item = (usize, usize);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let (start, mut end) = self.ranges.next()?.line_range(self.text);
|
||||
while let Some((next_start, next_end)) =
|
||||
self.ranges.peek().map(|range| range.line_range(self.text))
|
||||
{
|
||||
// Merge overlapping and adjacent ranges.
|
||||
// This subtraction cannot underflow because the ranges are sorted.
|
||||
if next_start - end <= 1 {
|
||||
end = next_end;
|
||||
self.ranges.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Some((start, end))
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
@@ -724,25 +787,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.
|
||||
@@ -761,12 +819,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 {
|
||||
@@ -776,21 +829,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 {
|
||||
@@ -1021,14 +1102,12 @@ mod test {
|
||||
|
||||
#[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
|
||||
@@ -1038,8 +1117,14 @@ mod test {
|
||||
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!(
|
||||
@@ -1077,9 +1162,9 @@ mod test {
|
||||
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(
|
||||
@@ -1119,6 +1204,32 @@ mod test {
|
||||
assert_eq!(Range::new(12, 0).line_range(s), (0, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_line_ranges() {
|
||||
let (text, selection) = crate::test::print(
|
||||
r#" L0
|
||||
#[|these]# line #(|ranges)# are #(|merged)# L1
|
||||
L2
|
||||
single one-line #(|range)# L3
|
||||
L4
|
||||
single #(|multiline L5
|
||||
range)# L6
|
||||
L7
|
||||
these #(|multiline L8
|
||||
ranges)# are #(|also L9
|
||||
merged)# L10
|
||||
L11
|
||||
adjacent #(|ranges)# L12
|
||||
are merged #(|the same way)# L13
|
||||
"#,
|
||||
);
|
||||
let rope = Rope::from_str(&text);
|
||||
assert_eq!(
|
||||
vec![(1, 1), (3, 3), (5, 6), (8, 10), (12, 13)],
|
||||
selection.line_ranges(rope.slice(..)).collect::<Vec<_>>(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cursor() {
|
||||
let r = Rope::from_str("\r\nHi\r\nthere!");
|
||||
@@ -1171,13 +1282,15 @@ mod test {
|
||||
|
||||
#[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(),
|
||||
|
@@ -1,18 +1,16 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{movement::Direction, search, Range, Selection};
|
||||
use crate::{
|
||||
graphemes::next_grapheme_boundary,
|
||||
match_brackets::{
|
||||
find_matching_bracket, find_matching_bracket_fuzzy, get_pair, is_close_bracket,
|
||||
is_open_bracket,
|
||||
},
|
||||
movement::Direction,
|
||||
search, Range, Selection, Syntax,
|
||||
};
|
||||
use ropey::RopeSlice;
|
||||
|
||||
pub const PAIRS: &[(char, char)] = &[
|
||||
('(', ')'),
|
||||
('[', ']'),
|
||||
('{', '}'),
|
||||
('<', '>'),
|
||||
('«', '»'),
|
||||
('「', '」'),
|
||||
('(', ')'),
|
||||
];
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
PairNotFound,
|
||||
@@ -34,32 +32,68 @@ impl Display for Error {
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Given any char in [PAIRS], return the open and closing chars. If not found in
|
||||
/// [PAIRS] return (ch, ch).
|
||||
/// Finds the position of surround pairs of any [`crate::match_brackets::PAIRS`]
|
||||
/// using tree-sitter when possible.
|
||||
///
|
||||
/// ```
|
||||
/// use helix_core::surround::get_pair;
|
||||
/// # Returns
|
||||
///
|
||||
/// assert_eq!(get_pair('['), ('[', ']'));
|
||||
/// assert_eq!(get_pair('}'), ('{', '}'));
|
||||
/// assert_eq!(get_pair('"'), ('"', '"'));
|
||||
/// ```
|
||||
pub fn get_pair(ch: char) -> (char, char) {
|
||||
PAIRS
|
||||
.iter()
|
||||
.find(|(open, close)| *open == ch || *close == ch)
|
||||
.copied()
|
||||
.unwrap_or((ch, ch))
|
||||
/// Tuple `(anchor, head)`, meaning it is not always ordered.
|
||||
pub fn find_nth_closest_pairs_pos(
|
||||
syntax: Option<&Syntax>,
|
||||
text: RopeSlice,
|
||||
range: Range,
|
||||
skip: usize,
|
||||
) -> Result<(usize, usize)> {
|
||||
match syntax {
|
||||
Some(syntax) => find_nth_closest_pairs_ts(syntax, text, range, skip),
|
||||
None => find_nth_closest_pairs_plain(text, range, skip),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_nth_closest_pairs_pos(
|
||||
fn find_nth_closest_pairs_ts(
|
||||
syntax: &Syntax,
|
||||
text: RopeSlice,
|
||||
range: Range,
|
||||
mut skip: usize,
|
||||
) -> Result<(usize, usize)> {
|
||||
let is_open_pair = |ch| PAIRS.iter().any(|(open, _)| *open == ch);
|
||||
let is_close_pair = |ch| PAIRS.iter().any(|(_, close)| *close == ch);
|
||||
let mut opening = range.from();
|
||||
// We want to expand the selection if we are already on the found pair,
|
||||
// otherwise we would need to subtract "-1" from "range.to()".
|
||||
let mut closing = range.to();
|
||||
|
||||
while skip > 0 {
|
||||
closing = find_matching_bracket_fuzzy(syntax, text, closing).ok_or(Error::PairNotFound)?;
|
||||
opening = find_matching_bracket(syntax, text, closing).ok_or(Error::PairNotFound)?;
|
||||
// If we're already on a closing bracket "find_matching_bracket_fuzzy" will return
|
||||
// the position of the opening bracket.
|
||||
if closing < opening {
|
||||
(opening, closing) = (closing, opening);
|
||||
}
|
||||
|
||||
// In case found brackets are partially inside current selection.
|
||||
if range.from() < opening || closing < range.to() - 1 {
|
||||
closing = next_grapheme_boundary(text, closing);
|
||||
} else {
|
||||
skip -= 1;
|
||||
if skip != 0 {
|
||||
closing = next_grapheme_boundary(text, closing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the original direction.
|
||||
if let Direction::Forward = range.direction() {
|
||||
Ok((opening, closing))
|
||||
} else {
|
||||
Ok((closing, opening))
|
||||
}
|
||||
}
|
||||
|
||||
fn find_nth_closest_pairs_plain(
|
||||
text: RopeSlice,
|
||||
range: Range,
|
||||
mut skip: usize,
|
||||
) -> Result<(usize, usize)> {
|
||||
let mut stack = Vec::with_capacity(2);
|
||||
let pos = range.from();
|
||||
let mut close_pos = pos.saturating_sub(1);
|
||||
@@ -67,7 +101,7 @@ pub fn find_nth_closest_pairs_pos(
|
||||
for ch in text.chars_at(pos) {
|
||||
close_pos += 1;
|
||||
|
||||
if is_open_pair(ch) {
|
||||
if is_open_bracket(ch) {
|
||||
// Track open pairs encountered so that we can step over
|
||||
// the corresponding close pairs that will come up further
|
||||
// down the loop. We want to find a lone close pair whose
|
||||
@@ -76,7 +110,7 @@ pub fn find_nth_closest_pairs_pos(
|
||||
continue;
|
||||
}
|
||||
|
||||
if !is_close_pair(ch) {
|
||||
if !is_close_bracket(ch) {
|
||||
// We don't care if this character isn't a brace pair item,
|
||||
// so short circuit here.
|
||||
continue;
|
||||
@@ -157,7 +191,11 @@ pub fn find_nth_pairs_pos(
|
||||
)
|
||||
};
|
||||
|
||||
Option::zip(open, close).ok_or(Error::PairNotFound)
|
||||
// preserve original direction
|
||||
match range.direction() {
|
||||
Direction::Forward => Option::zip(open, close).ok_or(Error::PairNotFound),
|
||||
Direction::Backward => Option::zip(close, open).ok_or(Error::PairNotFound),
|
||||
}
|
||||
}
|
||||
|
||||
fn find_nth_open_pair(
|
||||
@@ -167,6 +205,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
|
||||
@@ -245,6 +287,7 @@ fn find_nth_close_pair(
|
||||
/// are automatically detected around each cursor (note that this may result
|
||||
/// in them selecting different surround characters for each selection).
|
||||
pub fn get_surround_pos(
|
||||
syntax: Option<&Syntax>,
|
||||
text: RopeSlice,
|
||||
selection: &Selection,
|
||||
ch: Option<char>,
|
||||
@@ -253,14 +296,19 @@ pub fn get_surround_pos(
|
||||
let mut change_pos = Vec::new();
|
||||
|
||||
for &range in selection {
|
||||
let (open_pos, close_pos) = match ch {
|
||||
Some(ch) => find_nth_pairs_pos(text, ch, range, skip)?,
|
||||
None => find_nth_closest_pairs_pos(text, range, skip)?,
|
||||
let (open_pos, close_pos) = {
|
||||
let range_raw = match ch {
|
||||
Some(ch) => find_nth_pairs_pos(text, ch, range, skip)?,
|
||||
None => find_nth_closest_pairs_pos(syntax, text, range, skip)?,
|
||||
};
|
||||
let range = Range::new(range_raw.0, range_raw.1);
|
||||
(range.from(), range.to())
|
||||
};
|
||||
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)
|
||||
}
|
||||
@@ -283,7 +331,7 @@ mod test {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
get_surround_pos(doc.slice(..), &selection, Some('('), 1).unwrap(),
|
||||
get_surround_pos(None, doc.slice(..), &selection, Some('('), 1).unwrap(),
|
||||
expectations
|
||||
);
|
||||
}
|
||||
@@ -298,7 +346,7 @@ mod test {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
get_surround_pos(doc.slice(..), &selection, Some('('), 1),
|
||||
get_surround_pos(None, doc.slice(..), &selection, Some('('), 1),
|
||||
Err(Error::PairNotFound)
|
||||
);
|
||||
}
|
||||
@@ -313,7 +361,7 @@ mod test {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
get_surround_pos(doc.slice(..), &selection, Some('('), 1),
|
||||
get_surround_pos(None, doc.slice(..), &selection, Some('('), 1),
|
||||
Err(Error::PairNotFound) // overlapping surround chars
|
||||
);
|
||||
}
|
||||
@@ -328,7 +376,7 @@ mod test {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
get_surround_pos(doc.slice(..), &selection, Some('['), 1),
|
||||
get_surround_pos(None, doc.slice(..), &selection, Some('['), 1),
|
||||
Err(Error::CursorOverlap)
|
||||
);
|
||||
}
|
||||
@@ -382,6 +430,21 @@ mod test {
|
||||
)
|
||||
}
|
||||
|
||||
#[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(None, 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.
|
||||
|
File diff suppressed because it is too large
Load Diff
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 @@ impl<A, M> Layer<A, M> {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ impl TextAnnotations {
|
||||
/// 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 @@ impl TextAnnotations {
|
||||
///
|
||||
/// 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 @@ impl TextAnnotations {
|
||||
///
|
||||
/// 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
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ use crate::chars::{categorize_char, char_is_whitespace, CharCategory};
|
||||
use crate::graphemes::{next_grapheme_boundary, prev_grapheme_boundary};
|
||||
use crate::line_ending::rope_is_line_ending;
|
||||
use crate::movement::Direction;
|
||||
use crate::surround;
|
||||
use crate::syntax::LanguageConfiguration;
|
||||
use crate::Range;
|
||||
use crate::{surround, Syntax};
|
||||
|
||||
fn find_word_boundary(slice: RopeSlice, mut pos: usize, direction: Direction, long: bool) -> usize {
|
||||
use CharCategory::{Eol, Whitespace};
|
||||
@@ -199,25 +199,28 @@ pub fn textobject_paragraph(
|
||||
}
|
||||
|
||||
pub fn textobject_pair_surround(
|
||||
syntax: Option<&Syntax>,
|
||||
slice: RopeSlice,
|
||||
range: Range,
|
||||
textobject: TextObject,
|
||||
ch: char,
|
||||
count: usize,
|
||||
) -> Range {
|
||||
textobject_pair_surround_impl(slice, range, textobject, Some(ch), count)
|
||||
textobject_pair_surround_impl(syntax, slice, range, textobject, Some(ch), count)
|
||||
}
|
||||
|
||||
pub fn textobject_pair_surround_closest(
|
||||
syntax: Option<&Syntax>,
|
||||
slice: RopeSlice,
|
||||
range: Range,
|
||||
textobject: TextObject,
|
||||
count: usize,
|
||||
) -> Range {
|
||||
textobject_pair_surround_impl(slice, range, textobject, None, count)
|
||||
textobject_pair_surround_impl(syntax, slice, range, textobject, None, count)
|
||||
}
|
||||
|
||||
fn textobject_pair_surround_impl(
|
||||
syntax: Option<&Syntax>,
|
||||
slice: RopeSlice,
|
||||
range: Range,
|
||||
textobject: TextObject,
|
||||
@@ -226,8 +229,7 @@ fn textobject_pair_surround_impl(
|
||||
) -> Range {
|
||||
let pair_pos = match ch {
|
||||
Some(ch) => surround::find_nth_pairs_pos(slice, ch, range, count),
|
||||
// Automatically find the closest surround pairs
|
||||
None => surround::find_nth_closest_pairs_pos(slice, range, count),
|
||||
None => surround::find_nth_closest_pairs_pos(syntax, slice, range, count),
|
||||
};
|
||||
pair_pos
|
||||
.map(|(anchor, head)| match textobject {
|
||||
@@ -574,7 +576,8 @@ mod test {
|
||||
let slice = doc.slice(..);
|
||||
for &case in scenario {
|
||||
let (pos, objtype, expected_range, ch, count) = case;
|
||||
let result = textobject_pair_surround(slice, Range::point(pos), objtype, ch, count);
|
||||
let result =
|
||||
textobject_pair_surround(None, slice, Range::point(pos), objtype, ch, count);
|
||||
assert_eq!(
|
||||
result,
|
||||
expected_range.into(),
|
||||
|
@@ -378,7 +378,9 @@ impl ChangeSet {
|
||||
macro_rules! map {
|
||||
($map: expr, $i: expr) => {
|
||||
loop {
|
||||
let Some((pos, assoc)) = positions.peek_mut() else { return; };
|
||||
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.
|
||||
@@ -405,7 +407,10 @@ impl ChangeSet {
|
||||
debug_assert!(old_pos <= **pos, "Reverse Iter across changeset works");
|
||||
continue 'outer;
|
||||
}
|
||||
let Some(new_pos) = $map(**pos, *assoc) else { break; };
|
||||
#[allow(clippy::redundant_closure_call)]
|
||||
let Some(new_pos) = $map(**pos, *assoc) else {
|
||||
break;
|
||||
};
|
||||
**pos = new_pos;
|
||||
positions.next();
|
||||
}
|
||||
|
122
helix-core/src/uri.rs
Normal file
122
helix-core/src/uri.rs
Normal file
@@ -0,0 +1,122 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// A generic pointer to a file location.
|
||||
///
|
||||
/// Currently this type only supports paths to local files.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[non_exhaustive]
|
||||
pub enum Uri {
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
impl Uri {
|
||||
// This clippy allow mirrors url::Url::from_file_path
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn to_url(&self) -> Result<url::Url, ()> {
|
||||
match self {
|
||||
Uri::File(path) => url::Url::from_file_path(path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_path(&self) -> Option<&Path> {
|
||||
match self {
|
||||
Self::File(path) => Some(path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_path_buf(self) -> Option<PathBuf> {
|
||||
match self {
|
||||
Self::File(path) => Some(path),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PathBuf> for Uri {
|
||||
fn from(path: PathBuf) -> Self {
|
||||
Self::File(path)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Uri> for PathBuf {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(uri: Uri) -> Result<Self, Self::Error> {
|
||||
match uri {
|
||||
Uri::File(path) => Ok(path),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UrlConversionError {
|
||||
source: url::Url,
|
||||
kind: UrlConversionErrorKind,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UrlConversionErrorKind {
|
||||
UnsupportedScheme,
|
||||
UnableToConvert,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for UrlConversionError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.kind {
|
||||
UrlConversionErrorKind::UnsupportedScheme => {
|
||||
write!(f, "unsupported scheme in URL: {}", self.source.scheme())
|
||||
}
|
||||
UrlConversionErrorKind::UnableToConvert => {
|
||||
write!(f, "unable to convert URL to file path: {}", self.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for UrlConversionError {}
|
||||
|
||||
fn convert_url_to_uri(url: &url::Url) -> Result<Uri, UrlConversionErrorKind> {
|
||||
if url.scheme() == "file" {
|
||||
url.to_file_path()
|
||||
.map(|path| Uri::File(helix_stdx::path::normalize(path)))
|
||||
.map_err(|_| UrlConversionErrorKind::UnableToConvert)
|
||||
} else {
|
||||
Err(UrlConversionErrorKind::UnsupportedScheme)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<url::Url> for Uri {
|
||||
type Error = UrlConversionError;
|
||||
|
||||
fn try_from(url: url::Url) -> Result<Self, Self::Error> {
|
||||
convert_url_to_uri(&url).map_err(|kind| Self::Error { source: url, kind })
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&url::Url> for Uri {
|
||||
type Error = UrlConversionError;
|
||||
|
||||
fn try_from(url: &url::Url) -> Result<Self, Self::Error> {
|
||||
convert_url_to_uri(url).map_err(|kind| Self::Error {
|
||||
source: url.clone(),
|
||||
kind,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use url::Url;
|
||||
|
||||
#[test]
|
||||
fn unknown_scheme() {
|
||||
let url = Url::parse("csharp:/metadata/foo/bar/Baz.cs").unwrap();
|
||||
assert!(matches!(
|
||||
Uri::try_from(url),
|
||||
Err(UrlConversionError {
|
||||
kind: UrlConversionErrorKind::UnsupportedScheme,
|
||||
..
|
||||
})
|
||||
));
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ use helix_core::{
|
||||
syntax::{Configuration, Loader},
|
||||
Syntax,
|
||||
};
|
||||
use helix_stdx::rope::RopeSliceExt;
|
||||
use ropey::Rope;
|
||||
use std::{ops::Range, path::PathBuf, process::Command};
|
||||
|
||||
@@ -34,7 +35,7 @@ fn test_treesitter_indent_rust_helix() {
|
||||
.unwrap();
|
||||
let files = String::from_utf8(files.stdout).unwrap();
|
||||
|
||||
let ignored_files = vec![
|
||||
let ignored_files = [
|
||||
// Contains many macros that tree-sitter does not parse in a meaningful way and is otherwise not very interesting
|
||||
"helix-term/src/health.rs",
|
||||
];
|
||||
@@ -43,6 +44,7 @@ fn test_treesitter_indent_rust_helix() {
|
||||
if ignored_files.contains(&file) {
|
||||
continue;
|
||||
}
|
||||
#[allow(clippy::single_range_in_vec_init)]
|
||||
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
|
||||
@@ -186,7 +188,7 @@ fn test_treesitter_indent(
|
||||
lang_scope: &str,
|
||||
ignored_lines: Vec<std::ops::Range<usize>>,
|
||||
) {
|
||||
let loader = Loader::new(indent_tests_config());
|
||||
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"));
|
||||
@@ -197,7 +199,7 @@ fn test_treesitter_indent(
|
||||
let indent_style = IndentStyle::from_str(&language_config.indent.as_ref().unwrap().unit);
|
||||
let highlight_config = language_config.highlight_config(&[]).unwrap();
|
||||
let text = doc.slice(..);
|
||||
let syntax = Syntax::new(text, highlight_config, std::sync::Arc::new(loader)).unwrap();
|
||||
let syntax = Syntax::new(text, highlight_config, |_| None).unwrap();
|
||||
let indent_query = language_config.indent_query().unwrap();
|
||||
|
||||
for i in 0..doc.len_lines() {
|
||||
@@ -205,7 +207,7 @@ fn test_treesitter_indent(
|
||||
if ignored_lines.iter().any(|range| range.contains(&(i + 1))) {
|
||||
continue;
|
||||
}
|
||||
if let Some(pos) = helix_core::find_first_non_whitespace_char(line) {
|
||||
if let Some(pos) = line.first_non_whitespace_char() {
|
||||
let tab_width: usize = 4;
|
||||
let suggested_indent = treesitter_indent_for_pos(
|
||||
indent_query,
|
||||
|
@@ -13,16 +13,15 @@ homepage.workspace = true
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-core = { path = "../helix-core" }
|
||||
helix-config = { path = "../helix-config" }
|
||||
|
||||
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 = "5.0.0"
|
||||
thiserror.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
fern = "0.6"
|
||||
|
@@ -2,7 +2,7 @@ use crate::{
|
||||
requests::DisconnectArguments,
|
||||
transport::{Payload, Request, Response, Transport},
|
||||
types::*,
|
||||
Error, Result, ThreadId,
|
||||
Error, Result,
|
||||
};
|
||||
use helix_core::syntax::DebuggerQuirks;
|
||||
|
||||
@@ -113,7 +113,7 @@ impl Client {
|
||||
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)
|
||||
@@ -157,8 +157,8 @@ impl Client {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn starting_request_args(&self) -> &Option<Value> {
|
||||
&self.starting_request_args
|
||||
pub fn starting_request_args(&self) -> Option<&Value> {
|
||||
self.starting_request_args.as_ref()
|
||||
}
|
||||
|
||||
pub async fn tcp_process(
|
||||
|
@@ -1,146 +0,0 @@
|
||||
use anyhow::bail;
|
||||
use helix_config::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
options! {
|
||||
struct DebugAdapterConfig {
|
||||
#[name = "debugger.name"]
|
||||
name: Option<String> = None,
|
||||
#[name = "debugger.transport"]
|
||||
#[read = copy]
|
||||
transport: Transport = Transport::Stdio,
|
||||
#[name = "debugger.command"]
|
||||
#[read = deref]
|
||||
command: String = "",
|
||||
#[name = "debugger.args"]
|
||||
#[read = deref]
|
||||
args: List<String> = List::default(),
|
||||
#[name = "debugger.port-arg"]
|
||||
#[read = deref]
|
||||
port_arg: String = "",
|
||||
#[name = "debugger.templates"]
|
||||
#[read = deref]
|
||||
templates: List<DebugTemplate> = List::default(),
|
||||
#[name = "debugger.quirks.absolut-path"]
|
||||
#[read = copy]
|
||||
absolut_path: bool = false,
|
||||
#[name = "terminal.command"]
|
||||
terminal_command: Option<String> = get_terminal_provider().map(|term| term.command),
|
||||
#[name = "terminal.args"]
|
||||
#[read = deref]
|
||||
terminal_args: List<String> = get_terminal_provider().map(|term| term.args.into_boxed_slice()).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Transport {
|
||||
Stdio,
|
||||
Tcp,
|
||||
}
|
||||
|
||||
impl Ty for Transport {
|
||||
fn from_value(val: Value) -> anyhow::Result<Self> {
|
||||
match &*String::from_value(val)? {
|
||||
"stdio" => Ok(Transport::Stdio),
|
||||
"tcp" => Ok(Transport::Tcp),
|
||||
val => bail!("expected 'stdio' or 'tcp' (got {val:?})"),
|
||||
}
|
||||
}
|
||||
fn to_value(&self) -> Value {
|
||||
match self {
|
||||
Transport::Stdio => "stdio".into(),
|
||||
Transport::Tcp => "tcp".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum DebugArgumentValue {
|
||||
String(String),
|
||||
Array(Vec<String>),
|
||||
Boolean(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct AdvancedCompletion {
|
||||
pub name: Option<String>,
|
||||
pub completion: Option<String>,
|
||||
pub default: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case", untagged)]
|
||||
pub enum DebugConfigCompletion {
|
||||
Named(String),
|
||||
Advanced(AdvancedCompletion),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct DebugTemplate {
|
||||
pub name: String,
|
||||
pub request: String,
|
||||
pub completion: Vec<DebugConfigCompletion>,
|
||||
pub args: Map<DebugArgumentValue>,
|
||||
}
|
||||
|
||||
// TODO: integrate this better with the new config system (less nesting)
|
||||
// the best way to do that is probably a rewrite. I think these templates
|
||||
// are probably overkill here. This may be easier to solve by moving the logic
|
||||
// to scheme
|
||||
config_serde_adapter!(DebugTemplate);
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
|
||||
pub struct TerminalConfig {
|
||||
pub command: String,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn get_terminal_provider() -> Option<TerminalConfig> {
|
||||
use helix_config::env::binary_exists;
|
||||
|
||||
if binary_exists("wt") {
|
||||
return Some(TerminalConfig {
|
||||
command: "wt".into(),
|
||||
args: vec![
|
||||
"new-tab".into(),
|
||||
"--title".into(),
|
||||
"DEBUG".into(),
|
||||
"cmd".into(),
|
||||
"/C".into(),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Some(TerminalConfig {
|
||||
command: "conhost".into(),
|
||||
args: vec!["cmd".into(), "/C".into()],
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, target_os = "wasm32")))]
|
||||
fn get_terminal_provider() -> Option<TerminalConfig> {
|
||||
use helix_config::env::{binary_exists, env_var_is_set};
|
||||
|
||||
if env_var_is_set("TMUX") && binary_exists("tmux") {
|
||||
return Some(TerminalConfig {
|
||||
command: "tmux".into(),
|
||||
args: vec!["split-window".into()],
|
||||
});
|
||||
}
|
||||
|
||||
if env_var_is_set("WEZTERM_UNIX_SOCKET") && binary_exists("wezterm") {
|
||||
return Some(TerminalConfig {
|
||||
command: "wezterm".into(),
|
||||
args: vec!["cli".into(), "split-pane".into()],
|
||||
});
|
||||
}
|
||||
|
||||
None
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
mod client;
|
||||
mod config;
|
||||
mod transport;
|
||||
mod types;
|
||||
|
||||
@@ -20,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>;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -311,7 +311,8 @@ pub struct Variable {
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Module {
|
||||
pub id: String, // TODO: || number
|
||||
#[serde(deserialize_with = "from_number")]
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub path: Option<PathBuf>,
|
||||
@@ -331,6 +332,23 @@ pub struct Module {
|
||||
pub address_range: Option<String>,
|
||||
}
|
||||
|
||||
fn from_number<'de, D>(deserializer: D) -> Result<String, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum NumberOrString {
|
||||
Number(i64),
|
||||
String(String),
|
||||
}
|
||||
|
||||
match NumberOrString::deserialize(deserializer)? {
|
||||
NumberOrString::Number(n) => Ok(n.to_string()),
|
||||
NumberOrString::String(s) => Ok(s),
|
||||
}
|
||||
}
|
||||
|
||||
pub mod requests {
|
||||
use super::*;
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
@@ -887,4 +905,18 @@ pub mod events {
|
||||
pub offset: usize,
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_module_id_from_number() {
|
||||
let raw = r#"{"id": 0, "name": "Name"}"#;
|
||||
let module: super::Module = serde_json::from_str(raw).expect("Error!");
|
||||
assert_eq!(module.id, "0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_module_id_from_string() {
|
||||
let raw = r#"{"id": "0", "name": "Name"}"#;
|
||||
let module: super::Module = serde_json::from_str(raw).expect("Error!");
|
||||
assert_eq!(module.id, "0");
|
||||
}
|
||||
}
|
||||
|
@@ -12,5 +12,18 @@ homepage.workspace = true
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot"] }
|
||||
parking_lot = { version = "0.12", features = ["send_guard"] }
|
||||
ahash = "0.8.11"
|
||||
hashbrown = "0.14.5"
|
||||
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 {}
|
@@ -1,8 +1,205 @@
|
||||
//! `helix-event` contains systems that allow (often async) communication between
|
||||
//! different editor components without strongly coupling them. Currently this
|
||||
//! crate only contains some smaller facilities but the intend is to add more
|
||||
//! functionality in the future ( like a generic hook system)
|
||||
//! 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.
|
||||
|
||||
pub use redraw::{lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard};
|
||||
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, RequestRedrawOnDrop,
|
||||
};
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -5,16 +5,20 @@ use std::future::Future;
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
/// A `Notify` instance that can be used to (asynchronously) request
|
||||
/// the editor the render a new frame.
|
||||
static REDRAW_NOTIFY: Notify = Notify::const_new();
|
||||
use crate::runtime_local;
|
||||
|
||||
/// A `RwLock` that prevents the next frame from being
|
||||
/// drawn until an exclusive (write) lock can be acquired.
|
||||
/// This allows asynchsonous 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(());
|
||||
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, ()>;
|
||||
|
||||
@@ -47,3 +51,12 @@ pub fn start_frame() {
|
||||
pub fn lock_frame() -> RenderLockGuard {
|
||||
RENDER_LOCK.read()
|
||||
}
|
||||
|
||||
/// A zero sized type that requests a redraw via [request_redraw] when the type [Drop]s.
|
||||
pub struct RequestRedrawOnDrop;
|
||||
|
||||
impl Drop for RequestRedrawOnDrop {
|
||||
fn drop(&mut self) {
|
||||
request_redraw();
|
||||
}
|
||||
}
|
||||
|
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)
|
||||
}
|
@@ -15,21 +15,22 @@ 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.workspace = true
|
||||
once_cell = "1.19"
|
||||
log = "0.4"
|
||||
which = "5.0.0"
|
||||
|
||||
# TODO: these two should be on !wasm32 only
|
||||
|
||||
# cloning/compiling tree-sitter grammars
|
||||
cc = { version = "1" }
|
||||
threadpool = { version = "1.0" }
|
||||
tempfile = "3.9.0"
|
||||
tempfile = "3.10.1"
|
||||
dunce = "1.0.4"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
@@ -50,6 +50,7 @@ fn main() {
|
||||
.ok()
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|x| String::from_utf8(x.stdout).ok())
|
||||
.map(|x| x.trim().to_string())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -67,6 +68,7 @@ fn main() {
|
||||
.ok()
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|x| String::from_utf8(x.stdout).ok())
|
||||
.map(|x| x.trim().to_string())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@@ -86,10 +86,8 @@ pub fn get_language(name: &str) -> Result<Language> {
|
||||
}
|
||||
|
||||
fn ensure_git_is_available() -> Result<()> {
|
||||
match which::which("git") {
|
||||
Ok(_cmd) => Ok(()),
|
||||
Err(err) => Err(anyhow::anyhow!("'git' could not be found ({err})")),
|
||||
}
|
||||
helix_stdx::env::which("git")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn fetch_grammars() -> Result<()> {
|
||||
@@ -424,7 +422,7 @@ fn build_tree_sitter_library(
|
||||
}
|
||||
}
|
||||
|
||||
let recompile = needs_recompile(&library_path, &parser_path, &scanner_path)
|
||||
let recompile = needs_recompile(&library_path, &parser_path, scanner_path.as_ref())
|
||||
.context("Failed to compare source and binary timestamps")?;
|
||||
|
||||
if !recompile {
|
||||
@@ -570,7 +568,7 @@ fn build_tree_sitter_library(
|
||||
fn needs_recompile(
|
||||
lib_path: &Path,
|
||||
parser_c_path: &Path,
|
||||
scanner_path: &Option<PathBuf>,
|
||||
scanner_path: Option<&PathBuf>,
|
||||
) -> Result<bool> {
|
||||
if !lib_path.exists() {
|
||||
return Ok(true);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user