Repository navigation
refactor(lsp): move Deno detection out of the editor and into a plugin - #3168
Conversation
|
I don't believe that one is this PR's, for three reasons:
So this reads as the runner-load flake this repo already has rather than something to fix here, and there is no existing fix to port. I have not touched the test: making it robust would mean changing timing constants in remote-channel code this PR has no business in, and skipping or quarantining it is not on the table. What I can say against the alternative: this PR does add ~15s of test time to a ~1060s suite, so it is not literally load-neutral. If a re-run comes back red on the same test I will treat it as this PR's and dig into it properly rather than re-running again. Re-running the failed job now (my one re-run — the first attempt was refused while the sibling macOS/Windows jobs were still in flight). Generated by Claude Code |
e7b88b4 to
de68fe3
Compare
`configure_lsp_servers` hard-coded one project convention — a root with a `deno.json` or `deno.jsonc` is served by `deno lsp` — into window construction. That is a claim about projects, not about the editor: it cannot be turned off, inspected or replaced without a rebuild, and every further convention costs another branch in code whose job is wiring a manager. #3111 had to add its runtime check inside that same block. It is now `plugins/deno_lsp.ts`, which switches JavaScript and TypeScript to `deno lsp` when the active window's root has the marker file and `deno` is on PATH, puts back what was configured before when a window without one becomes active, and caches its decision per root. `configure_lsp_servers` loses the block, its `root` parameter and the `Path`/`env` imports. A language the user turned off is left alone in both directions: the "Disable" rows persist `enabled: false`, and `registerLspServer` can only register an enabled server, so touching such a language would turn it back on. The core version replaced the entry regardless. Two differences from the core version, both noted in the plugin: the choice follows the active window rather than being fixed per window root, and it lands when the plugin loads, so an already-spawned server keeps its command until restarted (JS/TS are `auto_start: false` by default). Tests drive the real plugin through the harness: a Deno project with the runtime installed switches both languages, one without it keeps the configured server (#2981), a project with no marker file is untouched, a disabled language is neither switched nor re-enabled, and leaving a Deno project for a plain one restores the configured server. They pin the process globals, since `PATH` is one and these run as threads of one binary. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01SHsuKyMdSZ7soeFzDziRNw
de68fe3 to
776d7ff
Compare
Follow-up to #2981, on top of #3111. The runtime check it added is kept; what changes is where the convention lives, and what it leaves alone.
Before / after
Setup for all of these: a project with
package.json,index.tsandgit init, workspace trusted,typescript-language-serveronPATH. JS/TS areauto_start: false, so start the server withCtrl+P → Start/Restart LSP Server.A
deno.jsonin a project without Deno (#2981, kept from #3111)deno.jsoncto the project. Do not installdeno.index.ts, start the LSP.LSP (error), nothing spawned; both languages lost to a server that cannot starttypescript-language-server --stdiospawned,LSP (on)With
denoinstalled the same steps spawndeno lsp, as before.TypeScript the user disabled
lsp.typescripttoenabled: false(or pick "Disable LSP for typescript" in the LSP Servers popup once).deno.jsonc, installdeno, openindex.ts,Ctrl+P → Show LSP Status.deno lsp, enabled — the user's disable is undonetypescript-language-server, still disabled (popup offers "Enable LSP for typescript"); JavaScript, still enabled, switches todenoLeaving a Deno project
deno.jsonc,denoinstalled) →deno lsp.Ctrl+P → Switch Projectto a plain npm project, open itsindex.ts, start the LSP.typescript-language-serverwithrootUri= the new root; a language disabled inside the Deno project stays disabledWhy
configure_lsp_servershard-coded one project convention — a root holding adeno.jsonordeno.jsoncis served bydeno lsp— into window construction. That is a claim about projects, not about the editor: it cannot be turned off, inspected or replaced without a rebuild, every further convention costs another branch in a function whose job is wiring a manager, and #2981 had to fix it by adding the runtime check inside that same block.What this does
The block is gone, and so is
configure_lsp_servers'rootparameter — nothing else in it used the root. The convention isplugins/deno_lsp.ts, which:deno lspwhen the active window's root has adeno.json/deno.jsoncanddenois onPATH— the bug: LSP is switched to deno when a deno.json(c) is found whether deno is available or not #2981 condition, unchanged in meaning;Disable the plugin and the behaviour is gone; copy it and Fresh learns the same trick for another runtime.
What it leaves alone
A language the user has turned off stays off, in both directions. The "Disable LSP for …" rows persist
enabled: false;registerLspServercan only register an enabled server, so touching such a language would switch it back on. A user who configureddeno lspthemselves is likewise left with it, runtime present or not.Two differences from the core version
window_created,active_window_changed,buffer_activated) rather than being fixed per window root at construction.auto_start: falseby default, so nothing has started that early.Open question: the switch can be persisted
registerLspServerwrites into the runtime config as well as the window's manager (the core version touched only the manager), andsave_to_layersaves the runtime config's delta against the lower layers. So any config save while a Deno project is active — the LSP popup's Disable/Enable rows, a settings toggle — writesjavascript/typescript = deno lspinto the user'sconfig.json, where it survives leaving the project and the next launch. I reproduced this: after "Disable LSP for typescript" in a Deno project, the user config helddenofor both languages and a plain project auto-starteddenofor JavaScript.I have not changed that here because it is the API's contract, and
rust-lsp.tsrelies on it (its full/reduced-memory choice is meant to persist). Two ways out, and which one is a design call:setLspServerOverride(language, config | null)or similar): applied to every window's manager and to new windows, never written to the config. This plugin would then need no baseline at all — restore is "clear the override". It also fixes the same leak for language packs, whose servers currently land in the user's config on the next save.I'd take (1) if you agree; say the word and I'll do it in this PR or a follow-up.
Tests
tests/e2e/deno_lsp_plugin.rsdrives the real plugin through the harness with a stubdenoonPATH: a Deno project with the runtime switches both languages, one without it keeps its configured server (#2981), a project with no marker file is untouched, a disabled language is neither switched nor re-enabled, and leaving a Deno project (create_window_at+set_active_window) restores the configured server. They takepin_config_globals()sincePATHis a process global. I checked the positive case fails when the plugin's decision is neutered, so it tests the plugin rather than the default config.Verified interactively as well (tmux, real keystrokes, logging stubs for both servers): the eight combinations of marker file × runtime installed × user-configured
deno lsp, the disabled-language cases above, and Switch Project in both directions with and without the runtime.Two harness findings, both handled in the plugin:
plugins_loadedis not delivered in every embedding (the first evaluation happens at module load), andeditor.getEnvanswersundefinedfor an unset variable — a!== nullcheck onPATHEXTreads as Windows on Linux and splitsPATHon the wrong separator.cargo fmt --check,cargo check/clippy -p fresh-editor --all-targetsand the new tests are clean locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01SHsuKyMdSZ7soeFzDziRNw