diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index ca988c6f9..fc46d33fa 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -758,10 +758,13 @@ await CommandHelpers.GetCommandInfo( completionItem.Label, this.editorSession.PowerShellContext); - completionItem.Documentation = - await CommandHelpers.GetCommandSynopsis( - commandInfo, - this.editorSession.PowerShellContext); + if (commandInfo != null) + { + completionItem.Documentation = + await CommandHelpers.GetCommandSynopsis( + commandInfo, + this.editorSession.PowerShellContext); + } } // Send back the updated CompletionItem diff --git a/src/PowerShellEditorServices/Language/CommandHelpers.cs b/src/PowerShellEditorServices/Language/CommandHelpers.cs index 82002ba17..1a834c410 100644 --- a/src/PowerShellEditorServices/Language/CommandHelpers.cs +++ b/src/PowerShellEditorServices/Language/CommandHelpers.cs @@ -3,6 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using Microsoft.PowerShell.EditorServices.Utility; +using System.Collections.Generic; using System.Linq; using System.Management.Automation; using System.Threading.Tasks; @@ -14,6 +16,20 @@ namespace Microsoft.PowerShell.EditorServices /// public class CommandHelpers { + private static HashSet NounBlackList = + new HashSet + { + "Module", + "Script", + "Package", + "PackageProvider", + "PackageSource", + "InstalledModule", + "InstalledScript", + "ScriptFileInfo", + "PSRepository" + }; + /// /// Gets the CommandInfo instance for a command with a particular name. /// @@ -24,6 +40,18 @@ public static async Task GetCommandInfo( string commandName, PowerShellContext powerShellContext) { + Validate.IsNotNull(nameof(commandName), commandName); + + // Make sure the command's noun isn't blacklisted. This is + // currently necessary to make sure that Get-Command doesn't + // load PackageManagement or PowerShellGet because they cause + // a major slowdown in IntelliSense. + var commandParts = commandName.Split('-'); + if (commandParts.Length == 2 && NounBlackList.Contains(commandParts[1])) + { + return null; + } + PSCommand command = new PSCommand(); command.AddCommand(@"Microsoft.PowerShell.Core\Get-Command"); command.AddArgument(commandName);