diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
index 4200b10558..8c3eb882bf 100644
--- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
+++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
@@ -5907,21 +5907,32 @@ namespace System.Management.Automation
/// The namespace
private static void HandleNamespace(Dictionary entryCache, string @namespace)
{
- if (!string.IsNullOrEmpty(@namespace))
+ if (string.IsNullOrEmpty(@namespace))
{
+ return;
+ }
+
+ int dotIndex = 0;
+ while (dotIndex != -1)
+ {
+ dotIndex = @namespace.IndexOf('.', dotIndex + 1);
+ string subNamespace = dotIndex != -1
+ ? @namespace.Substring(0, dotIndex)
+ : @namespace;
+
TypeCompletionMapping entry;
- if (!entryCache.TryGetValue(@namespace, out entry))
+ if (!entryCache.TryGetValue(subNamespace, out entry))
{
entry = new TypeCompletionMapping
{
- Key = @namespace,
- Completions = { new NamespaceCompletion { Namespace = @namespace } }
+ Key = subNamespace,
+ Completions = { new NamespaceCompletion { Namespace = subNamespace } }
};
- entryCache.Add(@namespace, entry);
+ entryCache.Add(subNamespace, entry);
}
else if (!entry.Completions.OfType().Any())
{
- entry.Completions.Add(new NamespaceCompletion { Namespace = @namespace });
+ entry.Completions.Add(new NamespaceCompletion { Namespace = subNamespace });
}
}
}
diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1
new file mode 100644
index 0000000000..18a64f7827
--- /dev/null
+++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1
@@ -0,0 +1,9 @@
+Describe "Issue#682 - [system.manage] should work" {
+
+ It "[system.manage" {
+ $result = TabExpansion2 -inputScript "[system.manage" -cursorColumn "[system.manage".Length
+ $result | Should Not BeNullOrEmpty
+ $result.CompletionMatches.Count | Should Be 1
+ $result.CompletionMatches[0].CompletionText | Should Be "System.Management"
+ }
+}