LoginSignup
4
4

[Emacs] go-modeでeglotが起動しない

Posted at

現象

go のソースコードを開いたときにeglotが起動しない。M-x eglot だと正常に起動する。

以前は問題なく使えてと思う。Emacs30 をインストールした時からだろうか :thinking:

環境

Mac版Emacs

GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin22.6.0, NS
 appkit-2299.70 Version 13.5.1 (Build 22G90)) of 2023-08-21

調査1 Tree-Sitter

goプロジェクトのファイルを開くとTree-SitterのWarningが出るようになっていた:

⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for gomod is unavailable

関係ない気がするけど潰しておきたい。調べたところ、M-x treesit-install-language-grammargomod を選択したら解消した。

調べてる最中に treesit-font-lock-level という変数を知る。levelを上げていくと、より細かく色分けをしてくれるらしい。

(setq treesit-font-lock-level 4)

tree-sitterの警告は消せたけど、まだ問題は解消せず。goのファイルを開いたときに自動でeglotが立ち上がってくれない。

調査2 Hook

C-h go-mode-hookの結果は

go-mode-hook is a customizable variable defined in go-mode.el.

Value
(doom-modeline-env-setup-go
 eglot-ensure)

なので問題なさそうだが... :thinking: eglot のhookの設定を見直してみる。ずっと触ってないのだけれど

(use-package eglot
  :ensure t
  :bind (:map eglot-mode-map
              ("C-c C-d" . eglot-help-at-point)
              ("C-c C-r" . eglot-code-actions))
  :hook
  (go-mode . eglot-ensure))

eglot-ensure を以下の my-eglot-hook-functionに変え、再度goのファイルを開いてみる。

(defun my-eglot-hook-function ()
  (message "go-mode-hook triggered!")
  (eglot-ensure))

... Messageが出ない :fearful:
goのファイルで M-x describe-mode を実行すると

The major mode is Go mode defined in go-ts-mode.el:

Major mode for editing Go, powered by tree-sitter.

:hugging: go-ts-mode :hugging:

もしかしてEmacs29でtree-sitterが入ってから、xxx-ts-mode で書き換える必要があったのかな?

(go-ts-mode . eglot-ensure)

で無事解消しました :open_hands:

4
4
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
4
4