Haskell Ide Engineが特定のプロジェクトで動かなかった話
ビルドに成功するのにHaskell Ide Engineがエラーを吐き続けていた話です。
環境
Haskell Ide Engineを以下の手順でインストールしていた
git clone https://github.com/haskell/haskell-ide-engine cd haskell-ide-engine git submodule update --init stack install
問題
適当なプロジェクトを生成する。
stack new test yesodweb/simple
cd test vim app/main.rs
vimで適当なファイルを開くとエラーが出てしまう
[LC] [Error] Got error while processing diagnostics: <command li....12.0.3-LfvlcMFJAcY18uD1Y2O5Ig...
調査
とりあえず詳細なログを見たいのでneovimでdeinを使っているので、dein.tomlの'autozimu/LanguageClient-neovim'
の設定でログを出力するように書き足す
'haskell': ['hie-wrapper', '-d', '-l', '/tmp/hie.log', '--vomit']
保存したあと、もう一度エラーがおきたapp/main.hs
を開きエラーが出るまで待つ。エラーが出たら、その中からエラーの項目を探す。今回はgrepを使ったらうまく見つけることができた。
$ grep error /tmp/hie.log 2019-05-14 15:57:46.924647426 [ThreadId 6] - <--2--{"jsonrpc":"2.0","params":{"type":1,"message":"Got error while processing diagnostics: <command line>: cannot satisfy -package-id aeson-1.4.2.0-CD2t6teVNgAIuuNYZF3r8A: \n aeson-1.4.2.0-CD2t6teVNgAIuuNYZF3r8A is unusable due to missing dependencies:\n attoparsec-0.13.2.2-6XZWdvg7dAKGuzy18iXIM3 primitive-0.6.4.0-ILgywxtLpvnAOlEISPpP5b scientific-0.3.6.2-BboXwnuKby4BtCVtfss4TP tagged-0.8.6-AoE7RQX12AwJxLvAxGYxtP vector-0.12.0.3-LfvlcMFJAcY18uD1Y2O5Ig\n (use -v for more information)"},"method":"window/showMessage"} 2019-05-14 16:24:38.604911487 [ThreadId 6] - <--2--{"jsonrpc":"2.0","params":{"type":1,"message":"Got error while processing diagnostics: <command line>: cannot satisfy -package-id aeson-1.4.2.0-CD2t6teVNgAIuuNYZF3r8A: \n aeson-1.4.2.0-CD2t6teVNgAIuuNYZF3r8A is unusable due to missing dependencies:\n attoparsec-0.13.2.2-6XZWdvg7dAKGuzy18iXIM3 primitive-0.6.4.0-ILgywxtLpvnAOlEISPpP5b scientific-0.3.6.2-BboXwnuKby4BtCVtfss4TP tagged-0.8.6-AoE7RQX12AwJxLvAxGYxtP vector-0.12.0.3-LfvlcMFJAcY18uD1Y2O5Ig\n (use -v for more information)"},"method":"window/showMessage"}
上記の出力の{"type":1,"message":"Got error while processing diagnostics:...
が原因のように見える。このエラーをぐぐってみると同じエラーのissueがvscodeのhaskell-ide-engineのリポジトリで報告されていた。
issue曰く、hieのコンパイラのバージョンとstackが使用するコンパイラのバージョンが違うとダメらしい。
$ hie --compiler ghc-8.6.3 $ stack exec -- ghc --version The Glorious Glasgow Haskell Compilation System, version 8.6.5
プロジェクトのコンパイラとhieのコンパイラのバージョンがちがかったのでそういうことらしい。 とりあえずリポジトリをクローンし直す
git clone https://github.com/haskell/haskell-ide-engine cd haskell-ide-engine git submodule update --init stack ./install.hs Usage: stack install.hs <target> Targets: build Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2, 8.4.3, 8.4.4, 8.6.1, 8.6.2 and 8.6.3) build-all Builds hie and hoogle databases for all supported GHC versions cabal NOTE 3: This is needed for stack only projects too build-docs Builds the Hoogle database for all supported GHC versions test Runs hie tests icu-macos-fix Fixes icu related problems in MacOS dist Creates a tarball containing all the hie binaries help Show help hie-8.2.1 Builds hie for GHC version 8.2.1 only hie-8.2.2 Builds hie for GHC version 8.2.2 only hie-8.4.2 Builds hie for GHC version 8.4.2 only hie-8.4.3 Builds hie for GHC version 8.4.3 only hie-8.4.4 Builds hie for GHC version 8.4.4 only hie-8.6.1 Builds hie for GHC version 8.6.1 only hie-8.6.2 Builds hie for GHC version 8.6.2 only hie-8.6.3 Builds hie for GHC version 8.6.3 only build-doc-8.2.1 Builds the Hoogle database for GHC version 8.2.1 only build-doc-8.2.2 Builds the Hoogle database for GHC version 8.2.2 only build-doc-8.4.2 Builds the Hoogle database for GHC version 8.4.2 only build-doc-8.4.3 Builds the Hoogle database for GHC version 8.4.3 only build-doc-8.4.4 Builds the Hoogle database for GHC version 8.4.4 only build-doc-8.6.1 Builds the Hoogle database for GHC version 8.6.1 only build-doc-8.6.2 Builds the Hoogle database for GHC version 8.6.2 only build-doc-8.6.3 Builds the Hoogle database for GHC version 8.6.3 only
どうやらstack ./install.hs build-all
で全てのバージョンのhieとHoogleのデータベースを作ることができるらしいのでstack ./install.hs build-all
でビルドをする。
この後に問題が起きていたプロジェクトをvimで開いても問題は起きなくなった。(hie-wrapper
が適切なghcのバージョンのhie
を選んでくれる。)
まとめ
- Haskell Ide Engine (hie)とStackのプロジェクトに使うGHCは同じバージョンでなければならない。
stack ./install.hs build-all
でhieをビルドすれば何も考えなくていい(たぶん)hie-wrapper
がインストール済みの適切なGHCのバージョンのhieを選んでくれる。
おわりに
Qiitaにvscode と haskell-ide-engine で Haskell 開発環境を構築する - Qiitaという記事があり、この記事をしっかり読んでいれば問題は事前に回避できていました。おわり。