Lesson4

プログラミングとか読書とか日常のログ

VSCodeでRuby LSPをインストールしたときのエラー

これは何

  • VSCode拡張機能Rubyが非推奨になったのでRuby LSPに移行してくださいというメッセージが出たので移行した。
  • インストールしたら以下のようなエラーが出たので調べた
Failed to activate asdf environment: Command failed: /opt/homebrew/bin/fish -ic 'asdf exec ruby -rjson -e "printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump(ENV.to_h))"' unknown command: ruby. Perhaps you have to reshim?

調べた内容

  • Rubyのバージョン管理はrbenvでやっているしなぜ asdf が出てくるんだ?と思いながらネットを調べてみても特に同じ現象は見当たらず。
  • Ruby LSPのUsageをみたところ以下の文言があった。
Ruby version managers
To boot the server properly, the Ruby LSP uses a version manager to activate the right environment variables that point Bundler to the Ruby and gem paths. This is especially necessary when switching between projects that use different Ruby versions - since those paths change and need to be reactivated.

By default, the Ruby LSP will attempt to automatically determine which version manager it should use, checking which ones are available (auto option). If that fails, then the version manager must be manually configured. You can do so by clicking Change version manager in the language status center or by changing your VS Code user settings.
  • バージョンマネージャの判別ができなかったので設定から手動で切り替えて再起動したところ、エラーは解消した。 VSCodeのRuby LSPのバージョンマネージャの設定をrbenvに変更