Home Explore Blog CI



neovim

20th chunk of `runtime/doc/quickfix.txt`
b57e1f6dc9e80f131512bd2ce9250a9b1f69287e79dc3e650000000100000fa0
 possibly for the whole project) as soon as a Java
syntax file is loaded; then, `spotbugs` will attempt to analyze the quality of
the compilation unit of the buffer.

Vim commands proficient in 'makeprg' [0] can be composed with default actions.
Begin by considering which of the supported keys, "DefaultPreCompilerCommand",
"DefaultPreCompilerTestCommand", or "DefaultPostCompilerCommand", you need to
write an implementation for, observing that each of these keys corresponds to
a particular "*Action" key.  Follow it by defining a new function that always
declares an only parameter of type string and puts to use a command equivalent
of |:make|, and assigning its |Funcref| to the selected key.  For example:
>vim
	function! GenericPostCompilerCommand(arguments) abort
		execute 'make ' . a:arguments
	endfunction

	let g:spotbugs_properties = {
		\ 'DefaultPostCompilerCommand':
			\ function('GenericPostCompilerCommand'),
	\ }

When "PostCompilerAction" is available, "PostCompilerActionExecutor" is also
supported.  Its value must be a Funcref pointing to a function that always
declares a single parameter of type string and decides whether |:execute| can
be dispatched on its argument, containing a pending post-compiler action,
after ascertaining the current status of |:cc| (or |:ll|): >vim

	function! GenericPostCompilerActionExecutor(action) abort
		try
			cc
		catch /\<E42:/
			execute a:action
		endtry
	endfunction

Complementary, some or all of the available "Pre*Action"s (or "*Pre*Command"s)
may run `:doautocmd java_spotbugs_post User` in their implementations before
|:make| (or its equivalent) to define a once-only |ShellCmdPost| `:autocmd`
that will arrange for "PostCompilerActionExecutor" to be invoked; and then run
`:doautocmd java_spotbugs_post ShellCmdPost` to consume this event: >vim

	function! GenericPreCompilerCommand(arguments) abort
		if !exists('g:spotbugs_compilation_done')
			doautocmd java_spotbugs_post User
			execute 'make ' . a:arguments
			" only run doautocmd when :make was synchronous
			" see note below
			doautocmd java_spotbugs_post ShellCmdPost " XXX: (a)
			let g:spotbugs_compilation_done = 1
		else
			cc
		endif
	endfunction

	function! GenericPreCompilerTestCommand(arguments) abort
		if !exists('g:spotbugs_test_compilation_done')
			doautocmd java_spotbugs_post User
			execute 'make ' . a:arguments
			" only run doautocmd when :make was synchronous
			" see note below
			doautocmd java_spotbugs_post ShellCmdPost " XXX: (b)
			let g:spotbugs_test_compilation_done = 1
		else
			cc
		endif
	endfunction

	let g:spotbugs_properties = {
		\ 'compiler':		'maven',
		\ 'DefaultPreCompilerCommand':
			\ function('GenericPreCompilerCommand'),
		\ 'DefaultPreCompilerTestCommand':
			\ function('GenericPreCompilerTestCommand'),
		\ 'PostCompilerActionExecutor':
			\ function('GenericPostCompilerActionExecutor'),
	\ }

If a command equivalent of `:make` is capable of asynchronous execution and
consuming `ShellCmdPost` events, `:doautocmd java_spotbugs_post ShellCmdPost`
must be removed from such "*Action" (or "*Command") implementations (i.e. the
lines `(a)` and `(b)` in the listed examples) to retain a sequential order for
non-blocking execution, and any notification (see below) must be suppressed.
A `ShellCmdPost` `:autocmd` can be associated with any |:augroup| by assigning
its name to the "augroupForPostCompilerAction" key.

When default actions are not suited to a desired workflow, proceed by writing
arbitrary functions yourself and matching their Funcrefs to the supported
keys: "PreCompilerAction", "PreCompilerTestAction", and "PostCompilerAction".

The next example re-implements the default pre-compiler actions for a Maven
project and requests other default Maven settings with the "compiler" entry:
>vim
	function! MavenPreCompilerAction() abort
		call spotbugs#DeleteClassFiles()
		compiler maven
		make compile
		cc
	endfunction

	function! MavenPreCompilerTestAction() abort
		call spotbugs#DeleteClassFiles()

Title: Advanced SpotBugs Configuration: Actions, Executors, and Custom Functions
Summary
This section explains how to use `PostCompilerActionExecutor` in conjunction with `PostCompilerAction` and provides a generic example. It further elaborates on how `Pre*Action`s or `*Pre*Command`s can utilize `:doautocmd` to define and trigger `ShellCmdPost` autocmds, enabling specific actions after the compilation process. It also covers asynchronous execution considerations and the use of `augroupForPostCompilerAction` for associating `ShellCmdPost` with a specific augroup. It concludes by demonstrating how to write custom functions for pre- and post-compiler actions, providing a Maven project example.