Skip to content

Commit ab804d5

Browse files
committed
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 OneGet/oneget#275 is fixed. Related to PowerShell/vscode-powershell#647
1 parent 24d86cf commit ab804d5

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,13 @@ await CommandHelpers.GetCommandInfo(
758758
completionItem.Label,
759759
this.editorSession.PowerShellContext);
760760

761-
completionItem.Documentation =
762-
await CommandHelpers.GetCommandSynopsis(
763-
commandInfo,
764-
this.editorSession.PowerShellContext);
761+
if (commandInfo != null)
762+
{
763+
completionItem.Documentation =
764+
await CommandHelpers.GetCommandSynopsis(
765+
commandInfo,
766+
this.editorSession.PowerShellContext);
767+
}
765768
}
766769

767770
// Send back the updated CompletionItem

src/PowerShellEditorServices/Language/CommandHelpers.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.PowerShell.EditorServices.Utility;
7+
using System.Collections.Generic;
68
using System.Linq;
79
using System.Management.Automation;
810
using System.Threading.Tasks;
@@ -14,6 +16,20 @@ namespace Microsoft.PowerShell.EditorServices
1416
/// </summary>
1517
public class CommandHelpers
1618
{
19+
private static HashSet<string> NounBlackList =
20+
new HashSet<string>
21+
{
22+
"Module",
23+
"Script",
24+
"Package",
25+
"PackageProvider",
26+
"PackageSource",
27+
"InstalledModule",
28+
"InstalledScript",
29+
"ScriptFileInfo",
30+
"PSRepository"
31+
};
32+
1733
/// <summary>
1834
/// Gets the CommandInfo instance for a command with a particular name.
1935
/// </summary>
@@ -24,6 +40,18 @@ public static async Task<CommandInfo> GetCommandInfo(
2440
string commandName,
2541
PowerShellContext powerShellContext)
2642
{
43+
Validate.IsNotNull(nameof(commandName), commandName);
44+
45+
// Make sure the command's noun isn't blacklisted. This is
46+
// currently necessary to make sure that Get-Command doesn't
47+
// load PackageManagement or PowerShellGet because they cause
48+
// a major slowdown in IntelliSense.
49+
var commandParts = commandName.Split('-');
50+
if (commandParts.Length == 2 && NounBlackList.Contains(commandParts[1]))
51+
{
52+
return null;
53+
}
54+
2755
PSCommand command = new PSCommand();
2856
command.AddCommand(@"Microsoft.PowerShell.Core\Get-Command");
2957
command.AddArgument(commandName);

0 commit comments

Comments
 (0)