redguardtoo / company-ctags

Fastest Emacs auto-completion using Company and Ctags
GNU General Public License v3.0
56 stars 3 forks source link

Support ctags output format? #5

Closed AmaiKinono closed 3 years ago

AmaiKinono commented 4 years ago

Now company-ctags can only use etags output format. If we don't use the -e option for universal ctags, we can enable various "fields" in the output, something like:

main
hello.c
/^int main(int argc,$/;"
kind:function
line:17
signature:(int argc,char * argv[])

(I've replaced the tabs with newlines for easy reading)

I think "kind" is useful for us. We can use this for the annotation command of company, so we can see if the candidate is a function/variable/etc., when go through them.

Another possibility is to use "line" and "signature" to get which lines the signature begins and ends, and we can go up or down to fetch the comment/docstring. This can be used for the meta and doc-buffer commands, but I don't think this can be implemented in a robust way (and personally I don't like to see a lot of popups when coding). So maybe we can leave this for now.

redguardtoo commented 4 years ago

-e option "Enable etags mode, which will create a tag file for use with the Emacs editor".

I understand the tags file for vim is generated without -e option. Currently I want to focus on Emacs format only.

There is also practical consideration. company-ctags is designed to be a faster version of company-etags. Supporting multiple regex for text extraction will slow down the speed.

This package's priority is speed. It can handle huge project like Linux Kernel without any lag. I'd rather enhance its core feature instead of add more secondary features.

I do understand the type information of function is very useful. But Microsoft's language server protocol ( https://langserver.org/ ) is more powerful and popular than ctags as a parser

The best solution is to combine the power of company-ctags and LSP. For code completion, using ctags because it's fast but when completion is done and cursor is still over the completed symbol, use lsp-mode (a LSP client) to get the exact type information.

I already written a howto on combining lsp-mode and company-ctags. See https://zhuanlan.zhihu.com/p/103591590 for technical details (it's written in Chinese, so you need use google translate).

AmaiKinono commented 4 years ago

I've actually seen that article. I am a chinese too, I left the pinned comment in this article, and I bet you remember me :)

I really don't want to use language server but I understand your concern. I'll see if I can feel comfortable without having the type information when doing completion.

AmaiKinono commented 4 years ago

Supporting multiple regex for text extraction will slow down the speed.

In fact I think we can just look at the first char in a tags file to decide its format, so there's no need to use multiple regex to parse one tags file. As far as I'm concerned, tags files generated by etags or ctags -e always start with a control sequence, while the ctags format doesn't.