This plugin adds support for writing neovim plugins/configuration in teal (ie. strongly typed lua) instead of (or in addition to) lua
This plugin requires that both tl and cyan have been installed via luarocks, and are both available on the PATH
This plugin follows the conventions that already exist in neovim for both lua and python. On startup, neovim will automatically modify the lua package.path value, so that any lua require statements will find any lua files inside any /lua directories on the neovim runtimepath. Neovim also supports a /python directory which works similarly. This plugin follows this same convention by adding support for a /teal directory on the runtimepath as well.
This same approach was also done for moonscript in the nvim-moonmaker plugin
-
Install the plugin using whatever neovim plugin manager you prefer.
-
Place some
tlfiles inside a/tealdirectory underneath one of the directories on the neovimruntimepath(see:h runtimepathfor details). If you're not making a plugin and instead want to just write some neovim configuration inteal, you can also just add a/tealdirectory alongside yourinit.lua/init.vim -
Place a file named
tlconfig.luaalongside the/tealdirectory with the following contents. See documentation for tl / cyan for more details on this config file.
return {
build_dir = "lua",
source_dir = "teal",
include_dir = { "teal" }
}
-
Execute
:TealBuild -
Your
tlfiles inside the/tealdirectory should now have been compiled to lua and placed where neovim expects them (the/luadirectory)
Notes:
-
In addition to
:TealBuild, there are several other ways to trigger a teal build:- Directly from lua/teal by importing
tealmaker:
local verbose_output = false require("tealmaker").build_all(verbose_output)- By calling
tealmaker#BuildAllfrom VimL:
local verbose_output = 0 call tealmaker#BuildAll(verbose_output) - Directly from lua/teal by importing
If you'd like to write your neovim configuration in teal, you might do something like this:
- Create a new
init.vimwith contents:
call plug#begin(stdpath('data') . '/plugged')
Plug 'svermeulen/nvim-teal-maker'
call plug#end()
- Note that we assume you already have vim-plug installed. Of course, any other plugin manager would be fine as well.
- Add a
/tealdirectory next to yourinit.vim - Place a file named
my_config.tlinside/tealwith some neovim configuration. As a random example:
require("vim")
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.incsearch = true
vim.o.hidden = true
vim.o.history = 5000
vim.o.tabstop = 4
vim.o.shiftwidth = vim.o.tabstop
vim.g.mapleader = " "
vim.keymap.set('n', '<space>q', ':qa<cr>')
vim.keymap.set('n', '<space>hw', function()
print("hello world")
end)
- Also add a
tlconfig.luafile as described in quick start section above - Open neovim, run
:PlugInstall, then execute:TealBuild. This should result in errors of the form:
Error 11 type errors in teal/my_config.tl
... teal/my_config.tl 2:1
... 2 | vim.o.ignorecase = true
... | ^^^
... | unknown variable: vim
-
This is because teal needs type definitions for the
vimobject that we are using. We can solve this problem by downloading thevim.d.tltype definition file from the teal-types repo here and placing it inside our/tealdirectory. -
Open neovim and execute
:TealBuildagain. The build should pass now with output:
Info Type checked teal/my_config.tl
Info Wrote lua/my_config.lua
- Next, let's make sure that our teal file automatically gets built on startup. Let's change our
init.vimto the following:
call plug#begin(stdpath('data') . '/plugged')
Plug 'svermeulen/nvim-teal-maker'
call plug#end()
call tealmaker#buildAll()
lua require('my_config')
-
Note that we are calling
call tealmaker#buildAll()before the call tolua require('my_config'). This is important, since otherwise therequirewould load the previously compiled version. -
With the above set up, we can now directly modify our
my_config.tlfile and the corresponding lua files will be automatically built the next time neovim is started. Try changing something inmy_config.tl, restarting neovim, and verifying that this works
let g:TealMaker_Prune = 0- Set this to
1to automatically delete any lua files that don't have corresponding teal files. However - requires a version of cyan that has--pruneoption (version must be >0.1.0). Also note that when this option is enabled, any lua files inside the/tealdirectory will be automatically copied to/luaas well, since you can't place lua files inside/luadirectly with this option enabled, and it can be common to have some source files in lua.
- Set this to
-
If you are writing a plugin, you don't need to depend on this plugin, since you can just include the compiled lua files (which is exactly what this plugin does)
-
If your plugin contains multiple
tlfiles and you want to avoid polluting the root require path, you can put your teal files into subdirectories underneath thetealfolder. Then you can userequire("dir1.dir2.filename")to use them from othertlfiles