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

LSP client problem with ALE, Language Server CCLS/clangd, and a project build by CMAKE in a OCI container #3948

Closed wosrediinanatour closed 3 years ago

wosrediinanatour commented 3 years ago

Information

VIM version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 15 2021 00:00:00)
Included patches: 1-3512

Operating System: Fedora Silverblue 34 (latest)

.vimrc:

    1 Plug 'dense-analysis/ale'
    2 let g:ale_cpp_cc_options = '-std=c++20 -Wall'
    3 " https://github.com/MaskRay/ccls/wiki/Customization
    4 let g:ale_cpp_ccls_init_options = {
    5          \   "cache": { "directory": "/tmp/ccls/cache" },
    6          \   "clang": {"pathMappings": "/repository/>" . getcwd() ."/"},
    7          \   "compilationDatabaseDirectory": getcwd() . "/build/"
    8          \ }
    9 let g:ale_fixers = {
   10          \   'cpp': ['clang-format'],
   11          \}
   12 "let g:ale_linters = {'cpp': ['ccls']}
   13 let g:ale_completion_enabled = 1
   14 let g:ale_hover_to_preview = 1
   15 nn <silent> gd :ALEGoToDefinition<cr>
   16 nn <silent> gt :ALEGoToTypeDefinition<cr>
   17 nn <silent> gr :ALEFindReferences -relative<cr>
   18 nn <silent> gs :ALESymbolSearch -relative <query><cr>
   19 nn <silent> gh :ALEHover<cr>
   20 " Show the full linter message for the problem nearest to the cursor on the
   21 " given line in the preview window.
   22 nn <silent> ge :ALEDetail<cr>

CMAKE builds the project in a container, which produces a build/compile_commands.json.

LSP client CCLS is installed.

What went wrong

:ALEGoToDefinition, :ALEGoToTypeDefinition, :ALEFindReferences -relative, :ALESymbolSearch -relative <query>, :ALEHover do not work (do nothing).

Reproducing the bug

:ALEInfo

 ALEInfo
 Current Filetype: cpp
Available Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'flawfinder']
   Linter Aliases:
'cc' -> ['gcc', 'clang', 'g++', 'clang++']
  Enabled Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'flawfinder']
  Ignored Linters: []
 Suggested Fixers:
  'astyle' - Fix C/C++ with astyle.
  '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_cpp_cc_executable = '<auto>'
let g:ale_cpp_cc_options = '-std=c++20 -Wall'
let g:ale_cpp_ccls_executable = 'ccls'
let g:ale_cpp_ccls_init_options = {'clang': {'pathMappings': '/repository/>/var/home/fxaver/Sources/{ROOT}/'}, 'compilationDatabaseDirectory': '/var/home/fxaver/Sources/{ROOT}/build/'}
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_extra_options = ''
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 = '/var/home/fxaver/.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 = ''
 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 = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
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 = 0
let g:ale_fixers = {'cpp': ['clang-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 = 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 = {}
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 - success) clang++
(finished - exit code 1) ['/bin/bash', '-c', '''clang++'' -S -x c++ -o /dev/null -iquote ''/var/home/fxaver/Sources/{ROOT}'' -std=c++20 -Wall - < ''/tmp/vNPUvSY/8/service.h''']

<<<OUTPUT STARTS>>>
In file included from <stdin>:13:
./core-amqp/strategy.h:11:10: fatal error: 'core-amqp/domain.h' file not found
#include "core-amqp/domain.h"
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.
<<<OUTPUT ENDS>>>

(executable check - success) ccls
(executable check - success) clang-check
(finished - exit code -1) ['/bin/bash', '-c', '''clang-check'' -analyze ''/var/home/fxaver/Sources/{ROOT}/{SOME_DIR}/service.h'' -p ''/var/home/fxaver/Sources/{ROOT}''']

<<<OUTPUT STARTS>>>
LLVM ERROR: Cannot chdir into "/repository/build"!
 #0 0x00007f7bd76173f6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM-12.so+0xc063f6)
 #1 0x00007f7bd76152e4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM-12.so+0xc042e4)
 #2 0x00007f7bd7615466 (/lib64/libLLVM-12.so+0xc04466)
 #3 0x00007f7bd6660320 __restore_rt (/lib64/libc.so.6+0x3d320)
 #4 0x00007f7bd66602a2 raise (/lib64/libc.so.6+0x3d2a2)
 #5 0x00007f7bd66498a4 abort (/lib64/libc.so.6+0x268a4)
 #6 0x00007f7bd7563d2e llvm::report_fatal_error(llvm::Twine const&, bool) (/lib64/libLLVM-12.so+0xb52d2e)
 #7 0x00007f7bde89a2e5 (/lib64/libclang-cpp.so.12+0x22c12e5)
 #8 0x0000558250aa93c5 (/usr/bin/clang-check+0x63c5)
 #9 0x00007f7bd664ab75 __libc_start_main (/lib64/libc.so.6+0x27b75)
#10 0x0000558250aa9f2e (/usr/bin/clang-check+0x6f2e)
<<<OUTPUT ENDS>>>

(executable check - success) clangd
(executable check - success) clang-tidy
(finished - exit code -1) ['/bin/bash', '-c', '''clang-tidy'' ''/var/home/fxaver/Sources/{ROOT}/{SOME_DIR}/service.h'' -p ''/var/home/fxaver/Sources/{ROOT}''']

<<<NO OUTPUT RETURNED>>>

(executable check - failure) clazy-standalone
(executable check - failure) cppcheck
(executable check - failure) cpplint
(executable check - failure) cquery
(executable check - failure) flawfinder
(executable check - failure) cquery
(executable check - failure) cquery
(started) ['/bin/bash', '-c', '''clangd'' -compile-commands-dir=''/var/home/fxaver/Sources/{ROOT}'']
(executable check - failure) cquery
wosrediinanatour commented 3 years ago

I found the problem. When I make these changes, it works:

-let g:ale_cpp_ccls_init_options = {
-         \   "cache": { "directory": "/tmp/ccls/cache" },
-         \   "clang": {"pathMappings": "/repository/>" . getcwd() ."/"},
-         \   "compilationDatabaseDirectory": getcwd() . "/build/"
-         \ }
+let g:ale_cpp_ccls_init_options = {"clang": {"pathMappings": ["/repository/>/var/home/fxaver/Sources/railx/"]}, "compilationDatabaseDirectory": "/var/home/fxaver/Sources/railx/build/"}

Seems to be a problem with JSON and CCLS.