Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kotlin-lsp を Emacs で使えるようにしてみた / use kotlin-lsp...

Avatar for nabeo nabeo
June 13, 2025

kotlin-lsp を Emacs で使えるようにしてみた / use kotlin-lsp in Emacs

Avatar for nabeo

nabeo

June 13, 2025
Tweet

More Decks by nabeo

Other Decks in Technology

Transcript

  1. Copyright © Henry, Inc. All rights reserved. nabeo@株式会社ヘンリー Server-Side Kotlin

    LT 大会 vol. 15 kotlin-lsp を Emacs で使えるようにしてみた
  2. Copyright © Henry, Inc. All rights reserved. 自己紹介 • nabeo

    (渡辺 道和) • 株式会社 ヘンリーでインフラ寄りな SRE をやっています ◦ 普段は Terraform がメイン ◦ Kotlin 歴 == 現職での社歴 ◦ Kotlin は稀に書くだけで基本的に読み専 X: @nabeo BlueSky: @nabeo.bsky.social Blog: https://nabeop.hatenablog.com/ 2
  3. Copyright © Henry, Inc. All rights reserved. No Emacs, No

    Life Emacs の開発終了が 僕のエンジニア人生の終了だと思っている 3
  4. Copyright © Henry, Inc. All rights reserved. • Emacs で

    Kotlin 開発 ◦ LSP サーバ実装はあるけど、イマイチ使えない ◦ Kotlin 力がないので、コードを読むときに参照ジャンプや定義元ジャンプは必須 ▪ GNU Global で TAG ジャンプも試したけど、厳しい • Kotlin 開発は IntelliJ IDEA がデファクトスタンダード ◦ 実際便利 ◦ 個人的には Shift キーを連打して出てくる「どこでも検索」がないと生きていけない 現実 is 厳しい 4
  5. Copyright © Henry, Inc. All rights reserved. • JetBrains さんのビジネスモデルを考えると公式で

    LSP サーバ実装は出てこ ないでしょ、と思っていた ◦ 実際に公式フォーラムでも「Instead, we’re focusing on providing the best possible Kotlin development experience in our own IDE, IntelliJ IDEA.」という回答があった ▪ 2017年時点での回答なのでかなり古い見解ではあるが、待望するコメントがたくさん ある ▪ ref: Any plan for Supporting Language Server Protocol? - Support - Kotlin Discussions LSP サーバ実装さえあれば... 5
  6. Copyright © Henry, Inc. All rights reserved. KotlinConf 2025 Unpacked:

    Upcoming Language Features, AI-Powered Development, and Kotlin Multiplatform Upgrades | The Kotlin Blog Kotlin Conf 2025 で希望の光が...!! 7
  7. Copyright © Henry, Inc. All rights reserved. 親の顔より見た • standalone

    版に同梱されている kotlin-lsp.sh の Java のオプションに -Xmx24G を追加 • JVM_OPTS 環境変数などで外部から渡すことも考えたい ◦ が、一旦は kotlin-lsp.sh を直接書き換えてお茶を濁している 9
  8. Copyright © Henry, Inc. All rights reserved. Emacs + eglot

    での設定 • standalone 版の zip ファイルを ~/.emacs.d/data/kotlin-lsp 以下に展開す る • eglot は Emacs 30 から標準でついてくる LSP クライアント実装 • eglot-server-programs の Kotlin 向けの設定を追加する ◦ emacs 30 に同梱されている eglot のデフォルトでは fwcd/kotlin-language-server の設定 が入っている 10
  9. Copyright © Henry, Inc. All rights reserved. 定義ジャンプができる喜び Kotlin/kotlin-lsp で

    xref-find-definitions (M-.) して定義を探している様子 11
  10. Copyright © Henry, Inc. All rights reserved. • あくまでもアルファ版以前のアーリーステージという扱いなので転んでも泣 かない

    • 対象の Kotlin プロジェクトの規模によってはそこそこの計算機パワーを使う ◦ メモリもそうだけど、LSP サーバ起動時の initialize 処理で1分以上かかる その他の注意点 12