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

Function & Cmdlet Name Tab Completion Broken in the ConfigManager (CMSITE) Provider #20803

Closed
5 tasks done
alexlarner opened this issue Nov 28, 2023 · 12 comments · Fixed by #20815, #20915 or #20919
Closed
5 tasks done
Labels
In-PR Indicates that a PR is out for the issue

Comments

@alexlarner
Copy link

Prerequisites

Steps to reproduce

Summary

7.4.0 seems to have broken cmdlet & function name tab completion for all cmdlet & functions while the location is set to the Config Manager provider (CMSITE). This was working just fine in previous versions of PowerShell 7.

Scope

  • Tab completion for cmdlet & function parameter names & values is not broken, even when the location is set to the CMSITE provider.
  • Cmdlet & Function name tab completion is not broken when the location is set to any of the built-in providers.
  • I can reproduce this on multiple machines.

Workaround

Reverting back to a previous version of PowerShell, i.e. 7.3.10, fixes the issue.

Background Info

My version of the ConfigurationManager module shouldn't matter since reverting back to PowerShell 7.3.10 fixes the issue, but just in case I am using version 5.2303.1089.1000 of the module.

Setup Code

PS C:\> Import-Module ConfigurationManager
PS C:\> $SiteCode = Get-PSDrive -PSProvider CMSITE
PS C:\> Set-Location -Path "$($SiteCode.Name):\"
PS DCC:\> Get-Ite{Tab}
PS DCC:\> function Test-TabCompletion {}
PS DCC:\> Test-TabCompletio{Tab}

Expected behavior

PS DCC:\> Get-Item
PS DCC:\> Test-TabCompletion

Actual behavior

PS DCC:\> Get-Ite
PS DCC:\> Test-TabCompletio

Error details

No response

Environment data

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

Visuals

No response

@alexlarner alexlarner added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 28, 2023
@MartinGC94
Copy link
Contributor

It's probably related to the change I made here: #19489 I don't have any way to test tab completion in that provider though. Can you try to CD into that provider and run this: TabExpansion2 -inputScript Get- and post the full error details when it hopefully throws?

@alexlarner
Copy link
Author

Here's the error details from that:

PSMessageDetails      : 
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "CompleteInput" with "3" argument(s): "An item with the same key has already been added. Key: [Config Manager Primary FQDN Redacted]"
                         ---> System.ArgumentException: An item with the same key has already been added. Key: [Config Manager Primary FQDN Redacted]
                           at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
                           at CallSite.Target(Closure, CallSite, Dictionary`2, Object, Object)
                           at System.Management.Automation.CompletionCompleters.GetDefaultProviderResults(CompletionContext context, ProviderInfo provider, Collection`1 resolvedPaths, String filterText, Boolean containersOnly, Boolean relativePaths, Boolean literalPaths, Boolean inputUsedHome, String providerPrefix, StringConstantType stringType)
                           at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean containerOnly, HashSet`1 extension)
                           at System.Management.Automation.CompletionAnalysis.CompleteFileNameAsCommand(CompletionContext completionContext)
                           at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength)
                           at System.Management.Automation.CompletionAnalysis.GetResultHelper(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength)
                           at System.Management.Automation.CompletionAnalysis.GetResults(PowerShell powerShell, Int32& replacementIndex, Int32& replacementLength)
                           at System.Management.Automation.CommandCompletion.CompleteInputImpl(Ast ast, Token[] tokens, IScriptPosition positionOfCursor, Hashtable options)
                           at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
                           at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                           at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
                           at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ArgumentException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock><End>, <No file>: line 40
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

@MartinGC94
Copy link
Contributor

MartinGC94 commented Nov 28, 2023

Okay, it's probably failing here: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L4786 because it's somehow finding 2 items with the same name in a folder/container.
Can you run the following from that same location? ls -LiteralPath .\ | select -ExpandProperty PSPath and see if the same path shows up twice in the results?
Also, can you run this: Get-PSProvider -PSProvider CMSITE | select -ExpandProperty ItemSeparator and validate that the reported item separator matches the one you see for each item in that list?
Finally, can you tell me if it includes the provider name in the pspath results from before? Like: Microsoft.PowerShell.Core\FileSystem::C:\Users\Martin\.dotnet

@alexlarner
Copy link
Author

  1. ls -LiteralPath .\ | select -ExpandProperty PSPath
    • Returns 21 identical entries of AdminUI.PS\CMSite::[Config Manager Primary FQDN Redacted]\
  2. Get-PSProvider -PSProvider CMSITE | select -ExpandProperty ItemSeparator
    • Returns \
  3. Yes CMSITE is included in all the PSPath entries above

@MartinGC94
Copy link
Contributor

Seems like the SCCM team misunderstood the purpose of the PSPath property in the provider system. The whole idea behind the provider system is that you can refer to objects by a path, similar to what you would do on a filesystem but obviously that can't work if the same path points to 21 different objects.
It would have been nice if this had been enforced from the start but I guess that ship has sailed so we'll just have to handle their mistake by ignoring duplicates. I'll create a PR to fix this later today.

@alexlarner
Copy link
Author

Thanks

@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Nov 29, 2023
@MartinGC94
Copy link
Contributor

I've created the PR here: #20815 if you have the time feel free to download the Windows build that will get created as part of the automatic tests and then confirm that the changes I made actually fixed the issue for you.

Copy link
Contributor

📣 Hey @alexlarner, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 aka.ms/PSRepoFeedback

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 8, 2023
@alexlarner
Copy link
Author

I've created the PR here: #20815 if you have the time feel free to download the Windows build that will get created as part of the automatic tests and then confirm that the changes I made actually fixed the issue for you.

Sorry, for the late response, but that didn't seem to fix it.

And now when I try to run TabExpansion2 -inputScript Get-, I get this error instead.

ErrorRecord                 : Exception calling "CompleteInput" with "3" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
WasThrownFromThrowStatement : False
TargetSite                  : Void ConvertToMethodInvocationException(System.Exception, System.Type, System.String, Int32, System.Reflection.MemberInfo)
Message                     : Exception calling "CompleteInput" with "3" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
Data                        : {}
InnerException              : System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. (Parameter 'startIndex')
                                 at System.String.Remove(Int32 startIndex)
                                 at System.Management.Automation.CompletionCompleters.GetDefaultProviderResults(CompletionContext context, ProviderInfo provider, Collection`1 resolvedPaths, String filterText, Boolean containersOnly,
                              Boolean relativePaths, Boolean literalPaths, Boolean inputUsedHome, String providerPrefix, StringConstantType stringType) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionCompleters.cs:line 4820
                                 at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean containerOnly, HashSet`1 extension) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionCompleters.cs:line 4560
                                 at System.Management.Automation.CompletionAnalysis.CompleteFileNameAsCommand(CompletionContext completionContext) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 2398
                                 at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 2121
                                 at System.Management.Automation.CompletionAnalysis.GetResultHelper(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 437
                                 at System.Management.Automation.CompletionAnalysis.GetResults(PowerShell powerShell, Int32& replacementIndex, Int32& replacementLength) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 390
                                 at System.Management.Automation.CommandCompletion.CompleteInputImpl(Ast ast, Token[] tokens, IScriptPosition positionOfCursor, Hashtable options) in
                              D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CommandCompletion.cs:line 535
                                 at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo) in
                              D:\a\1\s\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 2111
                                 at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                                 at <ScriptBlock><End>(Closure, FunctionContext)

I believe I downloaded the right build. I downloaded this.

@MartinGC94
Copy link
Contributor

Thanks. I've found a premade SCCM lab by MS that I can download and test this on. Will investigate and try to fix it in the near future.

@alexlarner
Copy link
Author

@alexlarner You can download daily build from home page of the repository and if you still see the issue please report in #20803

The repo home page Windows link takes you to a PowerShell-CI-windows pipeline, however there is also a PowerShell-CI-Windows-daily listed under Pipelines. I didn't know which of those you were referring to, so I attempted to test the latest of both.

I was able to download and run PR-20913-20231212.03 from the PowerShell-CI-windows pipeline, and it had the same issue

I couldn't get the latest two PowerShell-CI-Windows-daily builds to run as they were blocked from running by our company's Windows security.

Copy link
Contributor

microsoft-github-policy-service bot commented Dec 14, 2023

📣 Hey @alexlarner, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue
Projects
None yet
3 participants