- Watch the video on YouTube!
- Check out the final code on GitHub
- Episode 8 of the Emacs From Scratch series
- Episode 1 of the Emacs IDE series
¶What is lsp-mode?
¶Initial Configuration
(use-package lsp-mode :commands (lsp lsp-deferred) :init (setq lsp-keymap-prefix "C-c l") ;; Or 'C-l', 's-l' :config (lsp-enable-which-key-integration t))
¶Basic Completions
completion-at-pointfor completions- Signatures when writing methods (
C-n,C-pto cycle signatures)
¶Hover
¶Find Definitions and References
lsp-find-definition:C-c l g rlsp-find-references:C-c l g g
¶Rename Symbol
lsp-rename:C-c l r r
¶Diagnostics
flymake-show-diagnostics-bufferto show diagnostics
¶Code Actions
¶Code Formatting
lsp-format-buffer:C-c l ===
Configure formatting options for some languages with lsp-<language>-format- variables
¶Header Breadcrumb
(defun efs/lsp-mode-setup () (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) (lsp-headerline-breadcrumb-mode)) :hook (lsp-mode . efs/lsp-mode-setup)
¶Better Completions with company-mode
(use-package company :after lsp-mode :hook (prog-mode . company-mode) :bind (:map company-active-map ("<tab>" . company-complete-selection)) (:map lsp-mode-map ("<tab>" . company-indent-or-complete-common)) :custom (company-minimum-prefix-length 1) (company-idle-delay 0.0)) (use-package company-box :hook (company-mode . company-box-mode))
¶More UI Enhancements lsp-ui-mode
(use-package lsp-ui :hook (lsp-mode . lsp-ui-mode))
¶Documentation
lsp-ui-doc-focus-frameto enter the documentation frame to navigate and search aroundlsp-ui-doc-unfocus-frameto leave documentation frame
(setq lsp-ui-doc-position 'bottom)
¶Sideline
(setq lsp-ui-sideline-enable nil) (setq lsp-ui-sideline-show-hover nil)
¶Peek
lsp-ui-peek-find-referencesto show references inline (M-n,M-pto cycle)
¶lsp-treemacs
Provides an even nicer UI on top of lsp-mode using Treemacs
lsp-treemacs-symbols- Show a tree view of the symbols in the current filelsp-treemacs-references- Show a tree view for the references of the symbol under the cursorlsp-treemacs-error-list- Show a tree view for the diagnostic messages in the project
(use-package lsp-treemacs :after lsp)
¶Quicker symbol searching with lsp-ivy
(use-package lsp-ivy)
¶TypeScript
(use-package typescript-mode :mode "\\.ts\\'" :hook (typescript-mode . lsp-deferred) :config (setq typescript-indent-level 2))
Install the typescript-language-server:
npm install -g typescript-language-server
¶C
Install the ccls language server.
¶Bonus: Commenting lines
M-; does comment, but the behavior sometimes isn’t exactly what you’d expect.
evil-nerd-commenter on GitHub
(use-package evil-nerd-commenter :bind ("M-/" . evilnc-comment-or-uncomment-lines))
¶There’s more to talk about later!
- dap-mode for debugging
- yasnippet
- running compilers and unit test tools
- language-specific videos
