Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'book/src/languages.md')
| -rw-r--r-- | book/src/languages.md | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/book/src/languages.md b/book/src/languages.md index b47c05cf..944ebf09 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -1,4 +1,4 @@ -## Languages +# Languages Language-specific settings and settings for language servers are configured in `languages.toml` files. @@ -13,7 +13,7 @@ There are three possible locations for a `languages.toml` file: 2. In your [configuration directory](./configuration.md). This overrides values from the built-in language configuration. For example, to disable - auto-formatting for Rust: + auto-LSP-formatting in Rust: ```toml # in <config_dir>/helix/languages.toml @@ -42,7 +42,7 @@ name = "mylang" scope = "source.mylang" injection-regex = "mylang" file-types = ["mylang", "myl"] -comment-tokens = "#" +comment-token = "#" indent = { tab-width = 2, unit = " " } formatter = { command = "mylang-formatter" , args = ["--stdin"] } language-servers = [ "mylang-lsp" ] @@ -60,21 +60,16 @@ These configuration keys are available: | `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-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 | +| `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 `unit` (the text inserted into the document when indenting; usually set to N spaces or `"\t"` for tabs) and `tab-width` (the number of spaces rendered for a tab) | | `language-servers` | The Language Servers used for this language. See below for more information in the section [Configuring Language Servers for a language](#configuring-language-servers-for-a-language) | | `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) | -| `formatter` | The formatter for the language, it will take precedence over the lsp when defined. The formatter must be able to take the original file as input from stdin and write the formatted file to stdout. The filename of the current buffer can be passed as argument by using the `%{buffer_name}` expansion variable. See below for more information in the [Configuring the formatter command](#configuring-the-formatter-command) | -| `soft-wrap` | [editor.softwrap](./editor.md#editorsoft-wrap-section) +| `formatter` | The formatter for the language, it will take precedence over the lsp when defined. The formatter must be able to take the original file as input from stdin and write the formatted file to stdout | +| `soft-wrap` | [editor.softwrap](./configuration.md#editorsoft-wrap-section) | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set, defaults to `editor.text-width` | -| `rulers` | Overrides the `editor.rulers` config key for the language. | -| `path-completion` | Overrides the `editor.path-completion` config key for the language. | -| `word-completion` | Overrides the [`editor.word-completion`](./editor.md#editorword-completion-section) configuration for the language. | | `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml`. Overwrites the setting of the same name in `config.toml` if set. | | `persistent-diagnostic-sources` | An array of LSP diagnostic sources assumed unchanged when the language server resends the same set of diagnostics. Helix can track the position for these diagnostics internally instead. Useful for diagnostics that are recomputed on save. -| `rainbow-brackets` | Overrides the `editor.rainbow-brackets` config key for the language | ### File-type detection and the `file-types` key @@ -83,36 +78,24 @@ from the above section. `file-types` is a list of strings or tables, for example: ```toml -file-types = ["toml", { glob = "Makefile" }, { glob = ".git/config" }, { glob = ".github/workflows/*.yaml" } ] +file-types = ["Makefile", "toml", { suffix = ".git/config" }] ``` When determining a language configuration to use, Helix searches the file-types with the following priorities: -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`. - -### Configuring the formatter command - -[Command line expansions](./command-line.md#expansions) are supported in the arguments -of the formatter command. In particular, the `%{buffer_name}` variable can be passed as -argument to the formatter: - -```toml -formatter = { command = "mylang-formatter" , args = ["--stdin", "--stdin-filename", "%{buffer_name}"] } -``` +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. ## Language Server configuration @@ -137,14 +120,13 @@ 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` | Language server 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. | +| 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" }` | 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). @@ -164,8 +146,6 @@ 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. @@ -254,4 +234,4 @@ use-grammars = { except = [ "yaml", "json" ] } When omitted, all grammars are fetched and built. -[treesitter-language-injection]: https://tree-sitter.github.io/tree-sitter/3-syntax-highlighting.html#language-injection +[treesitter-language-injection]: https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection |