Add more parameters to the DMD linting command (#3639)

* Add more parameters to the DMD linting command

fixes #3637

* adding tests for dmd linter

* adding dmd test for windows
This commit is contained in:
Remi Thebault 2021-03-23 00:31:52 +01:00 committed by GitHub
parent f7852dbd0a
commit c6b61950f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 136 additions and 5 deletions

View File

@ -11,7 +11,12 @@ function! s:GetDUBCommand(buffer) abort
" directory where we found the dub config, and then run `dub describe`
" from that directory.
if !empty(l:config)
return [fnamemodify(l:config, ':h'), 'dub describe --import-paths']
return [fnamemodify(l:config, ':h'), 'dub describe --data-list
\ --data=import-paths
\ --data=string-import-paths
\ --data=versions
\ --data=debug-versions
\']
endif
endif
@ -36,16 +41,46 @@ endfunction
function! ale_linters#d#dmd#DMDCommand(buffer, dub_output, meta) abort
let l:import_list = []
let l:str_import_list = []
let l:versions_list = []
let l:deb_versions_list = []
let l:list_ind = 1
let l:seen_line = 0
" Build a list of import paths generated from DUB, if available.
" Build a list of options generated from DUB, if available.
" DUB output each path or version on a single line.
" Each list is separated by a blank line.
" Empty list are represented by a blank line (followed and/or
" preceded by a separation blank line)
for l:line in a:dub_output
" line still has end of line char on windows
let l:line = substitute(l:line, '[\r\n]*$', '', '')
if !empty(l:line)
" The arguments must be '-Ifilename', not '-I filename'
call add(l:import_list, '-I' . ale#Escape(l:line))
if l:list_ind == 1
call add(l:import_list, '-I' . ale#Escape(l:line))
elseif l:list_ind == 2
call add(l:str_import_list, '-J' . ale#Escape(l:line))
elseif l:list_ind == 3
call add(l:versions_list, '-version=' . ale#Escape(l:line))
elseif l:list_ind == 4
call add(l:deb_versions_list, '-debug=' . ale#Escape(l:line))
endif
let l:seen_line = 1
elseif !l:seen_line
" if list is empty must skip one empty line
let l:seen_line = 1
else
let l:seen_line = 0
let l:list_ind += 1
endif
endfor
return 'dmd '. join(l:import_list) . ' -o- -wi -vcolumns -c %t'
return 'dmd ' . join(l:import_list) . ' ' .
\ join(l:str_import_list) . ' ' .
\ join(l:versions_list) . ' ' .
\ join(l:deb_versions_list) . ' -o- -wi -vcolumns -c %t'
endfunction
function! ale_linters#d#dmd#Handle(buffer, lines) abort

View File

@ -0,0 +1,96 @@
Before:
runtime ale_linters/d/dmd.vim
After:
call ale#linter#Reset()
Execute(DMD command line should be correct with imports):
AssertEqual
\ 'dmd ' .
\ '-I' . ale#Escape('source') . ' ' .
\ '-I' . ale#Escape('/prefix/include/d') . ' ' .
\ '-I' . ale#Escape('/home/user/.dub/packages/pkg-0.0.1/pkg/src') . ' ' .
\ ' ' .
\ ' ' .
\ ' ' .
\ '-o- -wi -vcolumns -c %t',
\ ale_linters#d#dmd#DMDCommand(bufnr(''), [
\ 'source',
\ '/prefix/include/d',
\ '/home/user/.dub/packages/pkg-0.0.1/pkg/src',
\ '',
\ '',
\ '',
\ '',
\ '',
\ '',
\ ], {})
Execute(DMD command line should be correct with imports and version):
AssertEqual
\ 'dmd ' .
\ '-I' . ale#Escape('source') . ' ' .
\ '-I' . ale#Escape('/prefix/include/d') . ' ' .
\ '-I' . ale#Escape('/home/user/.dub/packages/pkg-0.0.1/pkg/src') . ' ' .
\ ' ' .
\ '-version=' . ale#Escape('SOME_VERSION') . ' ' .
\ ' ' .
\ '-o- -wi -vcolumns -c %t',
\ ale_linters#d#dmd#DMDCommand(bufnr(''), [
\ 'source',
\ '/prefix/include/d',
\ '/home/user/.dub/packages/pkg-0.0.1/pkg/src',
\ '',
\ '',
\ '',
\ 'SOME_VERSION',
\ '',
\ '',
\ ], {})
Execute(DMD command line should be correct):
AssertEqual
\ 'dmd ' .
\ '-I' . ale#Escape('source') . ' ' .
\ '-I' . ale#Escape('/prefix/include/d') . ' ' .
\ '-I' . ale#Escape('/home/user/.dub/packages/pkg-0.0.1/pkg/src') . ' ' .
\ '-J' . ale#Escape('views') . ' ' .
\ '-version=' . ale#Escape('SOME_VERSION') . ' ' .
\ '-version=' . ale#Escape('SOME_OTHER_VERSION') . ' ' .
\ '-debug=' . ale#Escape('SomeFeature') . ' ' .
\ '-o- -wi -vcolumns -c %t',
\ ale_linters#d#dmd#DMDCommand(bufnr(''), [
\ 'source',
\ '/prefix/include/d',
\ '/home/user/.dub/packages/pkg-0.0.1/pkg/src',
\ '',
\ 'views',
\ '',
\ 'SOME_VERSION',
\ 'SOME_OTHER_VERSION',
\ '',
\ 'SomeFeature',
\ ], {})
Execute(DMD command line should be correct with CR):
" on windows, the function is called with carriage return
AssertEqual
\ 'dmd ' .
\ '-I' . ale#Escape('source') . ' ' .
\ '-I' . ale#Escape('C:\prefix\include\d') . ' ' .
\ '-I' . ale#Escape('C:\Users\user\AppData\Local\Dub\packages\pkg-0.0.1\pkg\src') . ' ' .
\ ' ' .
\ ' ' .
\ ' ' .
\ '-o- -wi -vcolumns -c %t',
\ ale_linters#d#dmd#DMDCommand(bufnr(''), [
\ "source\r",
\ "C:\\prefix\\include\\d\r",
\ "C:\\Users\\user\\AppData\\Local\\Dub\\packages\\pkg-0.0.1\\pkg\\src\r",
\ "\r",
\ "\r",
\ "\r",
\ "\r",
\ "\r",
\ "\r",
\ ], {})