VSCodeに拡張機能Ruby LSPを入れるとLSPのインストールが上手くいかない

に公開

概要

Rubyを始める際にRuby本体の実行環境を整えた上で、VSCodeにも拡張機能を入れたらRuby LSPのインストールが上手くいかなかった時の備忘録

環境

Windows11 24H2
Ruby 3.3.8

解決する前の状態

ridk installで1~3番まで全部インストール済み
Ruby自体は普通に動く

エラーの詳細

Automatic Ruby environment activation with rubyInstaller failed: Cannot find any Ruby installations

と表示されるので、その後の画面で直接Ruby.exeを指定してやると

Failed to setup the bundle: Command failed: gem install ruby-lsp ERROR: Error installing ruby-lsp: ERROR: Failed to build gem native extension.
current directory: C:/Users/[ユーザー名]/.local/share/gem/ruby/3.3.0/gems/prism-1.4.0/ext/prism C:/Ruby33-x64/bin/ruby.exe extconf.rb checking for prism.h in C:/Users/[ユーザー名]/.local/share/gem/ruby/3.3.0/gems/prism-1.4.0/include... yes checking for prism/extension.h in C:/Users/[ユーザー名]/.local/share/gem/ruby/3.3.0/gems/prism-1.4.0/ext... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details.
You may need configuration options.
Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include=${opt-dir}/include --without-opt-include --with-opt-lib=${opt-dir}/lib --without-opt-lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=C:/Ruby33-x64/bin/$(RUBY_BASE_NAME) extco.

とエラーメッセージが表示される

解決法

MSYS2のshellで以下を実行する

pacman -Syu
pacman -S base-devel mingw-w64-x86_64-toolchain

この後にVSCodeを再読み込みするとRubyのLSPのインストールが始まり、正常に終了した。

あとがき

結局原因はMSYS2の依存関係が足りていなかったような感じでした。

GitHubで編集を提案

Discussion