Skip to content

Restart the language server on config changes after a failed start - #2257

Merged
webpro merged 2 commits into
webpro-nl:mainfrom
fixfon:fix/2255-ls-restart-after-failed-start
Oct 30, 2026
Merged

webpro merged 2 commits into
webpro-nl:mainfrom
fixfon:fix/2255-ls-restart-after-failed-start

Conversation

@fixfon

@fixfon fixfon commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #2255

If the language server fails to start (for example because of a broken knip.json), fixing the config didn't restart it. handleFileChanges returned early whenever there was no session, so the change was ignored until a manual restart.

Now a failed start() records the current revision. When knip.json or package.json changes and there's no session, the server restarts only if the last start failed at that revision. A server that was stopped explicitly bumps the revision, so it stays stopped.

Added tests in lifecycle.test.js for both config files and for the stopped-after-failure case.

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@2257
npm i https://pkg.pr.new/@knip/language-server@2257
npm i https://pkg.pr.new/@knip/mcp@2257

commit: 8d5e391

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! The premise checks out over the real server: after a failed start, base ignores every file change until a manual restart, and this branch starts again on the next config change. Tracking the failed start's revision is the right shape: falling through the early return would also start after knip.stop and before a deferred first start, and the monotonic revision needs no resets. The lifecycle tests fail without the change for the intended reason.

Optional: a test for a source-only change after a failed start (one createOptions call, one logged error) would pin the !session guard in handleFileChanges, which no current test catches when removed.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at the new head: the added lifecycle test pins the !session guard and the restart-only trigger.

@webpro
webpro merged commit f7db448 into webpro-nl:main Oct 30, 2026
32 checks passed
@webpro

webpro commented Oct 31, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.44.1. See Release 6.44.1 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

🐛 Language server never recovers when the config was invalid at startup

2 participants