From 07215c936045629a7ac5d1fe18afbe62baee5695 Mon Sep 17 00:00:00 2001 From: adityapatwardhan Date: Mon, 22 May 2017 18:13:19 -0700 Subject: [PATCH 1/8] Fix various about topic help issues * Fix double help topic printing issue * Fix regressions introduced by change a52adcd3cf4f87f474131f0d3421841c39cf09c0 * Use wildcardPattern to fix tab completion --- .../engine/CommandCompletion/CompletionCompleters.cs | 12 +++++++----- .../help/MUIFileSearcher.cs | 7 ++++++- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 12 ++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index cd4abe7f694..695418546db 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4076,7 +4076,8 @@ internal static IEnumerable CompleteFilename(CompletionContext { // We want to prefer relative paths in a completion result unless the user has already // specified a drive or portion of the path. - var executionContext = context.ExecutionContext; + var powershell = context.Helper.CurrentPowerShell; + var executionContext = powershell.GetContextFromTLS(); var defaultRelative = string.IsNullOrWhiteSpace(wordToComplete) || (wordToComplete.IndexOfAny(Utils.Separators.Directory) != 0 && !Regex.Match(wordToComplete, @"^~[\\/]+.*").Success && @@ -4089,11 +4090,11 @@ internal static IEnumerable CompleteFilename(CompletionContext wordToComplete = WildcardPattern.Escape(wordToComplete, Utils.Separators.StarOrQuestion); } - if (!defaultRelative && wordToComplete.Length >= 2 && wordToComplete[1] == ':' && char.IsLetter(wordToComplete[0]) && executionContext != null) + if (!defaultRelative && wordToComplete.Length >= 2 && wordToComplete[1] == ':' && char.IsLetter(wordToComplete[0]) && context.ExecutionContext != null) { // We don't actually need the drive, but the drive must be "mounted" in PowerShell before completion // can succeed. This call will mount the drive if it wasn't already. - executionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global"); + context.ExecutionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global"); } var powerShellExecutionHelper = context.Helper; @@ -5952,14 +5953,15 @@ private static string GetNamespaceToRemove(CompletionContext context, TypeComple internal static List CompleteHelpTopics(CompletionContext context) { var results = new List(); - var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + "\\" + CultureInfo.CurrentCulture.Name; + var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + Path.DirectorySeparatorChar + CultureInfo.CurrentCulture.Name; var wordToComplete = context.WordToComplete + "*"; var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase); string[] files = null; try { - files = Directory.GetFiles(dirPath, wordToComplete); + var wildcardPattern = WildcardPattern.Get(wordToComplete, WildcardOptions.IgnoreCase); + files = Directory.GetFiles(dirPath).Where(f => wildcardPattern.IsMatch(Path.GetFileName(f))).ToArray(); } catch (Exception) { diff --git a/src/System.Management.Automation/help/MUIFileSearcher.cs b/src/System.Management.Automation/help/MUIFileSearcher.cs index c39aaec247c..682cd3bbc9e 100644 --- a/src/System.Management.Automation/help/MUIFileSearcher.cs +++ b/src/System.Management.Automation/help/MUIFileSearcher.cs @@ -304,12 +304,17 @@ private static Collection NormalizeSearchPaths(string target, Collection /// private static string GetMshDefaultInstallationPath() { - string returnValue = CommandDiscovery.GetShellPathFromRegistry(Utils.DefaultPowerShellShellID); + string returnValue = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID); + //On CoreCLR we use ApplicationBase assembly location. That gives us the directory name. + //Hence we do not need to extract the directory name from returnValue. + +#if !CORECLR if (returnValue != null) { returnValue = Path.GetDirectoryName(returnValue); } +#endif // returnValue can be null. return returnValue; diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index af40e77ade5..7f6bc307d34 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -200,6 +200,18 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' $help.count | Should Be 1 $help | Should BeExactly "Hello" } + + It "Get-Help for about_Variable should return only one help object" { + + $help = Get-Help about_Variables + $help.count | Should Be 1 + } + + It "Get-Help for about_* should return more than 1 help objects" { + + $help = Get-Help about_* + $help.Count | Should BeGreaterThan 1 + } } Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') { From 2655953fa24716a9842a91d029cae434cb357525 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 14 Jun 2017 17:05:47 -0700 Subject: [PATCH 2/8] Tests for fixes --- test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 6 ++++++ test/powershell/engine/Help/HelpSystem.Tests.ps1 | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 6fe7f0ea859..56e4e5e746f 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -103,6 +103,12 @@ Describe "TabCompletion" -Tags CI { $res.CompletionMatches[0].CompletionText | Should Be 'namespace' } + It 'Should complete about help topic' { + $res = TabExpansion2 -inputScript 'get-help about_forea' -cursorColumn 'get-help about_fo'.Length + $res.CompletionMatches.Count | Should Be 1 + $res.CompletionMatches[0].CompletionText | Should BeExactly 'about_ForEach' + } + Context NativeCommand { BeforeAll { $nativeCommand = (Get-Command -CommandType Application -TotalCount 1).Name diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 7f6bc307d34..e229b68dc37 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -206,12 +206,6 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' $help = Get-Help about_Variables $help.count | Should Be 1 } - - It "Get-Help for about_* should return more than 1 help objects" { - - $help = Get-Help about_* - $help.Count | Should BeGreaterThan 1 - } } Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') { From cb3f9718d5a488c0349de83dec41a2a048ecf84a Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 15 Jun 2017 11:07:07 -0700 Subject: [PATCH 3/8] Fix test failure --- .../Host/TabCompletion/TabCompletion.Tests.ps1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 56e4e5e746f..83c5259740f 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -104,9 +104,18 @@ Describe "TabCompletion" -Tags CI { } It 'Should complete about help topic' { - $res = TabExpansion2 -inputScript 'get-help about_forea' -cursorColumn 'get-help about_fo'.Length + + $aboutHelpPath = Join-Path $PSHOME (Get-Culture).Name + + ## If help content does not exist, tab completion will not work. So update it first. + if(-not (Test-Path (Join-Path $aboutHelpPath "about_ForEach-Parallel.help.txt"))) + { + Update-Help -Force -ErrorAction SilentlyContinue + } + + $res = TabExpansion2 -inputScript 'get-help about_foreach-p' -cursorColumn 'get-help about_foreach-p'.Length $res.CompletionMatches.Count | Should Be 1 - $res.CompletionMatches[0].CompletionText | Should BeExactly 'about_ForEach' + $res.CompletionMatches[0].CompletionText | Should BeExactly 'about_ForEach-Parallel' } Context NativeCommand { From d1d9f3b02416ccf143c0585f75ec44ab60a27098 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 15 Jun 2017 11:30:53 -0700 Subject: [PATCH 4/8] Fix typo and failure on Windows --- test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 83c5259740f..24467867ac3 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -108,14 +108,14 @@ Describe "TabCompletion" -Tags CI { $aboutHelpPath = Join-Path $PSHOME (Get-Culture).Name ## If help content does not exist, tab completion will not work. So update it first. - if(-not (Test-Path (Join-Path $aboutHelpPath "about_ForEach-Parallel.help.txt"))) + if(-not (Test-Path (Join-Path $aboutHelpPath "about_Splatting.help.txt"))) { Update-Help -Force -ErrorAction SilentlyContinue } - $res = TabExpansion2 -inputScript 'get-help about_foreach-p' -cursorColumn 'get-help about_foreach-p'.Length + $res = TabExpansion2 -inputScript 'get-help about_spla' -cursorColumn 'get-help about_spla'.Length $res.CompletionMatches.Count | Should Be 1 - $res.CompletionMatches[0].CompletionText | Should BeExactly 'about_ForEach-Parallel' + $res.CompletionMatches[0].CompletionText | Should BeExactly 'about_Splatting' } Context NativeCommand { From 7096cdc836fd435436850c0adda20ed4236a53c4 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 16 Jun 2017 14:47:33 -0700 Subject: [PATCH 5/8] Addressed code review feedback --- .../CommandCompletion/CompletionCompleters.cs | 40 +++++++++++-------- .../help/MUIFileSearcher.cs | 28 +------------ 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 695418546db..e2bcc216340 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -1325,7 +1325,7 @@ internal static List CompleteCommandArgument(CompletionContext { // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - var commandResults = CompleteCommand(new CompletionContext { WordToComplete = context.WordToComplete, Helper = context.Helper }); + var commandResults = CompleteCommand(new CompletionContext { WordToComplete = context.WordToComplete, Helper = context.Helper, ExecutionContext = context.ExecutionContext }); if (commandResults != null) result.AddRange(commandResults); } @@ -2088,7 +2088,7 @@ private static void NativeCommandArgumentCompletion( { // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - var commandResults = CompleteCommand(new CompletionContext { WordToComplete = context.WordToComplete, Helper = context.Helper }); + var commandResults = CompleteCommand(new CompletionContext { WordToComplete = context.WordToComplete, Helper = context.Helper, ExecutionContext = context.ExecutionContext }); if (commandResults != null) result.AddRange(commandResults); } @@ -2778,7 +2778,7 @@ private static void NativeCompletionGetCommand(string commandName, string module RemoveLastNullCompletionResult(result); // Available commands - var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, moduleName); + var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, moduleName); if (commandResults != null) result.AddRange(commandResults); @@ -2788,7 +2788,7 @@ private static void NativeCompletionGetCommand(string commandName, string module // ps1 files and directories. We only complete the files with .ps1 extension for Get-Command, because the -Syntax // may only works on files with .ps1 extension var ps1Extension = new HashSet(StringComparer.OrdinalIgnoreCase) { StringLiterals.PowerShellScriptFileExtension }; - var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, false, ps1Extension)); + var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, false, ps1Extension)); if (moduleFilesResults.Count > 0) result.AddRange(moduleFilesResults); } @@ -2813,7 +2813,7 @@ private static void NativeCompletionGetCommand(string commandName, string module } } - moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, false); + moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, false); if (moduleResults != null) { foreach (CompletionResult moduleResult in moduleResults) @@ -2838,20 +2838,20 @@ private static void NativeCompletionGetHelpCommand(string commandName, string pa // Available commands const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Alias | CommandTypes.ExternalScript | CommandTypes.Workflow | CommandTypes.Configuration; - var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, null, commandTypes); + var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, null, commandTypes); if (commandResults != null) result.AddRange(commandResults); // ps1 files and directories var ps1Extension = new HashSet(StringComparer.OrdinalIgnoreCase) { StringLiterals.PowerShellScriptFileExtension }; - var fileResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, false, ps1Extension)); + var fileResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, false, ps1Extension)); if (fileResults.Count > 0) result.AddRange(fileResults); if (isHelpRelated) { // Available topics - var helpTopicResults = CompleteHelpTopics(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }); + var helpTopicResults = CompleteHelpTopics(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }); if (helpTopicResults != null) result.AddRange(helpTopicResults); } @@ -3093,7 +3093,7 @@ private static void NativeCompletionModuleCommands(string assemblyOrModuleName, StringLiterals.PowerShellCmdletizationFileExtension, StringLiterals.WorkflowFileExtension }; - var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper }, false, moduleExtensions)); + var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, false, moduleExtensions)); if (moduleFilesResults.Count > 0) result.AddRange(moduleFilesResults); @@ -3104,7 +3104,7 @@ private static void NativeCompletionModuleCommands(string assemblyOrModuleName, } } - var moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper }, loadedModulesOnly); + var moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, loadedModulesOnly); if (moduleResults != null && moduleResults.Count > 0) result.AddRange(moduleResults); @@ -3115,7 +3115,7 @@ private static void NativeCompletionModuleCommands(string assemblyOrModuleName, RemoveLastNullCompletionResult(result); var moduleExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) { ".dll" }; - var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper }, false, moduleExtensions)); + var moduleFilesResults = new List(CompleteFilename(new CompletionContext { WordToComplete = assemblyOrModuleName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, false, moduleExtensions)); if (moduleFilesResults.Count > 0) result.AddRange(moduleFilesResults); @@ -3490,12 +3490,12 @@ private static void NativeCompletionAliasCommands(string commandName, string par // Complete for the parameter Definition // Available commands const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.ExternalScript | CommandTypes.Workflow | CommandTypes.Configuration; - var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = powerShellExecutionHelper }, null, commandTypes); + var commandResults = CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = powerShellExecutionHelper, ExecutionContext = context.ExecutionContext }, null, commandTypes); if (commandResults != null && commandResults.Count > 0) result.AddRange(commandResults); // The parameter Definition takes a file - var fileResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = powerShellExecutionHelper })); + var fileResults = new List(CompleteFilename(new CompletionContext { WordToComplete = commandName, Helper = powerShellExecutionHelper, ExecutionContext = context.ExecutionContext })); if (fileResults.Count > 0) result.AddRange(fileResults); } @@ -4076,8 +4076,7 @@ internal static IEnumerable CompleteFilename(CompletionContext { // We want to prefer relative paths in a completion result unless the user has already // specified a drive or portion of the path. - var powershell = context.Helper.CurrentPowerShell; - var executionContext = powershell.GetContextFromTLS(); + var executionContext = context.ExecutionContext; var defaultRelative = string.IsNullOrWhiteSpace(wordToComplete) || (wordToComplete.IndexOfAny(Utils.Separators.Directory) != 0 && !Regex.Match(wordToComplete, @"^~[\\/]+.*").Success && @@ -5956,12 +5955,19 @@ internal static List CompleteHelpTopics(CompletionContext cont var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + Path.DirectorySeparatorChar + CultureInfo.CurrentCulture.Name; var wordToComplete = context.WordToComplete + "*"; var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase); - string[] files = null; + ArrayList files = new ArrayList(); try { var wildcardPattern = WildcardPattern.Get(wordToComplete, WildcardOptions.IgnoreCase); - files = Directory.GetFiles(dirPath).Where(f => wildcardPattern.IsMatch(Path.GetFileName(f))).ToArray(); + + foreach(var file in Directory.GetFiles(dirPath)) + { + if(wildcardPattern.IsMatch(Path.GetFileName(file))) + { + files.Add(file); + } + } } catch (Exception) { diff --git a/src/System.Management.Automation/help/MUIFileSearcher.cs b/src/System.Management.Automation/help/MUIFileSearcher.cs index 682cd3bbc9e..bac0b7b30a4 100644 --- a/src/System.Management.Automation/help/MUIFileSearcher.cs +++ b/src/System.Management.Automation/help/MUIFileSearcher.cs @@ -283,7 +283,7 @@ private static Collection NormalizeSearchPaths(string target, Collection } // step 3: locate the file in the default PowerShell installation directory. - string defaultPSPath = GetMshDefaultInstallationPath(); + string defaultPSPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID); if (defaultPSPath != null && !result.Contains(defaultPSPath) && Directory.Exists(defaultPSPath)) @@ -294,32 +294,6 @@ private static Collection NormalizeSearchPaths(string target, Collection return result; } - /// - /// Helper method which returns the default monad installation path based on ShellID - /// registry key. - /// - /// string representing path. - /// - /// If ShellID is not defined or Path property is not defined returns null. - /// - private static string GetMshDefaultInstallationPath() - { - string returnValue = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID); - - //On CoreCLR we use ApplicationBase assembly location. That gives us the directory name. - //Hence we do not need to extract the directory name from returnValue. - -#if !CORECLR - if (returnValue != null) - { - returnValue = Path.GetDirectoryName(returnValue); - } -#endif - - // returnValue can be null. - return returnValue; - } - #endregion #region Static API's From 196ddc6ff288c90d3e11f95122b93d07a0beca76 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 16 Jun 2017 15:10:41 -0700 Subject: [PATCH 6/8] Addressed feedback --- .../engine/CommandCompletion/CompletionCompleters.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index e2bcc216340..33e20accb64 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4089,11 +4089,11 @@ internal static IEnumerable CompleteFilename(CompletionContext wordToComplete = WildcardPattern.Escape(wordToComplete, Utils.Separators.StarOrQuestion); } - if (!defaultRelative && wordToComplete.Length >= 2 && wordToComplete[1] == ':' && char.IsLetter(wordToComplete[0]) && context.ExecutionContext != null) + if (!defaultRelative && wordToComplete.Length >= 2 && wordToComplete[1] == ':' && char.IsLetter(wordToComplete[0]) && executionContext != null) { // We don't actually need the drive, but the drive must be "mounted" in PowerShell before completion // can succeed. This call will mount the drive if it wasn't already. - context.ExecutionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global"); + executionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global"); } var powerShellExecutionHelper = context.Helper; @@ -5955,7 +5955,7 @@ internal static List CompleteHelpTopics(CompletionContext cont var dirPath = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID) + Path.DirectorySeparatorChar + CultureInfo.CurrentCulture.Name; var wordToComplete = context.WordToComplete + "*"; var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase); - ArrayList files = new ArrayList(); + List files = new List(); try { From 5dd5cc38a15ac6d428462b11637aa5a6e04d7ff8 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 16 Jun 2017 16:13:51 -0700 Subject: [PATCH 7/8] Fix missed places --- .../engine/CommandCompletion/CompletionCompleters.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 33e20accb64..24d7031e8bf 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -76,7 +76,7 @@ public static IEnumerable CompleteCommand(string commandName, } var helper = new PowerShellExecutionHelper(PowerShell.Create(RunspaceMode.CurrentRunspace)); - return CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = helper }, moduleName, commandTypes); + return CompleteCommand(new CompletionContext { WordToComplete = commandName, Helper = helper, ExecutionContext = helper.CurrentPowerShell.GetContextFromTLS() }, moduleName, commandTypes); } internal static List CompleteCommand(CompletionContext context) @@ -2800,7 +2800,7 @@ private static void NativeCompletionGetCommand(string commandName, string module RemoveLastNullCompletionResult(result); var modules = new HashSet(StringComparer.OrdinalIgnoreCase); - var moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = commandName, Helper = context.Helper }, true); + var moduleResults = CompleteModuleName(new CompletionContext { WordToComplete = commandName, Helper = context.Helper, ExecutionContext = context.ExecutionContext }, true); if (moduleResults != null) { foreach (CompletionResult moduleResult in moduleResults) @@ -4035,7 +4035,7 @@ public static IEnumerable CompleteFilename(string fileName) } var helper = new PowerShellExecutionHelper(PowerShell.Create(RunspaceMode.CurrentRunspace)); - return CompleteFilename(new CompletionContext { WordToComplete = fileName, Helper = helper }); + return CompleteFilename(new CompletionContext { WordToComplete = fileName, Helper = helper, ExecutionContext = helper.CurrentPowerShell.GetContextFromTLS() }); } internal static IEnumerable CompleteFilename(CompletionContext context) @@ -4484,7 +4484,7 @@ public static IEnumerable CompleteVariable(string variableName } var helper = new PowerShellExecutionHelper(PowerShell.Create(RunspaceMode.CurrentRunspace)); - return CompleteVariable(new CompletionContext { WordToComplete = variableName, Helper = helper }); + return CompleteVariable(new CompletionContext { WordToComplete = variableName, Helper = helper, ExecutionContext = helper.CurrentPowerShell.GetContextFromTLS() }); } private static readonly string[] s_variableScopes = new string[] { "Global:", "Local:", "Script:", "Private:" }; @@ -5861,7 +5861,7 @@ public static IEnumerable CompleteType(string typeName) : PowerShell.Create(RunspaceMode.CurrentRunspace); var helper = new PowerShellExecutionHelper(powershell); - return CompleteType(new CompletionContext { WordToComplete = typeName, Helper = helper }); + return CompleteType(new CompletionContext { WordToComplete = typeName, Helper = helper, ExecutionContext = helper.CurrentPowerShell.GetContextFromTLS() }); } internal static List CompleteType(CompletionContext context, string prefix = "", string suffix = "") From a8f25e31fb2187158cedfad0643aceef917cd7ee Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Sun, 18 Jun 2017 17:50:49 -0700 Subject: [PATCH 8/8] Minor fix --- .../engine/CommandCompletion/CompletionCompleters.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 24d7031e8bf..bbedae54980 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -3597,8 +3597,7 @@ private static void NativeCompletionNewItemCommand(string itemTypeToComplete, st return; } - var powershell = context.Helper.CurrentPowerShell; - var executionContext = powershell.GetContextFromTLS(); + var executionContext = context.ExecutionContext; var boundArgs = GetBoundArgumentsAsHashtable(context); var providedPath = boundArgs["Path"] as string ?? executionContext.SessionState.Path.CurrentLocation.Path;