on master help sign in
replace all submodule documentation with flags documentation
8081e9fMichael Davis
README.md+5−2
@@ -36,12 +36,14 @@ We provide packaging for various distributions, but here's a quick method to
36build from source.
36build from source.
37
37
38```
38```
39−git clone --recurse-submodules --shallow-submodules -j8 https://github.com/helix-editor/helix
39+git clone https://github.com/helix-editor/helix
40cd helix
40cd helix
41cargo install --path helix-term
41cargo install --path helix-term
42+hx --fetch-grammars
43+hx --build-grammars
42```
44```
43
45
44−This will install the `hx` binary to `$HOME/.cargo/bin`.
46+This will install the `hx` binary to `$HOME/.cargo/bin` and build tree-sitter grammars.
45
47
46Helix also needs its runtime files so make sure to copy/symlink the `runtime/` directory into the
48Helix also needs its runtime files so make sure to copy/symlink the `runtime/` directory into the
47config directory (for example `~/.config/helix/runtime` on Linux/macOS, or `%AppData%/helix/runtime` on Windows).
49config directory (for example `~/.config/helix/runtime` on Linux/macOS, or `%AppData%/helix/runtime` on Windows).
@@ -56,6 +58,7 @@ that sets the variable to the install dir.
56[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions)
58[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions)
57
59
58## MacOS
60## MacOS
61+
59Helix can be installed on MacOS through homebrew via:
62Helix can be installed on MacOS through homebrew via:
60
63
61```
64```
book/src/configuration.md+1
@@ -131,6 +131,7 @@ Search specific options.
131## LSP
131## LSP
132
132
133To display all language server messages in the status line add the following to your `config.toml`:
133To display all language server messages in the status line add the following to your `config.toml`:
134+
134```toml
135```toml
135[lsp]
136[lsp]
136display-messages = true
137display-messages = true
book/src/guides/adding_languages.md+58−39
@@ -1,45 +1,68 @@
1# Adding languages
1# Adding languages
2
2
3−## Submodules
3+## Language configuration
4
4
5−To add a new language, you should first add a tree-sitter submodule. To do this,
5+To add a new language, you need to add a `language` entry to the
6−you can run the command
6+[`languages.toml`][languages.toml] found in the root of the repository;
7−```sh
7+this `languages.toml` file is included at compilation time, and is
8−git submodule add -f <repository> helix-syntax/languages/tree-sitter-<name>
8+distinct from the `languages.toml` file in the user's [configuration
9−```
9+directory](../configuration.md).
10−For example, to add tree-sitter-ocaml you would run
10+
11−```sh
11+```toml
12−git submodule add -f https://github.com/tree-sitter/tree-sitter-ocaml helix-syntax/languages/tree-sitter-ocaml
12+[[language]]
13+name = "mylang"
14+scope = "scope.mylang"
15+injection-regex = "^mylang$"
16+file-types = ["mylang", "myl"]
17+comment-token = "#"
18+indent = { tab-width = 2, unit = " " }
13```
19```
14−Make sure the submodule is shallow by doing
20+
15−```sh
21+These are the available keys and descriptions for the file.
16−git config -f .gitmodules submodule.helix-syntax/languages/tree-sitter-<name>.shallow true
22+
23+| Key | Description |
24+| ---- | ----------- |
25+| `name` | The name of the language |
26+| `scope` | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
27+| `injection-regex` | 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. |
28+| `file-types` | The filetypes of the language, for example `["yml", "yaml"]`. Extensions and full file names are supported. |
29+| `shebangs` | The interpreters from the shebang line, for example `["sh", "bash"]` |
30+| `roots` | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
31+| `auto-format` | Whether to autoformat this language when saving |
32+| `diagnostic-severity` | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) |
33+| `comment-token` | The token to use as a comment-token |
34+| `indent` | The indent to use. Has sub keys `tab-width` and `unit` |
35+| `config` | Language server configuration |
36+| `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) |
37+
38+## Grammar configuration
39+
40+If a tree-sitter grammar is available for the language, add a new `grammar`
41+entry to `languages.toml`.
42+
43+```toml
44+[[grammar]]
45+name = "mylang"
46+source = { git = "https://github.com/example/mylang", rev = "a250c4582510ff34767ec3b7dcdd3c24e8c8aa68" }
17```
47```
18
48
19−or you can manually add `shallow = true` to `.gitmodules`.
49+Grammar configuration takes these keys:
20
50
21−## languages.toml
51+| Key | Description |
52+| --- | ----------- |
53+| `name` | The name of the tree-sitter grammar |
54+| `path` | A path within the grammar directory which should be built. Some grammar repositories host multiple grammars (for example `tree-sitter-typescript` and `tree-sitter-ocaml`) in subdirectories. This key is used to point `hx --build-grammars` to the correct path for compilation. When ommitted, the root of the grammar directory is used |
55+| `source` | The method of fetching the grammar - a table with a schema defined below |
22
56
23−Next, you need to add the language to the [`languages.toml`][languages.toml] found in the root of
57+Where `source` is a table with either these keys when using a grammar from a
24−the repository; this `languages.toml` file is included at compilation time, and
58+git repository:
25−is distinct from the `language.toml` file in the user's [configuration
26−directory](../configuration.md).
27
59
28−These are the available keys and descriptions for the file.
60+| Key | Description |
61+| --- | ----------- |
62+| `git` | A git remote URL from which the grammar should be cloned |
63+| `rev` | The revision (commit hash or tag) which should be fetched |
29
64
30−| Key | Description |
65+Or a `path` key with an absolute path to a locally available grammar directory.
31−| ---- | ----------- |
32−| name | The name of the language |
33−| scope | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
34−| injection-regex | 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. |
35−| file-types | The filetypes of the language, for example `["yml", "yaml"]` |
36−| shebangs | The interpreters from the shebang line, for example `["sh", "bash"]` |
37−| roots | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
38−| auto-format | Whether to autoformat this language when saving |
39−| diagnostic-severity | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) |
40−| comment-token | The token to use as a comment-token |
41−| indent | The indent to use. Has sub keys `tab-width` and `unit` |
42−| config | Language server configuration |
43
66
44## Queries
67## Queries
45
68
@@ -51,18 +74,14 @@ gives more info on how to write queries.
51
74
52> NOTE: When evaluating queries, the first matching query takes
75> NOTE: When evaluating queries, the first matching query takes
53precedence, which is different from other editors like neovim where
76precedence, which is different from other editors like neovim where
54−the last matching query supercedes the ones before it. See
77+the last matching query supersedes the ones before it. See
55[this issue][neovim-query-precedence] for an example.
78[this issue][neovim-query-precedence] for an example.
56
79
57## Common Issues
80## Common Issues
58
81
59−- If you get errors when building after switching branches, you may have to remove or update tree-sitter submodules. You can update submodules by running
82+- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --fetch-grammars` to fetch the grammars and `hx --build-grammars` to build any out-of-date grammars.
60− ```sh
61− git submodule sync; git submodule update --init
62− ```
63−- Make sure to not use the `--remote` flag. To remove submodules look inside the `.gitmodules` and remove directories that are not present inside of it.
64
83
65−- If a parser is segfaulting or you want to remove the parser, make sure to remove the submodule *and* the compiled parser in `runtime/grammar/<name>.so`
84+- If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/<name>.so`
66
85
67- The indents query is `indents.toml`, *not* `indents.scm`. See [this](https://github.com/helix-editor/helix/issues/114) issue for more information.
86- The indents query is `indents.toml`, *not* `indents.scm`. See [this](https://github.com/helix-editor/helix/issues/114) issue for more information.
68
87
book/src/install.md+7−1
@@ -44,7 +44,7 @@ sudo dnf install helix
44## Build from source
44## Build from source
45
45
46```
46```
47−git clone --recurse-submodules --shallow-submodules -j8 https://github.com/helix-editor/helix
47+git clone https://github.com/helix-editor/helix
48cd helix
48cd helix
49cargo install --path helix-term
49cargo install --path helix-term
50```
50```
@@ -54,3 +54,9 @@ This will install the `hx` binary to `$HOME/.cargo/bin`.
54Helix also needs it's runtime files so make sure to copy/symlink the `runtime/` directory into the
54Helix also needs it's runtime files so make sure to copy/symlink the `runtime/` directory into the
55config directory (for example `~/.config/helix/runtime` on Linux/macOS). This location can be overriden
55config directory (for example `~/.config/helix/runtime` on Linux/macOS). This location can be overriden
56via the `HELIX_RUNTIME` environment variable.
56via the `HELIX_RUNTIME` environment variable.
57+
58+## Building tree-sitter grammars
59+
60+Tree-sitter grammars must be fetched and compiled if not pre-packaged.
61+Fetch grammars with `hx --fetch-grammars` (requires `git`) and compile them
62+with `hx --build-grammars` (requires a C compiler).
book/src/languages.md+19−1
@@ -4,10 +4,28 @@ Language-specific settings and settings for particular language servers can be c
4
4
5Changes made to the `languages.toml` file in a user's [configuration directory](./configuration.md) are merged with helix's defaults on start-up, such that a user's settings will take precedence over defaults in the event of a collision. For example, the default `languages.toml` sets rust's `auto-format` to `true`. If a user wants to disable auto-format, they can change the `languages.toml` in their [configuration directory](./configuration.md) to make the rust entry read like the example below; the new key/value pair `auto-format = false` will override the default when the two sets of settings are merged on start-up:
5Changes made to the `languages.toml` file in a user's [configuration directory](./configuration.md) are merged with helix's defaults on start-up, such that a user's settings will take precedence over defaults in the event of a collision. For example, the default `languages.toml` sets rust's `auto-format` to `true`. If a user wants to disable auto-format, they can change the `languages.toml` in their [configuration directory](./configuration.md) to make the rust entry read like the example below; the new key/value pair `auto-format = false` will override the default when the two sets of settings are merged on start-up:
6
6
7−```
7+```toml
8# in <config_dir>/helix/languages.toml
8# in <config_dir>/helix/languages.toml
9
9
10[[language]]
10[[language]]
11name = "rust"
11name = "rust"
12auto-format = false
12auto-format = false
13```
13```
14+
15+## Tree-sitter grammars
16+
17+Tree-sitter grammars can also be configured in `languages.toml`:
18+
19+```toml
20+# in <config_dir>/helix/languages.toml
21+
22+[[grammar]]
23+name = "rust"
24+source = { git = "https://github.com/tree-sitter/tree-sitter-rust", rev = "a250c4582510ff34767ec3b7dcdd3c24e8c8aa68" }
25+
26+[[grammar]]
27+name = "c"
28+source = { path = "/path/to/tree-sitter-c" }
29+```
30+
31+If a user has a `languages.toml`, only the grammars in that `languages.toml` are evaluated when running `hx --fetch-grammars` and `hx --build-grammars`. Otherwise the [default `languages.toml`](https://github.com/helix-editor/helix/blob/master/languages.toml) is used.
helix-core/src/config.rs+1−1
@@ -25,7 +25,7 @@ pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> {
25pub fn default_syntax_loader() -> crate::syntax::Configuration {
25pub fn default_syntax_loader() -> crate::syntax::Configuration {
26 default_lang_config()
26 default_lang_config()
27 .try_into()
27 .try_into()
28− .expect("Could not serialize built-in language.toml")
28+ .expect("Could not serialize built-in languages.toml")
29}
29}
30/// Syntax configuration loader based on user configured languages.toml.
30/// Syntax configuration loader based on user configured languages.toml.
31pub fn user_syntax_loader() -> Result<crate::syntax::Configuration, toml::de::Error> {
31pub fn user_syntax_loader() -> Result<crate::syntax::Configuration, toml::de::Error> {