PowerShell/CompletionPredictor

Predictive completion not working with completion scripts generated by the cobra library

shellwhale opened this issue · 3 comments

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

  1. Import the CompletionPredictor module with Import-Module -Name CompletionPredictor
  2. Set the PredictionSource option to HistoryAndPlugin with Set-PSReadLineOption -PredictionSource HistoryAndPlugin
  3. Generate and execute a cobra-generated completion script (e.g., kubectl completion powershell | Out-String | Invoke-Expression)
  4. Type a command that uses the completion script (e.g., kubectl get pods) and try to use predictive completion.

Expected behavior

~ ❯ kubectl get
> kubectl get pods                                                                         [Completion]
> kubectl get csr                                                                          [Completion]
> kubectl get nodes                                                                        [Completion]
> ...

Actual behavior

~ ❯ kubectl get
> kubectl get pods                                                                         [History]

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

0.1.0

Visuals

No response

‌‌‌‌‌‌Hi @daxian-dbw, currently, all custom completions and executable files do not prompt. Is there a way to achieve this functionality?

image
image

image
image

Unfortunately, the completion for native commands doesn't work with completion predictor today because they are too slow.
For a predictor to work with PSReadLine today, it needs to return results within 20ms, which is impossibly for most of native command completers. We have a work item in PSReadLine to allow longer timeout by separating the prediction rendering from the user typing rendering, but we haven't got to it yet.

Thanks for your reply! I've just seen the latest vscode terminal integration do something similar, but I'm using Windows Terminal more often than not.