From eecbacb742f0e884e2f47f0aee57caf9cb2dd683 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Sun, 7 Jan 2018 17:53:01 +0100 Subject: [PATCH 1/2] Removed unneeded `SetDirectory` call in proto handler test. The test already handled arbitrary paths reasonably well, but setting the directory interfered via leakage with others tests for some reason. This patch removes the call to `SetDirectory` in the fixture setup and the subsequent cleanup in the teardown as they are not required. --- test/command_callback/test_proto_command_callback.vader | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/command_callback/test_proto_command_callback.vader b/test/command_callback/test_proto_command_callback.vader index 2fd7775..79c1cf8 100644 --- a/test/command_callback/test_proto_command_callback.vader +++ b/test/command_callback/test_proto_command_callback.vader @@ -1,11 +1,9 @@ Before: - call ale#test#SetDirectory('/testplugin/test/command_callback') call ale#test#SetFilename('test.proto') After: Restore - call ale#test#RestoreDirectory() call ale#linter#Reset() Execute(The default command should be correct): From b5a5cdf920a9875650b021c8116ac02b739a9e9e Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Sat, 6 Jan 2018 20:56:28 +0100 Subject: [PATCH 2/2] Make it possible to inject flags of protoc invocation. Typically proto files depend on and make use of proto definitions in other files. When invoking protoc user can supply paths to inspect for dependencies. This patch makes it possible to configure flags passed to protoc. This makes it e.g., possible to change include paths of the linter's protoc invocation. --- ale_linters/proto/protoc_gen_lint.vim | 14 +++++++++++--- doc/ale-proto.txt | 9 +++++++++ .../test_proto_command_callback.vader | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ale_linters/proto/protoc_gen_lint.vim b/ale_linters/proto/protoc_gen_lint.vim index 9d5ceac..c8b5c33 100644 --- a/ale_linters/proto/protoc_gen_lint.vim +++ b/ale_linters/proto/protoc_gen_lint.vim @@ -1,12 +1,20 @@ " Author: Jeff Willette " Description: run the protoc-gen-lint plugin for the protoc binary +call ale#Set('proto_protoc_gen_lint_options', '') + function! ale_linters#proto#protoc_gen_lint#GetCommand(buffer) abort let l:dirname = expand('#' . a:buffer . ':p:h') - return 'protoc' - \ . ' -I ' . ale#Escape(l:dirname) - \ . ' --lint_out=. ' . '%s' + let l:options = ['-I ' . ale#Escape(l:dirname)] + + if !empty(ale#Var(a:buffer, 'proto_protoc_gen_lint_options')) + let l:options += [ale#Var(a:buffer, 'proto_protoc_gen_lint_options')] + endif + + let l:options += ['--lint_out=. ' . '%s'] + + return 'protoc' . ' ' . join(l:options) endfunction call ale#linter#Define('proto', { diff --git a/doc/ale-proto.txt b/doc/ale-proto.txt index 6a25638..734e23d 100644 --- a/doc/ale-proto.txt +++ b/doc/ale-proto.txt @@ -20,5 +20,14 @@ protoc-gen-lint *ale-proto-protoc-gen-lint* The linter is a plugin for the `protoc` binary. As long as the binary resides in the system path, `protoc` will find it. +g:ale_proto_protoc_gen_lint_options *g:ale_proto_protoc_gen_lint_options* + + Type: |String| + Default: `''` + + This variable can be changed to modify flags given to protoc. Note that the + directory of the linted file is always passed as an include path with '-I' + before any user-supplied options. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/test/command_callback/test_proto_command_callback.vader b/test/command_callback/test_proto_command_callback.vader index 79c1cf8..76050c6 100644 --- a/test/command_callback/test_proto_command_callback.vader +++ b/test/command_callback/test_proto_command_callback.vader @@ -4,9 +4,18 @@ Before: After: Restore + unlet! b:ale_proto_protoc_gen_lint_options + call ale#linter#Reset() Execute(The default command should be correct): AssertEqual \ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --lint_out=. ' . '%s', \ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr('')) + +Execute(The callback should include any additional options): + let b:ale_proto_protoc_gen_lint_options = '--some-option' + + AssertEqual + \ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --some-option --lint_out=. ' . '%s', + \ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr(''))