dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.49k stars 1.43k forks source link

The option `previewpopup` causes errors when set #3213

Open jmdevin opened 4 years ago

jmdevin commented 4 years ago

Information

VIM version

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun 16 2020 22:38:24) Included patches: 1-992

Operating System

Ubuntu 20.04

What went wrong

When the 'previewpopup' option is non-empty, an ALE command which makes the popup window the "current" window (such as with :wincmd P) will throw E441: There is no preview window. This can be seen with :ALEDetail.

Relevant :help for 'previewpopup':

When not empty a popup window is used for commands that would open a preview window.

Reproducing the bug

  1. Open vim to a file linted by ALE.
  2. Do :set previewpopup=height:10,width:60
  3. Create an error in the file so that ALE indicates the error.
  4. Place the cursor on the same line as the error.
  5. Do :ALEDetail
  6. See the message:
Error detected while processing function ale#cursor#ShowCursorDetail[17]..<SNR>112_S
howCursorDetailForItem[6]..ale#preview#Show:
line    4:
E441: There is no preview window

The relevant function is this one:

function! ale#preview#Show(lines, ...) abort
    let l:options = get(a:000, 0, {})

    silent pedit ALEPreviewWindow
    wincmd P

    setlocal modifiable
    setlocal noreadonly
    [it goes on but that's the relevant part]
endfunction

It can be seen that the wincmd P on line 4 is causing the error, as popup windows cannot be entered directly for editing. Either this case should be checked for in advance, or this function should use a different method to modify the preview window, such as win_execute(), setwinvar(), setbufvar(), or popup_settext().

:ALEInfo

 Current Filetype: vim
Available Linters: ['ale_custom_linting_rules', 'vimls', 'vint']
  Enabled Linters: ['ale_custom_linting_rules', 'vimls', 'vint']
 Suggested Fixers: 
  '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.
 Linter Variables:

let g:ale_vim_vimls_config = {}
let g:ale_vim_vimls_executable = 'vim-language-server'
let g:ale_vim_vimls_use_global = 0
let g:ale_vim_vint_executable = 'vint'
let g:ale_vim_vint_show_style_issues = 1
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
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_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '[%severity%] %code: %%s [%linter%]'
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 = 1
let g:ale_fixers = {'dart': ['dartfmt'], 'python': ['autopep8']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 1
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 = {'sh': ['language_server', 'shell', 'shellcheck'], 'dart': ['language_server'], 'python': ['bandit', 'flake8', 'mypy']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 5
let g:ale_loclist_msg_format = '[%severity%] %code: %%s [%linter%]'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = v:null
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_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 = 0
let g:ale_sign_column_always = v:null
let g:ale_sign_error = v:null
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = v:null
let g:ale_sign_highlight_linenrs = v:null
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) vim-language-server
(executable check - success) vint
(finished - exit code 0) ['/bin/bash', '-c', '''vint'' --version']

<<<OUTPUT STARTS>>>
0.4a4.dev8+g5b05880
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/bin/bash', '-c', '''vint'' -s --no-color -f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})" ''/tmp/v7WAIZa/2/vimrc''']

<<<OUTPUT STARTS>>>
/tmp/v7WAIZa/2/vimrc:402:29: error: unexpected token: <EOL> (see vim-jp/vim-vimlparser)
Total violations: 1
<<<OUTPUT ENDS>>>

(executable check - failure) vim-language-server
(finished - exit code 1) ['/bin/bash', '-c', '''vint'' -s --no-color -f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})" ''/tmp/v7WAIZa/3/vimrc''']

<<<OUTPUT STARTS>>>
/tmp/v7WAIZa/3/vimrc:264:5: error: E492: Not an editor command: ddd (see vim-jp/vim-vimlparser)
Total violations: 1
<<<OUTPUT ENDS>>>
jsit commented 4 years ago

Looks like something similar happened here. May have been a change in Vim? They seem to have fixed it by writing their own popup creation function

w0rp commented 4 years ago

We can fix this error by overriding the previewpopup setting temporarily in the function to force the preview window to appear. I don't know why a previewpopup setting was ever implemented. You can't run commands on the popups like you can with the preview window, which behaves pretty much like all Vim windows, so all it does is break things.

So far, I haven't found the newer popups to be useful at all. They look ugly, and you can't set custom syntax highlights in them. They just aren't anywhere near as good as the popups you'll see in something like VSCode. At least with the old preview windows you can import different syntax files and highlight code blocks for difference languages all at the same time, set keybinds, and all manner of useful things.

w0rp commented 4 years ago

I'm still going to implement popup support at some point, but it won't ever be as good as the preview windows are.

jsit commented 4 years ago

I have a popup-related PR here