Add smarter eglot-ensure hooks

Check if language server exists and if file is part of a project
before starting automatically
This commit is contained in:
Evie Litherland-Smith 2024-07-22 07:32:44 +01:00
parent 553eae89aa
commit c0ba4c15ca

19
init.el
View file

@ -902,7 +902,24 @@
:bind ( :map prog-mode-map :bind ( :map prog-mode-map
("C-c c a" . eglot-code-actions) ("C-c c a" . eglot-code-actions)
("C-c c r" . eglot-rename)) ("C-c c r" . eglot-rename))
:hook ((eglot-managed-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)))) :hook ((eglot-managed-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)))
(nix-mode . (lambda () (if (and (project-current nil)
(executable-find "nil" t))
(eglot-ensure))))
(python-base-mode . (lambda () (if (and (project-current nil)
(or (executable-find "pyright" t)
(executable-find "pylsp" t)))
(eglot-ensure))))
(lua-mode . (lambda () (if (and (project-current nil)
(executable-find "lua-language-server" t))
(eglot-ensure))))
((rust-ts-mode rust-mode) . (lambda () (if (and (project-current nil)
(executable-find "rust-analyzer" t))
(eglot-ensure))))
((js-base-mode typescript-ts-base-mode) . (lambda () (if (and (project-current nil)
(executable-find "typescript-language-server" t))
(eglot-ensure))))
)
:custom :custom
(eglot-menu-string "lsp") (eglot-menu-string "lsp")
(eglot-send-changes-idle-time 1) (eglot-send-changes-idle-time 1)