Initialize error when switching branches in VS Code
Description
Ruby LSP Information
Ruby LSP Information
VS Code Version
1.105.0
Ruby LSP Extension Version
0.9.32
Ruby LSP Server Version
Unknown
Ruby LSP Add-ons
Ruby Version
3.3.8
Ruby Version Manager
mise
Installed Extensions
Click to expand
- gitlens (17.7.1)
- material-icon-theme (5.29.0)
- ruby-lsp (0.9.32)
- theme-dracula (2.25.1)
- vscode-eslint (3.0.16)
- vscode-fileutils (3.10.3)
- vscode-pull-request-github (0.120.2)
Ruby LSP Settings
Click to expand
Workspace
{}
User
{
"enabledFeatures": {
"codeActions": true,
"diagnostics": true,
"documentHighlights": true,
"documentLink": true,
"documentSymbols": false,
"foldingRanges": true,
"formatting": true,
"hover": true,
"inlayHint": true,
"onTypeFormatting": true,
"selectionRanges": true,
"semanticHighlighting": true,
"completion": true,
"codeLens": false,
"definition": true,
"workspaceSymbol": true,
"signatureHelp": false,
"typeHierarchy": false
},
"featuresConfiguration": {},
"addonSettings": {},
"rubyVersionManager": {
"identifier": "mise",
"miseExecutablePath": "/opt/homebrew/bin/mise"
},
"customRubyCommand": "",
"formatter": "auto",
"linters": null,
"bundleGemfile": "/Users/seb/Code/ruby-lsp/Gemfile",
"testTimeout": 30,
"branch": "",
"pullDiagnosticsOn": "both",
"useBundlerCompose": false,
"bypassTypechecker": false,
"rubyExecutablePath": "",
"indexing": {},
"erbSupport": true,
"featureFlags": {},
"sigOpacityLevel": "1"
}
Reproduction steps
- Start the Ruby LSP using a certain editor
- Open a Ruby file
- Do something
- See unexpected behavior
Code snippet or error message
Error processing initialize: /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2330:in `unlink': No such file or directory @ apply2files - .ruby-lsp/bundle_env (Errno::ENOENT)
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2330:in `block in remove_file'
If I restart the editor it works fine, but when switching branches I randomly get this error.
Thanks for the report. Whenever we start the LSP, we should be composing the bundle first (which is what creates the bundle_env file). I'm not sure how the file is not getting generated before we launch the server.
In your Output tab under Ruby LSP, do you see logs mentioning that we're re-composing the bundle when you switch branches?
I will check next time this gets triggered again. It doesn’t seem to happen on every branch switch, but I can’t say for sure what causes it.
We only auto-restart when there's a change to the lockfile. This is because the LSP integrates with your app's bundle and there's no easy way of unloading every gem, resetting the Bundler state and setting up again without restarting the whole process.
I suspect it's happening when you switch between branches that have a gem updated.
Thanks for the info, knowing that it was easy to reproduce the issue. I am using Windsurf instead of VS Code, but I mentioned VS Code because probably a lot of people are not familiar with Windsurf. I hope it's not an issue with this IDE. I will try to set up VS Code on my machine and see if it does the same thing. Here is the full output:
2025-11-27 16:06:27.473 [info] (app) Restarting the Ruby LSP because /Users/seb/Code/stuff/app/Gemfile.lock changed, matching {Gemfile.lock,gems.locked}
2025-11-27 16:06:27.530 [info] (app) Recomposing the bundle ahead of restart
2025-11-27 16:06:29.148 [info] (app) Determined that document should be indexed: file:///Users/seb/Code/stuff/app/app/controllers/stuff_controller.rb
2025-11-27 16:06:48.357 [info] (app) Restarting the Ruby LSP because /Users/seb/Code/stuff/app/Gemfile.lock changed, matching {Gemfile.lock,gems.locked}
2025-11-27 16:06:48.459 [info] (app) Recomposing the bundle ahead of restart
2025-11-27 16:06:50.904 [info] (app) Running command: `/opt/homebrew/bin/mise x -- ruby -EUTF-8:UTF-8 '/Users/seb/.windsurf/extensions/shopify.ruby-lsp-0.9.32-universal/activation.rb'` in /Users/seb/Code/ruby-lsp using shell: /bin/zsh
2025-11-27 16:06:50.959 [info] (app) [Error - 16:06:50] Server process exited with code 0.
2025-11-27 16:06:52.025 [info] (app) Initializing Ruby LSP v0.26.4 https://github.com/Shopify/ruby-lsp/releases/tag/v0.26.4....
2025-11-27 16:06:52.026 [info] (app) [Error - 16:06:52] Server initialization failed.
2025-11-27 16:06:52.026 [info] (app) Message: /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2330:in `unlink': No such file or directory @ apply2files - .ruby-lsp/bundle_env (Errno::ENOENT)
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2330:in `block in remove_file'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2335:in `platform_support'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:2329:in `remove_file'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:1474:in `remove_file'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:1222:in `block in rm'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:1221:in `each'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/3.3.0/fileutils.rb:1221:in `rm'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/lib/ruby_lsp/server.rb:228:in `run_initialize'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/lib/ruby_lsp/server.rb:16:in `process_message'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/lib/ruby_lsp/base_server.rb:87:in `block in start'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/lib/ruby_lsp/utils.rb:320:in `each_message'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/lib/ruby_lsp/base_server.rb:39:in `start'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.26.4/exe/ruby-lsp:160:in `<top (required)>'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `load'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `activate_and_load_bin_path'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/bin/ruby-lsp:25:in `<top (required)>'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:59:in `load'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:59:in `kernel_load'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli/exec.rb:23:in `run'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:456:in `exec'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:538:in `dispatch'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:35:in `dispatch'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/cli.rb:29:in `start'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/bundler-2.7.2/exe/bundle:28:in `block in <top (required)>'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/bundler/friendly_errors.rb:118:in `with_friendly_errors'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/gems/3.3.0/gems/bundler-2.7.2/exe/bundle:20:in `<top (required)>'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `load'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/lib/ruby/site_ruby/3.3.0/rubygems.rb:319:in `activate_and_load_bin_path'
from /Users/seb/.local/share/mise/installs/ruby/3.3.8/bin/bundle:25:in `<main>'
I noticed that you have "rubyLsp.bundleGemfile": "/Users/seb/Code/ruby-lsp/Gemfile" in your settings and I wonder if this is related to using a separate bundle.
If you remove that setting, does the issue go away?