Skip to content

Commit

Permalink
Add support for nimlsp (dense-analysis#2815)
Browse files Browse the repository at this point in the history
* Add support for nimlsp.vim
* Add test and docs for nimlsp
* Add nimlsp to supported-tools.md
* Add nimlsp to doc/ale-supported-languages-and-tools.txt
  • Loading branch information
jeremija authored and timlag1305 committed Nov 5, 2019
1 parent bf19557 commit 583de67
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ale_linters/nim/nimlsp.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
" Author: jeremija <https://github.com/jeremija>
" Description: Support for nimlsp (language server for nim)

call ale#Set('nim_nimlsp_nim_sources', '')

function! ale_linters#nim#nimlsp#GetProjectRoot(buffer) abort
let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git')

if !empty(l:project_root)
return fnamemodify(l:project_root, ':h:h')
endif

return ''
endfunction

function! ale_linters#nim#nimlsp#GetCommand(buffer) abort
let l:nim_sources = ale#Var(a:buffer, 'nim_nimlsp_nim_sources')

if !empty(l:nim_sources)
let l:nim_sources = ale#Escape(l:nim_sources)
endif

return '%e' . ale#Pad(l:nim_sources)
endfunction

call ale#linter#Define('nim', {
\ 'name': 'nimlsp',
\ 'lsp': 'stdio',
\ 'executable': 'nimlsp',
\ 'command': function('ale_linters#nim#nimlsp#GetCommand'),
\ 'language': 'nim',
\ 'project_root': function('ale_linters#nim#nimlsp#GetProjectRoot'),
\})
25 changes: 25 additions & 0 deletions doc/ale-nim.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
===============================================================================
ALE Nim Integration *ale-nim-options*


===============================================================================
nimcheck *ale-nim-nimcheck*

ALE does not provide additional configuration options for `nimcheck` at this
point.


===============================================================================
nimlsp *ale-nim-nimlsp*

g:nim_nimlsp_nim_sources *g:nim_nimlsp_nim_sources*

Type: |String|
Default: `''`

Sets the path to Nim source repository as the first argument to `nimlsp`
command.


===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Notes:
* `nasm`!!
* Nim
* `nim check`!!
* `nimlsp`
* nix
* `nix-instantiate`
* `nixpkgs-fmt`
Expand Down
3 changes: 3 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,9 @@ documented in additional help files.
mmc...................................|ale-mercury-mmc|
nasm....................................|ale-nasm-options|
nasm..................................|ale-nasm-nasm|
nim.....................................|ale-nim-options|
nimcheck..............................|ale-nim-nimcheck|
nimlsp................................|ale-nim-nimlsp|
nix.....................................|ale-nix-options|
nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
nroff...................................|ale-nroff-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ formatting.
* [nasm](https://www.nasm.us/) :floppy_disk:
* Nim
* [nim check](https://nim-lang.org/docs/nimc.html) :floppy_disk:
* [nimlsp](https://github.com/PMunch/nimlsp)
* nix
* [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate)
* [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
Expand Down
12 changes: 12 additions & 0 deletions test/command_callback/test_nimlsp_command_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Before:
call ale#assert#SetUpLinterTest('nim', 'nimlsp')

After:
call ale#assert#TearDownLinterTest()

Execute(It does not set nim sources by default):
AssertLinter 'nimlsp', ale#Escape('nimlsp')

Execute(Sets nimlsp and escapes sources from g:ale_nim_nimlsp_nim_sources):
let g:ale_nim_nimlsp_nim_sources = '/path/to /Nim'
AssertLinter 'nimlsp', ale#Escape('nimlsp') . ' ' . ale#Escape('/path/to /Nim')
Empty file.
19 changes: 19 additions & 0 deletions test/test_nimlsp_project_root.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Before:
runtime ale_linters/nim/nimlsp.vim
call ale#test#SetDirectory('/testplugin/test')

After:
if isdirectory(g:dir . '/.git')
call delete(g:dir . '/.git', 'd')
endif

call ale#test#RestoreDirectory()
call ale#linter#Reset()


Execute(Detect root of nim project with .git/ correctly):
call ale#test#SetFilename('nim-test-files/with-git/src/source.nim')
call mkdir(g:dir . '/.git')
AssertEqual
\ ale#path#Simplify(g:dir),
\ ale_linters#nim#nimlsp#GetProjectRoot(bufnr(''))

0 comments on commit 583de67

Please sign in to comment.