lsp-mode で company による補完が行われない

結論

lsp-mode.el の defcustom の実装が更新されており、 lsp-document-sync-method に指定すべき値が更新されていました。

(setq lsp-document-sync-method lsp--sync-incremental) ;; 'inclemental を指定してはいけない

lsp-mode の更新について

久々に Emacs のパッケージを更新してみたところ、 lsp-mode が上手く動作しなくなってしまいました。

謎の補完が行われるし、シンタックスエラーが出ない
適切な補完候補が表示されず、更にシンタックスエラーの表示もされない

company-diag を見ても問題なさそうで原因特定に時間がかかったのですが、色々試してみた結果 lsp-document-sync-method が原因だということが分かり、リポジトリを見てみると以下の commit で実装が更新されていました。

https://github.com/emacs-lsp/lsp-mode/commit/348d5e476cc4fda70e20efe5b55d8f50e74e3745#diff-b1e9bc82c3b6bd6e95470e18ee41a19bL340-R378

:type '(choice (const :tag "Documents should not be synced at all." nil)
               (const :tag "Documents are synced by always sending the full content of the document." lsp--sync-full)
               (const :tag "Documents are synced by always sending incremental changes to the document." lsp--sync-incremental)

となっているので、変更箇所をインクリメンタルに適用する場合は lsp-document-sync-method に lsp–sync-incremental を指定してあげれば良さそうです。 use-package.el や leaf.el を採用していて custom キーワードで指定する場合、値である 2 を直接指定する必要があります。

ちゃんと動くようになった!

おまけ

company-lsp について

今回色々調べている途中に知ったのですが、いつの間にか company-lsp が保守されなくなっていました。現在は代わりに company-capf (もしくは completion-at-point)を使用することが推奨されています。

Code completion – company-capf / completion-at-point (note that company-lsp is no longer supported).

lsp-mode/README.md at 97f91274f1174274c1b6e68c1edb35e8008895f5 · emacs-lsp/lsp-mode · GitHub

どうやら lsp-mode が company-capf をサポートするようになったみたいです。

https://github.com/emacs-lsp/lsp-mode/issues/1305

これに伴い lsp-mode に lsp-prefer-capf という変数が追加されており、この変数に t に指定しておくと自動的に company-backends に company-capf を追加してくれるようです。

https://github.com/emacs-lsp/lsp-mode/blob/97f91274f1174274c1b6e68c1edb35e8008895f5/lsp-mode.el#L7185-L7194

breadcrumb 機能追加

つい先日、画面上部に breadcrumb を表示する PR が merge されていました。

https://github.com/emacs-lsp/lsp-mode/pull/1799

lsp-headerline-breadcrumb-mode を有効にすると表示されます。

かっこいい〜

lsp-mode で company による補完が行われない」への2件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です