Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration with ALE? #51

Open
collinarnett opened this issue Jan 7, 2023 · 5 comments
Open

Configuration with ALE? #51

collinarnett opened this issue Jan 7, 2023 · 5 comments
Labels
A-vim Area: Vim/Neovim C-support Catagory: support questions

Comments

@collinarnett
Copy link

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.

@oxalica oxalica added C-support Catagory: support questions A-vim Area: Vim/Neovim labels Jan 8, 2023
@oxalica
Copy link
Owner

oxalica commented Jan 8, 2023

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

@collinarnett
Copy link
Author

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

@oxalica
Copy link
Owner

oxalica commented Jan 10, 2023

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.

@SamuelKurtzer
Copy link

SamuelKurtzer commented Mar 8, 2024

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'),
\})

@martinetd
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vim Area: Vim/Neovim C-support Catagory: support questions
Projects
None yet
Development

No branches or pull requests

4 participants