dense-analysis / dense-analysis/ale

Consider supporting ale#command#Run for uses other than writing ALE linters or fixers

Open
#3,636 6 comments 0 reactions 1 assignee Claimed by @w0rp View on GitHub
enhancement
Dominant language
Vim Script
Stars
14k
Forks
1.5k
Avg merge
17h 49m
Merged PRs (30d)
1

Description

## w0rp's Edit

This was originally filed as a bug report, but everything is actually working as intended. It's worth carefully considering this use case here.

## Information

**VIM version**

NVIM v0.5.0-418-g87d892afa
Build type: RelWithDebInfo

Operating System: Linux Mint

## What went wrong

I'm trying to use the [other sources](https://github.com/dense-analysis/ale/blob/master/doc/ale.txt#L253) interface to run a linter on all text files. The specific linter is for catching style issues in any source/text file, so I think [this](https://github.com/PrincetonUniversity/blocklint/tree/master/integration/ale) is the correct way to integrate with ALE. Using `ale#linter#Define` or aliasing would require listing all the filetypes I want.

The function appears to work when opening a file, but then will not update on buffer changes, `:ALELint`, or file writes.

Oddly, this is only for filetypes that have other linters enabled. E.g. text, markdown and vimscript (without any installed linters) work as expected on every buffer exit, but python or c files (which have flake8 or gcc) only update when opening the file. If I set `g:ale_linters_explicit=1` to disable all the c linters, the other source dispatching works again.

## Reproducing the bug
1. Assuming you have gcc and grep, this will mark lines with `asdf`:
```
" .vimrc
augroup SomeGroupName
autocmd!
autocmd User ALEWantResults call Hook(g:ale_want_results_buffer)
augroup END

function! Hook(buffer) abort
" Tell ALE we're going to check this buffer.
call ale#other_source#StartChecking(a:buffer, 'some-name')
call ale#command#Run(a:buffer, 'grep -n asdf',
\ function('WorkDone'), {'read_buffer': 1})
endfunction

function! WorkDone(buffer, results, metadata) abort
" Send results to ALE after they have been collected.
let l:pattern = '\v^(\d+):(.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:results, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1],
\ 'text': 'grepping',
\ 'type': 'E'})
endfor
call ale#other_source#ShowResults(a:buffer, 'some-name', l:output)
endfunction
```
2. Open buffers with `test.c` and `test.txt` and add a few lines with `asdf`.
3. The text file updates, while the c file does not.

### :ALEInfo
#### For text file (working)
```
ALEInfo
Current Filetype: text
Available Linters: ['alex', 'languagetool', 'proselint', 'redpen', 'textlint', 'vale', 'writegood']
Linter Aliases:
'writegood' -> ['write-good']
Enabled Linters: []
Ignored Linters: []
Suggested Fixers:
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'textlint' - Fix text files with textlint --fix
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
Linter Variables:

Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '[%linter%] %s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '[%linter%] %s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
Command History:

(finished - exit code 0) ['/bin/bash', '-c', 'grep -n asdf < ''/tmp/nvimKch7HV/3/test.txt''']

<<>>
1:asdf
2:asdf
3:asdf
4:asdf
5:asdf
<<>>
```

#### c file (not working)
```
ALEInfo
Current Filetype: c
Available Linters: ['cc', 'ccls', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder']
Linter Aliases:
'cc' -> ['gcc', 'clang']
Enabled Linters: ['cc', 'ccls', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder']
Ignored Linters: []
Suggested Fixers:
'astyle' - Fix C/C++ with astyle.
'clang-format' - Fix C/C++ and cuda files with clang-format.
'clangtidy' - Fix C/C++ and ObjectiveC files with clang-tidy.
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
'uncrustify' - Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.
Linter Variables:
let g:ale_c_always_make = 1
let g:ale_c_build_dir = ''
let g:ale_c_build_dir_names = ['build', 'bin']
let g:ale_c_cc_executable = ''
let g:ale_c_cc_options = '-std=c11 -Wall'
let g:ale_c_ccls_executable = 'ccls'
let g:ale_c_ccls_init_options = {}
let g:ale_c_clangd_executable = 'clangd'
let g:ale_c_clangd_options = ''
let g:ale_c_clangtidy_checks = []
let g:ale_c_clangtidy_executable = 'clang-tidy'
let g:ale_c_clangtidy_extra_options = ''
let g:ale_c_clangtidy_options = ''
let g:ale_c_cppcheck_executable = 'cppcheck'
let g:ale_c_cppcheck_options = '--enable=style'
let g:ale_c_cquery_cache_directory = '/home/troy/.cache/cquery'
let g:ale_c_cquery_executable = 'cquery'
let g:ale_c_flawfinder_error_severity = 6
let g:ale_c_flawfinder_executable = 'flawfinder'
let g:ale_c_flawfinder_minlevel = 1
let g:ale_c_flawfinder_options = ''
let g:ale_c_parse_compile_commands = 1
let g:ale_c_parse_makefile = 0
Global Variables:
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '[%linter%] %s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '[%linter%] %s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
Command History:
(executable check - failure) cppcheck
(executable check - failure) flawfinder
(started) ['/bin/bash', '-c', 'blocklint -e --stdin < ''/tmp/nvimKch7HV/23/test.c''']
(started) ['/bin/bash', '-c', 'grep -n asdf < ''/tmp/nvimKch7HV/24/test.c''']
(executable check - failure) clang
(finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -o /dev/null -iquote ''/home/troy/Desktop/test'' -std=c11 -Wall - < ''/tmp/nvimKch7HV/25/test.c''']
<<>>
: In function ‘main’:
:2:9: warning: variable ‘asdf’ set but not used [-Wunused-but-set-variable]
<<>>
(executable check - failure) cppcheck
(executable check - failure) flawfinder
(started) ['/bin/bash', '-c', 'blocklint -e --stdin < ''/tmp/nvimKch7HV/26/test.c''']
(started) ['/bin/bash', '-c', 'grep -n asdf < ''/tmp/nvimKch7HV/27/test.c''']
(executable check - failure) clang
(finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -o /dev/null -iquote ''/home/troy/Desktop/test'' -std=c11 -Wall - < ''/tmp/nvimKch7HV/28/test.c''']
<<>>
: In function ‘main’:
:2:9: warning: variable ‘asdf’ set but not used [-Wunused-but-set-variable]
<<>>
(executable check - failure) cppcheck
(executable check - failure) flawfinder
(started) ['/bin/bash', '-c', 'blocklint -e --stdin < ''/tmp/nvimKch7HV/29/test.c''']
(started) ['/bin/bash', '-c', 'grep -n asdf < ''/tmp/nvimKch7HV/30/test.c''']
(executable check - failure) clang
(finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -o /dev/null -iquote ''/home/troy/Desktop/test'' -std=c11 -Wall - < ''/tmp/nvimKch7HV/31/test.c''']
<<>>
: In function ‘main’:
:2:9: warning: variable ‘asdf’ set but not used [-Wunused-but-set-variable]
<<>>
(executable check - failure) cppcheck
(executable check - failure) flawfinder
```
Note that `grep` starts but does not return an output after the file is opened.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.