Skip to content

Commit

Permalink
Improve cim ETS member inference completion
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGC94 authored and SeeminglyScience committed Dec 12, 2024
1 parent 7cc8a9a commit 1452374
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ internal IList<object> GetMembersByInferredType(PSTypeName typename, bool isStat
// Look in the type table first.
if (!isStatic)
{
var consolidatedString = new ConsolidatedString(new[] { typename.Name });
// The Ciminstance type adapter adds the full typename with and without a namespace to the list of type names.
// So if we see one with a full typename we need to also get the types for the short version.
// For example: "CimInstance#root/standardcimv2/MSFT_NetFirewallRule" and "CimInstance#MSFT_NetFirewallRule"
Match match = Regex.Match(typename.Name, "(Microsoft\\.Management\\.Infrastructure\\.CimInstance#)(.+\\/)(.+$)");

ConsolidatedString consolidatedString = match.Success
? new ConsolidatedString(new[] { typename.Name, match.Groups[1].Value + match.Groups[3].Value })
: new ConsolidatedString(new[] { typename.Name });
results.AddRange(ExecutionContext.TypeTable.GetMembers<PSMemberInfo>(consolidatedString));
}

Expand Down
5 changes: 5 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ ConstructorTestClass(int i, bool b)
$res.CompletionMatches[0].CompletionText | Should -BeExactly Cat
}

It 'Should complete cim ETS member added by shortname' -Skip:(!$IsWindows) {
$res = TabExpansion2 -inputScript '(Get-NetFirewallRule).Nam'
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Name'
}

It 'Should complete variable assigned with Data statement' {
$TestString = 'data MyDataVar {"Hello"};$MyDatav'
$res = TabExpansion2 -inputScript $TestString
Expand Down

0 comments on commit 1452374

Please sign in to comment.