From 0ad10ce6f7159bc857eef1445a6c5cc28ae6a249 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 20 Jun 2022 18:15:50 -0500 Subject: rewrite language configuration docs (#2838) This change moves the configuration tables from the Adding Languages guide into the overall Languages section. It also adds more detailed documentation on the `language-server` configuration key and fixes a typo in the "mylang" example (the scope was `scope.mylang` instead of `source.mylang`).--- book/src/guides/adding_languages.md | 67 ++++--------------------------------- 1 file changed, 7 insertions(+), 60 deletions(-) (limited to 'book/src/guides') diff --git a/book/src/guides/adding_languages.md b/book/src/guides/adding_languages.md index 0cd6c27b..5be7a264 100644 --- a/book/src/guides/adding_languages.md +++ b/book/src/guides/adding_languages.md @@ -2,40 +2,8 @@ ## Language configuration -To add a new language, you need to add a `language` entry to the -[`languages.toml`][languages.toml] found in the root of the repository; -this `languages.toml` file is included at compilation time, and is -distinct from the `languages.toml` file in the user's [configuration -directory](../configuration.md). - -```toml -[[language]] -name = "mylang" -scope = "scope.mylang" -injection-regex = "^mylang$" -file-types = ["mylang", "myl"] -comment-token = "#" -indent = { tab-width = 2, unit = " " } -language-server = { command = "mylang-lsp", args = ["--stdio"] } -``` - -These are the available keys and descriptions for the file. - -| Key | Description | -| ---- | ----------- | -| `name` | The name of the language | -| `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.` or `text.` in case of markup languages | -| `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. | -| `file-types` | The filetypes of the language, for example `["yml", "yaml"]`. Extensions and full file names are supported. | -| `shebangs` | The interpreters from the shebang line, for example `["sh", "bash"]` | -| `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 | -| `indent` | The indent to use. Has sub keys `tab-width` and `unit` | -| `language-server` | The Language Server to run. Has sub keys `command` and `args` | -| `config` | Language Server configuration | -| `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) | +To add a new language, you need to add a `[[language]]` entry to the +`languages.toml` (see the [language configuration section]). When adding a new language or Language Server configuration for an existing language, run `cargo xtask docgen` to add the new configuration to the @@ -45,32 +13,12 @@ When adding a Language Server configuration, be sure to update the ## Grammar configuration -If a tree-sitter grammar is available for the language, add a new `grammar` +If a tree-sitter grammar is available for the language, add a new `[[grammar]]` entry to `languages.toml`. -```toml -[[grammar]] -name = "mylang" -source = { git = "https://github.com/example/mylang", rev = "a250c4582510ff34767ec3b7dcdd3c24e8c8aa68" } -``` - -Grammar configuration takes these keys: - -| Key | Description | -| --- | ----------- | -| `name` | The name of the tree-sitter grammar | -| `source` | The method of fetching the grammar - a table with a schema defined below | - -Where `source` is a table with either these keys when using a grammar from a -git repository: - -| Key | Description | -| --- | ----------- | -| `git` | A git remote URL from which the grammar should be cloned | -| `rev` | The revision (commit hash or tag) which should be fetched | -| `subpath` | 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 --grammar build` to the correct path for compilation. When omitted, the root of repository is used | - -Or a `path` key with an absolute path to a locally available grammar directory. +You may use the `source.path` key rather than `source.git` with an absolute path +to a locally available grammar for testing, but switch to `source.git` before +submitting a pull request. ## Queries @@ -91,8 +39,7 @@ the last matching query supersedes the ones before it. See - If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/.so` -[treesitter-language-injection]: https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection -[languages.toml]: https://github.com/helix-editor/helix/blob/master/languages.toml +[language configuration section]: ../languages.md [neovim-query-precedence]: https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090 [install-lsp-wiki]: https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers [lang-support]: ../lang-support.md -- cgit v1.2.3-70-g09d2 From 67f6c85792dbdbe0ff3f9328874c7ab23ff5569b Mon Sep 17 00:00:00 2001 From: Connor Lay (Clay) Date: Sat, 18 Jun 2022 14:24:01 -0700 Subject: text-objects: add test capture & elixir queries --- book/src/guides/textobject.md | 2 ++ book/src/keymap.md | 2 ++ book/src/usage.md | 1 + helix-term/src/commands.rs | 12 ++++++++++++ helix-term/src/keymap/default.rs | 2 ++ runtime/queries/elixir/textobjects.scm | 8 +++++++- 6 files changed, 26 insertions(+), 1 deletion(-) (limited to 'book/src/guides') diff --git a/book/src/guides/textobject.md b/book/src/guides/textobject.md index cccd4bbf..8a217354 100644 --- a/book/src/guides/textobject.md +++ b/book/src/guides/textobject.md @@ -20,6 +20,8 @@ The following [captures][tree-sitter-captures] are recognized: | `function.around` | | `class.inside` | | `class.around` | +| `test.inside` | +| `test.around` | | `parameter.inside` | | `comment.inside` | | `comment.around` | diff --git a/book/src/keymap.md b/book/src/keymap.md index fef76efb..7efbdd23 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -282,6 +282,8 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire | `[a` | Go to previous argument/parameter (**TS**) | `goto_prev_parameter` | | `]o` | Go to next comment (**TS**) | `goto_next_comment` | | `[o` | Go to previous comment (**TS**) | `goto_prev_comment` | +| `]t` | Go to next test (**TS**) | `goto_next_test` | +| `]t` | Go to previous test (**TS**) | `goto_prev_test` | | `]p` | Go to next paragraph | `goto_next_paragraph` | | `[p` | Go to previous paragraph | `goto_prev_paragraph` | | `[space` | Add newline above | `add_newline_above` | diff --git a/book/src/usage.md b/book/src/usage.md index ad21a94c..ba631b62 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -143,6 +143,7 @@ Currently supported: `word`, `surround`, `function`, `class`, `parameter`. | `c` | Class | | `a` | Argument/parameter | | `o` | Comment | +| `t` | Test | > NOTE: `f`, `c`, etc need a tree-sitter grammar active for the current document and a special tree-sitter query file to work properly. [Only diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c9c8e6a9..046351a3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -395,6 +395,8 @@ impl MappableCommand { goto_prev_parameter, "Goto previous parameter", goto_next_comment, "Goto next comment", goto_prev_comment, "Goto previous comment", + goto_next_test, "Goto next test", + goto_prev_test, "Goto previous test", goto_next_paragraph, "Goto next paragraph", goto_prev_paragraph, "Goto previous paragraph", dap_launch, "Launch debug target", @@ -4098,6 +4100,14 @@ fn goto_prev_comment(cx: &mut Context) { goto_ts_object_impl(cx, "comment", Direction::Backward) } +fn goto_next_test(cx: &mut Context) { + goto_ts_object_impl(cx, "test", Direction::Forward) +} + +fn goto_prev_test(cx: &mut Context) { + goto_ts_object_impl(cx, "test", Direction::Backward) +} + fn select_textobject_around(cx: &mut Context) { select_textobject(cx, textobject::TextObject::Around); } @@ -4141,6 +4151,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { 'f' => textobject_treesitter("function", range), 'a' => textobject_treesitter("parameter", range), 'o' => textobject_treesitter("comment", range), + 't' => textobject_treesitter("test", range), 'p' => textobject::textobject_paragraph(text, range, objtype, count), 'm' => textobject::textobject_surround_closest(text, range, objtype, count), // TODO: cancel new ranges if inconsistent surround matches across lines @@ -4170,6 +4181,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { ("f", "Function (tree-sitter)"), ("a", "Argument/parameter (tree-sitter)"), ("o", "Comment (tree-sitter)"), + ("t", "Test (tree-sitter)"), ("m", "Matching delimiter under cursor"), (" ", "... or any character acting as a pair"), ]; diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 0f0b09dd..c3695117 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -104,6 +104,7 @@ pub fn default() -> HashMap { "c" => goto_prev_class, "a" => goto_prev_parameter, "o" => goto_prev_comment, + "t" => goto_prev_test, "p" => goto_prev_paragraph, "space" => add_newline_above, }, @@ -114,6 +115,7 @@ pub fn default() -> HashMap { "c" => goto_next_class, "a" => goto_next_parameter, "o" => goto_next_comment, + "t" => goto_next_test, "p" => goto_next_paragraph, "space" => add_newline_below, }, diff --git a/runtime/queries/elixir/textobjects.scm b/runtime/queries/elixir/textobjects.scm index 52a6f66d..227a52f4 100644 --- a/runtime/queries/elixir/textobjects.scm +++ b/runtime/queries/elixir/textobjects.scm @@ -16,7 +16,7 @@ (pair value: (_) @function.inside))?)? (do_block (_)* @function.inside)?) - (#match? @_keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp|test|describe|setup)$")) @function.around + (#match? @_keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) @function.around (anonymous_function (stab_clause right: (body) @function.inside)) @function.around @@ -25,3 +25,9 @@ target: (identifier) @_keyword (do_block (_)* @class.inside)) (#match? @_keyword "^(defmodule|defprotocol|defimpl)$")) @class.around + +((call + target: (identifier) @_keyword + (arguments ((string) . (_)?)) + (do_block (_)* @test.inside)?) + (#match? @_keyword "^(test|describe)$")) @test.around -- cgit v1.2.3-70-g09d2