From be21aa5cda39850d9f0261e3b6cac9d48a170756 Mon Sep 17 00:00:00 2001 From: Auri Date: Wed, 17 Oct 2018 18:11:41 +0300 Subject: New linter: dls (#1992) * New linter: dls --- README.md | 2 +- ale_linters/d/dls.vim | 22 ++++++++++++++++++++++ ale_linters/d/dmd.vim | 16 +--------------- autoload/ale/d.vim | 16 ++++++++++++++++ doc/ale-d.txt | 11 +++++++++++ doc/ale.txt | 3 ++- test/command_callback/test_d_dls_callbacks.vader | 19 +++++++++++++++++++ 7 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 ale_linters/d/dls.vim create mode 100644 autoload/ale/d.vim create mode 100644 test/command_callback/test_d_dls_callbacks.vader diff --git a/README.md b/README.md index f388aa86..a99b500f 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ formatting. | CSS | [csslint](http://csslint.net/), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | Cucumber | [cucumber](https://cucumber.io/) | | Cython (pyrex filetype) | [cython](http://cython.org/) | -| D | [dmd](https://dlang.org/dmd-linux.html), [uncrustify](https://github.com/uncrustify/uncrustify) | +| D | [dls](https://github.com/d-language-server/dls), [dmd](https://dlang.org/dmd-linux.html), [uncrustify](https://github.com/uncrustify/uncrustify) | | Dafny | [dafny](https://rise4fun.com/Dafny) !! | | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server), [dartfmt](https://github.com/dart-lang/sdk/tree/master/utils/dartfmt) | | Dockerfile | [hadolint](https://github.com/hadolint/hadolint) | diff --git a/ale_linters/d/dls.vim b/ale_linters/d/dls.vim new file mode 100644 index 00000000..7210d21e --- /dev/null +++ b/ale_linters/d/dls.vim @@ -0,0 +1,22 @@ +" Author: aurieh +" Description: A Language Server implementation for D + +call ale#Set('d_dls_executable', 'dls') + +function! ale_linters#d#dls#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'd_dls_executable') +endfunction + +function! ale_linters#d#dls#FindProjectRoot(buffer) abort + " Note: this will return . if dub config is empty + " dls can run outside DUB projects just fine + return fnamemodify(ale#d#FindDUBConfig(a:buffer), ':h') +endfunction + +call ale#linter#Define('d', { +\ 'name': 'dls', +\ 'lsp': 'stdio', +\ 'executable_callback': 'ale_linters#d#dls#GetExecutable', +\ 'command_callback': 'ale_linters#d#dls#GetExecutable', +\ 'project_root_callback': 'ale_linters#d#dls#FindProjectRoot', +\}) diff --git a/ale_linters/d/dmd.vim b/ale_linters/d/dmd.vim index d64b6c3d..c816d592 100644 --- a/ale_linters/d/dmd.vim +++ b/ale_linters/d/dmd.vim @@ -1,20 +1,6 @@ " Author: w0rp " Description: "dmd for D files" -function! s:FindDUBConfig(buffer) abort - " Find a DUB configuration file in ancestor paths. - " The most DUB-specific names will be tried first. - for l:possible_filename in ['dub.sdl', 'dub.json', 'package.json'] - let l:dub_file = ale#path#FindNearestFile(a:buffer, l:possible_filename) - - if !empty(l:dub_file) - return l:dub_file - endif - endfor - - return '' -endfunction - function! ale_linters#d#dmd#DUBCommand(buffer) abort " If we can't run dub, then skip this command. if !executable('dub') @@ -22,7 +8,7 @@ function! ale_linters#d#dmd#DUBCommand(buffer) abort return '' endif - let l:dub_file = s:FindDUBConfig(a:buffer) + let l:dub_file = ale#d#FindDUBConfig(a:buffer) if empty(l:dub_file) return '' diff --git a/autoload/ale/d.vim b/autoload/ale/d.vim new file mode 100644 index 00000000..0e232203 --- /dev/null +++ b/autoload/ale/d.vim @@ -0,0 +1,16 @@ +" Author: Auri +" Description: Functions for integrating with D linters. + +function! ale#d#FindDUBConfig(buffer) abort + " Find a DUB configuration file in ancestor paths. + " The most DUB-specific names will be tried first. + for l:possible_filename in ['dub.sdl', 'dub.json', 'package.json'] + let l:dub_file = ale#path#FindNearestFile(a:buffer, l:possible_filename) + + if !empty(l:dub_file) + return l:dub_file + endif + endfor + + return '' +endfunction diff --git a/doc/ale-d.txt b/doc/ale-d.txt index 8db04774..55596062 100644 --- a/doc/ale-d.txt +++ b/doc/ale-d.txt @@ -2,6 +2,17 @@ ALE D Integration *ale-d-options* +=============================================================================== +dls *ale-d-dls* + +g:ale_d_dls_executable *g:ale_d_dls_executable* + *b:ale_d_dls_executable* + Type: |String| + Default: `dls` + +See |ale-integrations-local-executables| + + =============================================================================== uncrustify *ale-d-uncrustify* diff --git a/doc/ale.txt b/doc/ale.txt index dd3e195b..e9dd3a8e 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -67,6 +67,7 @@ CONTENTS *ale-contents* cuda..................................|ale-cuda-options| nvcc................................|ale-cuda-nvcc| d.....................................|ale-d-options| + dls.................................|ale-d-dls| uncrustify..........................|ale-d-uncrustify| dart..................................|ale-dart-options| dartanalyzer........................|ale-dart-dartanalyzer| @@ -394,7 +395,7 @@ Notes: * CSS: `csslint`, `prettier`, `stylelint` * Cucumber: `cucumber` * Cython (pyrex filetype): `cython` -* D: `dmd`, `uncrustify` +* D: `dls`, `dmd`, `uncrustify` * Dafny: `dafny`!! * Dart: `dartanalyzer`!!, `language_server`, dartfmt!! * Dockerfile: `hadolint` diff --git a/test/command_callback/test_d_dls_callbacks.vader b/test/command_callback/test_d_dls_callbacks.vader new file mode 100644 index 00000000..156ebf66 --- /dev/null +++ b/test/command_callback/test_d_dls_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('d', 'dls') + + Save &filetype + let &filetype = 'd' + +After: + call ale#assert#TearDownLinterTest() + +Execute(The language string should be correct): + AssertLSPLanguage 'd' + +Execute(The default executable should be correct): + AssertLinter 'dls', 'dls' + +Execute(The executable should be configurable): + let g:ale_d_dls_executable = 'foobar' + + AssertLinter 'foobar', 'foobar' -- cgit v1.2.3