Skip to content
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

AutoCompletion Support #2 #1260

Open
wants to merge 62 commits into
base: main
Choose a base branch
from

Conversation

JKamsker
Copy link

@JKamsker JKamsker commented Jul 19, 2023

Base stolen from #727 . fixed & extended

I know there is alot going on there and i wasn't always sure if i was doing it in the right way. Comments&Changes welcome!

Status:

  • Static Command-Tree-based Completion
  • Static Property-Attribute-based Completion
  • Dynamic Handler-based Completion
  • Powershell Integration

Non-Goal:

  • Other integrations than Powershell for now.

Edit:
The powershell integration seems to have turned out a bit wonky. Maybe we want to extract it into a pre-release library until its stable enough


Please upvote 👍 this pull request if you are interested in it.

@JKamsker
Copy link
Author

@microsoft-github-policy-service agree

@JKamsker
Copy link
Author

I am going to mention the people from the other pr and #267, they might be interested, otherwise: Sorry 😅

@Jawz84 @phil-scott-78 @FrankRay78 @OskarKlintrot

@JKamsker
Copy link
Author

Commit JKamsker@a39517f implements static completions, attribute based
grafik

Objections? anyone?
@patriksvensson @phil-scott-78

@JKamsker JKamsker changed the title AutoCompletion Support #2 [WIP] AutoCompletion Support #2 Jul 21, 2023
@nils-a
Copy link
Contributor

nils-a commented Sep 15, 2023

image

I like it. Will do more tests tomorrow.

examples/Cli/AutoCompletion/AutoCompletion.csproj Outdated Show resolved Hide resolved
examples/Examples.sln Outdated Show resolved Hide resolved
@JKamsker
Copy link
Author

@nils-a I apologize for the delay. I fell ill over the weekend and am still recovering. I'll address this pull request once I'm in better shape.

@JKamsker JKamsker force-pushed the AutoCompletion branch 4 times, most recently from 557a233 to 80d5b91 Compare September 24, 2023 17:29
@JKamsker
Copy link
Author

@FrankRay78

Ok, so you have my interest @JKamsker . I'm certainly no expert on this, so can you tell me if this is PowerShell specific? (ie. does the compiled command line application that uses spectre.console need to run in PowerShell) Or does it / can it with some kind of extension also support other shells?

The primary functionality of this PR isn't exclusive to PowerShell. It's a universal tab completion engine, with the PowerShell module serving as an example of how it can be utilized. In principle, any shell could leverage it with the appropriate wrapper code.

The command line interface for this is .\AutoCompletion.exe cli complete "WORDTOCOMPLETE" (--position NUMBER). You can find more details here.

I'm trying to understand the scope of the implementation ie. Win/Linux/Mac and also breadth of shell ie. cmd / PS / bash etc

The goal here is to introduce a universal tab completion engine that any shell can utilize. The PowerShell module is merely the first implementation, with more to follow in the future. Implementing such a completion feature isn't overly complex and it doesn't rely on any spectre.console internals, unlike the core command cli complete.

I ask, because whilst I can't find the link, I kind of remember seeing MS Terminal provide a number of different shims (?) for autocomplete across different shells (?). I wondered if this was similar.

UPDATE: here is the link: How to enable tab completion for the .NET CLI

Theoretically, the completion code provided should work with the shims you've mentioned, although I haven't personally tested these.

Whilst I'm not the maintainer of this sub-system @JKamsker so can't approve the PR, I am interested and plan to make time over the weekend to review the commits and test it locally.

Cool, i really appreciate some extra eyes on this. I'm happy to answer any questions you might have.
Did you already have time to look at the code? I'm curious to hear your thoughts.

Quick Reminder:

@alex-fomin
Copy link

It would be so cool to have a pre-populated command settings in IAsyncCommandCompletable.GetSuggestionsAsync(https://github.com/spectreconsole/spectre.console/pull/1260/files#diff-62f314eab97b968fe2cd2edf30cbb3e1fb7f4f24ee5a26d306436f662e928063R14). Or, at least, the command line arguments themselves. Sometimes dynamic suggestions are depended from already entered parameters.

@JKamsker
Copy link
Author

JKamsker commented Nov 8, 2023

@alex-fomin Thanks for the suggestion! I'm a bit tied up at the moment and won't be able to get to it right away, but it's definitely on my radar to tackle as soon as I can.

In the meantime, if you're up for it, you're totally welcome to take a stab at it by forking my PR and adding the changes yourself. Cheers!

@JKamsker
Copy link
Author

@alex-fomin I have added the functionality to
https://www.nuget.org/packages/JKToolKit.Spectre.AutoCompletion.Integrations and https://www.nuget.org/packages/JKToolKit.Spectre.AutoCompletion (Version 0.0.4)
It works almost the same, except u have to add it explicitly.

public static void Main(string[] args)
{
    var app = new CommandApp();
    app.Configure
    (
        config =>
        {
            config
                .AddAutoCompletion(x => x.AddPowershell())
                .AddCommand<LionCommand>("lion");
        }
    ) ;
}

Will port it to this pr when i got time.

@krisrok
Copy link
Contributor

krisrok commented Nov 20, 2023

Heyo @JKamsker, great job so far. Subscribed to the discussion and eager to try it out as soon as I get the chance.
Just wanted to let you know the packages’ repos are private. If it‘s by choice don‘t mind me.

@JKamsker
Copy link
Author

Now published as separate repo.
https://github.com/JKamsker/JKToolKit.Spectre.AutoCompletion

@krisrok

@github-actions github-actions bot added the ⭐ top pull request Top pull request. label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ top pull request Top pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants