niosus / EasyClangComplete

:boom: Robust C/C++ code completion for Sublime Text 3/4
https://niosus.github.io/EasyClangComplete/
MIT License
575 stars 79 forks source link

C/C++ header completion #231

Closed jerrykal closed 5 years ago

jerrykal commented 7 years ago

Is possible to add C/C++ header completion like Xcode?

2017-03-23 09_28_15

--- Did you help close this issue? Go claim the **[$5 bounty](https://www.bountysource.com/issues/43339678-c-c-header-completion?utm_campaign=plugin&utm_content=tracker%2F32731927&utm_medium=issues&utm_source=github)** on [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F32731927&utm_medium=issues&utm_source=github).
simia commented 7 years ago

I am making a lot of assumptions below so treat what I say as wild guess :) I don't think that header completion is possible with libclang completion as headers (especially those not included) are not part of the TU. On the other hand ECC requires valid clang configuration file so it also has all required include directories. Grepping file names from include dirs and then injecting them to the completion list shouldn't be to hard.

So either way it should be possible to provide this functionality. The other question is if we (and by we I mean @niosus :D ) want to introduce it?

simia commented 7 years ago

Sky is the limit :)

niosus commented 7 years ago

@ooJerryLeeoo yes, it should be possible. It is not provided by libclang itself, so we will have to parse things on our own.

@simia I am definitely for it. The problem here is that we have to be really careful with implementation. We can have hundreds of folders and thousands of headers. We need a fast way to search for them using a given prefix.

Maybe we can start with a relatively dumb implementation and replace it with something smarter later.

simia commented 7 years ago

@niosus I was thinking about getting all headers names at plugin startup and holding them in some tree like structure for a fast lookup.

niosus commented 7 years ago

Yeah, that seems like the obvious solution. We just need to make sure that this job is asynchronous. Should be simple with the thread pool in place. If the speed is not enough, we can use a trie (I think this is the first time in my life when it makes sense to use this data structure :laughing: )

Related: https://github.com/google/pygtrie

UPD: as a side note, we should probably consider just throwing all of them into sublime completions and let sublime filter them itself. Seems it's doing a pretty good job at that.

niosus commented 7 years ago

Just thought, that we need to be careful with storing all headers as people tend to delete and create new files.

simia commented 7 years ago

Yeah, people tend to do such a nonsense for some reason :smiley_cat:

niosus commented 7 years ago

But depending on how long it takes we can probably preload all headers on file open in a separate thread.

jdumas commented 7 years ago

One suggestion regarding the cached path: I would distinguish between system folders (which are mostly fixed and could be cached once at plugin load) and project folders (where user might add/remove stuff, so they should be watched/monitored in a separate thread).

Also, it would be nice if you could make use of ST's fuzzy string matching to find the header file to include, but I don't know if plugins can do that.

niosus commented 7 years ago

This is a valid point @jdumas

I believe it is possible. We just need to try to throw all headers into sublime's completion engine.

bigboze commented 7 years ago

It would be awesome if you could you the same data structure to navigate to the header file using a mouse click. :) Sorry if this is out of scope for here.

niosus commented 7 years ago

@bigboze I believe it should be possible once we nail down the completion.

rwols commented 7 years ago

There's a package for autocompleting header file paths: https://packagecontrol.io/packages/Include%20Autocomplete

niosus commented 7 years ago

Thanks for a suggestion, but that package doesn't really work for me. We could probably adapt it to this plugin to some degree, considering that we already have all the include folders.

Viterzgir commented 7 years ago

Here is another package. https://github.com/ljesparis/CHeaders

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just comment here to prevent this from happening.

jdumas commented 5 years ago

:(

niosus commented 5 years ago

@jdumas I believe this is going to land some day. But I can't find the time to finish up the crude PR I started... Stale was not intended here.

jdumas commented 5 years ago

It's ok, I'll just keep commenting if the bot is acting up again ... no rush here :D

niosus commented 5 years ago

It's gonna react again in 60 days. I hope it won't need to :laughing:

niosus commented 5 years ago

Closed in #411