dense-analysis / ale

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

let g:ale_c_parse_makefile = 1 doesn't work for me #2382

Closed sshsu closed 5 years ago

sshsu commented 5 years ago

Information

I want to use let g:ale_c_parse_makefile =1 to let ale work with makefile, but it doesn't work as expected

VIM version VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 1 2019 09:58:54) Included patches: 1-865

Operating System: Ubuntu 16.04.4 LTS

What went wrong

I add let g:ale_c_parse_makefile = 1 to my vim configure file, but it does't work

Reproducing the bug

  1. I did this. I add let g:ale_c_parse_makefile = 1 to my vim configure file, and then create a file which directory structure like this

    ├── include
    │   ├── mytool1.c
    │   └── mytool1.h
    ├── main.c
    └── Makefile

    and the content of file like this ----main.c-----

    #include<stdio.h>                                                                                                                                                    
    #include"mytool1.h"
    
    int main(){
    fn();
    return 0;
    }

    ------mytool1.h--------

    void fn();  

------mytool1.c--------

#include "mytool1.h"                                                                                                                    
#include<stdio.h>                                                                                                                                                      

void fn(){                                                                                                                                                                                                                                                                    
    printf("hhhhhh\n");                                                                                                                 
} 

------Makefile--------

cc=gcc
include_dir=include
target=main
obj=main.o mytool1.o 

$(target):$(obj)
    $(cc) $(obj) -Wall -o $(target)
main.o:main.c
    $(cc) -c main.c -I$(include_dir)
mytool1.o: $(include_dir)/mytool1.c
    $(cc) -c $(include_dir)/mytool1.c
.PHONY:clean
    $(RM) *.o $(target)

we can check the what the makefile will do

root@acnszavl00033:~/temp# make -n
gcc -c main.c -Iinclude
gcc -c include/mytool1.c
gcc main.o mytool1.o  -Wall -o main

the makefile also works right when I use 'make' to generate obj file 'main', and it runs as expecting

  1. Then this happened. however, when I open main.c, ale still reports errors like this image and this image

ale should parse makefile and find the where is 'mytool1,h' and symbol 'fn()'

:ALEInfo

Current Filetype: Available Linters: [] Enabled Linters: [] 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:

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 = v:null 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%: %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 = v:null 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_list_vertical = v:null let g:ale_list_window_size = v:null let g:ale_loclist_msg_format = v:null let g:ale_lsp_root = {} let g:ale_max_buffer_history_size = v:null let g:ale_max_signs = v:null let g:ale_maximum_file_size = v:null let g:ale_open_list = v:null 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 = 1 let g:ale_sign_column_always = v:null let g:ale_sign_error = '✖' let g:ale_sign_info = 'ⓘ' 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 = '⚠' let g:ale_statusline_format = v:null let g:ale_type_map = v:null 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

mboros1 commented 5 years ago

Hi @sshsu ,

I copied your test project and my linter is properly parsing the include path:

Command History: (executable check - success) gcc (finished - exit code 0) ['/bin/bash', '-c', 'cd /home/mboros04/Source/test_c && make -n'] (finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/home/mboros04/Source/test_c'' -I/home/mboros0 4/Source/test_c/include -std=c11 -Wall - < ''/tmp/nvimOAURvl/2/main.c'''] <<<NO OUTPUT RETURNED>>>

In the ALEInfo you included, it's showing let g:ale_linters = {}, try running ALEInfo with the main.c file open in vim and see what linters are loading. It works for me with let g:ale_linters = {'cpp': ['gcc'], 'rust': ['rls','cargo'],'c': ['gcc']} (only gcc for my c linter), you probably have more linters loading that are throwing erroneous errors because they aren't configured properly for ALE

sshsu commented 5 years ago

Hi @sshsu ,

I copied your test project and my linter is properly parsing the include path:

Command History: (executable check - success) gcc (finished - exit code 0) ['/bin/bash', '-c', 'cd /home/mboros04/Source/test_c && make -n'] (finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/home/mboros04/Source/test_c'' -I/home/mboros0 4/Source/test_c/include -std=c11 -Wall - < ''/tmp/nvimOAURvl/2/main.c'''] <<<NO OUTPUT RETURNED>>>

In the ALEInfo you included, it's showing let g:ale_linters = {}, try running ALEInfo with the main.c file open in vim and see what linters are loading. It works for me with let g:ale_linters = {'cpp': ['gcc'], 'rust': ['rls','cargo'],'c': ['gcc']} (only gcc for my c linter), you probably have more linters loading that are throwing erroneous errors because they aren't configured properly for ALE

thank you , I haven't configure any linters and now I add it

let g:ale_linters = {'c': ['gcc'], 'c++': ['g++'] }

gcc linter can be found now , but errors ''mytool1.h 'file not found ' and 'use of undeclared identifier fn' still exist, here is my ale info:

  Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['gcc']
 Suggested Fixers:
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = '%severity%: %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 = 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 = {'c': ['gcc'], 'c++': ['g++']}
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 = '%severity%: %linter%: %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 = 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_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) gcc
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/temp && make -n']
(finished - exit code 0) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/root/temp'' -I/root/temp/include -std=c11 -Wall - < ''/tmp/vqeEUem/6/main.c''']

<<<NO OUTPUT RETURNED>>>
mboros1 commented 5 years ago

Okay, I have the same ALEInfo on my project but it's working properly, based on the Command History looks like it should work, unfortunately I can't reproduce the error. When I save the file, ALE recognizes the header and drops all errors.

w0rp commented 5 years ago

Could you run make -n from the same directory and attach the output? There's probably some difference in the output which ALE isn't parsing properly, perhaps a space in a filesystem path or similar that isn't handled.

annacrombie commented 5 years ago

I am getting a similar issue. I am developing a ruby extension in c and want to use ALE as my linter, but it chokes on #include <ruby.h>

The output of make -n:

echo compiling altprintf.c
gcc -I. -I/home/lattis/.local/share/rbenv/versions/2.6.2/include/ruby-2.6.0/i686-linux -I/home/lattis/.local/share/rbenv/versions/2.6.2/include/ruby-2.6.0/ruby/backward -I/home/lattis/.local/share/rbenv/versions/2.6.2/include/ruby-2.6.0 -I. -DRUBY_EXTCONF_H=\"extconf.h\" -I/home/lattis/.local/share/rbenv/versions/2.6.2/include  -D_FILE_OFFSET_BITS=64  -fPIC -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -o altprintf.o -c altprintf.c
echo linking shared-object altprintf.so
rm -f altprintf.so
gcc -shared -o altprintf.so altprintf.o -L. -L/home/lattis/.local/share/rbenv/versions/2.6.2/lib -Wl,-rpath,/home/lattis/.local/share/rbenv/versions/2.6.2/lib -L. -L/home/lattis/.local/share/rbenv/versions/2.6.2/lib  -fstack-protector-strong -rdynamic -Wl,-export-dynamic -L/home/lattis/.local/share/rbenv/versions/2.6.2/lib  -Wl,--compress-debug-sections=zlib    -lm   -lc

ALEInfo:

 Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['gcc']
 Suggested Fixers:
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_linter_aliases = {}
let g:ale_linters = {'c': ['gcc'], 'ruby': ['ruby'], 'rust': ['rls']}
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 = 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_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) gcc
(finished - exit code 0) ['/bin/zsh', '-c', 'cd /home/lattis/dev/c/altprintf/gem/ext && make -n']
(finished - exit code 1) ['/bin/zsh', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/home/lattis/dev/c/altprintf/gem/ext'' -std=c11 -Wall - < ''
/tmp/nvimHjEzV8/2/altprintf.c''']
<<<OUTPUT STARTS>>>
<stdin>:1:10: fatal error: ruby.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>
(finished - exit code 0) ['/bin/zsh', '-c', 'cd /home/lattis/dev/c/altprintf/gem/ext && make -n']
(finished - exit code 1) ['/bin/zsh', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/home/lattis/dev/c/altprintf/gem/ext'' -std=c11 -Wall - < ''
/tmp/nvimHjEzV8/3/altprintf.c''']
<<<OUTPUT STARTS>>>
<stdin>:1:10: fatal error: ruby.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>
(finished - exit code 0) ['/bin/zsh', '-c', 'cd /home/lattis/dev/c/altprintf/gem/ext && make -n']
(finished - exit code 1) ['/bin/zsh', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/home/lattis/dev/c/altprintf/gem/ext'' -std=c11 -Wall - < ''
/tmp/nvimHjEzV8/4/altprintf.c''']
<<<OUTPUT STARTS>>>
<stdin>:1:10: fatal error: ruby.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>

C file:

#include <ruby.h>
w0rp commented 5 years ago

Can you share a link to your project? If I can try to compile the same code, I might be able to repeat a bug.

annacrombie commented 5 years ago

okay, here is a project that reproduces my issue: https://github.com/annacrombie/effective-octo-rotary-phone. Note that Makefile and extconf.h were generated by running the extconf.rb script. You need to re-run that script to regenerate the Makefile with the correct path to your ruby headers.

sshsu commented 5 years ago

question

here is also a same question, project is here: https://github.com/meetecho/janus-gateway, proceure of installation might be a little complicated, when anything confiugre done, ALE reports error like this in file 'pulgin.h' : 捕获 however, glib can be found by Makefile , it should not be wrong, so I check my ALEinfo then find ALE treats file 'plugin.h' as a c++ project file instead a c project file (this is a c project ) so ale doesn't load a lot of compile options from Makefile.

aleinfo

here is my ALEInfo when I generate it in file 'plugin.h'

 Current Filetype: cpp
Available Linters: ['ccls', 'clang', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'flawfinder', 'gcc']
   Linter Aliases:
'gcc' -> ['g++']
  Enabled Linters: ['ccls', 'clang', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'flawfinder', 'gcc']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-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_cpp_ccls_executable = 'ccls'
let g:ale_cpp_ccls_init_options = {}
let g:ale_cpp_clang_executable = 'clang++'
let g:ale_cpp_clang_options = '-std=c++14 -Wall'
let g:ale_cpp_clangcheck_executable = 'clang-check'
let g:ale_cpp_clangcheck_options = ''
let g:ale_cpp_clangd_executable = 'clangd'
let g:ale_cpp_clangd_options = ''
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_cpp_clangtidy_options = ''
let g:ale_cpp_clazy_checks = ['level1']
let g:ale_cpp_clazy_executable = 'clazy-standalone'
let g:ale_cpp_clazy_options = ''
let g:ale_cpp_cppcheck_executable = 'cppcheck'
let g:ale_cpp_cppcheck_options = '--enable=style'
let g:ale_cpp_cpplint_executable = 'cpplint'
let g:ale_cpp_cpplint_options = ''
let g:ale_cpp_cquery_cache_directory = '/root/.cache/cquery'
let g:ale_cpp_cquery_executable = 'cquery'
let g:ale_cpp_flawfinder_executable = 'flawfinder'
let g:ale_cpp_flawfinder_minlevel = 1
let g:ale_cpp_flawfinder_options = ''
let g:ale_cpp_gcc_executable = 'gcc'
let g:ale_cpp_gcc_options = '-std=c++14 -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 = '%severity%: %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 = 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 = {'c': ['gcc', 'cppcheck'], 'c++': ['g++', 'cppcheck']}
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 = '%severity%: %linter%: %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 = 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_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', 'cd /root/git/janus-gateway && make -n']
(executable check - success) clang-check
(finished - exit code 1) ['/bin/bash', '-c', '''clang-check'' -analyze ''/root/git/janus-gateway/plugins/plugin.h'' -extra-arg -Xclang -extra-arg -analyzer-output=text']

<<<OUTPUT STARTS>>>
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/root/git/janus-gateway/plugins/plugin.h"
No compilation database found in /root/git/janus-gateway/plugins or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
/root/git/janus-gateway/plugins/plugin.h:158:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^
1 error generated.
Error while processing /root/git/janus-gateway/plugins/plugin.h.
<<<OUTPUT ENDS>>>

(executable check - failure) clang-tidy
(executable check - failure) clazy-standalone
(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c++ --enable=style ''/tmp/v3Pza6Q/10/plugin.h''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(executable check - failure) cpplint
(executable check - failure) flawfinder
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''clang++'' -S -x c++ -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c++14 -Wall - < ''/tmp/v3Pza6Q/11/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^
1 error generated.
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c++ -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c++14 -Wall - < ''/tmp/v3Pza6Q/12/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:18: fatal error: glib.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>

guess and verify

in order to verify my guess, I open another file 'videoroom.c' within this project, then generate aleinfo, it tell clearly this is a c project file. so , for this problem , it is because ale treats file 'plugin.h' as a c++ project file only according to file name suffix '.h' but it actually a c project file which leads to ale chosees a wrong linter and doesn't load compile option.

here is my ALEInfo when I generate it in file 'videoroom.c'

 Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['cppcheck', 'gcc']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_cppcheck_executable = 'cppcheck'
let g:ale_c_cppcheck_options = '--enable=style'
let g:ale_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = '%severity%: %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 = 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 = {'c': ['gcc', 'cppcheck'], 'c++': ['g++', 'cppcheck']}
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 = '%severity%: %linter%: %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 = 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_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) cppcheck
(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c --enable=style ''/tmp/vP5t40g/6/janus_videoroom.c''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(executable check - success) gcc
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' --silent --tag=CC --mode=compile gcc -DPACKAGE_NAME=\"Janus\ WebRTC\ Server\" -DPACKAGE_TARNAME=\"janus-gateway\" -DPACKAGE_VERSION=\"0.7.0\" -DPACKAGE_STRING=\"Janus\ WebRTC\ Server\ 0.7.0\" -DPACKAGE_BUGREPORT=\"https://github.com/meetecho/janus-gateway\" -DPACKAGE_URL=\"https://janus.conf.meetecho.com\" -DPACKAGE=\"janus-gateway\" -DVERSION=\"0.7.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_PORTRANGE=1 -DHAVE_LIBNICE_TCP=1 -DHAVE_SRTP_2=1 -DHAVE_SRTP_AESGCM=1 -DHAVE_LIBCURL=1 -DHAVE_TURNRESTAPI=1 -DHAVE_SAMPLEEVH=1 -DHAVE_WEBSOCKETS=1 -DHAVE_LIBWEBSOCKETS_PEER_SIMPLE=1 -DHAVE_PFUNIX=1 -I/root/git/janus-gateway/. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -fPIC -fstack-protector-all -fstrict-aliasing -ggdb3 -pthread -Wall -Warray-bounds -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self -Winline -Wlarger-than=65537 -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wno-aggregate-return -Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef -Wno-unused-parameter -Wold-style-definition -Wpacked -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wswitch-default -Wunused -Wwrite-strings -Wcast-align -Wno-override-init -Wunsafe-loop-optimizations -Wunused-but-set-variable -MT plugins/plugins_libjanus_videoroom_la-janus_videoroom.lo -MD -MP -MF plugins/.deps/plugins_libjanus_videoroom_la-janus_videoroom.Tpo -f ''plugins/janus_videoroom.c'' || echo ''./''`plugins/janus_videoroom.c -std=c11 -Wall - < ''/tmp/vP5t40g/7/janus_videoroom.c''']

<<<OUTPUT STARTS>>>
/bin/bash: -c: line 0: unexpected EOF while looking for matching ``'
/bin/bash: -c: line 1: syntax error: unexpected end of file
<<<OUTPUT ENDS>>>

need && help

so Is there any configuration in ale which make files with suffix '.h' recongnized to c project files? thanks~

mboros1 commented 5 years ago

@sshsu

If you run the command :se ft, you'll see what filetype vim is associating with .h files. Most likely it's cpp.

ALE get's the file type from vim, you can test this by running the command set filetype=c and then running ALEInfo again

sshsu commented 5 years ago

@mboros1
follow your advice, I open file 'plugin.h' and use command set filetype=c and test the file type is 'c' then generate aleinfo

 Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['cppcheck', 'gcc']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_cppcheck_executable = 'cppcheck'
let g:ale_c_cppcheck_options = '--enable=style'
let g:ale_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = '%severity%: %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 = 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 = {'c': ['gcc', 'cppcheck'], 'c++': ['g++', 'cppcheck']}
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 = '%severity%: %linter%: %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 = 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_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', 'cd /root/git/janus-gateway && make -n']
(executable check - success) clang-check
(finished - exit code 1) ['/bin/bash', '-c', '''clang-check'' -analyze ''/root/git/janus-gateway/plugins/plugin.h'' -extra-arg -Xclang -extra-arg -analyzer-output=text']

<<<OUTPUT STARTS>>>
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/root/git/janus-gateway/plugins/plugin.h"
No compilation database found in /root/git/janus-gateway/plugins or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
/root/git/janus-gateway/plugins/plugin.h:158:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^
1 error generated.
Error while processing /root/git/janus-gateway/plugins/plugin.h.
<<<OUTPUT ENDS>>>

(executable check - failure) clang-tidy
(executable check - failure) clazy-standalone
(executable check - success) cppcheck
(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c++ --enable=style ''/tmp/v2WHNNH/6/plugin.h''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(executable check - failure) cpplint
(executable check - failure) flawfinder
(executable check - success) gcc
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c++ -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c++14 -Wall - < ''/tmp/v2WHNNH/7/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:18: fatal error: glib.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/bin/bash', '-c', '''clang++'' -S -x c++ -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c++14 -Wall - < ''/tmp/v2WHNNH/8/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^
1 error generated.
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c --enable=style ''/tmp/v2WHNNH/11/plugin.h''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c11 -Wall - < ''/tmp/v2WHNNH/12/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:18: fatal error: glib.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>

we can see the error: "Could not auto-detect compilation database for file "/root/git/janus-gateway/plugins/plugin.h, No compilation database found in /root/git/janus-gateway/plugins or any parent directory".

I wonder is the command set filetype=c was executed so late since ale has detected filetype when open file and loaded compilation database; So I add /* vim: ft=c */ at the top of file(or the end ) in order to change filetype from cpp to c, however it doesn't change file type and I don't know why; Then I directly rename plugin.h to plugin.c, and the filetype is 'c' now and there is no error, aleinfo like this:

 Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['cppcheck', 'gcc']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_cppcheck_executable = 'cppcheck'
let g:ale_c_cppcheck_options = '--enable=style'
let g:ale_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = '%severity%: %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 = 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 = {'c': ['gcc', 'cppcheck'], 'c++': ['g++', 'cppcheck']}
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 = '%severity%: %linter%: %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 = 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_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) cppcheck
(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c --enable=style ''/tmp/vJkXQZk/6/plugin.c''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(executable check - success) gcc
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -DPACKAGE_NAME=\"Janus\ WebRTC\ Server\" -DPACKAGE_TARNAME=\"janus-gateway\" -DPACKAGE_VERSION=\"0.7.0\" -DPACKAGE_STRING=\"Janus\ WebRTC\ Server\ 0.7.0\" -DPACKAGE_BUGREPORT=\"https://github.com/meetecho/janus-gateway\" -DPACKAGE_URL=\"https://janus.conf.meetecho.com\" -DPACKAGE=\"janus-gateway\" -DVERSION=\"0.7.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_PORTRANGE=1 -DHAVE_LIBNICE_TCP=1 -DHAVE_SRTP_2=1 -DHAVE_SRTP_AESGCM=1 -DHAVE_LIBCURL=1 -DHAVE_TURNRESTAPI=1 -DHAVE_SAMPLEEVH=1 -DHAVE_WEBSOCKETS=1 -DHAVE_LIBWEBSOCKETS_PEER_SIMPLE=1 -DHAVE_PFUNIX=1 -I/root/git/janus-gateway/. -pthread -I/usr/include/nice -I/usr/include/gupnp-igd-1.0 -I/usr/include/gupnp-1.0 -I/usr/include/gssdp-1.0 -I/usr/include/libsoup-2.4 -I/usr/include/libxml2 -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -DPLUGINDIR=\"/opt/janus/lib/janus/plugins\" -DTRANSPORTDIR=\"/opt/janus/lib/janus/transports\" -DEVENTDIR=\"/opt/janus/lib/janus/events\" -DCONFDIR=\"/opt/janus/etc/janus\" -g -O2 -fPIC -fstack-protector-all -fstrict-aliasing -ggdb3 -pthread -Wall -Warray-bounds -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self -Winline -Wlarger-than=65537 -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wno-aggregate-return -Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef -Wno-unused-parameter -Wold-style-definition -Wpacked -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wswitch-default -Wunused -Wwrite-strings -Wcast-align -Wno-override-init -Wunsafe-loop-optimizations -Wunused-but-set-variable -MT plugins/janus-plugin.o -MD -MP -MF plugins/.deps/janus-plugin.Tpo -f ''plugins/plugin.c'' || echo ''./''`plugins/plugin.c -std=c11 -Wall - < ''/tmp/vJkXQZk/7/plugin.c''']

how can I make vim file type detectation for all files with suffix .h to result 'c'?

mboros1 commented 5 years ago

If you add:

au BufRead,BufNewFile *.h set filetype=c

to your .vimrc for vim or init.vim file in neovim it should work. Works in neovim, I don't use vim but I'm guessing it's the same or similar. Not sure if this is the best way to do this but I had a similar problem with *.rs files getting associated to something other then Rust and it fixed it.

Let us know if this fixes the problem, probably should based on your test with changing the file extension to .c

sshsu commented 5 years ago

@mboros1 sorry for late, command au BufRead,BufNewFile *.h set filetype=c makes effect on changing filetype which with suffix *.h from cpp file to c file, however, compile options still not be loaded, ALEInfo like this:

 Current Filetype: c
Available Linters: ['ccls', 'clang', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder', 'gcc']
  Enabled Linters: ['cppcheck', 'gcc']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-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_c_cppcheck_executable = 'cppcheck'
let g:ale_c_cppcheck_options = '--enable=style'
let g:ale_c_gcc_executable = 'gcc'
let g:ale_c_gcc_options = '-std=c11 -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 = '%severity%: %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 = 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 = {'c': ['gcc', 'cppcheck'], 'c++': ['g++', 'cppcheck']}
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 = '%severity%: %linter%: %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 = 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_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) cppcheck
(finished - exit code 1) ['/bin/bash', '-c', '''cppcheck'' -q --language=c --enable=style ''/tmp/vWK2wOP/6/plugin.h''']

<<<OUTPUT STARTS>>>
cppcheck: Failed to load library configuration file 'std.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled without CFGDIR set. Either the std.cfg should be available in cfg or the CFGDIR should be configured.
<<<OUTPUT ENDS>>>

(executable check - success) gcc
(finished - exit code 0) ['/bin/bash', '-c', 'cd /root/git/janus-gateway && make -n']
(finished - exit code 1) ['/bin/bash', '-c', '''gcc'' -S -x c -fsyntax-only -iquote ''/root/git/janus-gateway/plugins'' -std=c11 -Wall - < ''/tmp/vWK2wOP/7/plugin.h''']

<<<OUTPUT STARTS>>>
<stdin>:158:18: fatal error: glib.h: No such file or directory
compilation terminated.
<<<OUTPUT ENDS>>>
w0rp commented 5 years ago

Header files aren't translation units, so there's no command for compiling them. I might patch the code so the options for C files with a similar name are used to get the options. Otherwise the best you could do is grab all of the options in common for all files that will be compiled and hope that it works.

mboros1 commented 5 years ago

I've had no problem with linting header files in my projects as long as the file is included by a .cpp/.c file that is being compiled in the Makefile. Because my projects are fairly small, everything under 10k lines of code, I've had no issues just using gcc as a linter. Is that not intended to be working right now?

@sshsu

So it looks like your cppcheck is failing because your std.cfg file is not set up? I'm not familiar with cppcheck but most likely it needs some configuration to work properly.

In the output of your gcc, it's saying <stdin>:158:18: fatal error: glib.h: No such file or directory Are you able to compile the project successfully? The project has a ton of dependencies so I didn't really have time to test it, but on your end it looks like the error is that ALE cannot find glib.h using the Makefile.

I was able to get mine to work by making sure I had a project that compiled by simply using make, then using gcc as my only linter and checking the errors to see why it wasn't compiling. Also, with clangd as a linter, it worked very well with minimal set up, just needed to install the latest version. But, I'm only really writing C++ code not C.

sshsu commented 5 years ago

@w0rp I would appreciate if you patch the code

w0rp commented 5 years ago

What do you suggest?

sshsu commented 5 years ago

@mboros1 yeah, there are some problems with my cppcheck and I I haven't had time to fix it yet, and I can compile this project and run it. It might be like w0rp say that 'Header files aren't translation units, so there's no command for compiling them'

sshsu commented 5 years ago

What do you suggest? @w0rp I trust your conclusion 'Header files aren't translation units, so there's no command for compiling them'. So can you patch the code so the options for C files with a similar name are used to get the options for circumstance like this?

mboros1 commented 5 years ago

ALE can lint header files as long as they are included by a source code file that is being compiled and there's a makefile that can be properly parsed.

If gcc and ale_c_parse_makefile are not working, it's generally because the way ALE parses makefile's needs a lot of work on anything that isn't simple; there are many makefiles that can compile that ALE parses in a way that does not compile. For my projects, I just tweak the makefile till ALE can figure it out.

It would be a nice project for someone to pick up; taking a fairly complex project makefile from github and working on the ALE makefile parser till it works.