4.4 KiB
Language servers provide auto completion and syntax highlighting capabilities making them essential for development.
Lsp Mode
Lsp Mode is a package that adds language server functionalities to Emacs.
Breadcrumb Header Line
This adds a headerline that shows the scope of where the cursor is in the code. For example if the user is in the main function, the headerline will contain main.
(defun jm/lsp-mode-setup ()
(setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols))
(lsp-headerline-breadcrumb-mode))
Install Lsp Mode
Below I am installing the actual package and adding some basic configuration.
(use-package lsp-mode
:init (setq lsp-keymap-prefix "C-c l") ; Lsp mode prefix
:hook (lsp-mode . jm/lsp-mode-setup)
:commands (lsp lsp-deferred) ; Startup commands
:config (lsp-enable-which-key-integration t))
Lsp Additional Packages
(use-package lsp-ui
:hook (lsp-mode . lsp-ui-mode)
:config (setq lsp-ui-sideline-show-diagnostics t))
Company Mode
Company is a package that automatically finds completions instead of making the user run a command for completions.
(use-package company
:after lsp-mode
:hook (lsp-mode . company-mode)
:bind (:map company-active-map ; Map tab to select completion
("<tab>" . company-complete-selection))
(:map lsp-mode-map
("<tab>" . company-indent-or-complete-common)))
Flycheck
(use-package flycheck
:init (global-flycheck-mode))
Language Servers
This will include any language server packages and configuration.
HTML
(use-package web-mode
:defer t
:mode "\\.html\\'"
:hook (web-mode . lsp-deferred))
JavaScript/Typescript
(use-package typescript-mode
:defer t
:mode ("\\.ts\\'" "\\.js\\'")
:hook (typescript-mode . lsp-deferred))
Install the typescript-language-server
through npm.
npm install -g typescript-language-server
Python
(use-package python-mode
:defer t
:mode ("\\.py\\'")
:hook (python-mode . lsp-deferred))
Install the python-lsp-server
though pip.
pip install python-lsp-server
C/C++
(use-package ccls
:defer t
:hook ((c-mode cc-mode c++-mode objc-mode cuda-mode) .
(lambda () (require 'ccls) (lsp)))
:config
(setq ccls-executable "/usr/bin/ccls"))
Install ccls
with homebrew using the following command.
sudo apt install ccls
Golang
(use-package go-mode
:defer t
:hook (go-mode . lsp-deferred))
Rust
(use-package rustic
:defer t
:hook (rust-mode . lsp-deferred))
C#
(use-package csharp-mode
:defer t
:hook (csharp-mode . lsp-deferred))
JSON
(use-package json-mode
:defer t
:hook (json-mode . lsp-deferred))
Yaml
(use-package yaml-mode
:defer t
:hook (yaml-mode . lsp-deferred))
Yara
To install the corresponding LSP, you need to install yls
. Using the command pip install -U yls-yara
. Keep in mind that yls
is dependent on an up to date version of yara-python
.
(use-package yara-mode
:defer t
:hook (yara-mode . lsp-deferred)
:config
(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration
'(yara-mode . "yara"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection "yls")
:activation-fn (lsp-activate-on "yara")
:server-id 'yls))))
R
(use-package ess
:defer t
:hook (R-mode . lsp-deferred))
Haskell
(use-package haskell-mode
:defer t
:hook (haskell-mode . lsp-deferred))
(use-package lsp-haskell
:defer t
:hook (lsp-literate-mode . lsp-deferred))
Ledger
Ledger is a Unix program that implements a finance tracking system or ledger. To implement this into emacs, you can install the ledger-mode
emacs package.
(use-package ledger-mode
:mode ("\\.ledger\\'"))