LoginSignup
0
0

More than 3 years have passed since last update.

Windows10上のSpacemacsでMetalsを使う

Last updated at Posted at 2020-02-01

SpacemacsでScalaを使う際、合わせて Ensime or Metalsを使うと良さそう。定義ジャンプや補完機能が充実している。

ただ、Windows10でEnsimeを使った際に定義ジャンプが一手間必要でしんどさを感じたので、本稿ではMetalsを使う。

Ensimeはドキュメントに従えば良いが、Metalsはところがぎっちょんなのでメモ。

Metals Serverのインストール

Spacemacs公式 developブランチ Scala Layerドキュメント Metalsの章より、

Currently, you must manually install the metals server. It is possible to do so via coursier; the latest version can be built using the following commands, where 0.7.6 can be replaced with the current version of Metals:

_人人人人人人人人人人人_
>  manually install  <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^ ̄

Ensimeと違い、手動インストールを迫られている :innocent:

Coursierのインストール

Spacemacs公式ドキュメントでは、 Coursier経由でのインストール方法が書かれている。

まずCoursierをインストールする。

Coursier公式ドキュメントより、Windowsでは以下の2コマンドからダウンロードしてくるようだ。

bitsadmin /transfer downloadCoursierCli https://git.io/coursier-cli "%cd%\coursier"
bitsadmin /transfer downloadCoursierBat https://git.io/coursier-bat "%cd%\coursier.bat"

bitsadminコマンドはPowerShellで使える。が、

BITSADMIN version 3.0
BITS administration utility.
(C) Copyright Microsoft Corp.

Unable to add file - 0x80070057
パラメーターが間違っています。

:innocent: :innocent: :innocent:

同じような問題での質問があり、解決策が示されていた。
BitsAdmin URI Query → Unable to add file to job - 0x80070057 The parameter is incorrect

回答者は14年前の議論を発掘していて(すごい)、曰く「絶対パスで書け」っぽい。
つまり先ほどの2コマンドは、ファイルのダウンロード先を 以下のように絶対パスで書く必要がある。

bitsadmin /transfer downloadCoursierCli https://git.io/coursier-cli C:\coursier\coursier
bitsadmin /transfer downloadCoursierBat https://git.io/coursier-bat C:\coursier\coursier.bat

※ Cドライブ直下に coursierディレクトリがある状態で実行すれば、そのディレクトリ内にダウンロードされる

最後に、ダウンロードした2ファイルがあるディレクトリを環境変数Pathに追加する。この後に起動したPowerShellで、 coursierコマンドが使えるはず。

なお、 ERROR: JAVA_HOME is set to an invalid directoryエラーが発生した場合は、環境変数 JAVA_HOMEの値が ~/binまで含まれている可能性がある。
JAVA_HOMEの値はbinディレクトリの直上にとどめると解決する(代わりに環境変数 Path%JAVA_HOME%/binのように指定する)
参考 => https://qiita.com/toon258/items/6c85d6a7183f715482bd

Metalsのインストール

Spacemacs公式で紹介されているコマンドはこれ(なおPowerShellでは動かない :innocent:

./coursier bootstrap \
  --java-opt -Xss4m \
  --java-opt -Xms100m \
  --java-opt -Dmetals.client=emacs \
  org.scalameta:metals_2.12:0.7.6 \
  -r bintray:scalacenter/releases \
  -r sonatype:snapshots \
  -o /usr/local/bin/metals-emacs -f

PowerShellではこう。
C:\user_installs\metals-emacs\に最新版をインストールした)

coursier bootstrap `
--java-opt -Xss4m `
--java-opt -Xms100m `
--java-opt -Dmetals/client=emacs org.scalameta:metals_2.12:0.8.4 `
-r bintray:scalacenter/releases `
-r sonatype:snapshots `
-o C:\user_installs\metals-emacs\metals-emacs -f

最後に環境変数 PathにMetalsのあるディレクトリを追加する。

.spacemacsの設定

Spacemacs公式ドキュメントに従い、設定ファイル .spacemacs ( Space f e d)に以下を追記する。

(setq-default dotspacemacs-configuration-layers
  '(
      (scala :variables scala-backend 'scala-metals) ; この位置
  )
)

Language Serverは自動でLSPを使うが、別途に設定する場合は LSP LayerがあるのでSpacemacsの設定に加えられそう。

おまけ

  • Metalsを最初に使うとき、projectどこにするか訊かれたのでちゃんとソースファイルが属するプロジェクトのディレクトリ名を選択した(その時点で .metalsディレクトリが作成されるので、以降は訊かれなくなる)
  • Metalsを起動すると、しばらくの間CPUが100%に貼り付いてしんどい… :innocent: どうして
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0