diff options
-rw-r--r-- | ale_linters/d/dmd.vim | 45 | ||||
-rw-r--r-- | test/linter/test_dmd_commandline.vader | 96 |
2 files changed, 136 insertions, 5 deletions
diff --git a/ale_linters/d/dmd.vim b/ale_linters/d/dmd.vim index 1a38b89e..82668a21 100644 --- a/ale_linters/d/dmd.vim +++ b/ale_linters/d/dmd.vim @@ -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 diff --git a/test/linter/test_dmd_commandline.vader b/test/linter/test_dmd_commandline.vader new file mode 100644 index 00000000..609fc073 --- /dev/null +++ b/test/linter/test_dmd_commandline.vader @@ -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", + \ ], {}) |