Solargraphをgem installしているにもかかわらず、vscodeの拡張機能であるRuby Solargraph
が以下のようなエラーを表示することがあります。
わたしの環境では、拡張機能側がSolargraphを探せていないことがこの原因でした。 拡張機能Ruby Solargraphは項目Command Pathの設定値をもとにSolargraph Gemを探し、そのデフォルト値はsolargraphとなっています。
そこでおもむろに以下のようなコマンドを打ち込んでみると、確かにsolargraphが見つかりませんでした。繰り返すようにSolargraphはgem install済みです、gem install時にsolarpathコマンドのPATHが通るはずですが、何らかの事情で通らなかったのでしょう。
$ solargraph help
-bash: solargraph: command not found
-
solargraphの実体を探して、PATHを通す -
solargraphの実体を探して、そのフルパスをCommand Pathに設定する。
この問題の解消法としては以上の2つが思いつきますが、今回、わたしは2を選択しました。まずはgem envコマンドでsolargraphコマンドが設置されているディレクトリを探します。
$ gem env | grep "EXECUTABLE DIRECTORY"
- EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/2.6.0/bin
つまり/usr/local/lib/ruby/gems/2.6.0/bin/solargraphが目的のコマンドになるはずなので、それを以下の通りに確認します。
$ /usr/local/lib/ruby/gems/2.6.0/bin/solargraph help
Commands:
solargraph --version, -v # Print the version
solargraph available-cores # List available documentation versions
solargraph clear-cores # Clear the cached core documentation
solargraph config [DIRECTORY] # Create or overwrite a default configuration file
solargraph download-core [VERSION] # Download core documentation
solargraph help [COMMAND] # Describe available commands or one specific command
solargraph list-cores # List the local documentation versions
solargraph reporters # Get a list of diagnostics reporters
solargraph socket # Run a Solargraph socket server
solargraph stdio # Run a Solargraph stdio server
あとは以下のようにCommand Pathにsolargraphのフルパスを指定してやるだけで、ポップアップは表示されなくなり、拡張機能が正しく稼働するようになるはず。


