@tsrx/language-server 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -15
- package/dist/language-server.js +1 -1
- package/dist/{server-Dn5OWBDY.js → server-y1HvqjeS.js} +2453 -2254
- package/dist/server-y1HvqjeS.js.map +1 -0
- package/dist/server.js +2 -1
- package/package.json +8 -3
- package/types/server.d.ts +6 -0
- package/dist/server-Dn5OWBDY.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,27 +37,85 @@ pnpm dlx @tsrx/language-server --stdio
|
|
|
37
37
|
|
|
38
38
|
Configure your editor's LSP client for `*.tsrx` files with the language ID `tsrx`.
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
## Which TypeScript it uses
|
|
41
|
+
|
|
42
|
+
When the editor does not choose a backend, the server runs the `classic` backend,
|
|
43
|
+
which needs a `typescript` package. On the `native` backend (TypeScript 7) and the
|
|
44
|
+
`plugin` backend (which VS Code uses), it loads no TypeScript and searches for
|
|
45
|
+
none.
|
|
46
|
+
|
|
47
|
+
On the `classic` backend, it uses the first `typescript` it finds:
|
|
48
|
+
|
|
49
|
+
1. The `typescript.tsdk` initialization option, when the editor passes one: the
|
|
50
|
+
`lib` folder of a TypeScript installation. The `typescript` package folder
|
|
51
|
+
above it works too. When the folder does not contain TypeScript, the server
|
|
52
|
+
shows a warning that names the folder, and goes on to the next step.
|
|
53
|
+
2. The project's: `node_modules/typescript` in each open workspace folder and its
|
|
54
|
+
parent folders, the way Node finds a package. The first folder that has one
|
|
55
|
+
wins. When the editor names no folder, the server searches from the folder it
|
|
56
|
+
was started in.
|
|
57
|
+
3. The one next to the server: `node_modules/typescript` from the server's own
|
|
58
|
+
folder up.
|
|
59
|
+
|
|
60
|
+
Any version below 7 works. `typescript` is an optional peer dependency, so npm and
|
|
61
|
+
pnpm do not install one with the server. Install it in the project:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install -D typescript
|
|
65
|
+
# or
|
|
66
|
+
pnpm add -D typescript
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
When the server does not find `typescript`, or finds TypeScript 7, it still starts
|
|
70
|
+
and shows one warning that says what it found and what to do. `.tsrx` files then
|
|
71
|
+
do not get type checking, hover or completions. TSRX compile errors, CSS in
|
|
72
|
+
`<style>`, the outline, formatting and closing tags still work.
|
|
73
|
+
|
|
74
|
+
To use another TypeScript than the one it finds, pass that TypeScript's `lib`
|
|
75
|
+
folder:
|
|
76
|
+
|
|
77
|
+
```jsonc
|
|
78
|
+
// LSP initialize params
|
|
79
|
+
{
|
|
80
|
+
"initializationOptions": {
|
|
81
|
+
"typescript": { "tsdk": "/path/to/node_modules/typescript/lib" },
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### TypeScript 7
|
|
87
|
+
|
|
88
|
+
TypeScript 7's npm package is the native compiler and has no JavaScript API, so
|
|
89
|
+
the `classic` backend cannot run it. For `.tsrx` files on TypeScript 7:
|
|
90
|
+
|
|
91
|
+
1. Install TypeScript `7.1.0-dev.20260923.1` or newer and
|
|
92
|
+
[`@tsrx/content-mapper`](https://github.com/tsrx-org/tsrx/tree/main/packages/content-mapper)
|
|
93
|
+
in the project, and declare the mapper in `tsconfig.json`:
|
|
94
|
+
|
|
95
|
+
```jsonc
|
|
96
|
+
{
|
|
97
|
+
"tsrx": { "compiler": "@tsrx/react" },
|
|
98
|
+
"contentMappers": [
|
|
99
|
+
{ "package": "@tsrx/content-mapper", "extensions": [".tsrx"] },
|
|
100
|
+
],
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
2. Have the editor run TypeScript 7's language server, `tsc --lsp --stdio`, for
|
|
105
|
+
`.tsrx` files, with the initialization option `runExternalCode: true`. It
|
|
106
|
+
serves types, hover, completions and errors, TSRX compile errors included.
|
|
107
|
+
3. Run this server next to it with `--typescript-backend=native`, for what
|
|
108
|
+
TypeScript 7 does not do: CSS in `<style>`, the outline, formatting and closing
|
|
109
|
+
tags. It loads no TypeScript in that mode.
|
|
48
110
|
|
|
49
111
|
## TypeScript backends
|
|
50
112
|
|
|
51
113
|
The server runs beside one of two TypeScript backends. Never run both on the same
|
|
52
114
|
file.
|
|
53
115
|
|
|
54
|
-
- `classic` (default): the server hosts TypeScript
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
initialization option, the absolute path of a TypeScript `lib` directory (the
|
|
58
|
-
one containing `typescript.js`); the VS Code extension passes the TypeScript VS
|
|
59
|
-
Code runs for the workspace. Without the option the server loads the
|
|
60
|
-
`typescript` package resolvable from its own location (the peer dependency).
|
|
116
|
+
- `classic` (default): the server hosts TypeScript itself through Volar and serves
|
|
117
|
+
every feature for `.tsrx` files, including type-aware ones. Which TypeScript it
|
|
118
|
+
hosts: [Which TypeScript it uses](#which-typescript-it-uses).
|
|
61
119
|
- `native`: TypeScript 7 owns every TypeScript feature for `.tsrx` files through
|
|
62
120
|
[`@tsrx/content-mapper`](https://github.com/tsrx-org/tsrx/tree/main/packages/content-mapper)
|
|
63
121
|
(diagnostics including TSRX compile errors, hover, completions, signature help,
|
|
@@ -163,6 +221,60 @@ Other formatters for `.tsrx` files return no edits:
|
|
|
163
221
|
In VS Code, TSRX is the default formatter for `.tsrx` files, so neither gets in
|
|
164
222
|
the way.
|
|
165
223
|
|
|
224
|
+
## Closing tags
|
|
225
|
+
|
|
226
|
+
When you type the `>` that ends an opening tag, the server inserts the closing tag
|
|
227
|
+
after the cursor: `<div>` becomes `<div></div>`. It does not close a void element
|
|
228
|
+
such as `<br>`, a self-closing tag such as `<div />`, or a tag that is already
|
|
229
|
+
closed.
|
|
230
|
+
|
|
231
|
+
Editors ask for the closing tag in one of two ways:
|
|
232
|
+
|
|
233
|
+
- **On-type formatting** (`textDocument/onTypeFormatting`), with `>` as the only
|
|
234
|
+
trigger character. A text edit cannot move the cursor, so the cursor stays
|
|
235
|
+
between the tags only in an editor that keeps it before text inserted at the
|
|
236
|
+
cursor. Zed 1.17 or newer, Neovim and JetBrains IDEs do. The READMEs of the TSRX
|
|
237
|
+
plugins for
|
|
238
|
+
[Zed](https://github.com/tsrx-org/tsrx/tree/main/packages/zed-plugin#closing-tags),
|
|
239
|
+
[Neovim](https://github.com/tsrx-org/tsrx/tree/main/packages/nvim-plugin#closing-tags),
|
|
240
|
+
[Sublime Text](https://github.com/tsrx-org/tsrx/tree/main/packages/sublime-text-plugin#closing-tags)
|
|
241
|
+
and
|
|
242
|
+
[JetBrains IDEs](https://github.com/tsrx-org/tsrx/tree/main/packages/intellij-plugin#closing-tags)
|
|
243
|
+
say what each editor needs.
|
|
244
|
+
- **Volar's `volar/client/autoInsert` request**, which the VS Code extension
|
|
245
|
+
sends. The server answers with a snippet (`$0</div>`) that puts the cursor
|
|
246
|
+
between the tags.
|
|
247
|
+
|
|
248
|
+
To turn closing tags off, set `tsrx.autoClosingTags.enabled` to `false`. The
|
|
249
|
+
server reads it through `workspace/configuration`.
|
|
250
|
+
|
|
251
|
+
An editor that closes tags another way sets the `closeTagsOnType` initialization
|
|
252
|
+
option to `false`. The server then offers no on-type formatting, so the editor
|
|
253
|
+
does not get a second closing tag. The VS Code extension does this, because VS
|
|
254
|
+
Code's TypeScript closes the tags, or on TypeScript 7 the extension sends
|
|
255
|
+
`volar/client/autoInsert`:
|
|
256
|
+
|
|
257
|
+
```jsonc
|
|
258
|
+
// LSP initialize params
|
|
259
|
+
{ "initializationOptions": { "closeTagsOnType": false } }
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Restarts after package changes
|
|
263
|
+
|
|
264
|
+
When a `package.json` or a lockfile changes (`pnpm install`, for example), the
|
|
265
|
+
server must restart to load the TSRX compiler again. By default it exits with code
|
|
266
|
+
0, and the editor must start it again.
|
|
267
|
+
|
|
268
|
+
An editor that can restart the server itself sets the `restartNotification`
|
|
269
|
+
initialization option. The server then sends a `tsrx/restartServer` notification
|
|
270
|
+
and keeps running until the editor stops it (`shutdown`, then `exit`) and starts
|
|
271
|
+
it again. The VS Code extension does this:
|
|
272
|
+
|
|
273
|
+
```jsonc
|
|
274
|
+
// LSP initialize params
|
|
275
|
+
{ "initializationOptions": { "restartNotification": true } }
|
|
276
|
+
```
|
|
277
|
+
|
|
166
278
|
## More
|
|
167
279
|
|
|
168
280
|
See the [TSRX documentation](https://tsrx.dev/) and
|
package/dist/language-server.js
CHANGED