From ab804d5b86fe1d040b0679a848434b09102a22b1 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 6 Apr 2017 19:58:05 -0700 Subject: [PATCH] Temporarily mitigate intermittent IntelliSense slowness This change mitigates seemingly intermittent IntelliSense slowness by preventing Get-Command and Get-Help from being called on cmdlets from the PowerShellGet and PackageManagement modules. Something in the PackageManagement module is causing completions to be returned at 10x delay when that module is loaded. If the module is removed from the session, completions go back to their normal duration. By avoiding calling Get-Command on these cmdlets, we avoid loading PackageManagement when the user types a string like `Get-P` which incidentally happens to make VS Code see the `Get-Package` cmdlet and try to resolve its details. This fix is temporary and will be removed in the future once https://github.com/OneGet/oneget/issues/275 is fixed. Related to PowerShell/vscode-powershell#647 --- .../Server/LanguageServer.cs | 11 +++++--- .../Language/CommandHelpers.cs | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) 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);