Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Allow LSP server to use builtin watcher on Windows and macOS - #4288

Merged
Andrew Branch (andrewbranch) merged 4 commits into
microsoft:mainfrom
andrewbranch:lsp-builtin-watcher-base
Jun 12, 2026
Merged

Andrew Branch (andrewbranch) merged 4 commits into
microsoft:mainfrom
andrewbranch:lsp-builtin-watcher-base

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

You can't yet opt into this, and won't enable at all outside of Windows and macOS, because the work to make the backends that require marking every directory in a tree work efficiently is a lot bigger, and I've extracted into a separate branch that we can look into when less crunched for time.

Adds an in-process file watcher (lspwatcher) that the LSP server uses
instead of LSP-based file watching when the client lacks dynamic watch
registration, or when the useBuiltinWatcher initialization option is set.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 11, 2026 22:07
Comment thread internal/fswatch/watcher.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an in-process (“builtin”) file watching fallback for the TypeScript-Go LSP server on platforms where recursive watching is efficient (Windows and macOS/FSEvents), so the server can still receive workspace/didChangeWatchedFiles-shaped events even when the LSP client lacks dynamic watch registration.

Changes:

  • Enable builtin watcher fallback in internal/lsp/server.go when the client lacks dynamic workspace/didChangeWatchedFiles registration and the default fswatch backend is fast-recursive.
  • Introduce internal/lsp/lspwatcher to translate fswatch events into LSP FileEvent batches, including logic for missing directories and recovery after directory deletion.
  • Add fswatch.DefaultHasFastRecursiveBackend() helpers and comprehensive unit tests for the new watcher behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/lsp/server.go Selects between client-driven watching and builtin in-process watching; wires builtin watcher into session change notifications and shutdown.
internal/lsp/lspwatcher/lspwatcher.go New in-process watcher implementation that maps fswatch subscriptions to LSP watcher registrations and batches events.
internal/lsp/lspwatcher/lspwatcher_test.go Tests covering event forwarding, kind filtering, missing-directory promotion, termination recovery, and rollback behavior.
internal/fswatch/watcher.go Adds helpers to detect whether the default watcher backend supports efficient recursive watching.

Comment thread internal/lsp/lspwatcher/lspwatcher.go Resolved
Comment thread internal/lsp/lspwatcher/lspwatcher.go Resolved
@andrewbranch
Andrew Branch (andrewbranch) added this pull request to the merge queue Jun 12, 2026
Merged via the queue into microsoft:main with commit 3e6ed73 Jun 12, 2026
21 checks passed
@andrewbranch
Andrew Branch (andrewbranch) deleted the lsp-builtin-watcher-base branch June 12, 2026 21:57
Christian Vuerings (christianvuerings) added a commit to christianvuerings/typescript-go that referenced this pull request Jun 12, 2026
* origin/main:
  Make LS checkers time out after being idle, segment based on use (take 2) (microsoft#3435)
  Fix external helper crash after module-status updates (microsoft#3994)
  Allow LSP server to use builtin watcher on Windows and macOS (microsoft#4288)
  Rebuilt CLI watcher around new `fswatch` package (microsoft#4026)
  Fix stack overflow crash in base constraint resolution (microsoft#4242)

# Conflicts:
#	internal/project/session.go
Jake Bailey (jakebailey) pushed a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants