From 06f57ca9733aab6e6b67015917fdfd4bf1c70c48 Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Tue, 30 Mar 2021 08:47:59 +0200 Subject: [PATCH] improve DMD handler (#3647) * improve DMD handler - ignore errors from other files - catch 'Deprecation' as warning - add tests * adding filename key instead of filtering * update dmd test * fix test dmd windows --- ale_linters/d/dmd.vim | 15 +++++++---- test/handler/test_dmd_handler.vader | 41 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test/handler/test_dmd_handler.vader diff --git a/ale_linters/d/dmd.vim b/ale_linters/d/dmd.vim index 82668a21..f38e812c 100644 --- a/ale_linters/d/dmd.vim +++ b/ale_linters/d/dmd.vim @@ -87,15 +87,20 @@ function! ale_linters#d#dmd#Handle(buffer, lines) abort " Matches patterns lines like the following: " /tmp/tmp.qclsa7qLP7/file.d(1): Error: function declaration without return type. (Note that constructors are always named 'this') " /tmp/tmp.G1L5xIizvB.d(8,8): Error: module weak_reference is in file 'dstruct/weak_reference.d' which cannot be read - let l:pattern = '^[^(]\+(\([0-9]\+\)\,\?\([0-9]*\)): \([^:]\+\): \(.\+\)' + let l:pattern = '\v^(\f+)\((\d+)(,(\d+))?\): (\w+): (.+)$' let l:output = [] + let l:dir = expand('#' . a:buffer . ':p:h') for l:match in ale#util#GetMatches(a:lines, l:pattern) + " If dmd was invoked with relative path, match[1] is relative, otherwise it is absolute. + " As we invoke dmd with the buffer path (in /tmp), this will generally be absolute already + let l:fname = ale#path#GetAbsPath(l:dir, l:match[1]) call add(l:output, { - \ 'lnum': l:match[1], - \ 'col': l:match[2], - \ 'type': l:match[3] is# 'Warning' ? 'W' : 'E', - \ 'text': l:match[4], + \ 'filename': l:fname, + \ 'lnum': l:match[2], + \ 'col': l:match[4], + \ 'type': l:match[5] is# 'Warning' || l:match[5] is# 'Deprecation' ? 'W' : 'E', + \ 'text': l:match[6], \}) endfor diff --git a/test/handler/test_dmd_handler.vader b/test/handler/test_dmd_handler.vader new file mode 100644 index 00000000..32a04982 --- /dev/null +++ b/test/handler/test_dmd_handler.vader @@ -0,0 +1,41 @@ +Before: + runtime ale_linters/d/dmd.vim + call ale#test#SetDirectory('/testplugin/test/dmd') + call ale#test#SetFilename('test.d') + +After: + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(Basic errors should be handled by dmd): + AssertEqual + \ [ + \ { + \ 'filename': ale#path#Simplify(g:dir . '/test.d'), + \ 'lnum': '5', + \ 'col' : '8', + \ 'type': 'E', + \ 'text': 'module weak_reference is in file ''dstruct/weak_reference.d'' which cannot be read' + \ }, + \ { + \ 'filename': ale#path#Simplify(g:dir . '/test.d'), + \ 'lnum': '20', + \ 'col' : '10', + \ 'type': 'W', + \ 'text': 'function test.thisoldfunc is deprecated' + \ }, + \ { + \ 'filename': ale#path#Simplify(g:dir . '/foo.d'), + \ 'lnum': '230', + \ 'col' : '9', + \ 'type': 'W', + \ 'text': 'statement is not reachable' + \ } + \ ], + \ ale_linters#d#dmd#Handle(bufnr(''), [ + \ 'test.d(5,8): Error: module weak_reference is in file ''dstruct/weak_reference.d'' which cannot be read', + \ 'import path[0] = source', + \ 'import path[1] = /usr/include/dlang/dmd', + \ ale#path#Simplify(g:dir . '/test.d') . '(20,10): Deprecation: function test.thisoldfunc is deprecated', + \ 'foo.d(230,9): Warning: statement is not reachable', + \ ])