Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tooling/rx-language-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ node bin/server.js --stdio
```

`initializationOptions: { typescript: { tsdk } }` picks TypeScript's `lib`
folder; without it, the server uses its own `typescript`.
folder; without it, the server uses the nearest `node_modules/typescript` at or
above a workspace folder, else its own `typescript`.

## Type-checking from the command line

Expand Down
23 changes: 21 additions & 2 deletions tooling/rx-language-server/bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@
// The .rx language server over stdio (or whatever transport the client asks for): Volar's TypeScript project with the
// .rx language plugin, TypeScript's services, and the crate's diagnostics.
const { createConnection, createServer, createTypeScriptProject, loadTsdkByPath } = require("@volar/language-server/node");
const fs = require("node:fs");
const path = require("node:path");
const { fileURLToPath } = require("node:url");
const { create: createTypeScriptServices } = require("volar-service-typescript");
const { rxLanguagePlugin, rxDiagnostics } = require("../src/index.js");

/** TypeScript's lib folder: the client's, else the nearest `node_modules/typescript` at or above a workspace folder
* (a hoisted workspace's), else our own. Walks the folders itself: require.resolve would also try global folders. */
function tsdkFor(params) {
const given = params.initializationOptions?.typescript?.tsdk;
if (given) return given;
const folders = params.workspaceFolders?.map(f => f.uri) ?? (params.rootUri ? [params.rootUri] : []);
for (const uri of folders) {
if (!uri.startsWith("file:")) continue;
for (let dir = fileURLToPath(uri); ; dir = path.dirname(dir)) {
const lib = path.join(dir, "node_modules", "typescript", "lib");
if (fs.existsSync(path.join(lib, "typescript.js"))) return lib;
if (path.dirname(dir) === dir) break;
}
}
return path.dirname(require.resolve("typescript"));
}

const connection = createConnection();
const server = createServer(connection);

connection.listen();

connection.onInitialize(params => {
const tsdkPath = params.initializationOptions?.typescript?.tsdk ?? require("node:path").dirname(require.resolve("typescript"));
const tsdk = loadTsdkByPath(tsdkPath, params.locale);
const tsdk = loadTsdkByPath(tsdkFor(params), params.locale);
return server.initialize(
params,
createTypeScriptProject(tsdk.typescript, tsdk.diagnosticMessages, () => ({ languagePlugins: [rxLanguagePlugin(tsdk.typescript)] })),
Expand Down
8 changes: 5 additions & 3 deletions tooling/zed-rx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ with Zed's Node over stdio.
The project needs a `tsconfig.json` with Solid's JSX (`"jsx": "preserve"`,
`"jsxImportSource": "@solidjs/web"`) and `@solidjs/web` in its `node_modules`;
the server writes the projection's prelude to `node_modules/.reactivescript/`.
It uses the worktree's `node_modules/typescript`, else its own TypeScript.
It uses the worktree's `node_modules/typescript`, else the nearest one above the
worktree (a server newer than 0.3.1 looks), else the server's own TypeScript.

## Installing as a dev extension

Expand Down Expand Up @@ -79,8 +80,9 @@ All under `lsp.rx-language-server` in Zed's `settings.json`:
- `settings.rxc.path`: an `rxc` binary for the server to run per request
instead of its bundled WebAssembly build (sets `RXC`).
- `settings.typescript.tsdk`: TypeScript's `lib` folder. Unset: the worktree's
`node_modules/typescript/lib` if there is one (the worktree root only, not a
parent workspace's), else the server's own.
`node_modules/typescript/lib` if there is one, else the nearest one above the
worktree, such as a hoisted workspace's (the server looks, from the release
after 0.3.1), else the server's own.
- `initialization_options`: merged over what the extension sends
(`{ "typescript": { "tsdk": … } }`).

Expand Down
Loading