mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
feat(lua): add treesit support
This commit is contained in:
@ -1,5 +1,26 @@
|
|||||||
;;; lang/lua/autoload/lua.el -*- lexical-binding: t; -*-
|
;;; 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 ()
|
(defun +lua-love-build-command ()
|
||||||
(when-let (root (+lua-love-project-root))
|
(when-let (root (+lua-love-project-root))
|
||||||
(format "%s %s"
|
(format "%s %s"
|
||||||
|
@ -8,10 +8,11 @@
|
|||||||
;;; Major modes
|
;;; Major modes
|
||||||
|
|
||||||
(use-package! lua-mode
|
(use-package! lua-mode
|
||||||
:defer t
|
:interpreter "\\<lua\\(?:jit\\)?"
|
||||||
:init
|
:init
|
||||||
;; lua-indent-level defaults to 3 otherwise. Madness.
|
;; lua-indent-level defaults to 3 otherwise. Madness.
|
||||||
(setq lua-indent-level 2)
|
(setq lua-indent-level 2)
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(set-lookup-handlers! 'lua-mode :documentation 'lua-search-documentation)
|
(set-lookup-handlers! 'lua-mode :documentation 'lua-search-documentation)
|
||||||
(set-electric! 'lua-mode :words '("else" "end"))
|
(set-electric! 'lua-mode :words '("else" "end"))
|
||||||
@ -20,31 +21,32 @@
|
|||||||
|
|
||||||
(when (modulep! +lsp)
|
(when (modulep! +lsp)
|
||||||
(add-hook 'lua-mode-local-vars-hook #'lsp! 'append)
|
(add-hook 'lua-mode-local-vars-hook #'lsp! 'append)
|
||||||
|
|
||||||
(when (modulep! :tools lsp +eglot)
|
(when (modulep! :tools lsp +eglot)
|
||||||
(defvar +lua-lsp-dir (concat doom-data-dir "lsp/lua-language-server/")
|
(set-eglot-client! 'lua-mode (+lua-generate-lsp-server-command)))))
|
||||||
"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 ()
|
(use-package! lua-ts-mode
|
||||||
;; The absolute path to lua-language-server binary is necessary because
|
:when (modulep! +tree-sitter)
|
||||||
;; the bundled dependencies aren't found otherwise. The only reason this
|
:when (fboundp 'lua-ts-mode) ; 30.1+ only
|
||||||
;; is a function is to dynamically change when/if `+lua-lsp-dir' does
|
:defer t
|
||||||
(list (or (executable-find "lua-language-server")
|
:init
|
||||||
(doom-path +lua-lsp-dir
|
(set-tree-sitter! 'lua-mode 'lua-ts-mode
|
||||||
(cond ((featurep :system 'macos) "bin/macOS")
|
'((lua :url "https://github.com/tree-sitter-grammars/tree-sitter-lua"
|
||||||
((featurep :system 'linux) "bin/Linux")
|
:rev "v0.3.0")))
|
||||||
((featurep :system 'windows) "bin/Windows"))
|
:config
|
||||||
"lua-language-server"))
|
(set-lookup-handlers! 'lua-ts-mode :documentation 'lua-search-documentation)
|
||||||
"-E" "-e" "LANG=en"
|
(set-electric! 'lua-ts-mode :words '("else" "end"))
|
||||||
(doom-path +lua-lsp-dir "main.lua")))
|
(set-repl-handler! 'lua-ts-mode #'+lua/open-repl)
|
||||||
|
(set-company-backend! 'lua-ts-mode '(company-lua company-yasnippet))
|
||||||
|
|
||||||
(set-eglot-client! 'lua-mode (+lua-generate-lsp-server-command)))
|
(when (modulep! +lsp)
|
||||||
|
(add-hook 'lua-ts-mode-local-vars-hook #'lsp! 'append)
|
||||||
|
(when (modulep! :tools lsp +eglot)
|
||||||
|
(set-eglot-client! 'lua-ts-mode (+lua-generate-lsp-server-command))))
|
||||||
|
|
||||||
(when (modulep! +tree-sitter)
|
;; HACK: Get rid of redundancies, rely on `major-mode-remap-defaults'
|
||||||
(add-hook 'lua-mode-local-vars-hook #'tree-sitter! 'append))))
|
(cl-callf2 delete '("\\.lua\\'" . lua-ts-mode) auto-mode-alist)
|
||||||
|
(cl-callf2 delete '("\\<lua\\(?:jit\\)?" . lua-ts-mode) interpreter-mode-alist))
|
||||||
|
|
||||||
|
|
||||||
(use-package! moonscript
|
(use-package! moonscript
|
||||||
@ -60,6 +62,7 @@ lua-language-server.")
|
|||||||
(require 'flycheck-moonscript nil t)))
|
(require 'flycheck-moonscript nil t)))
|
||||||
|
|
||||||
|
|
||||||
|
;; TODO: fennel-ts-mode
|
||||||
(use-package! fennel-mode
|
(use-package! fennel-mode
|
||||||
:when (modulep! +fennel)
|
:when (modulep! +fennel)
|
||||||
:mode "\\.fenneldoc\\'"
|
:mode "\\.fenneldoc\\'"
|
||||||
@ -75,17 +78,14 @@ lua-language-server.")
|
|||||||
tab-width 2
|
tab-width 2
|
||||||
;; Don't treat autoloads or sexp openers as outline headers, we have
|
;; Don't treat autoloads or sexp openers as outline headers, we have
|
||||||
;; hideshow for that.
|
;; hideshow for that.
|
||||||
outline-regexp "[ \t]*;;;;* [^ \t\n]")
|
outline-regexp "[ \t]*;;;;* [^ \t\n]"))
|
||||||
|
|
||||||
(when (modulep! +tree-sitter)
|
|
||||||
(add-hook! 'fennel-mode-local-vars-hook 'tree-sitter! 'append)))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Frameworks
|
;;; Frameworks
|
||||||
|
|
||||||
(def-project-mode! +lua-love-mode
|
(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)
|
:when (+lua-love-project-root)
|
||||||
:on-load
|
:on-load
|
||||||
(progn
|
(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")
|
@ -41,7 +41,6 @@
|
|||||||
(julia "https://github.com/tree-sitter/tree-sitter-julia" nil nil nil nil)
|
(julia "https://github.com/tree-sitter/tree-sitter-julia" nil nil nil nil)
|
||||||
(kotlin "https://github.com/fwcd/tree-sitter-kotlin" nil nil nil nil)
|
(kotlin "https://github.com/fwcd/tree-sitter-kotlin" nil nil nil nil)
|
||||||
(latex "https://github.com/latex-lsp/tree-sitter-latex" nil nil nil nil)
|
(latex "https://github.com/latex-lsp/tree-sitter-latex" nil nil nil nil)
|
||||||
(lua "https://github.com/tree-sitter-grammars/tree-sitter-lua" nil nil nil nil)
|
|
||||||
(make "https://github.com/tree-sitter-grammars/tree-sitter-make" nil nil nil nil)
|
(make "https://github.com/tree-sitter-grammars/tree-sitter-make" nil nil nil nil)
|
||||||
(nix "https://github.com/nix-community/tree-sitter-nix" nil nil nil nil)
|
(nix "https://github.com/nix-community/tree-sitter-nix" nil nil nil nil)
|
||||||
(nu "https://github.com/nushell/tree-sitter-nu" nil nil nil nil)
|
(nu "https://github.com/nushell/tree-sitter-nu" nil nil nil nil)
|
||||||
|
Reference in New Issue
Block a user