Skip to content

Commit

Permalink
Merge pull request #430 from daviwil/avoid-completion-slowness
Browse files Browse the repository at this point in the history
Temporarily mitigate intermittent IntelliSense slowness
  • Loading branch information
daviwil authored Apr 7, 2017
2 parents 24d86cf + ab804d5 commit f862b8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/PowerShellEditorServices/Language/CommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,20 @@ namespace Microsoft.PowerShell.EditorServices
/// </summary>
public class CommandHelpers
{
private static HashSet<string> NounBlackList =
new HashSet<string>
{
"Module",
"Script",
"Package",
"PackageProvider",
"PackageSource",
"InstalledModule",
"InstalledScript",
"ScriptFileInfo",
"PSRepository"
};

/// <summary>
/// Gets the CommandInfo instance for a command with a particular name.
/// </summary>
Expand All @@ -24,6 +40,18 @@ public static async Task<CommandInfo> 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);
Expand Down

0 comments on commit f862b8c

Please sign in to comment.