@tsrx/language-server 0.6.0 → 0.6.1
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 +87 -15
- package/dist/language-server.js +1 -1
- package/dist/{server-Dn5OWBDY.js → server-BnzVhVsF.js} +2304 -2243
- package/dist/server-BnzVhVsF.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,83 @@ 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.
|
|
51
|
+
2. The project's: `node_modules/typescript` in each open workspace folder and its
|
|
52
|
+
parent folders, the way Node finds a package. The first folder that has one
|
|
53
|
+
wins. When the editor names no folder, the server searches from the folder it
|
|
54
|
+
was started in.
|
|
55
|
+
3. The one next to the server: `node_modules/typescript` from the server's own
|
|
56
|
+
folder up.
|
|
57
|
+
|
|
58
|
+
Any version below 7 works. `typescript` is an optional peer dependency, so npm and
|
|
59
|
+
pnpm do not install one with the server. Install it in the project:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install -D typescript
|
|
63
|
+
# or
|
|
64
|
+
pnpm add -D typescript
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
When the server finds no `typescript`, or finds TypeScript 7, it still starts and
|
|
68
|
+
shows one warning that says what it found and what to do. `.tsrx` files then get
|
|
69
|
+
no type checking, hover or completions. TSRX compile errors, CSS in `<style>`, the
|
|
70
|
+
outline, formatting and closing tags still work.
|
|
71
|
+
|
|
72
|
+
To use another TypeScript than the one it finds, pass that TypeScript's `lib`
|
|
73
|
+
folder:
|
|
74
|
+
|
|
75
|
+
```jsonc
|
|
76
|
+
// LSP initialize params
|
|
77
|
+
{
|
|
78
|
+
"initializationOptions": {
|
|
79
|
+
"typescript": { "tsdk": "/path/to/node_modules/typescript/lib" },
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### TypeScript 7
|
|
85
|
+
|
|
86
|
+
TypeScript 7's npm package is the native compiler and has no JavaScript API, so
|
|
87
|
+
the `classic` backend cannot run it. For `.tsrx` files on TypeScript 7:
|
|
88
|
+
|
|
89
|
+
1. Install TypeScript `7.1.0-dev.20260923.1` or newer and
|
|
90
|
+
[`@tsrx/content-mapper`](https://github.com/tsrx-org/tsrx/tree/main/packages/content-mapper)
|
|
91
|
+
in the project, and declare the mapper in `tsconfig.json`:
|
|
92
|
+
|
|
93
|
+
```jsonc
|
|
94
|
+
{
|
|
95
|
+
"tsrx": { "compiler": "@tsrx/react" },
|
|
96
|
+
"contentMappers": [
|
|
97
|
+
{ "package": "@tsrx/content-mapper", "extensions": [".tsrx"] },
|
|
98
|
+
],
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
2. Have the editor run TypeScript 7's language server, `tsc --lsp --stdio`, for
|
|
103
|
+
`.tsrx` files, with the initialization option `runExternalCode: true`. It
|
|
104
|
+
serves types, hover, completions and errors, TSRX compile errors included.
|
|
105
|
+
3. Run this server next to it with `--typescript-backend=native`, for what
|
|
106
|
+
TypeScript 7 does not do: CSS in `<style>`, the outline, formatting and closing
|
|
107
|
+
tags. It loads no TypeScript in that mode.
|
|
48
108
|
|
|
49
109
|
## TypeScript backends
|
|
50
110
|
|
|
51
111
|
The server runs beside one of two TypeScript backends. Never run both on the same
|
|
52
112
|
file.
|
|
53
113
|
|
|
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).
|
|
114
|
+
- `classic` (default): the server hosts TypeScript itself through Volar and serves
|
|
115
|
+
every feature for `.tsrx` files, including type-aware ones. Which TypeScript it
|
|
116
|
+
hosts: [Which TypeScript it uses](#which-typescript-it-uses).
|
|
61
117
|
- `native`: TypeScript 7 owns every TypeScript feature for `.tsrx` files through
|
|
62
118
|
[`@tsrx/content-mapper`](https://github.com/tsrx-org/tsrx/tree/main/packages/content-mapper)
|
|
63
119
|
(diagnostics including TSRX compile errors, hover, completions, signature help,
|
|
@@ -163,6 +219,22 @@ Other formatters for `.tsrx` files return no edits:
|
|
|
163
219
|
In VS Code, TSRX is the default formatter for `.tsrx` files, so neither gets in
|
|
164
220
|
the way.
|
|
165
221
|
|
|
222
|
+
## Restarts after package changes
|
|
223
|
+
|
|
224
|
+
When a `package.json` or a lockfile changes (`pnpm install`, for example), the
|
|
225
|
+
server must restart to load the TSRX compiler again. By default it exits with code
|
|
226
|
+
0, and the editor must start it again.
|
|
227
|
+
|
|
228
|
+
An editor that can restart the server itself sets the `restartNotification`
|
|
229
|
+
initialization option. The server then sends a `tsrx/restartServer` notification
|
|
230
|
+
and keeps running until the editor stops it (`shutdown`, then `exit`) and starts
|
|
231
|
+
it again. The VS Code extension does this:
|
|
232
|
+
|
|
233
|
+
```jsonc
|
|
234
|
+
// LSP initialize params
|
|
235
|
+
{ "initializationOptions": { "restartNotification": true } }
|
|
236
|
+
```
|
|
237
|
+
|
|
166
238
|
## More
|
|
167
239
|
|
|
168
240
|
See the [TSRX documentation](https://tsrx.dev/) and
|
package/dist/language-server.js
CHANGED