Giter Site home page Giter Site logo

Comments (9)

chrisant996 avatar chrisant996 commented on June 3, 2024 1

If I type winget install Python and hit tab, it completes the command line by turning it into winget install "Python. Basically, it adds double quotes at the beginning of the query and doesn't suggest anything else. I suppose this is due to the fact that there are packages that contain spaces, such as Python Launcher. I don't know if this is the expected behaviour (I know that winget complete isn't doing that).

@loriswit That's how Readline (and bash) is meant to work. The difference isn't about your script versus the new script: it's the fact that Clink v1.4.13 fixed a bug in the quoting, which had been malfunctioning before.

  • The first Tab complete command inserts the longest common prefix from the matches that fit what's been typed so far.
  • Since Python is already the longest common prefix of everything matching Python, nothing is appended on the first Tab.

If it doesn't insert a quote upon PythonTab, then it's impossible to complete anything with a space, without manually backing up and inserting a space quote. But it's conservative, and only inserts a space if the next character in any of the matches requires quoting. So typing PytTab doesn't insert a quote because the next possible characters are h or i. But typing PythTab will append on (longest common prefix) and insert a quote (because the next possible characters after Python are or ., one of which is a character that requires a quote ( requires a quote).

Now, if I hit tab again, absolutely nothing happens (and nothings is suggested). But if I hit tab a third time, then I receive the expected suggestion.

The complete command prints a list of matches if the previous Tab didn't modify the input line.

And when Readline inserts a quote, it considers that as having modified the input line, so the next Tab will not print a list of matches.

Thus the 3 Tab presses needed to print a list when the first Tab inserts a quote.

P.S. You can observe the same in bash, by creating a subdirectory and some files with the same names as from the winget completions.

Also note that if the query isn't a whole word (Pyt), then no quotes are being added to the query, and I only need to hit tab twice:

Since Pyt is already the longest common prefix of everything matching Pyt, nothing is appended on the first Tab.

If you typed Pyth then it would append on, making Python, since that's the longest common prefix from the matches that fit Pyth. And it would require 2 more Tab presses to see a list of matches.

Finally, I also realized that the script I wrote myself (see first post) was showing these kind of "inline suggestions", i.e. text in a dim color that appears after the cursor (see picture below).

Screenshot 2023-01-27 141101

The script in this repository currently does not do that.

That was intentional; see below.

By the way, notice that the auto-suggestion is Python.Python.2. That's interesting, right? Why isn't it Python Launcher, which is the first match for Python? Because Python Launcher contains a space, and cannot be inserted without also inserting a quote. But there's no way to show the quote that would get inserted, and it's misleading to insert a quote that wasn't actually shown.

With your script, try this:

  1. Type winget install python and wait for the auto-suggestion to appear.
  2. Then rapidly type Backspace 6 times and type a and wait for the auto-suggestion to update.
  3. It never will.
  4. Because winget complete --word "" --commandline "winget install " --position 99999 returns no matches.
  5. And then winget complete --word "p" --commandline "winget install p" --position 99999 returns all matches starting with p, and Clink caches the list.
  6. From there on, all typing in that word position just filters the list of p matches.

That's why my script uses builder:setvolatile() to disable caching.

But disabling caching means a new network query is triggered each time a letter is input or deleted. Clink throttles it so there's only one query at a time, so typing several letters in rapid succession only triggers one for the first letter. That's a lot of network traffic, and it's a little rude to hit someone's server with that much traffic. But probably the total traffic from Clink users isn't even noticeable, since Clink is a niche tool.

But there's another issue. The following would happen, if the script didn't also use coroutine.running() to figure out when to disable the background auto-suggestion invocations of winget complete.

  1. You could type winget install python and wait for the auto-suggestion to appear.
  2. Then you could rapidly type Backspace 5 times and wait for the auto-suggestion to update.
  3. It would show Python.Python.2 as the suggestion.
  4. But the "correct" suggestion would by paddiM8.kalker, the first match for p that doesn't contain a character that requires quoting.

The issue there has to do with internal optimizations in Clink, regarding caching and reusing match lists. But winget complete --word "" --commandline "winget install" --position 99999 returns an empty list of matches. It refuses to collect any matches unless a non-empty --word is specified as a prefix. That prevents fetching the full list of matches (which is for the best -- the full list is huge and just keeps growing). The auto-suggestion implementation assumes that internal caching is possible, which is why it only does one query, for the first letter typed in rapid succession.

Clink could follow up with a second query after typing settles, after detecting that builder:setvolatile() was used during background auto-suggestion match collection.

Ok, I'll do two things:

  1. Re-enable the auto-suggestion capability in the script. I'll do that right now, which will regain the auto-suggestion behavior, but the subtle problem will still exist (which many people might not even care about).
  2. Make a change in Clink to re-issue another auto-suggestion generation pass when (1) the matches are marked as volatile and (2) the input line changed since the previous auto-suggestion generation pass. That will end up resolving the issues fully.

from clink-completions.

chrisant996 avatar chrisant996 commented on June 3, 2024 1

One last question: how would you complete a multi-word query, once you started typing the second word?

❯ winget install "Python Laun<tab>
<nothing>

Is it because closing quotes are missing and it's being considered a new argument?

@loriswit Thanks, I didn't notice that wasn't working. I'll look into it and find out what's happening. It might be something in Clink or it might be something in the winget.lua script.

from clink-completions.

chrisant996 avatar chrisant996 commented on June 3, 2024

Thanks for reporting this! Both info and help are bogus. It looks like they somehow survived the initial copy/paste that was used to start writing the script.

I didn't go through the whole script in details, but I suppose it doesn't rely enough on the winget complete command, which I suppose would help improving completion a lot.

At the top of the script is a comment saying that the reason it doesn't use winget complete is because it has a lot of gaps and fails to provide a bunch of completions that it should be providing (arguments to flags, for example), and if I remember correctly I think there were even cases where it offered completions for the wrong thing entirely.

I'll see what I can do about using a hybrid approach, though.

from clink-completions.

chrisant996 avatar chrisant996 commented on June 3, 2024

@loriswit how do the new updates to the winget completions work for you?

Two known issues remain:

  1. Until Clink v1.4.13 is released (in the new few days), completions for e.g. winget install powerTab won't be able to show the corresponding completions, because of a CPU busy-loop in Clink that I discovered while updating the winget completions script. In the meantime, the script works around the problem, and will automatically start working fully after updating to Clink v1.4.13.
  2. Winget has added some new flags, which aren't recognized yet. I'll add them in the next couple of days. The way that winget complete works is insufficient to support input line coloring, it also doesn't support file or directory completions where it should, and a few other limitations. So the completion script uses a hybrid approach of both having predefined commands and flags, and also invoking winget complete for certain places where winget is able to provide completions for package names and versions and some other things.

from clink-completions.

chrisant996 avatar chrisant996 commented on June 3, 2024

@loriswit Clink v1.4.13 is released, and winget.lua has been updated. I'll make a new release in the clink-completions repo later tonight.

If possible, it would be great to get feedback about the improvements.

from clink-completions.

loriswit avatar loriswit commented on June 3, 2024

Thanks, that was fast!

I just quickly tested the new versions of both clink and the completions. Looks like winget support is definitely better, but there are still a few weird things happening (note: I have default_bindings set to bash).

If I type winget install Python and hit tab, it completes the command line by turning it into winget install "Python. Basically, it adds double quotes at the beginning of the query and doesn't suggest anything else. I suppose this is due to the fact that there are packages that contain spaces, such as Python Launcher. I don't know if this is the expected behaviour (I know that winget complete isn't doing that).

Now, if I hit tab again, absolutely nothing happens (and nothings is suggested). But if I hit tab a third time, then I receive the expected suggestion.

❯ winget install Python<tab>
❯ winget install "Python<tab><tab>
Python Launcher        Python.Python.3.0  Python.Python.3.3  Python.Python.3.6  Python.Python.3.9   Python.Python.3.12
Python Tk Gui Builder  Python.Python.3.1  Python.Python.3.4  Python.Python.3.7  Python.Python.3.10
Python.Python.2        Python.Python.3.2  Python.Python.3.5  Python.Python.3.8  Python.Python.3.11

Also note that if the query isn't a whole word (Pyt), then no quotes are being added to the query, and I only need to hit tab twice:

❯ winget install Pyt<tab><tab>
Python Launcher        Python.Python.3.0  Python.Python.3.3  Python.Python.3.6  Python.Python.3.9   Python.Python.3.12
Python Tk Gui Builder  Python.Python.3.1  Python.Python.3.4  Python.Python.3.7  Python.Python.3.10  pytigon
Python.Python.2        Python.Python.3.2  Python.Python.3.5  Python.Python.3.8  Python.Python.3.11

Finally, I also realized that the script I wrote myself (see first post) was showing these kind of "inline suggestions", i.e. text in a dim color that appears after the cursor (see picture below).

Screenshot 2023-01-27 141101

The script in this repository currently does not do that.

from clink-completions.

loriswit avatar loriswit commented on June 3, 2024

Alright, thanks for the in-depth explanations and the quick fixes!

from clink-completions.

loriswit avatar loriswit commented on June 3, 2024

One last question: how would you complete a multi-word query, once you started typing the second word?

❯ winget install "Python Laun<tab>
<nothing>

Is it because closing quotes are missing and it's being considered a new argument?

from clink-completions.

chrisant996 avatar chrisant996 commented on June 3, 2024

One last question: how would you complete a multi-word query, once you started typing the second word?

❯ winget install "Python Laun<tab>
<nothing>

Is it because closing quotes are missing and it's being considered a new argument?

@loriswit This is a limitation in winget itself. The winget complete command apparently has no way to support quoted arguments (i.e. arguments that contain a space within them).

So that's something you'd need to take up with the winget team/repo.

from clink-completions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.