æ¦è¦
GNU Emacs >=29.1 㧠VS Code ç¸å½ã®ã³ã¼ãã»ãããã°æ¯æ´æ©è½ãè¨å®ãã¾ãã VS Code ã¯ã³ã¼ãæ¯æ´æ©è½ã« Language Server Protocol (LSP) ããããã°æ¯æ´æ©è½ã« Debug Adapter Protocol (DAP) ã使ç¨ãã¦ãã¾ãã Emacs ã§ã LSP/DAP ã¯ã©ã¤ã¢ã³ããéçºããã¦ãã¾ãã
ããã§ã¯æ¬¡ã®ããã±ã¼ã¸ã使ãã¾ããçè ãåå¿è ãã¤ãã®ãããªã®ã§ãªãã¹ãã¤ã³ã¹ãã¼ã«ãè¨å®ãæ軽ãããªãã®ãé¸ã³ã¾ãã
ä»å㯠Eglot ã«ã¤ãã¦æ¸ãã¾ãã
å ·ä½ä¾ã®ç°å¢
ä»ã®ç°å¢ã®æ¹ã¯é©å®èªã¿æ¿ãã¦ãã ããã
- macOS Sequoia 15.0.1 (arm64)
- the command line developer tools (
xcode-select --install
) - Homebrew
- GNU Emacs 29.4 (
brew install --cask emacs
) - C/C++
- the command line developer tools ä»å±ã® llvm
- Python
- Python 3.13.0 (
brew install python
)
- Python 3.13.0 (
Eglot
LSP ãµã¼ãã¼ã¨ã®é£æºã«ããä¸è¨ã®ãããªã³ã¼ãæ¯æ´æ©è½ãå©ç¨ã§ããã¨ã®ãã¨ã
- ã³ã¼ãè£å®
- é¢æ°ã»ã¯ã©ã¹ã®å®ç¾©ç®æã¸ã®ç§»å
- èå¥åã®èª¬æ表示
- ãªãã¡ã¯ã¿ãªã³ã° (ã½ã¼ã¹ ã³ã¼ãæ´ç)
- å³æ診æ (ææ³ä¸ã®èª¤ããªã©)
ã¤ã³ã¹ãã¼ã«
Emacs 29 ã«å èµ (built-in) ããã¦ãã¾ããä¸å ·åä¿®æ£ãç®å½ã¦ã« ELPA çã使ãã¾ãã
M-x package-install RET eglot RET
LSP ãµã¼ãã¼
Eglot ã§è¨å®ãã¿ã® LSP ãµã¼ãã¼ã®æ å ±ã Connecting to a server ã«ããã¾ãã
C/C++ ç¨ LSP ãµã¼ãã¼
Eglot 1.17 ã«è¨å®ãã¿ã® C/C++ ç¨ LSP ãµã¼ãã¼ã¯æ¬¡ã®ã¨ããã§ãã
ããã§ã¯ clangd ãé¸ã³ã¾ãã macOS ã® the command line developer tools ã«ä»å±ãã¦ãã¾ãã Homebrew ã® llvm ããã±ã¼ã¸ã«å«ã¾ãã¦ãããã®ã使ããã¨ãã§ãã¾ãã ccls 㯠Homebrew ã«ããã¾ãã
Python ç¨ LSP ãµã¼ãã¼
Eglot 1.17 ã«è¨å®ãã¿ã® Python ç¨ LSP ãµã¼ãã¼ã¯æ¬¡ã®ã¨ããã§ãã
- python-lsp-server (pylsp)
- python-language-server ããã®ãã©ã¼ã¯
- python-language-server (pyls)
- ç¾å¨ã¡ã³ããã³ã¹ããã¦ããªã
- pyright
- jedi-language-server
- ruff-lsp
ãã®ã»ã次ã®ãã®ãããã¾ãã
- basedpyright
- pyright ããã®ãã©ã¼ã¯
- ç»é²æ¹æ³: https://docs.basedpyright.com/latest/installation/ides/#eglot
- anakin-language-server
python-lsp-server, pyright, ruff-lsp, basedpyright 㯠Homebrew ã«ããã¾ããããã§ã¯ python-lsp-server (pylsp) 㨠basedpyright ãé¸ã³ã¾ãã
% brew install python-lsp-server basedpyright
python-lsp-server ã¯ãã©ã°ã¤ã³ã®ãã¨ãèæ
®ãã㨠pipx
ã§ã¤ã³ã¹ãã¼ã«ããã»ããããããããã¾ãã (詳細ã¯æªç¢ºèª) ã
% pipx install python-lsp-server % source ~/.local/pipx/venvs/python-lsp-server/bin/activate (python-lsp-server) % python -m pip install <plug-in> (python-lsp-server) % deactivate
Eglot ãè£å¼·ããããã±ã¼ã¸
- ã³ã¼ãè£å®
- ã³ã¼ãæç
- ããã¥ã¡ã³ã表示
- markdown-mode
- M-x package-install RET markdown-mode RET
- markdown-mode
ã³ã¼ãè£å®ã«ã¤ãã¦ããã§ã¯ Eglot ã®ããã¥ã¡ã³ãã«ä¸ä¾ã¨ãã¦æãããã¦ãã Company ãé¸ã³ã¾ãã
å®è¡
LSP ãµã¼ãã¼ãç¨æã§ãã¦ããã°é©å½ãªã½ã¼ã¹ ãã¡ã¤ã« (ããã§ã®ä¾ã§ã¯ .c
, .cpp
, .py
) ãéã M-x eglot RET
ã¨ã¿ã¤ããã㨠Eglot ãæ©è½ãå§ããã¯ãã§ããä¸æ¦ Eglot ãéå§ããã¨å½è©²ããã¸ã§ã¯ãé
ä¸ã®åé¡ã®ãã¡ã¤ã«ã管çããã®ã§é½åº¦ M-x eglot
ããå¿
è¦ã¯ããã¾ããã
使ãæ¹ã®è¦ç¹
ã³ã¼ãè£å®
Emacs çµã¿è¾¼ã¿
M-x | ãã¼ |
---|---|
complete-symbol | C-M-i |
Company
M-x company-mode ã§æå¹ã«ãã¦ã¿ã¤ããããæååããããããã¨è£å®åè£ãããã ã¢ãããã¾ããæåã§è¡¨ç¤ºãããã«ã¯ M-x company-complete ã
ãã¼ | åä½ |
---|---|
C-n/C-p | åè£ã®é¸æ移å |
<return> | è£å®ç¢ºå® |
<tab> | åè£ãå¯è½ãªéãçµãè¾¼ã |
|
åè£å ãæ¤ç´¢ |
|
ãã£ã«ã¿ã¼ (ãã°ã«) |
|
10 çªç®ã¾ã§ã®åè£ã®ä¸ããç´æ¥é¸æ |
<f1> | é¸æä½ç½®ã®åè£ã®ããã¥ã¡ã³ã表示 |
|
é¸æä½ç½®ã®åè£ã®ã½ã¼ã¹è¡¨ç¤º |
å½æ¹ã®ç°å¢ã¨å©ç¨ç¶æ³ã§ã¯ C-w 㯠No location available
ã¨åºã¦å¹æãè¦ããã¾ããã§ããã
èå¥åã®èª¬æ表示
M-x | ãã¼ |
---|---|
eldoc-doc-buffer | C-h . |
é¢æ°ã»ã¯ã©ã¹ã®å®ç¾©ç®æã¸ã®ç§»å
M-x | ãã¼ |
---|---|
xref-find-definitions | M-. |
xref-go-back | M-, |
imenu | M-g i |
Eglot ã®ã³ãã³ã
詳細㯠3.3 Eglot Commands ãªã©ãåç §ã
èå¥åã®ãªãã¼ã
è¨èªè§£æã«ãã£ã¦ããã®ã§ç½®æã«æ¯ã¹ç¢ºå®ã§ãã
M-x eglot-rename
ãã©ã¼ããã
M-x eglot-format
ãªãã¡ã¯ã¿ãªã³ã°
使ãè¾¼ãã§ããªããã¨ããã詳細ã¯ææ¡ãã¦ãã¾ããã
M-x eglot-code-actions
inlay-hints
é¢æ°ã®ä»®å¼æ°ã C++ 㧠auto
å®ç¾©ããå¤æ°ã®åãªã©ãã³ã¼ãä¸ã«åãè¾¼ã¾ãããã®ããã«è¡¨ç¤ºãã¾ãã python-lsp-server ã§ã¯ãµãã¼ãããã¦ããªãããã§ãã
M-x eglot-inlay-hints-mode ã§ãã°ã«ããã¯ãã§ããæåãç´æçã§ãªãã§ããé表示ã«ããå¾ on ã«ãã¦ãã½ã¼ã¹ ã³ã¼ãã«å¤æ´ããªãã¨å表示ãããªãã§ã (ãã°?) ã
è¨å®
å¤ãã®å ´åã¨ãã«è¨å®ããªãã¦ã使ãå§ãããã¨ãã§ãã¾ããçè
㯠~/.emacs.d/init.el
ã«æ¬¡ã®ããã«æ¸ãã¾ããã use-package ãæ´»ç¨ãã¦ãã¾ãã
~/.emacs.d/init.el
(use-package eglot :init ;; for Emacs 29.4 Built-In 1.12.29 (setq warning-minimum-level :error) :config (add-to-list 'eglot-server-programs `((python-mode python-ts-mode) . ,(eglot-alternatives '("pylsp" ("basedpyright-langserver" "--stdio"))))) :bind (:map eglot-mode-map ("C-c r" . 'eglot-rename) ("C-c f" . 'eglot-format) ("C-c a" . 'eglot-code-actions) ("C-c o" . 'eglot-code-action-organize-imports) ("C-c q" . 'eglot-code-action-quickfix) ("C-c e" . 'eglot-code-action-extract) ("C-c i" . 'eglot-code-action-inline) ("C-c w" . 'eglot-code-action-rewrite) ("C-c m" . 'eglot-inlay-hints-mode) ("C-c h" . 'eldoc)) :hook ((c-mode c++-mode) . eglot-ensure)) (use-package company :bind ("C-c SPC" . 'company-complete) :hook (eglot-managed-mode))
- Emacs 29.4 Built-In 1.12.29 ã§ã¯ Warning ã®ã¦ã¤ã³ãã¦ããã³ãã³éãã®ã§
warning-minimum-level
ã調ç¯ãã¦ãã¾ãã ELPA ææ°çã«ã¯ä¸è¦ã§ãã .py
ãã¡ã¤ã«ãéã M-x eglot ãå®è¡ãã㨠pylsp 㨠basedpyright ããé¸ã¹ãããã«ãªãã¾ã (Variable:eglot-server-programs
) ã <tab> ã§è£å®ãå¹ãã¾ãã- Eglot é¢é£ã³ãã³ãã«ãã¼ããã¤ã³ããã¾ã (
eglot-mode-map
)ã .c
/.cpp
ãã¡ã¤ã«ãéãã ã㧠Eglot ãæå¹ã«ãªãã¾ã (2.2 Starting Eglot) ã
LSP ãµã¼ãã¼ã®è©³ç´°è¨å®
詳細ã確èªãã¦ããªãã®ã§åç §å ã示ãã«çãã¾ãã
Eglot å´ããã® LSP ãµã¼ãã¼ã®è¨å®
LSP ãµã¼ãã¼å´ã§ã®è¨å®
è¨å®ãã¡ã¤ã«ãèªã¿è¾¼ã LSP ãµã¼ãã¼ãããã¾ããããã§åãä¸ãã LSP ãµã¼ãã¼ã¯ãããã該å½ããããã§ããå½ç¶ VS Code ãªã©ã®ä»ã® LSP ã¯ã©ã¤ã¢ã³ãã¨è¨å®ãå ±æãããã¨ã«ãªãã¾ãã
- clangd: Configuration
- python-lsp-server: Configuration
- basedpyright: Config files
ç¶ã
次å 㯠DAP ã¯ã©ã¤ã¢ã³ãã® Dape ã«ã¤ãã¦æ¸ãã¾ãã