nil icon indicating copy to clipboard operation
nil copied to clipboard

Configuration with ALE?

Open collinarnett opened this issue 2 years ago • 5 comments

I tried my best to get this working with A.L.E in vim and I'm having trouble. I can't seem to get past a simple errors in ALE.

function! GetCommand(buffer) abort
    return '%e' . ale#Pad('stdio')
endfunction

call ale#linter#Define('nix', {
\   'name': 'nil',
\   'lsp': 'stdio',
\   'executable': 'nil',
\   'command': function('GetCommand'),
\   'language': 'nix',
\   'project_root': '.'
\})

I also tried using nil as the command but that didn't work either. I feel like I'm missing something extremely basic.

collinarnett avatar Jan 07 '23 21:01 collinarnett

Maybe you could check out the configuration of rust-analyzer for reference.

oxalica avatar Jan 08 '23 01:01 oxalica

I think this is the final straw in moving to neovim. This and the latest advancements with tree-sitter and scala.

collinarnett avatar Jan 09 '23 18:01 collinarnett

I think this is the final straw in moving to neovim. This and the latest advancements with tree-sitter and scala.

Note that coc.nvim also works fluently on Vim and supports inlay hints only on Vim 9. (Neovim havn't implemented in-line decorations yet) tree-sitter should be strictly worse and slower than LSP semantic highlighting, since it serves as a light-but-general-LSP. Usually you need to turn it off when editing all-packages.nix.

oxalica avatar Jan 10 '23 18:01 oxalica

Managed to get this working, thanks to @oxalica for pointing me in the right direction. in ale/ale_linters/nix/nil.vim I have created this file:

call ale#Set('nix_nil_exec', 'nil')
call ale#Set('nix_nil_config', {})

function! ale_linters#nix#nil#GetCommand(buffer) abort
    return '%e'
endfunction

function! ale_linters#nix#nil#GetProjectRoot(buffer) abort
    let l:flake_file = ale#path#FindNearestFile(a:buffer, 'flake.nix')

    return !empty(l:flake_file) ? fnamemodify(l:flake_file, ':h') : ''
endfunction

call ale#linter#Define('nix', {
\   'name': 'nil',
\   'lsp': 'stdio',
\   'lsp_config': {b -> ale#Var(b, 'nix_nil_config')},
\   'executable': {b -> ale#Var(b, 'nix_nil_exec')},
\   'command': function('ale_linters#nix#nil#GetCommand'),
\   'project_root': function('ale_linters#nix#nil#GetProjectRoot'),
\})

and I've just added nil to my list of nix linters. I've made the root directory point to the closest flake atm but that may not work for all peoples setups. I'm going to have a look at some other linters and see how they handle it.

Edit: had a look at some of the go lsp's, they use .git location as their backup, but i think that would be perfect for the primary here. I'll use this for like a week and if nobody has any comments I'll make a PR to get this into ale.

call ale#Set('nix_nil_exec', 'nil')
call ale#Set('nix_nil_config', {})

function! ale_linters#nix#nil#GetCommand(buffer) abort
    return '%e'
endfunction

function! ale_linters#nix#nil#GetProjectRoot(buffer) abort
    let l:git_root = ale#path#FindNearestDirectory(a:buffer, '.git')

    return !empty(l:git_root) ? fnamemodify(l:git_root, ':h') : ''
endfunction

call ale#linter#Define('nix', {
\   'name': 'nil',
\   'lsp': 'stdio',
\   'lsp_config': {b -> ale#Var(b, 'nix_nil_config')},
\   'executable': {b -> ale#Var(b, 'nix_nil_exec')},
\   'command': function('ale_linters#nix#nil#GetCommand'),
\   'project_root': function('ale_linters#nix#nil#GetProjectRoot'),
\})

SamuelKurtzer avatar Mar 08 '24 00:03 SamuelKurtzer

Hi @SamuelKurtzer -- I don't see any PR for nil over there https://github.com/dense-analysis/ale/pulls?is%3Apr+nil , have you had a chance to find time to do it?

(just looking at nix linters landscape and was wondering what to use at this point and wondered about this. I'm not above manually adding this file, but it'll benefit everyone if it were merged upstream)

martinetd avatar Jul 21 '24 11:07 martinetd