mirror of
https://github.com/doomemacs/doomemacs
synced 2025-09-02 14:53:38 -05:00
@@ -24,8 +24,8 @@ This module adds Lua support to Doom Emacs.
|
||||
(supports EmmyLua, lua-language-server, and lua-lsp).
|
||||
- +tree-sitter ::
|
||||
Leverages tree-sitter for better syntax highlighting and structural text
|
||||
editing. Requires [[doom-module::tools tree-sitter]]. Has support for both Lua and
|
||||
Fennel.
|
||||
editing. Requires Emacs 30.1+ and [[doom-module::tools tree-sitter]]. Only
|
||||
supports Lua at the moment.
|
||||
- +moonscript ::
|
||||
Enable support for the Moonscript language.
|
||||
|
||||
|
@@ -1,5 +1,26 @@
|
||||
;;; lang/lua/autoload/lua.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defvar +lua-lsp-dir (concat doom-data-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.")
|
||||
|
||||
;;;###autoload
|
||||
(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 ((featurep :system 'macos) "bin/macOS")
|
||||
((featurep :system 'linux) "bin/Linux")
|
||||
((featurep :system 'windows) "bin/Windows"))
|
||||
"lua-language-server"))
|
||||
"-E" "-e" "LANG=en"
|
||||
(doom-path +lua-lsp-dir "main.lua")))
|
||||
|
||||
(defun +lua-love-build-command ()
|
||||
(when-let (root (+lua-love-project-root))
|
||||
(format "%s %s"
|
||||
|
@@ -7,44 +7,34 @@
|
||||
;;
|
||||
;;; Major modes
|
||||
|
||||
(defun +lua-common-config (mode)
|
||||
(set-lookup-handlers! mode :documentation 'lua-search-documentation)
|
||||
(set-electric! mode :words '("else" "end"))
|
||||
(set-repl-handler! mode #'+lua/open-repl)
|
||||
(set-company-backend! mode '(company-lua company-yasnippet))
|
||||
(when (modulep! +lsp)
|
||||
(add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append)
|
||||
(when (modulep! :tools lsp +eglot)
|
||||
(set-eglot-client! mode (+lua-generate-lsp-server-command)))))
|
||||
|
||||
|
||||
(use-package! lua-mode
|
||||
:interpreter "\\<lua\\(?:jit\\)?"
|
||||
:init
|
||||
(setq lua-indent-level 2) ; default is 3; madness!
|
||||
:config
|
||||
(+lua-common-config 'lua-mode))
|
||||
|
||||
|
||||
(use-package! lua-ts-mode
|
||||
:when (modulep! +tree-sitter)
|
||||
:defer t
|
||||
:init
|
||||
;; lua-indent-level defaults to 3 otherwise. Madness.
|
||||
(setq lua-indent-level 2)
|
||||
(set-tree-sitter! 'lua-mode 'lua-ts-mode
|
||||
'((lua :url "https://github.com/tree-sitter-grammars/tree-sitter-lua"
|
||||
:commit "db16e76558122e834ee214c8dc755b4a3edc82a9")))
|
||||
:config
|
||||
(set-lookup-handlers! 'lua-mode :documentation 'lua-search-documentation)
|
||||
(set-electric! 'lua-mode :words '("else" "end"))
|
||||
(set-repl-handler! 'lua-mode #'+lua/open-repl)
|
||||
(set-company-backend! 'lua-mode '(company-lua company-yasnippet))
|
||||
|
||||
(when (modulep! +lsp)
|
||||
(add-hook 'lua-mode-local-vars-hook #'lsp! 'append)
|
||||
|
||||
(when (modulep! :tools lsp +eglot)
|
||||
(defvar +lua-lsp-dir (concat doom-data-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 ((featurep :system 'macos) "bin/macOS")
|
||||
((featurep :system 'linux) "bin/Linux")
|
||||
((featurep :system '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)))
|
||||
|
||||
(when (modulep! +tree-sitter)
|
||||
(add-hook 'lua-mode-local-vars-hook #'tree-sitter! 'append))))
|
||||
(+lua-common-config 'lua-ts-mode))
|
||||
|
||||
|
||||
(use-package! moonscript
|
||||
@@ -60,6 +50,7 @@ lua-language-server.")
|
||||
(require 'flycheck-moonscript nil t)))
|
||||
|
||||
|
||||
;; TODO: fennel-ts-mode
|
||||
(use-package! fennel-mode
|
||||
:when (modulep! +fennel)
|
||||
:mode "\\.fenneldoc\\'"
|
||||
@@ -74,17 +65,14 @@ lua-language-server.")
|
||||
tab-width 2
|
||||
;; Don't treat autoloads or sexp openers as outline headers, we have
|
||||
;; hideshow for that.
|
||||
outline-regexp "[ \t]*;;;;* [^ \t\n]")
|
||||
|
||||
(when (modulep! +tree-sitter)
|
||||
(add-hook! 'fennel-mode-local-vars-hook 'tree-sitter! 'append)))
|
||||
outline-regexp "[ \t]*;;;;* [^ \t\n]"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Frameworks
|
||||
|
||||
(def-project-mode! +lua-love-mode
|
||||
:modes '(moonscript-mode lua-mode markdown-mode json-mode)
|
||||
:modes '(moonscript-mode lua-mode lua-ts-mode markdown-mode json-mode)
|
||||
:when (+lua-love-project-root)
|
||||
:on-load
|
||||
(progn
|
||||
|
13
modules/lang/lua/doctor.el
Normal file
13
modules/lang/lua/doctor.el
Normal file
@@ -0,0 +1,13 @@
|
||||
;;; lang/lua/doctor.el -*- lexical-binding: t; -*-
|
||||
|
||||
(assert! (or (not (modulep! +lsp))
|
||||
(modulep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(assert! (or (not (modulep! +tree-sitter))
|
||||
(modulep! :tools tree-sitter))
|
||||
"This module requires (:tools tree-sitter)")
|
||||
|
||||
(assert! (or (not (modulep! +tree-sitter))
|
||||
(fboundp 'lua-ts-mode))
|
||||
"Can't find `lua-ts-mode'; Emacs 30.1+ is required")
|
Reference in New Issue
Block a user