Skip to content

Don't start language servers in deleted workspace folders - #3073

Merged
rchl merged 3 commits into
mainfrom
fix/missing-workspace-folders
Oct 18, 2026
Merged

rchl merged 3 commits into
mainfrom
fix/missing-workspace-folders

Conversation

@rchl

@rchl rchl commented Oct 12, 2026

Copy link
Copy Markdown
Member

Fixes #1491

Sublime Text keeps folders in the window after they were deleted from disk. LSP used the first such folder as the server's working directory, which made spawning the process fail (e.g. NotADirectoryError on Windows). The folder was also sent to the server as rootUri / rootPath / workspaceFolders.

Changes:

  • sorted_workspace_folders() skips folders that don't exist, so they are neither used as cwd nor reported to the server. If all folders are gone, the session starts without workspace folders.
  • _start_subprocess() falls back to the default working directory (with a debug log) when the requested cwd doesn't exist. This also covers a cwd returned from a plugin's on_pre_start.
  • Tests for missing folders; test_longest_prefix now uses real temp directories since it relied on non-existent paths.

Note: a folder deleted while a session is already running is not handled here (ST doesn't report a folder change in that case).

rchl added 2 commits October 12, 2026 19:43
Sublime Text keeps folders in the window after they were deleted from
disk. Such folders were used as the server's working directory, which
made spawning the process fail, and were also sent to the server as
rootUri / workspaceFolders.

Skip folders that don't exist when computing the workspace folders for
a new session, and fall back to the default working directory when the
requested one (possibly provided by a plugin) doesn't exist.

Fixes #1491
Comment thread plugin/core/transports.py Resolved
Comment thread plugin/core/transports.py Resolved
@mataha

mataha commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Can confirm it's working as intended (log below).

Log
Unable to open /D/coding/.cloned/wontexistinamoment/script.py
LSP: working directory D:\coding\.cloned\wontexistinamoment does not exist, using current working directory instead
LSP: starting ['C:\\Users\\Mataha\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ruff\\.venv\\Scripts\\ruff', 'server'] in C:\Program Files\Sublime Text
LSP: LSP-ruff: Supported execute commands: ['ruff.applyFormat', 'ruff.applyAutofix', 'ruff.applyOrganizeImports', 'ruff.printDebugInformation']
LSP: LSP-ruff: supported code action kinds: ['quickfix', 'source.fixAll.ruff', 'source.organizeImports.ruff', 'notebook.source.fixAll.ruff', 'notebook.source.organizeImports.ruff']
[LSP-ty][INFO] Downloading server tarball: https://github.com/astral-sh/ty/releases/download/0.0.86/ty-x86_64-pc-windows-msvc.zip
LSP: starting ['C:\\Users\\Mataha\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-ty\\v0.0.86\\ty.exe', 'server'] in C:\Program Files\Sublime Text
LSP: LSP-ruff: registering capability: didChangeWatchedFilesProvider
LSP: LSP-ruff: registering capability: documentFormattingProvider
LSP: LSP-ruff: registering capability: rangeFormattingProvider
LSP: LSP-ty: Supported execute commands: ['ty.printDebugInformation']
LSP: LSP-ty: supported code action kinds: ['quickfix']
LSP: LSP-ty: Supported semantic token types: ['namespace', 'class', 'parameter', 'selfParameter', 'clsParameter', 'variable', 'property', 'function', 'method', 'keyword', 'string', 'number', 'decorator', 'builtinConstant', 'typeParameter', 'operator', 'regexp']
LSP: LSP-ty: Supported semantic token modifiers: ['definition', 'readonly', 'async', 'documentation']
LSP: LSP-ty: registering capability: didChangeWatchedFilesProvider

@rchl
rchl merged commit e66c591 into main Oct 18, 2026
9 checks passed
@rchl
rchl deleted the fix/missing-workspace-folders branch October 18, 2026 10:46
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.

Removed folder in project crashes LSP

4 participants