diff --git a/modules/lang/lua/README.org b/modules/lang/lua/README.org index a48afb5c0..43776cdc9 100644 --- a/modules/lang/lua/README.org +++ b/modules/lang/lua/README.org @@ -39,19 +39,28 @@ This module has no dedicated maintainers. * Prerequisites ** Language Server Protocol servers -Currently the servers supported depend on the =:tools lsp= flavor you are using +LSP server support depends on which flavor of the =:tools lsp= module you have +installed (Eglot or LSP-mode). + *** LSP-mode -This server is built in Java, so a ~java~ environment will be necessary -+ [[https://github.com/EmmyLua/EmmyLua-LanguageServer][EmmyLua-LanguageServer]] must be installed and configured to use the - configuration provided by emacs-lsp. +Three servers are supported, ordered from highest to lowest priority: + ++ [[https://github.com/EmmyLua/EmmyLua-LanguageServer][EmmyLua-LanguageServer]] :: Must be in =~/.emacs.d/.local/etc/lsp/EmmyLua-LS-all.jar=. See ~lsp-clients-emmy-lua-jar-path~ variable to change this. ++ [[https://github.com/sumneko/lua-language-server][Sumneko language server]] (lua-language-server) :: Must be in + =~/.config/emacs/.local/etc/lsp/lua-language-server/=. See + ~lsp-clients-lua-language-server-bin~ variable to change this. ++ [[https://github.com/Alloyed/lua-lsp][lua-lsp]] :: Must be available in =~/.luarocks/bin/lua-lsp=. See + ~lsp-clients-lua-lsp-server-install-dir~ variable to change this. [[https://emacs-lsp.github.io/lsp-mode/page/lsp-emmy-lua/][LSP-mode documentation]] has more information about setting up the server and the -configuration variables correctly (use a bare ~(setq -lsp-clients-emmy-lua-java-path value)~ in your =config.el=) +configuration variables correctly. + *** Eglot -This server is built in Lua, so a =lua= environment will be necessary -+ [[https://github.com/sumneko/lua-language-server][lua-language-server]] must be installed and built locally, with =+lua-lsp-dir= - variable pointing to the root of the repository +Eglot currently only supports one of the above servers out of the box: + ++ [[https://github.com/sumneko/lua-language-server][Sumneko language server]] (lua-language-server) :: Must be in + =~/.config/emacs/.local/etc/lsp/lua-language-server/=. See + ~+lua-lsp-dir~ variable to change this. * TODO Features # An in-depth list of features, how to use them, and their dependencies. diff --git a/modules/lang/lua/config.el b/modules/lang/lua/config.el index 9137b7806..4dc22b2ef 100644 --- a/modules/lang/lua/config.el +++ b/modules/lang/lua/config.el @@ -1,11 +1,5 @@ ;;; lang/lua/config.el -*- lexical-binding: t; -*- -(defvar +lua-lsp-dir (concat doom-etc-dir "lsp/lua-language-server/") - "Absolute path to the directory of sumneko's lua-language-server. - -This directory MUST contain the 'main.lua' file and be the in-source build of -lua-language-server.") - ;; sp's default rules are obnoxious, so disable them (provide 'smartparens-lua) @@ -25,27 +19,29 @@ lua-language-server.") (set-company-backend! 'lua-mode '(company-lua company-yasnippet)) (when (featurep! +lsp) - (defun +lua-generate-lsp-server-command () - ;; The absolute path to lua-language-server binary is necessary because - ;; the bundled dependencies aren't found otherwise. The only reason this - ;; is a function is to dynamically change when/if `+lua-lsp-dir' does - (list (doom-path +lua-lsp-dir - (cond (IS-MAC "bin/macOS") - (IS-LINUX "bin/Linux") - (IS-WINDOWS "bin/Windows")) - "lua-language-server") - "-E" "-e" "LANG=en" - (doom-path +lua-lsp-dir "main.lua"))) + (add-hook 'lua-mode-local-vars-hook #'lsp!) - (if (featurep! :tools lsp +eglot) - (set-eglot-client! 'lua-mode (+lua-generate-lsp-server-command)) - (after! lsp-mode - (lsp-register-client - (make-lsp-client :new-connection (lsp-stdio-connection '+lua-generate-lsp-server-command) - :major-modes '(lua-mode) - :priority -1 - :server-id 'lua-langserver)))) - (add-hook 'lua-mode-local-vars-hook #'lsp!))) + (when (featurep! :tools lsp +eglot) + (defvar +lua-lsp-dir (concat doom-etc-dir "lsp/lua-language-server/") + "Absolute path to the directory of sumneko's lua-language-server. + +This directory MUST contain the 'main.lua' file and be the in-source build of +lua-language-server.") + + (defun +lua-generate-lsp-server-command () + ;; The absolute path to lua-language-server binary is necessary because + ;; the bundled dependencies aren't found otherwise. The only reason this + ;; is a function is to dynamically change when/if `+lua-lsp-dir' does + (list (or (executable-find "lua-language-server") + (doom-path +lua-lsp-dir + (cond (IS-MAC "bin/macOS") + (IS-LINUX "bin/Linux") + (IS-WINDOWS "bin/Windows")) + "lua-language-server")) + "-E" "-e" "LANG=en" + (doom-path +lua-lsp-dir "main.lua"))) + + (set-eglot-client! 'lua-mode (+lua-generate-lsp-server-command))))) (use-package! moonscript diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index 0196866dc..8504610c5 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -40,7 +40,10 @@ Can be a list of backends; accepts any value `company-backends' accepts.") lsp-vetur-global-snippets-dir (expand-file-name "vetur" (or (bound-and-true-p +snippets-dir) (concat doom-private-dir "snippets/"))) - lsp-clients-emmy-lua-jar-path (concat lsp-server-install-dir "EmmyLua-LS-all.jar") + lsp-clients-lua-language-server-bin (concat lsp-server-install-dir "lua-language-server/" + (cond (IS-MAC "bin/macOS") + (IS-LINUX "bin/Linux") + (IS-WINDOWS "bin/Windows"))) lsp-xml-jar-file (concat lsp-server-install-dir "org.eclipse.lsp4xml-0.3.0-uber.jar") lsp-groovy-server-file (concat lsp-server-install-dir "groovy-language-server-all.jar"))