EasyClangComplete icon indicating copy to clipboard operation
EasyClangComplete copied to clipboard

C/C++ header completion

Open jerrykal opened this issue 9 years ago • 21 comments

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 on Bountysource.

jerrykal avatar Mar 23 '17 00:03 jerrykal

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 avatar Mar 23 '17 08:03 simia

Sky is the limit :)

simia avatar Mar 23 '17 08:03 simia

@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.

niosus avatar Mar 23 '17 09:03 niosus

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

simia avatar Mar 23 '17 09:03 simia

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 avatar Mar 23 '17 10:03 niosus

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

niosus avatar Apr 12 '17 07:04 niosus

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

simia avatar Apr 12 '17 07:04 simia

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

niosus avatar Apr 12 '17 07:04 niosus

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.

jdumas avatar Apr 27 '17 21:04 jdumas

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.

niosus avatar Apr 28 '17 08:04 niosus

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.

bigboze avatar Jun 06 '17 21:06 bigboze

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

niosus avatar Jun 07 '17 08:06 niosus

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

rwols avatar Jul 24 '17 07:07 rwols

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.

niosus avatar Jul 27 '17 04:07 niosus

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

Viterzgir avatar Aug 15 '17 18:08 Viterzgir

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.

stale[bot] avatar Nov 13 '18 10:11 stale[bot]

:(

jdumas avatar Nov 13 '18 10:11 jdumas

@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.

niosus avatar Nov 13 '18 10:11 niosus

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

jdumas avatar Nov 13 '18 10:11 jdumas

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

niosus avatar Nov 13 '18 10:11 niosus