-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable use of carapace completer as a library #655
Conversation
I'm a bit worried about the implications this has. Having a global storage was fine so far since the whole thing has a focused purpose and shouldn't cause issues in normal usage. I kept internals like RawValue so far private so i could make larger changes under the hood. Shell completion is quite complicated and i still expect some modifications here and there. |
Obviously, like for the other PRs, I'm neither in a hurry nor pushing for changes that would have long-term implications ! |
Pinging you on this too... I still desperately need to compile carapace into a console binary... But... having carapace executable as a runtime dependency is just too much when one can simply compile the logic into the binary (also considering the myriad carapace-bin completers than can then be used along) Regardless, I'll merge the most recent carapace branch into this PR one, to keep those unsuccessful checks silent... |
I'll have another look at it, but i think the biggest blocker to me was that there is currently no way to store arbitrary data to a command (there is Context, but that is intendend for sth. else). Not too fond of the current storage solution and the necessity of clearing it. Embedding carapace-bin wouldn't work btw. due to how the commands are constructed (using init) as well as some other design decisions. Challenge here is to consistently recreate cobra commands (as they can be executed only once) and to do a proper cleanup (for which it would be best to store the completions in the command and let the garbage collector do that). |
Storage type: this is up to you, I don't have an opinion on this. Storing arbitrary data for a command: you might not even realize it yourself (and that is a great compliment) but the way you designed your library just makes this possible out of the box, without any bugs or needs for workarounds ! Embedding carapace-bin: this not what I'm talking about here, this is about embedding carapace (and only carapace), that is, only embedding the completion engine. Thus there are no concerns about init functions. Challenge: so this is also something I had to solve (and did) in my console library. The simple and fully working workaround is to declare (bind) commands in a function that is called after each execution loop (see link shared below). To be clear: my console library works flawlessly with your carapace engine used as a library. It works just as good as used from a system shell with caparace-bin ! Precisely because my console uses cobra commands. I mean... I think you don't even realize how well designed your library is, and just how easy it is to use it in my own context ! A few lines to illustrate, if you want to see a proof for yourself:
|
Yes it works. What I am more concerned about is concurrency and cleaning up instances. |
I pulled your master changes onto this branch, for the sake of keeping up-to-date (this at least allows us to debate this with your most recent work). To note, even 200 commits later, everything seems to work great. I also saw your refactored your About this failing lint test: I'm not sure what causes that, as the code is strictly identical to master except for a newline added by my automatic formatter (I gave up trying to mute it for a few things)... If you have any idea or solution you would save me once again ! |
About that last sentence in your last message:
So it's true that as my current implementation stands, all commands completions are being cleared. About the |
Thinking of the In fact and despite the quite simplistic storage model (as it stands now), it is quite efficient because it obsviously stores pointers to commands, so that when carapace has to resolve the command to complete, it cannot confuse one command for the other, since they are all different in memory, and this regardless of how complex/deep your command tree is, or regardless of two subcommands having the same name. Lastly, and related to this, the only (not bothering but redundant) thing that could be done is: |
It is not known when a command is added to a parent which makes root command determination pretty much impossible. The references themself aren't an issue but they prevent garbage collection which will be a problem in a long running app where commands are constantly created. Regarding cobra's flagcompletion: cobra has global variables which keep references which can't be cleaned up because they are private. |
Carapace command: thanks for precising. Thanks ! |
- This is so that suffix-removal behavior is not induced in error when the flags don't need a multipart and the argument to the flag is a path starting with . (like ./relative/path).
I was looking at how to fallback on cobra completer functions for one my mentionned projectss, and that was a good occasion to realize why you didn't implement such fallbacks yet, because there are quite a few things to be sure of first. Overall implementing a fallback to cobra completer functions is not really hard fortunately, and will be really great once implemented in carapace. Between others, it seems that cobra added support for usage messages recently. This last remark (and most of this message) is not much related to this PR,,, but just to say some of your answers and your patience is suddenly clearer to me. |
Hello, Just a quick ping to know if you had time to reflect on this, or if you had any related ideas, or things to watch out for. To be clear this is just a ping for attempting to slowly but efficiently narrow down the problems at hand. As said in my very last comment, I've come to understand why this whole stuff needs to be forethought, and that anyway it also depends on the default behavior of other libraries (cobra in the first place). I also did not have time to to try new implementations (nor had a really good model come to my mind) for the So... yes any suggestion or note to add here would be welcome ! |
I've been thinking about it occasionally but haven't got a solution for it yet. |
Thinking out loud and writing this down:
|
I tried to reach out in the past, but it didn't seem possible to get anything forward at the time. |
Trying to advance a little bit on this. Avoiding global state for correct garbage collection
Alternative (but a bad one)I only see of one, and I'm not really fond at all with it... The only place where a Most likely working solutionTo me, the current way (as in this PR) to deal with closed-loop usage of carapace is to periodically clear the storage map and regenerate it. The good news here is that if cobra global state was the only obstacle to this, then the problem is likely to be solved very soon. What would be greatMaintaining this PR requires some work. Not big big tons, but still some stress and headaches each time (since I only catch up on your master every 3-4 months. All of this for the equivalent of a patch. (it will also help me get rid of a forked branch that I have to use in conjunction with a go Available when you need to work this out ! |
Had a look at |
Would https://github.com/rsteube/carapace/compare/experimental work for you? |
Hello @rsteube Absolutely perfect, it works like a charm ! |
Hello Rob, here again for a feature request, which will litterally save me.
Main subject
In the context of three projects of mine,
... I need to be able to use the carapace completer from within a shell program.
Not only that, but on top of it (and that is because the
Complete()
functionof this commit also returns the
common.Meta
), it enables the readline shelllibrary to have as fine-grained a control over the suffix pattern matchers.
So basically this commit is way, way less complex than the previous PRs I've submitted:
it just Exports the main
Complete()
function, and returns theRawValues
and theMeta
.It makes the necessary adjustements for the traditional cobra
_carapace
command.Needless to say it again, on this PR rests the entire future of the projects above, and
be sure that if accepted, they would have a definite edge over what exists in the space
at present. Having a full-fledged CLI application will become as trivial as it can be.
I would love to present you a demonstration of the results right now: it's running great.
It's just in my go workspace for now and I'm polishing a few things before pushing it.
Remarks on this PR code
Additionally, there is no way to move any further completion logic internally
(and there is absolutely no problem with that, don't get me wrong), so maybe
the name of the exported
Complete()
could be changed to something more explicit,or something that would ensure no one will use it mistakingly.
(On the other hand,
Complete()
is fine if one considers that none of your APIfunctions start with this verb)
it seems to me that they are not conflicting.
/
NoSpace suffix matcher to path completion: as far as my library isconcerned (but I guess it applies to all), it further enhances the default spacing
and autosuffix removal for path completion/insertion when the candidate is a
directory (and only if a directory).
I'll find a way to deactivate that, just did'nt look into it yet...
Additional things.
So I got over your code /recent commits (which I get to know quite well by now), or just used it
within the course of the aforementioned projects, and I got to remember that there
were a few side-fixes in my other PRs (for instance, better error filtering when flags
raise errors because they've not been fed a result yet).
And some other things, or suggestions.
I'll open separate (and each of them very small, I promess) PRs for those, so that you
can cherry pick.
Once again, really great, great work with this library. I don't cease to be amazed at what you've done.