感觉有点复杂。。。
我平时也是大量的 C++ 开发,一般用 htlm-xgtags 来查找定义,用 company-irony 来补全, flycheck 进行 on-the-fly 语法检查。
个人感觉还可以。
感觉有点复杂。。。
我平时也是大量的 C++ 开发,一般用 htlm-xgtags 来查找定义,用 company-irony 来补全, flycheck 进行 on-the-fly 语法检查。
个人感觉还可以。
wscript
里有逻辑下载 releases.llvm.org 的 clang+llvm,但里面没有32-bits Linux的。你安装系统包 clang 再试试 ./waf configure --llvm-config /usr/bin/llvm-config
。我猜cquery可能支持,但我没有验证过
wscript 233行
ctx.check_cxx(msg='Checking for library clang', lib=libname('clang'), uselib_store='clang', includes=includes, libpath=libpath)
我waf也懂得不多。这个应该会找libclang.so
,如果你没有的话可以ln -s libclang.so.5 libclang.so
lsp & lsp-python merged!!!
哈哈哈,刚收到邮件。这是憋了个大招出来(差不多吧)
@MaskRay .cquery / compile_commands.json 没起作用还是 cquery 不支持这么操作?
定义了一个平台相关的宏:
⋊> bear make | tee .cquery
gcc -D DARWIN main.c
然而条件编译当中的变量识别不到:
本地测试支持。
int main() {
#ifdef DARWIN
int a = 3;
return a;
#endif
}
# Makefile
CXXFLAGS := -D DARWIN
src/project.cc
:254行附近断点看看发生了什么
// This is most likely the file path we will be passing to clang.
if (EndsWith(arg, base_name))
arg = cleanup_maybe_relative_path(arg);
// TODO Exclude .a .o to make link command in compile_commands.json work.
// Also, clang_parseTranslationUnit2FullArgv does not seem to accept
// multiple source filenames.
else if (EndsWith(arg, ".a") || EndsWith(arg, ".o"))
continue;
}
result.args.push_back(arg);
我的调试方法是
rm -r /tmp/cquery; CQUERY_TRACEME=1 vi a.cc +'normal ,al'
CQUERY_TRACEME=1
会在main()
入口处SIGTSTP自身,需要gdb/lldb attach后continue
编译了 debug 版,把 log 打出来看了,.cquery
文件有加载:
...... 2018-02-28 19:22:51.812 (0.002s) [querydb] project.cc:324 0| Using .cquery arguments from /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery ......
arguments: /usr/local/bin/cquery --language-server --log-file=/tmp/cq.log --log-stdin-stdout-to-stderr Current dir: /Users/gqj/Dropbox/scratch/c/os-detecting-makefile File verbosity level: 9 date time ( uptime ) [ thread name/id] file:line v| 2018-02-28 19:22:51.811 ( 0.001s) [main thread ] loguru.hpp:2014 0| Logging to '/tmp/cq.log', mode: 'w', verbosity: 9 2018-02-28 19:22:51.812 ( 0.001s) [querydb ] initialize.cc:481 0| Init parameters: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cacheDirectory":"/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/","cacheFormat":"json","resourceDirectory":"","extraClangArguments":[],"progressReportFrequencyMs":500,"showDocumentLinksOnIncludes":true,"diagnosticsOnParse":true,"client":{"snippetSupport":false},"codeLens":{"localVariables":true},"completion":{"detailedLabel":false,"filterAndSort":true,"includeBlacklist":[],"includeMaxPathSize":30,"includeSuffixWhitelist":[".h",".hpp",".hh"],"includeWhitelist":[]},"index":{"attributeMakeCallsToCtor":true,"blacklist":[],"comments":2,"enabled":true,"logSkippedPaths":false,"threads":0,"whitelist":[]},"workspaceSymbol":{"maxNum":1000,"sort":true},"xref":{"container":false,"maxNum":2000},"dumpAST":[]} 2018-02-28 19:22:51.812 ( 0.001s) [querydb ] initialize.cc:485 0| [querydb] Initialize in directory /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/ with uri file:///Users/gqj/Dropbox/scratch/c/os-detecting-makefile/ 2018-02-28 19:22:51.812 ( 0.002s) [querydb ] initialize.cc:545 0| Using -resource-dir=/usr/local/Cellar/cquery/HEAD-5f3a240/lib/clang+llvm-5.0.1-x86_64-apple-darwin/lib/clang/5.0.1 2018-02-28 19:22:51.812 ( 0.002s) [stdout ] timer.cc:35 0| [e2e] Running initialize took 0.462ms 2018-02-28 19:22:51.812 ( 0.002s) [querydb ] project.cc:324 0| Using .cquery arguments from /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery 2018-02-28 19:22:51.813 ( 0.002s) [querydb ] timer.cc:35 0| [perf] Loaded compilation entries (1 files) took 0.354ms 2018-02-28 19:22:51.813 ( 0.002s) [querydb ] initialize.cc:602 0| Starting 3 indexers 2018-02-28 19:22:51.813 ( 0.003s) [querydb ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:22:51.813 ( 0.003s) [querydb ] timer.cc:35 0| [perf] Dispatched initial index requests took 0.97ms 2018-02-28 19:22:51.813 ( 0.003s) [indexer0 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 2018-02-28 19:22:51.813 ( 0.003s) [indexer0 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c.json 2018-02-28 19:22:51.813 ( 0.003s) [scan_includes] timer.cc:35 0| [perf] Scanning for includes took 0.476ms 2018-02-28 19:22:51.813 ( 0.003s) [indexer0 ]import_pipeline.cc:369 0| Parsing /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:22:51.815 ( 0.005s) [querydb ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 2018-02-28 19:22:51.815 ( 0.005s) [querydb ]message_handler.cc:81 0| "/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c" is being indexed. 2018-02-28 19:22:51.815 ( 0.005s) [querydb ] timer.cc:35 0| [querydb] Loading cached index file for DidOpen (blocks CodeLens) took 0.188ms 2018-02-28 19:22:51.816 ( 0.005s) [completeparse] clang_complete.cc:400 0| Creating completion session with arguments gcc -D DARWIN main.c -working-directory=/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/ /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c -resource-dir=/usr/local/Cellar/cquery/HEAD-5f3a240/lib/clang+llvm-5.0.1-x86_64-apple-darwin/lib/clang/5.0.1 -Wno-unknown-warning-option -fparse-all-comments -fspell-checking 2018-02-28 19:22:51.816 ( 0.005s) [indexer1 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 2018-02-28 19:22:51.816 ( 0.005s) [indexer1 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c.json 2018-02-28 19:22:51.816 ( 0.005s) [indexer1 ]import_pipeline.cc:369 0| Parsing /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:22:51.839 ( 0.028s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/stdio.h 2018-02-28 19:22:51.840 ( 0.029s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/cdefs.h 2018-02-28 19:22:51.841 ( 0.030s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/Availability.h 2018-02-28 19:22:51.842 ( 0.032s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/_types.h 2018-02-28 19:22:51.842 ( 0.032s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/_types.h 2018-02-28 19:22:51.842 ( 0.032s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/machine/_types.h 2018-02-28 19:22:51.842 ( 0.032s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/sys/_pthread/_pthread_types.h 2018-02-28 19:22:51.843 ( 0.032s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/stdio.h 2018-02-28 19:22:51.843 ( 0.033s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/secure/_stdio.h 2018-02-28 19:22:51.843 ( 0.033s) [ 13CAC2C] utils.cc:319 0| Reading /usr/include/i386/_types.h 2018-02-28 19:22:51.844 ( 0.034s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/_types/_va_list.h 2018-02-28 19:22:51.844 ( 0.034s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/_types/_size_t.h 2018-02-28 19:22:51.845 ( 0.034s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/_types/_off_t.h 2018-02-28 19:22:51.845 ( 0.035s) [ 13CAC2D] utils.cc:319 0| Reading /usr/include/sys/_types/_ssize_t.h 2018-02-28 19:22:51.849 ( 0.039s) [indexer1 ] utils.cc:319 0| Reading /usr/include/sys/_symbol_aliasing.h 2018-02-28 19:22:51.851 ( 0.041s) [indexer0 ] utils.cc:319 0| Reading /usr/include/sys/_posix_availability.h 2018-02-28 19:22:51.853 ( 0.043s) [indexer0 ] utils.cc:319 0| Reading /usr/include/AvailabilityInternal.h 2018-02-28 19:22:51.872 ( 0.062s) [indexer1 ] utils.cc:319 0| Reading /usr/include/sys/_types/_null.h 2018-02-28 19:22:51.886 ( 0.075s) [indexer1 ] utils.cc:319 0| Reading /usr/include/secure/_common.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/secure/_common.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types/_null.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_symbol_aliasing.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/Availability.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/i386/_types.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/machine/_types.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_pthread/_pthread_types.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/_types.h 2018-02-28 19:22:51.888 ( 0.078s) [indexer1 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/stdio.h 2018-02-28 19:22:51.890 ( 0.080s) [indexer2 ]import_pipeline.cc:453 0| Built index update for /usr/include/secure/_common.h (is_delta=0) 2018-02-28 19:22:51.890 ( 0.080s) [indexer2 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/secure/_common.h 2018-02-28 19:22:51.891 ( 0.080s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types/_null.h (is_delta=0) 2018-02-28 19:22:51.891 ( 0.080s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types/_null.h 2018-02-28 19:22:51.892 ( 0.081s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_symbol_aliasing.h (is_delta=0) 2018-02-28 19:22:51.892 ( 0.081s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_symbol_aliasing.h 2018-02-28 19:22:51.894 ( 0.083s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/secure/_common.h took 0.87ms 2018-02-28 19:22:51.894 ( 0.083s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types/_null.h took 0.14ms 2018-02-28 19:22:51.894 ( 0.084s) [indexer2 ]import_pipeline.cc:453 0| Built index update for /usr/include/Availability.h (is_delta=0) 2018-02-28 19:22:51.894 ( 0.084s) [indexer2 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/Availability.h 2018-02-28 19:22:51.894 ( 0.084s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/i386/_types.h (is_delta=0) 2018-02-28 19:22:51.894 ( 0.084s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/i386/_types.h 2018-02-28 19:22:51.896 ( 0.086s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/machine/_types.h (is_delta=0) 2018-02-28 19:22:51.896 ( 0.086s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/machine/_types.h 2018-02-28 19:22:51.897 ( 0.086s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_symbol_aliasing.h took 0.84ms 2018-02-28 19:22:51.897 ( 0.087s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/Availability.h took 0.133ms 2018-02-28 19:22:51.897 ( 0.087s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/i386/_types.h took 0.127ms 2018-02-28 19:22:51.897 ( 0.087s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/machine/_types.h took 0.15ms 2018-02-28 19:22:51.898 ( 0.088s) [indexer2 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_pthread/_pthread_types.h (is_delta=0) 2018-02-28 19:22:51.898 ( 0.088s) [indexer2 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_pthread/_pthread_types.h 2018-02-28 19:22:51.901 ( 0.091s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c (is_delta=0) 2018-02-28 19:22:51.901 ( 0.091s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:22:51.902 ( 0.092s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/_types.h (is_delta=0) 2018-02-28 19:22:51.902 ( 0.092s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/_types.h 2018-02-28 19:22:51.904 ( 0.094s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/stdio.h (is_delta=0) 2018-02-28 19:22:51.905 ( 0.094s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/stdio.h 2018-02-28 19:22:51.913 ( 0.103s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_pthread/_pthread_types.h, /usr/include/_types.h, /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c, /usr/include/stdio.h took 0.583ms 2018-02-28 19:22:51.913 ( 0.103s) [stdout ] timer.cc:35 0| [e2e] Running $cquery/publishSemanticHighlighting took 0.5ms 2018-02-28 19:22:52.014 ( 0.204s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/AvailabilityInternal.h 2018-02-28 19:22:52.014 ( 0.204s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_posix_availability.h 2018-02-28 19:22:52.015 ( 0.204s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types/_ssize_t.h 2018-02-28 19:22:52.015 ( 0.205s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types/_size_t.h 2018-02-28 19:22:52.015 ( 0.205s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types/_va_list.h 2018-02-28 19:22:52.015 ( 0.205s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/secure/_stdio.h 2018-02-28 19:22:52.016 ( 0.205s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/stdio.h 2018-02-28 19:22:52.016 ( 0.206s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types/_off_t.h 2018-02-28 19:22:52.016 ( 0.206s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/_types.h 2018-02-28 19:22:52.016 ( 0.206s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /usr/include/sys/cdefs.h 2018-02-28 19:22:52.018 ( 0.208s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_posix_availability.h (is_delta=0) 2018-02-28 19:22:52.018 ( 0.208s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_posix_availability.h 2018-02-28 19:22:52.020 ( 0.210s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_posix_availability.h took 0.36ms 2018-02-28 19:22:52.020 ( 0.210s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types/_ssize_t.h (is_delta=0) 2018-02-28 19:22:52.020 ( 0.210s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types/_ssize_t.h 2018-02-28 19:22:52.020 ( 0.210s) [indexer2 ]import_pipeline.cc:453 0| Built index update for /usr/include/AvailabilityInternal.h (is_delta=0) 2018-02-28 19:22:52.020 ( 0.210s) [indexer2 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/AvailabilityInternal.h 2018-02-28 19:22:52.021 ( 0.211s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types/_ssize_t.h took 0.26ms 2018-02-28 19:22:52.021 ( 0.211s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types/_size_t.h (is_delta=0) 2018-02-28 19:22:52.021 ( 0.211s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types/_size_t.h 2018-02-28 19:22:52.021 ( 0.211s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types/_size_t.h took 0.26ms 2018-02-28 19:22:52.021 ( 0.211s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types/_va_list.h (is_delta=0) 2018-02-28 19:22:52.022 ( 0.211s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types/_va_list.h 2018-02-28 19:22:52.022 ( 0.212s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/secure/_stdio.h (is_delta=0) 2018-02-28 19:22:52.022 ( 0.212s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/secure/_stdio.h 2018-02-28 19:22:52.022 ( 0.212s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/stdio.h (is_delta=0) 2018-02-28 19:22:52.022 ( 0.212s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/stdio.h 2018-02-28 19:22:52.022 ( 0.212s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types/_va_list.h took 0.29ms 2018-02-28 19:22:52.023 ( 0.213s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types/_off_t.h (is_delta=0) 2018-02-28 19:22:52.023 ( 0.213s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types/_off_t.h 2018-02-28 19:22:52.023 ( 0.213s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/stdio.h took 0.36ms 2018-02-28 19:22:52.024 ( 0.214s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types/_off_t.h took 0.30ms 2018-02-28 19:22:52.025 ( 0.215s) [indexer0 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/_types.h (is_delta=0) 2018-02-28 19:22:52.025 ( 0.215s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/secure/_stdio.h took 0.66ms 2018-02-28 19:22:52.025 ( 0.215s) [indexer1 ]import_pipeline.cc:453 0| Built index update for /usr/include/sys/cdefs.h (is_delta=0) 2018-02-28 19:22:52.026 ( 0.215s) [indexer1 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/cdefs.h 2018-02-28 19:22:52.026 ( 0.216s) [indexer0 ]import_pipeline.cc:458 0| Writing cached index to disk for /usr/include/sys/_types.h 2018-02-28 19:22:52.029 ( 0.219s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/sys/_types.h, /usr/include/sys/cdefs.h took 0.219ms 2018-02-28 19:22:52.105 ( 0.295s) [querydb ] timer.cc:35 0| Applying index update for /usr/include/AvailabilityInternal.h took 0.404ms 2018-02-28 19:22:55.964 ( 4.154s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/documentHighlight took 0.149ms 2018-02-28 19:22:55.967 ( 4.157s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/codeAction took 0.409ms 2018-02-28 19:22:55.969 ( 4.159s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/hover took 0.83ms 2018-02-28 19:22:56.795 ( 4.984s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/definition took 0.377ms 2018-02-28 19:22:57.306 ( 5.495s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/documentHighlight took 0.130ms 2018-02-28 19:22:57.308 ( 5.498s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/codeAction took 0.327ms 2018-02-28 19:22:57.311 ( 5.500s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/hover took 0.99ms 2018-02-28 19:25:05.908 ( 134.093s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/documentHighlight took 0.131ms 2018-02-28 19:25:05.911 ( 134.096s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/codeAction took 0.62ms 2018-02-28 19:25:05.913 ( 134.098s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/hover took 0.56ms 2018-02-28 19:25:06.915 ( 135.100s) [completequery] timer.cc:35 0| [complete] TryEnsureDocumentParsed took 0.0ms 2018-02-28 19:25:06.915 ( 135.100s) [completequery] timer.cc:35 0| [complete] Creating WorkingFile snapshot took 0.6ms 2018-02-28 19:25:06.916 ( 135.101s) [completequery] timer.cc:35 0| [complete] clang_reparseTranslationUnit took 1.1522ms 2018-02-28 19:25:07.713 ( 135.898s) [completequery] timer.cc:35 0| [complete] TryEnsureDocumentParsed took 0.0ms 2018-02-28 19:25:07.713 ( 135.898s) [completequery] timer.cc:35 0| [complete] Creating WorkingFile snapshot took 0.10ms 2018-02-28 19:25:07.720 ( 135.905s) [completequery] timer.cc:35 0| [complete] clang_reparseTranslationUnit took 6.6377ms 2018-02-28 19:25:08.385 ( 136.570s) [querydb ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:25:08.385 ( 136.570s) [indexer0 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 2018-02-28 19:25:08.385 ( 136.570s) [completeparse] clang_complete.cc:400 0| Creating completion session with arguments gcc -D DARWIN main.c -working-directory=/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/ /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c -resource-dir=/usr/local/Cellar/cquery/HEAD-5f3a240/lib/clang+llvm-5.0.1-x86_64-apple-darwin/lib/clang/5.0.1 -Wno-unknown-warning-option -fparse-all-comments -fspell-checking 2018-02-28 19:25:08.385 ( 136.570s) [indexer0 ] utils.cc:319 0| Reading /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/.cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c.json 2018-02-28 19:25:08.386 ( 136.571s) [indexer0 ]import_pipeline.cc:173 0| Timestamp has changed for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:25:08.386 ( 136.571s) [indexer0 ]import_pipeline.cc:369 0| Parsing /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:25:08.410 ( 136.595s) [indexer0 ]import_pipeline.cc:401 0| Emitting index result for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:25:08.410 ( 136.595s) [indexer2 ]import_pipeline.cc:453 0| Built index update for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c (is_delta=1) 2018-02-28 19:25:08.410 ( 136.595s) [indexer2 ]import_pipeline.cc:458 0| Writing cached index to disk for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c 2018-02-28 19:25:08.410 ( 136.595s) [querydb ] timer.cc:35 0| Applying index update for /Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c took 0.34ms 2018-02-28 19:25:08.411 ( 136.596s) [stdout ] timer.cc:35 0| [e2e] Running $cquery/publishSemanticHighlighting took 136492.136356118ms 2018-02-28 19:25:12.841 ( 141.026s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/documentHighlight took 1.1557ms 2018-02-28 19:25:12.842 ( 141.027s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/codeAction took 0.281ms 2018-02-28 19:25:12.845 ( 141.030s) [stdout ] timer.cc:35 0| [e2e] Running textDocument/hover took 0.275ms
但是生成的 cache 里除了源代码之外,并没有变量符号:
⋊> ag platf0rm .cquery_cached_index/ .cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 6: char *platf0rm = "Linux"; 9: char *platf0rm = "Darwin"; 13: printf("Hello, %s\n", platf0rm);
一旦把源代码里的 #ifdef ...
去掉,变量符号立刻就 parse 到了:
⋊> ag platf0rm .cquery_cached_index/ .cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c 5: char *platf0rm = "Linux"; 7: printf("Hello, %s\n", platf0rm); .cquery_cached_index/@Users@gqj@Dropbox@scratch@c@os-detecting-makefile/main.c.json 2:{"last_modification_time":1519817108,"language":1,"import_file":"/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c","args":["gcc -D DARWIN main.c","-working-directory=/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/","/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c","-resource-dir=/usr/local/Cellar/cquery/HEAD-5f3a240/lib/clang+llvm-5.0.1-x86_64-apple-darwin/lib/clang/5.0.1","-Wno-unknown-warning-option","-fparse-all-comments"],"includes":[{"line":0,"resolved_path":"/usr/include/stdio.h"}],"dependencies":["/usr/include/stdio.h","/usr/include/sys/cdefs.h","/usr/include/Availability.h","/usr/include/_types.h","/usr/include/sys/_types.h","/usr/include/machine/_types.h","/usr/include/sys/_pthread/_pthread_types.h","/usr/include/sys/stdio.h","/usr/include/secure/_stdio.h","/usr/include/i386/_types.h","/usr/include/sys/_types/_va_list.h","/usr/include/sys/_types/_size_t.h","/usr/include/sys/_types/_off_t.h","/usr/include/sys/_types/_ssize_t.h","/usr/include/sys/_symbol_aliasing.h","/usr/include/sys/_posix_availability.h","/usr/include/AvailabilityInternal.h","/usr/include/sys/_types/_null.h","/usr/include/secure/_common.h"],"skipped_by_preprocessor":[],"types":[{"id":0,"usr":17,"detailed_name":"","short_name_offset":0,"short_name_size":0,"kind":0,"hover":"","comments":"","declarations":[],"bases":[],"derived":[],"types":[],"funcs":[],"vars":[],"instances":[0],"uses":[]},{"id":1,"usr":13,"detailed_name":"","short_name_offset":0,"short_name_size":0,"kind":0,"hover":"","comments":"","declarations":[],"bases":[],"derived":[],"types":[],"funcs":[],"vars":[],"instances":[1,2],"uses":[]}],"funcs":[{"id":0,"usr":7924728095432766067,"detailed_name":"int main(int argc, char **argv)","short_name_offset":4,"short_name_size":4,"kind":12,"storage":1,"hover":"","comments":"","declarations":[],"spell":"3:5-3:9|-1|1|2","extent":"3:1-9:2|-1|1|0","bases":[],"derived":[],"vars":[0,1,2],"uses":[],"callees":[]}],"vars":[{"id":0,"usr":12398735953131332281,"detailed_name":"int argc","short_name_offset":4,"short_name_size":4,"hover":"","comments":"","declarations":[],"spell":"3:14-3:18|0|3|2","extent":"3:10-3:18|0|3|0","type":0,"uses":[],"kind":253,"storage":1},{"id":1,"usr":671456311703663748,"detailed_name":"char *[] argv","short_name_offset":9,"short_name_size":4,"hover":"","comments":"","declarations":[],"spell":"3:26-3:30|0|3|2","extent":"3:20-3:32|0|3|0","type":1,"uses":[],"kind":253,"storage":1}, {"id":2,"usr":11059741219555227032,"detailed_name":"char *platf0rm","short_name_offset":6, "short_name_size":8, "hover":"char *platf0rm = \"Linux\"","comments":"","declarations":[],"spell":"5:9-5:17|0|3|2","extent":"5:3-5:27|0|3|0","type":1,"uses":["7:25-7:33|0|3|4"],"kind":13,"storage":1}]}
libclang 5.0.0 有 #ifdef 問題 5.0.1 有segfault 問題 cquery最近改动与libclang.so一字节补丁 | MaskRay
https://github.com/cquery-project/cquery/blob/master/wscript 的 patch_byte_in_libclang 只用在了 ubuntu14.04
segfault 有 crash recovery 保护的,只有那一个文件的索引收到影响。只能在–log-file=…里看到 libclang ast error… / generic error 字样
不影响使用就好。
这次的 #ifdef
故障让我发现 homebrew 编译脚本里隐藏的问题:homebrew 安装了 llmv(5.0.0),但由于没有指明编译参数 --llvm-config
,所以 wscript 仍然会去下载 llvm(5.0.1)。浪费时间,而且两个版本的 llvm 混在一起,不确定到底使用了哪个。
现在我把所有编译参数都加上了:
└⋊> brew info ~/.repos/homebrew-cquery/Formula/cquery.rb
cquery: stable v20180215, HEAD
Low-latency language server supporting multi-million line C++ code-bases
https://github.com/cquery-project/cquery
/usr/local/Cellar/cquery/HEAD-2fccc1b (4 files, 10MB) *
Built from source on 2018-03-02 at 10:56:12 with: --variant=
From: ~/.repos/homebrew-cquery/Formula/cquery.rb
==> Dependencies
Required: llvm ✔
==> Options
--bundled-clang=
Bundled clang version, downloaded from https://releases.llvm.org/ , e.g. 4.0.0 5.0.1
--llvm-config=
Path to llvm-config, default is /usr/local/opt/llvm/bin/llvm-config
--variant=
Variant name for saving configuration and build results, e.g. release(default), debug, asan
--HEAD
Install HEAD version
编译时间缩短不少(墙内访问 llvm.org 还是挺费时的)。现在 release & debug 都没问题,但 asan 编译不过,无论是通过 homebrew 编译,还是直接从源代码仓库编译:
⋊> brew reinstall ~/.repos/homebrew-cquery/Formula/cquery.rb --variant=asan
==> Reinstalling cquery --variant=
==> Downloading https://github.com/cquery-project/cquery/archive/v20180215.tar.gz
Already downloaded: ~/.cache/homebrew/cquery-v20180215.tar.gz
==> Cloning https://github.com/onqtam/doctest.git
Updating ~/.cache/homebrew/cquery--doctest--git
==> Checking out revision b40b7e799deabac916d631d181a7f19f3060acc5
==> Cloning https://github.com/greg7mdp/sparsepp.git
Updating ~/.cache/homebrew/cquery--sparsepp--git
==> Checking out revision 1ca7189fe81ee8c59bf08196852f70843a68a63a
==> Cloning https://github.com/miloyip/rapidjson.git
Updating ~/.cache/homebrew/cquery--rapidjson--git
==> Checking out revision daabb88e001f562e1f7df5f44d7fed32a0c107c2
==> Cloning https://github.com/emilk/loguru.git
Updating ~/.cache/homebrew/cquery--loguru--git
==> Checking out revision 2c35b5e7251ab5d364b1b3164eccef7b5d2293c5
==> Cloning https://github.com/msgpack/msgpack-c.git
Updating ~/.cache/homebrew/cquery--msgpack-c--git
==> Checking out revision 208595b2620cf6260ce3d6d4cf8543f13b206449
==> ./waf configure --prefix=/usr/local/Cellar/cquery/v20180215 --variant=asan --llvm-config=/usr/local/opt/llvm/bin/llvm-config
==> ./waf build --variant=asan --llvm-config=/usr/local/opt/llvm/bin/llvm-config
Last 15 lines from ~/Library/Logs/Homebrew/cquery/02.waf:
"___ubsan_vptr_type_cache", referenced from:
ICacheManager::~ICacheManager() in cache_manager.cc.1.o
ICacheManager::~ICacheManager() in cache_manager.cc.1.o
ICacheManager::TryLoad(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in cache_manager.cc.1.o
ICacheManager::TryTakeOrLoad(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in cache_manager.cc.1.o
ICacheManager::TakeOrLoad(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in cache_manager.cc.1.o
ICacheManager::IterateLoadedCaches(std::__1::function<void (IndexFile*)>) in cache_manager.cc.1.o
std::__1::function<void (IndexFile*)>::operator()(IndexFile*) const in cache_manager.cc.1.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Waf: Leaving directory `/private/tmp/cquery-20180302-57037-1sdxysa/cquery-20180215/build/asan'
Build failed
-> task in 'bin/cquery' failed with exit status 1 (run with -v to display more information)
Do not report this issue to Homebrew/brew or Homebrew/core!
但由于没有指明编译参数 --llvm-config,所以 wscript 仍然会去下载 llvm(5.0.1)。浪费时间,而且两个版本的 llvm 混在一起,不确定到底使用了哪个。
今天还有另一个人抱怨了 cquery fails to compile due to poor decisions about finding libclang and ncurses libraries · Issue #483 · jacobdufault/cquery · GitHub wiki/Build不够清楚,加粗了
https://github.com/cquery-project/cquery/blob/master/wscript#L184
if 'asan' in ctx.options.variant:
cxxflags.append('-fsanitize=address,undefined')
ldflags.append('-fsanitize=address,undefined')
难道是Mac OS X上ldflags指定-fsanitize=address,undefined
不够?需要设法链接 libubsan.so
(Mac 应该是 .dylib)
在另一台电脑上出现奇怪的问题:cquery 错把 $HOME
当作项目根目录,然后打不开 compile_commands.json
[ thread name/id] file:line v| [ thread name/id] file:line v| [main thread ] loguru.hpp:2014 0| Logging to '/tmp/cq.log', mode: 'w', verbosity: 9 [querydb ] initialize.cc:483 0| Init parameters: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cacheDirectory":"/Volumes/HDD/Users/gqj/.cquery_cached_index/","cacheFormat":"json","resourceDirectory":"","extraClangArguments":[],"progressReportFrequencyMs":500,"showDocumentLinksOnIncludes":true,"diagnosticsOnParse":true,"client":{"snippetSupport":false},"codeLens":{"localVariables":true},"completion":{"detailedLabel":false,"filterAndSort":true,"includeBlacklist":[],"includeMaxPathSize":30,"includeSuffixWhitelist":[".h",".hpp",".hh"],"includeWhitelist":[]},"index":{"attributeMakeCallsToCtor":true,"blacklist":[],"comments":2,"enabled":true,"logSkippedPaths":false,"threads":0,"whitelist":[]},"workspaceSymbol":{"maxNum":1000,"sort":true},"xref":{"container":false,"maxNum":2000},"dumpAST":[]} [querydb ] initialize.cc:487 0| [querydb] Initialize in directory /Volumes/HDD/Users/gqj/ with uri file:///Volumes/HDD/Users/gqj/ [querydb ] initialize.cc:547 0| Using -resource-dir=/usr/local/Cellar/llvm/5.0.1/lib/clang/5.0.1 [stdout ] timer.cc:35 0| [e2e] Running initialize took 0.571ms [querydb ] project.cc:397 0| Trying to load compile_commands.json [querydb ] project.cc:411 0| Unable to load compile_commands.json located at "/Volumes/HDD/Users/gqj/"; using directory listing instead.
然后接着又把索引文件创建在 $HOME/.cquery_cached_index/
,其实项目目录是 $HOME/Dropbox/scratch/c/os-detecting-makefile/
:
[querydb ] project.cc:310 WARN| cquery has no clang arguments. Considering adding either a compile_commands.json or .cquery file. See the cquery README for more information. [querydb ] utils.cc:213 WARN| Unable to read file .#go-version-list.txt when reading directory /Volumes/HDD/Users/gqj/ [querydb ] timer.cc:35 0| [perf] Loaded compilation entries (0 files) took 145.145154ms [querydb ] initialize.cc:604 0| Starting 3 indexers [querydb ] timer.cc:35 0| [perf] Dispatched initial index requests took 0.4ms [querydb ] utils.cc:319 0| Reading /Volumes/HDD/Users/gqj/.cquery_cached_index/@Volumes@HDD@Users@gqj/Dropbox@scratch@c@[email protected] [scan_includes] utils.cc:213 WARN| Unable to read file .#go-version-list.txt when reading directory /Volumes/HDD/Users/gqj/ [scan_includes] timer.cc:35 0| [perf] Scanning for includes took 3.3033ms [querydb ]message_handler.cc:83 0| Unable to find file "/Volumes/HDD/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c" [querydb ] timer.cc:35 0| [querydb] Loading cached index file for DidOpen (blocks CodeLens) took 12.12542ms [completeparse] clang_complete.cc:380 0| Creating completion session with arguments %clang /Volumes/HDD/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c -fspell-checking [indexer0 ] utils.cc:319 0| Reading /Volumes/HDD/Users/gqj/.cquery_cached_index/@Volumes@HDD@Users@gqj/Dropbox@scratch@c@[email protected] [indexer0 ] utils.cc:319 0| Reading /Volumes/HDD/Users/gqj/.cquery_cached_index/@Volumes@HDD@Users@gqj/Dropbox@scratch@c@[email protected] [indexer0 ] utils.cc:319 0| Reading /Volumes/HDD/Users/gqj/.cquery_cached_index/@@Volumes@HDD@Users@gqj/@usr@[email protected]
由于 $HOME
下没有 compile_commands.json
,所有 #ifdef...
又 parse 不到了,除非我把项目的 compile_commands.json
拷贝到 $HOME
。
不知为何会出现这种情况,两台电脑系统/环境是一样的,只是这台的旧一点,然后加装了硬盘,$HOME
目录是从别的 HDD 链接过来的,难道是这个原因?
└⋊> ll /Users/
lrwxr-xr-x 1 root admin 22B 1 24 2015 gqj -> /Volumes/HDD/Users/gqj
所以我这台电脑上这三个路径是一样的:
/Volumes/HDD/Users/<user>
/Users/<user>
~
symlink ? find . -type l -printf '%p -> %l \n'
假设 initialization option "cacheDirectory"
是 /tmp/cquery
,源文件是/tmp/c/a.cc
,jq . < /tmp/cquery/@tmp@c/a.cc.json
看看里面那些路径写了什么
NormalizePath
很久以前被我改过不follow symlink的
索引当中都已经是绝对路径了:
└⋊> jq . < ~/.cquery_cached_index/@Volumes@HDD@Users@gqj/Dropbox@scratch@c@[email protected]
{
"last_modification_time": 1520075011,
"language": 1,
"import_file": "/Volumes/HDD/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c",
"args": [
"%clang",
"/Volumes/HDD/Users/gqj/Dropbox/scratch/c/os-detecting-makefile/main.c"
],
"includes": [
{
"line": 0,
"resolved_path": "/usr/include/stdio.h"
}
],
"dependencies": [...],
"skipped_by_preprocessor": [...],
"types": [...],
"funcs": [...],
"vars": [...]
}
src/project.cc
这里断点看 config->project_dir
是什么
用环境变量CQUERY_TRACEME=1
提早停下 Debugging · jacobdufault/cquery Wiki · GitHub
之后 gdb/lldb attach + continue
从执行的顺序看,早在 initialize.cc:482
cacheDirectory 就已经是 $HOME/.cquery_cached_index/
了:
L482 request->paramsinitializationOptions
是输入,没有修改过。。所以服务端是无辜的
我认为问题在于lsp-methods.el
(defun lsp--start (client &optional extra-init-params)
(when lsp--cur-workspace
(user-error "LSP mode is already enabled for this buffer"))
(cl-assert client)
(let* ((root (file-truename (funcall (lsp--client-get-root client))))
file-truename
展开了symlink
经过调试发现是 projectile 的锅:
ls--start
|
+ lsp--client-get-root
|
+-> cqeury--get-root
|
+--> projectile-project-root
projectile-project-root
返回的是 $HOME
解决方法是:
(with-eval-after-load 'projectile
(setq projectile-project-root-files-top-down-recurring
(append '("compile_commands.json"
".cquery")
projectile-project-root-files-top-down-recurring)))