A plugin for working with Aiken on Vim / NeoVim.
- Syntax Highlighting
- Automatic indentation
- Fold regions for
fn,testandbench - LSP-integration via coc.vim or nvim's native LSP client.
Installation / vim-plug
Simply use:
Plug 'aiken-lang/editor-integration-nvim'To enable fold regions, and in case your defaults are different from nvim's defaults, add the following:
autocmd FileType aiken setlocal foldenable foldlevelstart=0To only fold when files are "long":
augroup AikenDynamicFolds
autocmd!
autocmd FileType aiken call s:AikenDynamicFoldSetup()
augroup END
function! s:AikenDynamicFoldSetup() abort
let nlines = line('$')
if nlines < 100
setlocal foldlevel=99
setlocal foldlevelstart=99
else
setlocal foldlevel=0
setlocal foldlevelstart=0
endif
endfunctionInstallation / lazy.nvim
First add this to lazy.nvim setup:
{
"aiken-lang/editor-integration-nvim",
dependencies = {
'neovim/nvim-lspconfig',
}
}Then to enable the Aiken LSP, add the following to init.lua file:
require'lspconfig'.aiken.setup({})To enable the auto formatting on save, add the following to init.lua file:
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.ak",
callback = function()
vim.lsp.buf.format({async = false})
vim.opt_local.foldenable = true -- Optional, to enable or disable fold regions.
vim.opt_local.foldlevelstart = 0 -- Optional, start with all regions folded.
-- Or, to configure folding dynamically based on the file length
local buf = vim.api.nvim_get_current_buf()
local nlines = vim.api.nvim_buf_line_count(buf)
if nlines < 100 then
-- Small file: open all folds
vim.opt_local.foldlevel = 99
vim.opt_local.foldlevelstart = 99
else
-- Big file: start collapsed
vim.opt_local.foldlevel = 0
vim.opt_local.foldlevelstart = 0
end
end
})Copy the content of ftdetect, indent and syntax to your $HOME/.config/nvim/.
Make sure that :syntax is on.
{ "languageserver":
{ "aiken":
{ "command": "aiken"
, "args": ["lsp"]
, "trace.server": "verbose"
, "rootPatterns": ["aiken.toml"]
, "filetypes": ["aiken"]
}
}
}" Automatically format code on save
autocmd BufWritePre *.ak :silent! call CocAction('format')To use tags for navigation, use the following configuration:
--langdef=Aiken
--langmap=Aiken:.ak
--regex-Aiken=/^fn[ \t]+([a-zA-Z0-9_]+)/\1/f,functions/
--regex-Aiken=/^test[ \t]+([a-zA-Z0-9_]+)/\1/f,functions/
--regex-Aiken=/^bench[ \t]+([a-zA-Z0-9_]+)/\1/f,functions/
--regex-Aiken=/^const[ \t]+([a-zA-Z0-9_]+)/\1/v,varlambdas/
--regex-Aiken=/^type[ \t]+([a-zA-Z0-9_]+)/\1/t,types/