2017-08-28 15:33:55 +00:00
#+TITLE : Lua layer
2015-06-10 16:44:30 +00:00
2019-05-07 08:53:56 +00:00
#+TAGS : general|layer|multi-paradigm|programming
2019-05-05 17:26:40 +00:00
2015-06-10 16:44:30 +00:00
[[file:img/lua.gif ]]
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
- [[#features ][Features: ]]
- [[#install ][Install ]]
2019-11-12 03:29:50 +00:00
- [[#layer ][Layer ]]
- [[#backends ][Backends ]]
2019-11-30 23:39:37 +00:00
- [[#lua-mode ][Lua mode ]]
2021-02-13 21:53:57 +00:00
- [[#lsp ][LSP ]]
- [[#emmy-server-setup ][Emmy server setup ]]
- [[#lua-language-server-setup ][Lua-language server setup ]]
- [[#lua-lsp-server-setup ][Lua-lsp server setup ]]
2018-12-05 03:03:03 +00:00
- [[#key-bindings ][Key bindings ]]
2019-11-12 03:29:50 +00:00
- [[#lsp-1 ][LSP ]]
2017-05-22 14:16:12 +00:00
- [[#commands ][Commands ]]
2015-06-10 16:44:30 +00:00
* Description
This layer adds support for editing Lua.
2015-06-10 21:16:01 +00:00
** Features:
2015-06-10 16:44:30 +00:00
- Editing lua files using [[https://github.com/immerrr/lua-mode ][lua-mode ]]
2020-04-02 16:41:28 +00:00
- Code-Completion with =lsp= or =company-lua=
2015-06-10 16:44:30 +00:00
- Sending code to a lua REPL
2016-02-17 14:01:10 +00:00
- Code linting using [[https://github.com/mpeterv/luacheck ][Luacheck ]]
2019-11-30 23:39:37 +00:00
- Cross references (definitions, references, rename...)
2015-06-10 16:44:30 +00:00
* Install
2019-11-12 03:29:50 +00:00
** Layer
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =lua= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
2016-02-17 14:01:10 +00:00
In order to enable code linting, install [[https://github.com/mpeterv/luacheck ][Luacheck ]].
2015-06-10 16:44:30 +00:00
2019-11-12 03:29:50 +00:00
** Backends
Supported backends are:
2021-02-13 21:53:57 +00:00
- =lua-mode= using emacs packages
- =lsp= using one of below LSP servers
- emmy LSP server (default)
- lua-language-server.
- lua-lsp.
*** Lua mode
This backend provides basic support via pure emacs packages. It requires less setup than a full blown LSP setup
but also provides less features. To enable it set the =lua-backend= to =lua-mode= .
#+BEGIN_SRC elisp
(lua :variables
lua-backend 'lua-mode)
#+END_SRC
2019-11-12 03:29:50 +00:00
*** LSP
2021-02-13 21:53:57 +00:00
This is the prefered backend choice. It relies on an external server implementing the LSP protocol.
It requires installing one of the supported server implementations below:
- [[https://github.com/EmmyLua/EmmyLua-LanguageServer ][EmmyLua ]]
- [[https://github.com/sumneko/lua-language-server ][lua-language-server ]]
- [[https://github.com/Alloyed/lua-lsp ][lua-lsp ]]
2019-11-12 03:29:50 +00:00
2021-02-13 21:53:57 +00:00
Once it is installed the keybindings are provided by [[file:../../+tools/lsp/README.org ][LSP layer ]] allowing
consistent keybindings among different layers.
2019-11-12 03:29:50 +00:00
2021-02-13 21:53:57 +00:00
To enable LSP set =lua-backend= to =lsp= . If =lua-backend= is =nil= and the =LSP layer= is loaded
=LSP= will be used automatically otherwise it will fallback to =lua-mode= .
#+BEGIN_SRC elisp
(lua :variables
lua-backend 'lsp)
#+END_SRC
**** Emmy server setup
To use the =emmy= lsp server, please download the [[https://github.com/EmmyLua/EmmyLua-LanguageServer ][EmmyLua-LS-all.jar ]] and put it into =~/.emacs.d/= .
Then set the layer variable =lua-lsp-server= to =emmy= . This is also the default choice if no specific
lsp server has been selected.
=emmy= requires a working java installation in the path as well as the path to the LSP server jar.
2019-11-30 23:39:37 +00:00
The java path and the path to the server executable can be configured as is shown below:
2019-11-30 23:48:29 +00:00
#+BEGIN_SRC elisp
2019-11-12 03:29:50 +00:00
(lua :variables
2021-02-13 21:53:57 +00:00
lua-backend 'lsp
lua-lsp-server 'emmy
2021-01-20 22:20:32 +00:00
lsp-clients-emmy-lua-jar-path "~/.emacs.d/ .cache/lsp/EmmyLua-LS-all.jar" ; default path
lsp-clients-emmy-lua-java-path "java") ; default path
#+END_SRC
2021-02-13 21:53:57 +00:00
**** Lua-language server setup
To use the =lua-language-server= lsp server, please follow [[https://github.com/sumneko/lua-language-server ][lua-language-server ]] to compile the standalone binary.
Then set the layer variables as shown below:
2021-01-20 22:20:32 +00:00
#+BEGIN_SRC elisp
(lua :variables
2021-02-13 21:53:57 +00:00
lua-backend 'lsp
lua-lsp-server 'lua-language-server
2021-01-20 22:20:32 +00:00
lsp-clients-lua-language-server-bin "~/.emacs.d/ .cache/lsp/lua-language-server/bin/Linux/lua-language-server" ; default path
lsp-clients-lua-language-server-main-location "~/.emacs.d/ .cache/lsp/lua-language-server/main.lua") ; default path
2019-11-30 23:48:29 +00:00
#+END_SRC
2019-11-12 03:29:50 +00:00
2021-02-13 21:53:57 +00:00
**** Lua-lsp server setup
To use the =lua-lsp= lsp server, please follow [[https://github.com/Alloyed/lua-lsp ][lua-lsp ]] to install the server via
luarocks. Remember that the capabilities of this server are mainly dependent
on the installed luarocks packages, so make sure you have them all installed
for maximum benefit.
To instruct Spacemacs to use this server set your config as shown below:
#+BEGIN_SRC elisp
(lua :variables
lua-backend 'lsp
lua-lsp-server 'lua-lsp
lsp-clients-luarocks-bin-dir "~/.luarocks/bin/ ") ; default path
#+END_SRC
2019-11-12 03:29:50 +00:00
2018-12-05 03:03:03 +00:00
* Key bindings
2019-11-12 03:29:50 +00:00
** LSP
The default key bindings for the LSP implementations are defined and documented in
the [[file:../../+tools/lsp/README.org ][LSP layer ]].
2015-06-10 16:44:30 +00:00
** Commands
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+--------------------------------------------|
| ~SPC m d~ | lookup thing at point in lua documentation |
| ~SPC m s b~ | send buffer contents to REPL |
| ~SPC m s f~ | send current function to REPL |
| ~SPC m s l~ | send current line to REPL |
| ~SPC m s r~ | send current region to REPL |
2019-11-30 23:39:37 +00:00
| ~SPC m '~ | open repl buffer |