Skip to content

feat(intellij-plugin): choose the TypeScript the language server runs (#1009) - #1012

Merged
leonidaz merged 2 commits into
mainfrom
fix/intellij-tsdk-1009
Oct 3, 2026
Merged

leonidaz merged 2 commits into
mainfrom
fix/intellij-tsdk-1009

Conversation

@leonidaz

@leonidaz leonidaz commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1009

What you see

JetBrains IDEs with the LSP module (WebStorm, IntelliJ IDEA Ultimate, …) get a new settings page:

Settings → Languages & Frameworks → TSRX

TypeScript lib folder: [ /Users/me/ts6/node_modules/typescript/lib ] [Browse]
  The lib folder of the TypeScript the language server runs, for example
  node_modules/typescript/lib. A relative path starts at the project folder.
  Leave it empty to use the project's typescript.

What the plugin sends to @tsrx/language-server in initialize:

Setting initializationOptions
empty (the default) none, as before: the server finds the project's typescript itself
/Users/me/ts6/node_modules/typescript/lib { "typescript": { "tsdk": "/Users/me/ts6/node_modules/typescript/lib" } }
node_modules/typescript/lib (project at /work/app) { "typescript": { "tsdk": "/work/app/node_modules/typescript/lib" } }
../ts6/lib (project at /work/app) { "typescript": { "tsdk": "/work/ts6/lib" } }

When you press Apply or OK and the value changed, the TSRX server for that project restarts, so the new TypeScript is used right away. Applying the same value again does not restart it.

Design

  • Setting: a project-level PersistentStateComponent (TsrxSettings, a SimplePersistentStateComponent with a BaseState), saved in .idea/tsrx.xml. The value is trimmed; an empty value is stored as nothing. After Apply, the field shows the saved (trimmed) value.
  • Settings page: TsrxSettingsConfigurable, a Kotlin UI DSL BoundConfigurable with a folder chooser (FileChooserDescriptorFactory.singleDir()), under parentId="language", nonDefaultProject="true".
  • Where it is registered: both are in tsrx-lsp.xml (loaded only through tsrx-ultimate.xml when the IDE has the Ultimate and LSP modules), not in plugin.xml. Syntax-only IDEs load neither class and show no page that would do nothing. TsrxPluginPackagingTest now checks this.
  • Relative paths: the server resolves tsdk with path.resolve(tsdk), that is against its own working directory. The plugin starts it in serverInfo.root, the nearest folder with package.json, pnpm-workspace.yaml or .git above the .tsrx file that started it, which can be a sub-package in a monorepo. So the plugin resolves a relative setting against project.basePath first and always sends an absolute, normalized path. With no project folder, a relative setting is dropped (no options sent).
  • Restart: TsrxSettingsConfigurable.apply() compares the value before and after and calls LspServerManager.stopAndRestartIfNeeded(TsrxLspServerSupportProvider::class.java). That call was already used after the managed server install; it is now one helper, restartTsrxLanguageServer, used in both places. The restart builds a new TsrxLspServerDescriptor, whose createInitializationOptions() reads the current setting.
  • Server side: no change. resolve_typescript_tsdk in backend.js reads initializationOptions.typescript.tsdk, which is exactly what is sent. The server's warning says to "set the typescript.tsdk startup option"; the README now says the IntelliJ setting passes the folder as that option.

Docs and changeset

  • packages/intellij-plugin/README.md: the "Which TypeScript the language server uses" section now explains the setting (where it is, an example, relative paths, restart, where it is saved), in place of the "no setting yet" note.
  • .changeset/intellij-plugin-typescript-lib.md: patch for @tsrx/intellij-plugin.

Validation

Locally (macOS, Gradle 9.0.0 on Temurin 25):

  • packages/intellij-plugin/gradlew -p packages/intellij-plugin test verifyPluginProjectConfiguration buildPlugin verifyPluginStructure verifyPlugin: build successful, 65 tests, 0 failures. Plugin Verifier: Plugin tsrx.intellij-plugin:0.0.86 against WS-252.27397.92: Compatible, with no deprecated, experimental or internal API usages reported.
    • New TsrxInitializationOptionsTest: empty and blank setting → no options; absolute path; relative path → resolved against the project folder (including ./…/ and ../…); relative path without a project folder → no options; whitespace trimmed.
    • New in TsrxLspIntegrationTest: the descriptor sends options only when the project setting is set; the settings page restarts the server once per real change, not when nothing changed or only spaces were added, and shows the trimmed value after Apply.
  • pnpm test --project intellij-plugin: 11 passed.
  • pnpm changeset:check and pnpm format: clean.

Not done: a manual check in a running IDE (runIde). The page, its folder chooser and the restart are covered only by the tests above.

Related finding

If the setting names a folder with no TypeScript in it (for example the typescript package folder instead of its lib folder), the server skips it and uses the project's typescript without a warning. That is server behavior, so it is filed separately as #1013 and not changed here.

🤖 Generated with Claude Code


Note

Low Risk
IDE configuration and LSP startup options only; no changes to server auth, data handling, or core compile paths beyond which TypeScript SDK is selected.

Overview
Adds a project-level Settings → Languages & Frameworks → TSRX page with TypeScript lib folder, persisted in .idea/tsrx.xml. When set, the plugin sends LSP initializationOptions as { "typescript": { "tsdk": "<absolute lib path>" } } so @tsrx/language-server can run a different TypeScript (e.g. TS 6 while the project uses TS 7). Empty value keeps the previous behavior (server discovers the project’s typescript).

Relative paths are resolved against the project folder before startup (so monorepo package roots don’t mis-resolve tsdk). Applying a changed setting—or finishing a managed server install—restarts the TSRX LSP via a shared restartTsrxLanguageServer helper. Settings and the configurable register only in tsrx-lsp.xml (LSP-capable IDEs). README and a patch changeset document the feature; unit/integration tests cover path resolution, init options, restart-on-apply, and packaging.

Reviewed by Cursor Bugbot for commit c8f3a2a. Bugbot is set up for automated code reviews on this repo. Configure here.

leonidaz and others added 2 commits October 2, 2026 19:31
…#1009)

Add a per-project "TypeScript lib folder" setting under Settings →
Languages & Frameworks → TSRX. When it is set, the plugin starts
@tsrx/language-server with { "typescript": { "tsdk": "<path>" } } as
initialization options; a relative path is resolved against the project
folder first. Applying a change restarts the TSRX server. The service and
settings page are registered in tsrx-lsp.xml, so syntax-only IDEs do not
load them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The setting is saved trimmed. Reset the page after Apply so the field
shows the saved value and the page is no longer marked as modified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intellij-plugin: no way to choose the TypeScript @tsrx/language-server runs (typescript.tsdk)

1 participant