company-lsp 终于来了

Microsoft 主持开发的主流语言通用补全后端。

写了几行扔一边了 :sweat_smile:

哈哈,其实这个不是很难写,不过目前功能很有限就是了

5 个赞

哈哈,作者现身了

其实lsp-mode配合company-capf用起来已经可以了。company-lsp的功能都可以在lsp-mode里实现。只是我提交的pull-request一直没人理所以只能自己干了。

求指导company-capf怎么用,据说这个后端加company-flx可以fuzzy-match,帖子在这里

company-capf只有在你的buffer里指定了completion-at-point-functions的时候有用。一般是需要major mode实现或者由像lsp-mode这样的第三方包来实现。

我一般这样在我想要的mode里启用company-capf:

(add-hook 'java-mode-hook
          (lambda ()
            (set (make-variable-buffer-local 'company-backends)
                 '(company-capf))))

关键就是设置company-backends,这个变量指定了company的补全后端使用什么。

哦,completion-at-point-functions只有(tags-completion-at-point-function),怪不得我用company-capf没补全

如果那个 PR 已经没有意义了,建议关闭并删除相关分支

我也有过这种经历,我发 issue 表示有意汉化某项目,结果被无视了。

今天试了下,company-lsp结合yasnippet很好用,Python, Go, Java 中都能实现completion-at-point功能。

你这是什么gtk theme

這是 macOS :joy:

:joy:不好意思,孤陋寡闻了…

lsp-mode还是不成熟不稳定,用了几天放弃了。等段时间再看吧

java的话,可以做语义跳转么,不知道你之前用过java的哪些mode?这个lsp-mode会考虑项目管理么

能用于c++补全吗?

可以,配合cquery。

你说的cquery是什么?

比起我现在用的company-clang来补全, lsp + cquery 会更好吗?

Much better. GitHub - jacobdufault/cquery: C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more

1 个赞

cquery 裏 #i (#include)

顯示效果正常 screen

但是按回車確認補全項時輸出 #include <aio.h>include <aio.h> 。不知道是誰的鍋

read /home/maskray/Dev/Util/cquery/build/release/bin/cquery
{"jsonrpc":"2.0","method":"textDocument/completion","params":{"textDocument":{"uri":"file:///tmp/c/a.cc"},"position":{"line":0,"character":2}},"id":789}
write /home/maskray/Dev/Util/cquery/build/release/bin/cquery
{"jsonrpc":"2.0","id":789,"result":{"isIncomplete":true,"items":[{"label":"#include <aio.h>","kind":9,"detail":"aio.h","documentation":"","sortText":"","insertText":"","insertTextFor
mat":1,"textEdit":{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":2}},"newText":"#include <aio.h>"}},{"label":"#include <algorithm>","kind":9,"detail":"algorit
hm","documentation":"","sortText":"","insertText":"","insertTextFormat":1,"textEdit":{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":2}},"newText":"#include <algorithm>"}},{"label":"#include <any>","kind":9,"detail":"any","documentation":"","sortText":"","insertText":"","insertTextFormat":1,"textEdit":{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":2}},"newText":"#include <any>"}},{"label":"#include <arpa/inet.h>","kind":9,"detail":"arpa/inet.h","documentation":"","sortText":"","insertText":"","
insertTextFormat":1,"textEdit":{"range":{"start":{"line":0,"char