我正在使用 VIM 在 C11 中编程。
我正在尝试设置啤酒-I /path/to/include
但尽管传递了正确的标志(例如),但似乎 linters 找不到标题。
我正在使用 CMake,因此我已经导出了编译命令,并配置了 ALE 来读取它们,它甚至在 ALEInfo 中显示了正确的标志,但仍然找不到标题,因此整个项目都充满了错误。
我知道代码可以运行,因为它可以编译并且所有测试都通过。
发行版
$ neofetch
Manjaro Linux x86_64
5.3.0-1-MANJARO
Terminal: urxvt
Terminal Font: Fira Code Retina
窗口管理器
$ i3 -v
i3 version 4.17.1 (2019-08-30)
VIM
$ vim
:version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 21 2019 18:00:45)
Included patches: 1-1906
Compiled by Arch Linux
Huge version without GUI
.vimrc
set number
set linebreak
set showbreak=+++
set textwidth=100
set showmatch
set visualbell
set hlsearch
set smartcase
set ignorecase
set incsearch
set autoindent
set cindent
set expandtab
set shiftwidth=4
set smartindent
set smarttab
set softtabstop=4
set confirm
set ruler
set undolevels=1000
set backspace=indent,eol,start
set noshowmode
set nocompatible
filetype indent plugin on
syntax on
set wildmenu
set showcmd
set mouse=a
set encoding=UTF-8
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeFileExtensionHighlightFullName = 1
call plug#begin('~/.vim/plugged')
Plug 'valloric/youcompleteme' " autocmpletion
Plug 'scrooloose/nerdtree' " directory tree
Plug 'ryanoasis/vim-devicons' " icons for the tree
Plug 'tmsvg/pear-tree' " brackets pair
Plug 'w0rp/ale' " linters
Plug 'nanotech/jellybeans.vim' " colorscheme
Plug 'tpope/vim-fugitive' " git integration
Plug 'auxiliary/vim-layout' " i3 like layout
Plug 'ctrlpvim/ctrlp.vim' " file/dir manager
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdcommenter'
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
Plug 'idanarye/vim-vebugger'
call plug#end()
function! Formatonsave()
let l:formatdiff = 1
pyf /usr/share/clang/clang-format.py
endfunction
autocmd BufWritePre *.h,*.c,*.cc,*.cpp call Formatonsave()
command! HeaderGuard call fs_plugin#header_guard#HeaderGuard()
let g:airline#extensions#tabline#enabled = 1
let g:webdevicons_enable_nerdtree = 1
" ALE Config
let g:ale_linter_aliases = { 'h': 'c' }
let g:ale_linters = { 'c': ['clang'] }
let g:ale_c_parse_compile_commands = 1
let g:ale_c_build_dir = 'build'
ALE信息
您将在底部看到,clang 是使用正确的标志调用的,取自.compile_commands.json
。
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_build_dir = ''
let g:ale_c_build_dir_names = ['build', 'bin']
let g:ale_c_clang_executable = 'clang'
let g:ale_c_clang_options = '-std=c11 -Wall'
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_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 = {'h': 'c'}
let g:ale_linters = {'c': ['clang']}
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_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 - success) clang
(finished - exit code 0) ['/bin/bash', '-c', '''clang'' -S -x c -fsyntax-only -iquote ''/home/<user>/shared-folders/host-source/repos/CLIB/src/allocator'' -Dclib_EXPORTS -I /home/<user>/CLIB/include -flto=thin -fPIC -Wall -Wextra -pedantic-errors -fno-omit-frame-pointer -fPIC -m64 -fcolor-diagnostics -std=c11 -Wall - < ''/tmp/vpTGYTG/1/default_allocator.c''']
<<<OUTPUT STARTS>>>
^[[1m<stdin>:10:8: ^[[0m^[[0;1;35mwarning: ^[[0m^[[1mimplicit declaration of function 'posix_memalign' is invalid in C99 [-Wimplicit-function-declaration]^[[0m
if(posix_memalign(&p, align, sz))
^[[0;1;32m ^
^[[0m1 warning generated.
<<<OUTPUT ENDS>>>
答案1
远射:然而clangd
你的道路是怎样的?
当然Ubuntu 上的 Onivim(neovim GUI)无法对 C 进行 lint由于clangd
安装的特殊性。这个问题通过符号链接修复:
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-6.0 1000