幫忙改進 C++ LSP 體驗


編輯這個 Wiki https://github.com/jacobdufault/cquery/wiki/Emacs (我之前有篇簡單的介紹 )

改进 cquery.el 比如实现 $cquery/typeHierarchyTree

cquery#30 收集了一些可以改進的地方 模板有很多可改進的地方

Higher priority items I'd like to get addressed before publishing to the marketplace

make sure we don’t load cached file if real file is not present Very make_unique contributes constructor calls extern const char not included in outline? see ash_switches.h show warning for compile_commands.json, autogen if possible; maybe git rev-parse origin/master ; or git rev-parse HEAD Verify when loading project we add to end of queue so existing open files are indexed first we don’t need to reindex file unless it has timestamp change, ever, try to add metrics to count how many files get updated after sync reindex file is command line arguments change max number of code lens results otherwise vscode will hang if the file has 20k+ code lens Mention how to disable code lens in README Drop clang_args in favor of pref or move to .cquery or similar clang arg pref should be platform specific Only status update every few hundred milliseconds Reduce output index perf: don’t run every DoIdMap; stop after 500 or 1000 iterations Move completion entirely off querydb thread so it never touches querydb progress indicator needs to account for index threads which are busy (ie, +1 to a job when they remove the item from the queue until it is done being processed) Misc issues that need to be dealt with at some point

Make warning “launch.workingDirectory” say “cquery.launch.workingDirectory” std::sting -> std::string typo fixit does replaces trailing text content/space, it should insert the new string instead of replacing, likely a bug in FixIt generation Fix show references for function declaration parameters Code lens causing screen to scroll - Microsoft/vscode#12294 Show warning for old pref names No reload notification when adding new pref that changes from default value (include.blacklist) Find ref on lambda parameter gv on variable should show variables of the same type Freshen should drop existing index labeled stack traces on linux Insert include by typing a symbol (ie, global symbol search) see if we can set code lens command title to show custom string Prefer smallest path found for include when scanning Clickable controls in tooltips - Microsoft/vscode#29076 See if we can integrate commit characters for code completion Auto-implement doesn’t strip override Auto-implement select implemented content for fast ctrl-x ctrl-v Call tree in context menu Call tree - use icon for base/derived calls Completion list private with - or similar Don’t show errors for ie, *.mojom files Add task to reload compile_commands.json Call tree should store index lines and look it up when the user requests goto definition Add task to drop existing index and do a fresh import Reparse top document - might be possible by hooking directly into extension API and sending a notification $cquery/onView Call hierarchy; show class name and line, skip column MyMethod (Foobar:3). If no class name show file MyMethod (foo.cc:3) Call hierarchy: sort by file and then by location in that file Call tree fails on pure-virtual functions Investigate jemalloc Do not report global completions in certain situations, ie, o not report global completions in certain situations, ie, Example: type this: class Foo : public Bar {public: Idea: only do live-indexing after a save, but use completion thread to do it.







rtags 很慢,查找引用會有大量磁盤seek https://github.com/Andersbakken/rtags/issues/1007


(defcustom rtags-use-bookmarks t
  "Whether RTags uses bookmarks for locations."
  :group 'rtags
  :type 'boolean
  :safe 'booleanp)

LSP 通用,會有很多人幫忙改進 https://github.com/emacs-lsp/lsp-mode/graphs/contributors 不需要爲 C++ 和其他語言的 jedi 之類配置不同快捷鍵了

rtags reference tree 效果怎麼樣?https://github.com/jacobdufault/cquery/blob/master/src/messages/cquery_type_hierarchy_tree.cc 可能是類似的功能, 但 https://github.com/jacobdufault/cquery/blob/master/emacs/cquery.el 還沒人實現……




cquery 和lsp 和ycm 不是同一个维度的东西.lsp 是language server protocol 协议,而lsp-mode 是在Emacs 的具体实现,而cquery 是 lsp 协议下的C++语言的后端,而ycm 是vim 插件剥离出来的.cquery 是配合lsp-mode 使用的,比如cquery 是用作cpp 补全的,rls 是用作rust 语言补全的,lsp 就好像company 这个补全框架定义的规则那样,具体的语言补全就另外编写,但是lsp 是面对所有的编辑器的.


感谢楼上的信息. 我仔细看了一下这三个项目:


  • 如果只限于C/C++语言, lsp-mode和cquery都是lsp的实现, 用一个就够了.
  • ycmd实现了相似的功能, 但是和lsp没有直接关系.
  • 所以, 在这三个中选一个就够了

cquery声称实现了几乎全部的lsp, 从这一点上说, 以及很强大了. 我平时写得最多的就是C++, 准备装一个试试.



lsp-mode 只是一个客户端 lib,并没有针对某种语言的具体实现,更不包含服务端。

cquery 是 lsp 一个完整实现,包括服务端和客户端,而它的 Emacs 客户端正是基于 lsp-mode 实现的 https://github.com/jacobdufault/cquery/blob/2d6844ae/emacs/cquery.el#L9



感谢楼上的回复 :smiley:

我理解你的意思了, cquery中包含客户端和服务端, 其中客户端依赖于lsp-mode. 对吧?

还有个疑问, lsp-mode只是一个客户端lib, 不是完整的客户端吗?


是的,只是 lib,各种 lsp-<lang> 才是具体/完整实现:

  • lsp-css
  • lsp-go
  • lsp-haskell
  • lsp-java
  • lsp-javascript
  • lsp-ocaml
  • lsp-python
  • lsp-rust
  • lsp-vue




也就是说, 还没有c++的客户端. 比如lsp-cpp. 只能靠cquery中的打包的server和client了.



当然,cquery 是个好项目。


cquery 的 Emacs 客户端(cquery.el)就是 “lsp-cpp”。

服务端实现与 Emacs 无关。Emacs 无需知道服务端是谁/如何实现的,只要符合 lsp 协议即可:

server <-- socket/stdio --> client (Emacs / VSCode /...)


嗯,没错。 cquery,我没装成功,archlinux,按照wiki编译总是出错 :sweat_smile: 你装好了吗?


https://aur.archlinux.org/packages/cquery-git/ SilverRainZ有個回覆

lsp-ui 新功能 lsp-ui-doc.el child frame lsp-ui child frame 相信可以做更多事




我安装完之后只有一个 “cquery/bin/cquery”, 但是cquery wiki上又说要添加

(add-to-list 'load-path “/path/to/cquery/emacs”)

大家有安装成功cquery的吗? 这个问题该怎么解决呢?



构建 cquery 会得到可执行文件 cquery,Emacs 支持放源代码下的 emacs 文件夹下。


哦, 原来是这样, 多谢~~

  • 先是装了cquery, 没反应…
  • 然后又装了lsp-ui, 还是不能用. 提示(error “Buffer xxx.cpp has no process”).

是不是Emacs26才能用cquery和lsp-ui啊? :joy: 我用的Emacs版本是25.3.1.