Skip to content

Commit f862b8c

Browse files
authored
Merge pull request PowerShell#430 from daviwil/avoid-completion-slowness
Temporarily mitigate intermittent IntelliSense slowness
2 parents 24d86cf + ab804d5 commit f862b8c

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+7-4
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

+28
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)