Skip to content

Commit d866093

Browse files
committed
Updated the adding languages documentation to reflect the changes for multiple language servers
1 parent 8f0c2fd commit d866093

File tree

1 file changed

+71
-4
lines changed

1 file changed

+71
-4
lines changed

book/src/guides/adding_languages.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ injection-regex = "^mylang$"
1616
file-types = ["mylang", "myl"]
1717
comment-token = "#"
1818
indent = { tab-width = 2, unit = " " }
19-
language-server = { command = "mylang-lsp", args = ["--stdio"] }
19+
language-servers = [ "mylang-lsp" ]
2020
```
2121

22-
These are the available keys and descriptions for the file.
22+
These are the available keys and descriptions for a language.
2323

2424
| Key | Description |
2525
| ---- | ----------- |
2626
| `name` | The name of the language |
27+
| `language-id` | 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 |
2728
| `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 |
2829
| `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. |
2930
| `file-types` | The filetypes of the language, for example `["yml", "yaml"]`. Extensions and full file names are supported. |
@@ -33,10 +34,76 @@ These are the available keys and descriptions for the file.
3334
| `diagnostic-severity` | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) |
3435
| `comment-token` | The token to use as a comment-token |
3536
| `indent` | The indent to use. Has sub keys `tab-width` and `unit` |
36-
| `language-server` | The Language Server to run. Has sub keys `command` and `args` |
37-
| `config` | Language Server configuration |
37+
| `language-servers` | The Language Servers used for this language. See below for more information |
3838
| `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) |
3939

40+
41+
In case multiple language servers are specified, it's often useful to only enable certain language-server features for these language servers.
42+
For example `efm-lsp-prettier` (see in the next section for an example configuration for typescript) is used only with a formatting command `prettier`
43+
but everything else should be handled by the `typescript-language-server` (configured by default)
44+
The language configuration for typescript could look like this:
45+
46+
```toml
47+
[[language]]
48+
name = "typescript"
49+
language-servers = [ { name = "efm-lsp-prettier", only-features = [ "format" ] }, "typescript-language-server" ]
50+
```
51+
52+
or equivalent:
53+
54+
```toml
55+
[[language]]
56+
name = "typescript"
57+
language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "efm-lsp-prettier" ]
58+
```
59+
60+
Each requested LSP feature is priorized in the order of the `language-servers` array.
61+
62+
The list of supported features are:
63+
64+
- `format`
65+
- `goto-definition`
66+
- `goto-type-definition`
67+
- `goto-reference`
68+
- `goto-implementation`
69+
- `signature-help`
70+
- `hover`
71+
- `completion`
72+
- `code-action`
73+
- `document-symbols`
74+
- `workspace-symbols`
75+
- `diagnostics`
76+
- `rename-symbol`
77+
78+
79+
### Language server configuration
80+
81+
Language servers are configured separately in the table `language-server` in the same file as the languages [`languages.toml`][languages.toml]
82+
83+
84+
```toml
85+
[langauge-server.mylang-lsp]
86+
command = "mylang-lsp"
87+
args = ["--stdio"]
88+
config = { provideFormatter = true }
89+
90+
[language-server.efm-lsp-prettier]
91+
command = "efm-langserver"
92+
93+
[language-server.efm-lsp-prettier.config]
94+
documentFormatting = true
95+
languages = { typescript = [ { formatCommand ="prettier --stdin-filepath ${INPUT}", formatStdin = true } ] }
96+
```
97+
98+
These are the available keys and descriptions for a language server.
99+
100+
| Key | Description |
101+
| ---- | ----------- |
102+
| `command` | The command for the language server |
103+
| `args` | Arguments for the command |
104+
| `config` | Language Server configuration |
105+
| `timeout` | Timeout in seconds (default 20) for requests to the language server |
106+
40107
When adding a new language or Language Server configuration for an existing
41108
language, run `cargo xtask docgen` to add the new configuration to the
42109
[Language Support][lang-support] docs before creating a pull request.

0 commit comments

Comments
 (0)