dense-analysis / ale

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

Error while exiting Neovim from a java file #3956

Open m0xai opened 3 years ago

m0xai commented 3 years ago

Information

VIM version

NVIM v0.5.1 Build type: Release

Operating System: macOS Catalina (10.15.7)

What went wrong

Exiting java file from nvim produces error. It has no effect on file but it produces same error every time.

Reproducing the bug

  1. I did this. :wq

  2. Then this happened.

    Error detected while processing function <SNR>57_NeoVimCallback[29]..<lambda>5[1]..<SNR>50_ExitCallback[28]..<SNR>65_HandleExit:
    line    8:
    E484: Can't open file /var/folders/66/0q6xdy7d45l3pyjvb5hstlfc0000gn/T/nvimmHRl1E/4/Eingabe.java%

:ALEInfo

 Current Filetype: java
Available Linters: ['checkstyle', 'eclipselsp', 'javac', 'javalsp', 'pmd']
  Enabled Linters: ['checkstyle', 'eclipselsp', 'javac', 'javalsp', 'pmd']
  Ignored Linters: []
 Suggested Fixers: 
  'google_java_format' - Fix Java files with google-java-format.
  '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_java_checkstyle_config = '/google_checks.xml'
let g:ale_java_checkstyle_executable = 'checkstyle'
let g:ale_java_checkstyle_options = ''
let g:ale_java_eclipselsp_config_path = ''
let g:ale_java_eclipselsp_executable = 'java'
let g:ale_java_eclipselsp_javaagent = ''
let g:ale_java_eclipselsp_path = '/Users/m0xai/eclipse.jdt.ls'
let g:ale_java_eclipselsp_workspace_path = ''
let g:ale_java_javac_classpath = ''
let g:ale_java_javac_executable = 'javac'
let g:ale_java_javac_options = ''
let g:ale_java_javac_sourcepath = ''
let g:ale_java_javalsp_config = {}
let g:ale_java_javalsp_executable = ''
let g:ale_java_pmd_options = '-R category/java/bestpractices.xml'
 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 = '%code: %%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 = 1
let g:ale_fixers = {'java': ['google_java_format']}
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 = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
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 = '%code: %%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) checkstyle
(executable check - success) javac
(finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/Users/m0xai/code/hbrs/eidp/b04/a02'' && ''javac'' -Xlint -d ''/var/folders/66/0q6xdy7d45l3pyjvb5hstlfc0000gn/T/nvimluqlQK/2'' ''/var/folders/66/0q6xdy7d45l3pyjvb5hstlfc0000gn/T/nvimluqlQK/3/Eingabe.java''']

<<<NO OUTPUT RETURNED>>>

(executable check - failure) pmd
jhcl commented 1 year ago

On my setup exiting from d (linter dls), zig (linter zls), elm (linter elm_ls) and elixir (linters ['credo', 'dialyxir', 'dogma']) produce errors with wq. No error when exiting with q.

Error detected while processing function 98_NeoVimCallback[29]..6[1]..92_ExitCallback[28]..108_HandleExit: line 8: E484: Can't open file /tmp/nvimCqeZXh/2/hello.d

Error detected while processing function 95_NeoVimCallback[29]..8[1]..90_ExitCallback[28]..107_HandleExit: line 8: E484: Can't open file /tmp/nvim23IIwU/2/main.zig

Error detected while processing function 96_NeoVimCallback[29]..8[1]..91_ExitCallback[28]..106_HandleExit: line 8: E484: Can't open file /tmp/nvimyzl9kw/3/Main.elm

Error detected while processing function 111_NeoVimCallback[29]..6[1]..107_ExitCallback[28]..117_HandleExit: line 8: E484: Can't open file /tmp/nvim8qKcQL/4/dbc.exs

config:

set omnifunc=ale#completion#OmniFunc
let g:airline#extensions#branch#enabled = 1
let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]'
let g:airline_section_c_only_filename = 1
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#nerdtree_statusline = 1
set completeopt=menu,menuone,preview,noselect,noinsert
let g:ale_completion_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_linters = {
            \ 'cpp': ['clangd', 'g++'],
            \ 'd': ['dls'],
            \ 'javascript': ['eslint'],
            \ 'python': ['pylint', 'flake8'] ,}
if filereadable(findfile("Cargo.toml", ".;"))
    let ale_linters['rust'] = ['analyzer', 'cargo']
else
    let ale_linters['rust'] = ['analyzer', 'rustc']
endif
let g:ale_rust_analyzer_executable = '/home/calimero/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rust-analyzer'
let g:ale_d_dls_executable='/home/calimero/.dub/packages/.bin/dls-latest/dls'
let g:ale_fixers = { '*': ['remove_trailing_lines', 'trim_whitespace'],
            \ 'rust': ['rustfmt'],
            \ 'go': ['gofmt'],
            \ 'c': ['clang-format'],
            \ 'd': ['dfmt'],
            \ 'cpp': ['clang-format'],
            \ 'zig': ['zigfmt'],
            \ 'elm': ['elm-format'],
            \ 'javascript': ['eslint'],
            \ 'elixir': ['mix_format'],
            \ }
let g:ale_sign_column_always = 1
let g:ale_d_dfmt_options='--brace_style=otbs'
let g:ale_c_clangformat_style_option = '{BasedOnStyle: LLVM,
            \ IndentWidth: 4,
            \ ColumnLimit: 110,
            \ AllowShortFunctionsOnASingleLine: Empty }'
let g:ale_c_cc_executable = 'clang'
let g:ale_cpp_cc_executable = 'g++'
let g:ale_c_cc_options = '-std=gnu17 -Wall'
let g:ale_cpp_cc_options = '-std=c++17 -Wall'
let g:ale_python_flake8_options="--ignore=E127, E501"
let g:ruby_host_prog = 'rvm system do neovim-ruby-host'
let g:completion_enable_auto_popup = 1
let g:ale_rust_cargo_use_clippy = executable('cargo-clippy')
let g:ale_java_checkstyle_options = ' -c /home/calimero/.vim/plugged/ale/ale_linters/ '
let g:elm_format_autosave = 1
jhcl commented 1 year ago

Setting ale_fix_on_save to zero solves the problem but requires a manual ALEFix.

seanenck commented 1 year ago

A (not wonderful) workaround in nvim

 vim.api.nvim_create_autocmd({ "BufWrite" }, {
        pattern = { "*." .. extension },
        callback = function()
            vim.api.nvim_exec(":ALEFix", false)
            vim.api.nvim_exec("sleep 50m", false)
        end
    })

(where "extension" is a language I have a formatter for)

jhcl commented 1 year ago

@enckse I'm afraid that doesn't solve the problem. I changed the word extension to "zig" and now I got the error message both with ale_fix_on_save to 1 and 0.
Same with patterns "." and "*".
The error only happens with "wq". No problems with "w" and then "q".

seanenck commented 1 year ago

Given the issue as laid out, my running into this, a few other issues here, and browsing the code - my guess is that neovim is exiting before ALEFix finishes. Given my amateur sleuthing - if ale_fix_on_save = 1 with neovim, you are likely to encounter this bug (unless your formatter runs faster than any I use - this will be important later) when you do a wq (w alone is not triggering neovim to exit and q alone isn’t necessarily a save)

If you take my snippet above, you should have turned off ale_fix_on_save (=0) because my “fix” is calling ALEFix manually on buffer write (basically save). Why would you want to run ALEFix twice on write? I can’t (and wouldn’t try) to tune the sleep statement for all formatters in existence (I only care that the workaround I have in my config works for me). I would suggest looking at the neovim documentation for sleep (if you apply my workaround) and maybe increasing the sleep duration to fix wq issues (I optimized the sleep duration for the source code formatters I use)

My fix is basically re-implementing ale_fix_on_save locally in my neovim config to fix what looks like a race condition. Applying it elsewhere likely requires tweaking.

m0xai commented 1 year ago

Thank you for your contribute. But I have changed my computer, basically threw up :) that's why I can't reproduce. I hope your fix can help others and we can close this issue.

seanenck commented 1 year ago

There is still a bug here in ale so we shouldn’t necessarily close this issue in case someone can work out an actual fix in ale itself (though this workaround likely helps alleviate this already minor issue more)