2021-11-07 23:09:13 +01:00
:PROPERTIES:
:ID: cc668372-8d95-461b-a7c6-3e2b51de3f40
:END:
#+title : LSP
#+filetags : emacs-load
2022-07-31 11:03:59 +02:00
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
2023-01-15 01:16:04 +01:00
Disable server downloading suggestions.
#+begin_src emacs-lisp
(setq lsp-enable-suggest-server-download nil)
#+end_src
2021-11-07 23:09:13 +01:00
* Python
Using the Microsoft language server as it's the best afaik. It's weird because it doesn't lookup the path to itself via PATH but has to be statically set.
#+BEGIN_SRC emacs-lisp
2023-01-15 01:16:04 +01:00
(defun magic_rb/locate-python-executable-lsp-deffered ()
"Locates the python executable available to the current buffer and only then calls `lsp-deferred'."
(lambda ()
(require 'lsp-python-ms)
(envrc-mode)
(setq-local lsp-python-ms-executable (executable-find "python-language-server"))
(lsp-deferred)))
2021-11-07 23:09:13 +01:00
(use-package lsp-python-ms
:straight t
2023-01-09 13:06:55 +01:00
:after (lsp-mode)
2023-01-15 01:16:04 +01:00
:hook (python-mode . magic_rb/locate-python-executable-lsp-deffere)
2021-11-08 21:59:16 +01:00
:config
(defvar-local lsp-python-ms-executable ""))
2021-11-07 23:09:13 +01:00
#+END_SRC
* C/C++
This just requires hooking lsp onto ~c-mode~ and ~c++-mode~ .
#+BEGIN_SRC emacs-lisp
2023-01-09 13:06:55 +01:00
(use-package lsp-c++-c
:no-require t
:after (lsp-mode)
2023-01-15 01:16:04 +01:00
:hook ((c-mode-hook c++-mode-hook) . lsp-deferred))
2021-11-07 23:09:13 +01:00
#+END_SRC
* Haskell
Enable ~haskell-mode~ , and ~lsp-haskell~
#+BEGIN_SRC emacs-lisp
2022-01-18 00:26:49 +01:00
(use-package haskell-mode
:straight t
2023-01-15 01:16:04 +01:00
:hook
(((haskell-mode haskell-literate-mode) . interactive-haskell-mode)
((heskell-mode haskell-literate-mode) . haskell-indentation-mode))
2022-01-18 00:26:49 +01:00
:config
(setq lsp-haskell-plugin-ghcide-type-lenses-global-on nil
lsp-haskell-plugin-import-lens-code-lens-on nil))
(use-package lsp-haskell
:straight t
2023-01-09 13:06:55 +01:00
:after (haskell-mode lsp-mode)
2023-01-15 01:16:04 +01:00
:hook ((haskell-mode haskell-literate-mode) . lsp-deferred))
2021-11-07 23:09:13 +01:00
#+END_SRC
Disable the ~haskell-stack-ghc~ flycheck checker, it's not used when lsp starts, but it does get loaded just before it. Loading and unloading it is slow and causes Emacs to freeze for a few seconds, so just disable it.
#+BEGIN_SRC emacs-lisp
(with-eval-after-load "flycheck"
(add-to-list 'flycheck-disabled-checkers 'haskell-stack-ghc))
#+END_SRC
2023-01-09 13:06:55 +01:00
* Javascript
Enable ~rjsx-mode~ instead of ~javascript-mode~ or ~js2-mode~ as it properly handles inline HTML.
#+BEGIN_SRC emacs-lisp
(use-package rjsx-mode
:straight t
:config
:mode ("\\.js\\'" . rjsx-mode)
:mode ("\\.jsx\\'" . rjsx-mode)
2023-01-15 01:16:04 +01:00
:hook (rjsx-mode . lsp-deferred)
2023-01-09 13:06:55 +01:00
:init
;; Originally this function exits with a call to `error`, which causes the simple "PATH lookup"
;; scheme to not be tried
(cl-defun lsp--npm-dependency-path (&key package path &allow-other-keys)
"Return npm dependency PATH for PACKAGE."
(let ((path (executable-find
(f-join lsp-server-install-dir "npm" package
(cond ((eq system-type 'windows-nt) "")
(t "bin"))
path))))
(unless (and path (f-exists? path))
nil)
path)))
#+END_SRC
* Typescript
Enable ~typescript-mode~ for =.ts= , =.tsx= and hook ~lsp-mode~ on it. It doesn't specifically support inline HTML,
but aside from minor indentation issues it works fine.
#+BEGIN_SRC emacs-lisp
(use-package typescript-mode
:straight t
:config
:mode ("\\.ts\\'" . typescript-mode)
:mode ("\\.tsx\\'" . typescript-mode)
2023-01-15 01:16:04 +01:00
:hook (typescript-mode . lsp-deferred))
2023-01-09 13:06:55 +01:00
#+END_SRC
* HTML Markup Language
Enable ~web-mode~ for =.html= , =.xhtml= and hook ~lsp-mode~ on it.
#+BEGIN_SRC emacs-lisp
(use-package web-mode
:straight t
:mode ("\\.html\\'" . web-mode)
:mode ("\\.xhtml\\'" . web-mode)
2023-01-15 01:16:04 +01:00
:hook (web-mode . lsp-deferred))
2023-01-09 13:06:55 +01:00
#+END_SRC
* CSS Style Sheet Language
Enable ~css-mode~ for =.css= , =.scss= and hook ~lsp-mode~ on it. Also make ~flycheck~ happy.
#+BEGIN_SRC emacs-lisp
(use-package css-mode
:mode ("\\.css\\'" . css-mode)
:mode ("\\.scss\\'". css-mode)
2023-01-15 01:16:04 +01:00
:hook (css-mode . lsp-deferred)
2023-01-09 13:06:55 +01:00
:config
(with-eval-after-load "flycheck"
(flycheck-add-mode 'javascript-eslint 'web-mode)))
#+END_SRC