Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

aiken-lang/editor-integration-nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aiken Vim

A plugin for working with Aiken on Vim / NeoVim.

Features

  • Syntax Highlighting
  • Automatic indentation
  • Fold regions for fn, test and bench
  • LSP-integration via coc.vim or nvim's native LSP client.

Installation

Installation / vim-plug

Simply use:

Plug 'aiken-lang/editor-integration-nvim'

(optional) Enabling folds

To enable fold regions, and in case your defaults are different from nvim's defaults, add the following:

autocmd FileType aiken setlocal foldenable foldlevelstart=0

To 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
endfunction

Installation / 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
})

Installation / manual

Copy the content of ftdetect, indent and syntax to your $HOME/.config/nvim/. Make sure that :syntax is on.

LSP Configuration (coc.vim)

:CocConfig

{ "languageserver":
  { "aiken":
      { "command": "aiken"
      , "args": ["lsp"]
      , "trace.server": "verbose"
      , "rootPatterns": ["aiken.toml"]
      , "filetypes": ["aiken"]
      }
  }
}

Automatic formatting

" 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/

Preview

License

MPL-2.0

About

A plugin for working with Aiken on Vim / NeoVim.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •