dense-analysis / ale

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

ale can not parse some json files #2671

Closed cridemichel closed 5 years ago

cridemichel commented 5 years ago

Information

VIM version VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 28 2019 01:07:30) macOS version Included patches: 1-1722 Compiled by travis@Traviss-Mac.local Huge version with MacVim GUI. Features included (+) or not (-): +acl +file_in_path +mouse_urxvt -tcl +arabic +find_in_path +mouse_xterm +termguicolors +autocmd +float +multi_byte +terminal +autochdir +folding +multi_lang +terminfo -autoservername -footer -mzscheme +termresponse +balloon_eval +fork() +netbeans_intg +textobjects +balloon_eval_term +fullscreen +num64 +textprop +browse -gettext +odbeditor +timers ++builtin_terms -hangul_input +packages +title +byte_offset +iconv +path_extra +toolbar +channel +insert_expand +perl/dyn +transparency +cindent +job +persistent_undo +user_commands +clientserver +jumplist +postscript +vartabs +clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +virtualedit +cmdline_hist +langmap +python/dyn +visual +cmdline_info +libcall +python3/dyn +visualextra +comments +linebreak +quickfix +viminfo +conceal +lispindent +reltime +vreplace +cryptv +listcmds +rightleft +wildignore +cscope +localmap +ruby/dyn +wildmenu +cursorbind +lua/dyn +scrollbind +windows +cursorshape +menu +signs +writebackup +dialog_con_gui +mksession +smartindent -X11 +diff +modify_fname -sound -xfontset +digraphs +mouse +spell +xim +dnd +mouseshape +startuptime -xpm -ebcdic +mouse_dec +statusline -xsmp +emacs_tags -mouse_gpm -sun_workshop -xterm_clipboard +eval -mouse_jsbterm +syntax -xterm_save +ex_extra +mouse_netterm +tag_binary
+extra_search +mouse_sgr -tag_old_static
-farsi -mouse_sysmouse -tag_any_white
system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" defaults file: "$VIMRUNTIME/defaults.vim" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon -lm -lncurses -liconv -framework

Operating System:

Mac OSX Mojave 10.14.6

What went wrong

ALE is not able to parse some json files for compiling options in a C project and diagnostic information (i.e. warnings and errors) do not show up

Something went wrong in specifically this place, and I also searched through both open and closed issues for the same problem before reporting a bug here.

Are you having trouble configuring ALE? Try asking for help on Stack Exchange or perhaps on Reddit instead. The GitHub issue tracker should be used for reporting bugs or asking for new features.

Reproducing the bug

These are the steps I did to get the issue:

1) I generated the json file from a Makefile by using 'scan-build' utility (installed with 'pip3 install scan-build')

2) I opened a C file of the project but althoug linting is enable according to ALEInfo command no diagnostics information is showing up

Anyway, if I convert the json file to a slightly different format by using 'compdb' utility ( installed via pip3 install compdb) with the command

compdb -p . list > compile_commands.json

The json file generated by 'compdb' works well with ALE, hence it seems ALE is not able to parse json file generated by 'scan-build' utility. Could you fixe this issue or am I forced to use compdb?

An extract of the json file generated by scan-build is the following: [ { "arguments": [ "cc", "-c", "-Wall", "-D", "MD_MAC", "-O3", "-U", "MC_IBARRA_SIMPLER", "-D", "HC_ALGO_OPT", "-U", "MC_ELCONST_STRAIGHT", "-U", "MC_BOUNDING_SPHERES", "-U", "MC_ELASTIC_CONSTANTS", "-U", "ELCONST_NEWALGO", "-D", "ALIGN_POT", "-D", "MC_BOND_POS", "-D", "MC_NVE", "-U", "MC_FREEZE_BONDS", "-U", "MC_CLUSTER_MOVE", "-U", "MC_CLUSTER_NPT", "-U", "MC_ALT_ROT", "-D", "MC_FLIP_MOVE", "-U", "MC_OPT_BUILDATOMPOS", "-D", "MCIN_OPT", "-D", "MC_HC", "-D", "MC_SUS", "-U", "MC_CALC_COVADD", "-D", "MD_NO_SYSTEM", "-D", "MC_GRANDCAN", "-D", "MC_SIMUL", "-U", "MD_STANDALONE", "-D", "MD_LXYZ", "-U", "MD_CHAIN_SIM", "-U", "MD_CALC_VBONDING", "-U", "DMD_MULTIPLE_LL", "-D", "MD_DYNAMIC_OPROG", "-U", "MD_CALENDAR_HYBRID", "-D", "MD_SCALEPHI_STAGES", "-D", "MD_OPT_SCALEPHI", "-U", "MD_ALLOW_ONE_IGG_BOND", "-U", "MD_PROTEIN_DESIGN", "-U", "MD_PARANOID_CHECKS", "-D", "MD_GRAZING_TRYHARDER", "-D", "MD_GHOST_IGG", "-D", "MD_RABBIT", "-D", "MD_SAVE_SPOTS", "-D", "MD_SUPERELLIPSOID", "-U", "MD_ABSORPTION", "-U", "MD_FOUR_BEADS", "-D", "MD_BASIC_DT", "-U", "MD_EDHEFLEX_WALL", "-U", "MD_INELASTIC", "-U", "MD_POLYDISP", "-U", "MD_CALC_DPP", "-U", "MD_HE_PARALL", "-D", "MD_BIG_DT", "-D", "MD_ASYM_ITENS", "-D", "EDHE_FLEX", "-D", "MD_PATCHY_HE", "-U", "MD_GLOBALNR", "-D", "MD_GLOBALNRD", "-D", "MD_GLOBALNRNL", "-D", "MD_GLOBALNRDNL", "-U", "MD_USE_CBLAS", "-U", "MD_USE_LAPACK", "-D", "MD_STOREMGL", "-U", "MD_HSVISCO", "-D", "MD_LOADMESH", "-D", "XDISP", "-U", "ATPTENS", "-D", "MOLPTENS", "-U", "ATPRESS", "-I/usr/include/lam", "-I.", "-I/Users/demichel/MDsimul/include", "-I/Users/demichel/MDsimul/commSrc", "-o", "init.o", "init.c" ], "directory": "/Users/demichel/MDsimul/ellipsoid", "file": "init.c" }, [...] ] while an extract of the json file generated by compdb is the following:

[ { "directory": "/Users/demichel/MDsimul/ellipsoid", "command": "cc -c -Wall -D MD_MAC -O3 -U MC_IBARRA_SIMPLER -D HC_ALGO_OPT -U MC_ELCONST_STRAIGHT -U MC_BOUNDING_SPHERES -U MC_ELASTIC_CONSTANTS -U ELCONST_NEWALGO -D ALIGN_POT -D MC_BOND_POS -D MC_NVE -U MC_FREEZE_BONDS -U MC_CLUSTER_MOVE -U MC_CLUSTER_NPT -U MC_ALT_ROT -D MC_FLIP_MOVE -U MC_OPT_BUILDATOMPOS -D MCIN_OPT -D MC_HC -D MC_SUS -U MC_CALC_COVADD -D MD_NO_SYSTEM -D MC_GRANDCAN -D MC_SIMUL -U MD_STANDALONE -D MD_LXYZ -U MD_CHAIN_SIM -U MD_CALC_VBONDING -U DMD_MULTIPLE_LL -D MD_DYNAMIC_OPROG -U MD_CALENDAR_HYBRID -D MD_SCALEPHI_STAGES -D MD_OPT_SCALEPHI -U MD_ALLOW_ONE_IGG_BOND -U MD_PROTEIN_DESIGN -U MD_PARANOID_CHECKS -D MD_GRAZING_TRYHARDER -D MD_GHOST_IGG -D MD_RABBIT -D MD_SAVE_SPOTS -D MD_SUPERELLIPSOID -U MD_ABSORPTION -U MD_FOUR_BEADS -D MD_BASIC_DT -U MD_EDHEFLEX_WALL -U MD_INELASTIC -U MD_POLYDISP -U MD_CALC_DPP -U MD_HE_PARALL -D MD_BIG_DT -D MD_ASYM_ITENS -D EDHE_FLEX -D MD_PATCHY_HE -U MD_GLOBALNR -D MD_GLOBALNRD -D MD_GLOBALNRNL -D MD_GLOBALNRDNL -U MD_USE_CBLAS -U MD_USE_LAPACK -D MD_STOREMGL -U MD_HSVISCO -D MD_LOADMESH -D XDISP -U ATPTENS -D MOLPTENS -U ATPRESS -I/usr/include/lam -I. -I/Users/demichel/MDsimul/include -I/Users/demichel/MDsimul/commSrc -o init.o init.c", "file": "init.c" }, [...] ]

  1. I did this.
  2. Then this happened.

:ALEInfo

Current Filetype: c Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc'] Enabled Linters: ['clang'] Suggested Fixers: '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_clang_executable = 'clang' let g:ale_c_clang_options = '-Wall ' 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_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 = 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 = {'c': ['clang'], 'cpp': [], 'python': ['mypy', 'pylint', 'pyflakes']} let g:ale_linters_explicit = 0 let g:ale_list_vertical = 0 let g:ale_list_window_size = 10 let g:ale_loclist_msg_format = '%code: %%s' let g:ale_lsp_root = {} 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_set_balloons = 1 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_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 - success) clang (finished - exit code 0) ['/bin/bash', '-c', '''clang'' -S -x c -fsyntax-only -iquote ''/Users/demichel/MDsimul/ellipsoid'' -Wall - < ''/var/folders/26/9q3nft3x4xg2zbj45nzm__100000gn/T/vfBJMEy/1/hard_cylinders.c''']

<<>>

<<>>

cridemichel commented 5 years ago

According to json format specification (e.g. see https://clang.llvm.org/docs/JSONCompilationDatabase.html) either 'command' or 'arguments' field is required, hence ALE should check for both fields and use one of the two and not just try to use the 'command' field. Meanwhile a quick fix can be provided by the following script

generate_json.py.gz

which adds the dictionary key "command" to each element of json database generated by 'intercept-build' (https://pypi.org/project/scan-build/), where the value of "command" is obtained by joining the value of "arguments" field (i.e. a list with all arguments) in 'intercept-build' json file

I hope this script can be also useful for fixing this issue directly in ALE,

best regards, Cristiano

RyanSquared commented 5 years ago

related: #2123

sorry i haven't gotten to this sooner!

w0rp commented 5 years ago

Okay, I merged the old patch for this now, which just joins the arguments together and treats it like the command string, which should work about as well for now.