feat(emacs): Basic LSP

Includes basic Nix-mode config for the sake of testing the LSP.
This commit is contained in:
Madeleine Sydney
2025-02-12 17:45:58 -07:00
parent f53f58df5a
commit 03491612f2
5 changed files with 75 additions and 0 deletions

View File

@@ -61,4 +61,5 @@
(require 'syd-scratch) (require 'syd-scratch)
(require 'syd-smartparens) (require 'syd-smartparens)
(require 'syd-tramp) (require 'syd-tramp)
(require 'syd-tooling)
(require 'syd-ui) (require 'syd-ui)

View File

@@ -4,6 +4,10 @@
(require 'syd-constants) (require 'syd-constants)
(use-package dash)
(require 'dash)
(cl-defmacro syd-define-stub (cl-defmacro syd-define-stub
(name &key (desc "implement me!") interactive) (name &key (desc "implement me!") interactive)
(let ((todo (format "%s: TODO: %s" name desc))) (let ((todo (format "%s: TODO: %s" name desc)))
@@ -130,4 +134,35 @@ form."
(prog1 (progn ,@body) (prog1 (progn ,@body)
(message "")))))) (message ""))))))
(defun syd--parse-defadvice-args (arg-list)
"Parses the docstring and keywords provided to `syd-defadvice'."
(let (docstring
advice)
(when (stringp (car-safe arg-list))
(setq docstring (pop arg-list)))
(while (and (length> arg-list 2)
(keywordp (car arg-list)))
(let ((how (pop arg-list))
(sym (pop arg-list)))
(push (cons how sym) advice)))
;; What's left of `arg-list' is the body of the defun.
(list docstring advice arg-list)))
(defmacro syd-defadvice (name params &rest args)
"Define a function and add it as advice."
(declare (indent defun))
(-let (((docstring advice body) (syd--parse-defadvice-args args)))
`(progn (defun ,name ,params
,@(-some-> docstring list)
,@body)
,@(-map (lambda (arg)
(-let (((how . sym) arg))
`(advice-add ,sym ,how #',name)))
advice))))
(syd-defadvice syd-lsp-install-server-a ()
:override #'lsp-install-server
(user-error (concat "Ignoring a call to `lsp-install-server'"
" — tell the caller to use Nix!")))
(provide 'syd-prelude) (provide 'syd-prelude)

View File

@@ -0,0 +1,8 @@
;;; syd-lang-nix.el -*- lexical-binding: t; -*-
(use-package nix-mode
:mode "\\.nix\\'"
:config
(add-hook 'nix-mode-hook #'lsp))
(provide 'syd-lang-nix)

View File

@@ -2,5 +2,6 @@
(file-name-concat user-emacs-directory "modules" "lang")) (file-name-concat user-emacs-directory "modules" "lang"))
(require 'syd-lang-emacs-lisp) (require 'syd-lang-emacs-lisp)
(require 'syd-lang-nix)
(provide 'syd-lang) (provide 'syd-lang)

View File

@@ -0,0 +1,30 @@
;;; syd-tooling.el -*- lexical-binding: t; -*-
(use-package lsp-mode
:init
;; We'll bind things ourselves.
(setq lsp-keymap-prefix nil)
;; Keep state out of my config dir.
(setq lsp-session-file (file-name-concat syd-data-dir "lsp-session")
;; We disable `lsp-install-server', but I don't want this to be nil.
lsp-server-install-dir (file-name-concat syd-data-dir "lsp"))
;; Disable features that have great potential to be slow. LSPs tend to be
;; quite slow compared to non-LSP equivalents.
(setq lsp-enable-folding nil
lsp-enable-text-document-color nil)
;; Reduce unexpected modifications to code
(setq lsp-enable-on-type-formatting nil)
;; Make breadcrumbs opt-in; they're redundant with the modeline and imenu
(setq lsp-headerline-breadcrumb-enable nil)
:hook (lsp-mode . lsp-enable-which-key-integration)
:commands lsp
:config
(syd-defadvice syd-lsp-install-server-a ()
"Override and disbale `lsp-install-server'"
:override #'lsp-install-server
(user-error (concat "Ignoring a call to `lsp-install-server'"
" — tell the caller to use Nix!")))
(set-popup-rule! (rx line-start "*lsp-" (or "help" "install"))
:size 0.35 :quit t :select nil))
(provide 'syd-tooling)