diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs index 8e3ddc1c9..7e09735d6 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs @@ -76,36 +76,36 @@ public static async Task GetCommandSynopsisAsync( CommandInfo commandInfo, PowerShellContextService powerShellContext) { + Validate.IsNotNull(nameof(commandInfo), commandInfo); Validate.IsNotNull(nameof(powerShellContext), powerShellContext); - string synopsisString = string.Empty; - - if (commandInfo != null && - (commandInfo.CommandType == CommandTypes.Cmdlet || - commandInfo.CommandType == CommandTypes.Function || - commandInfo.CommandType == CommandTypes.Filter)) + // A small optimization to not run Get-Help on things like DSC resources. + if (commandInfo.CommandType != CommandTypes.Cmdlet && + commandInfo.CommandType != CommandTypes.Function && + commandInfo.CommandType != CommandTypes.Filter) { - PSCommand command = new PSCommand(); - command.AddCommand(@"Microsoft.PowerShell.Core\Get-Help"); - command.AddArgument(commandInfo); - command.AddParameter("ErrorAction", "Ignore"); + return string.Empty; + } - var results = await powerShellContext.ExecuteCommandAsync(command, sendOutputToHost: false, sendErrorToHost: false).ConfigureAwait(false); - PSObject helpObject = results.FirstOrDefault(); + PSCommand command = new PSCommand() + .AddCommand(@"Microsoft.PowerShell.Core\Get-Help") + // We use .Name here instead of just passing in commandInfo because + // CommandInfo.ToString() duplicates the Prefix if one exists. + .AddParameter("Name", commandInfo.Name) + .AddParameter("ErrorAction", "Ignore"); - if (helpObject != null) - { - // Extract the synopsis string from the object - synopsisString = - (string)helpObject.Properties["synopsis"].Value ?? - string.Empty; + var results = await powerShellContext.ExecuteCommandAsync(command, sendOutputToHost: false, sendErrorToHost: false).ConfigureAwait(false); + PSObject helpObject = results.FirstOrDefault(); - // Ignore the placeholder value for this field - if (string.Equals(synopsisString, "SHORT DESCRIPTION", System.StringComparison.CurrentCultureIgnoreCase)) - { - synopsisString = string.Empty; - } - } + // Extract the synopsis string from the object + string synopsisString = + (string)helpObject?.Properties["synopsis"].Value ?? + string.Empty; + + // Ignore the placeholder value for this field + if (string.Equals(synopsisString, "SHORT DESCRIPTION", System.StringComparison.CurrentCultureIgnoreCase)) + { + return string.Empty; } return synopsisString; diff --git a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs index b03389234..4640ab723 100644 --- a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs @@ -825,6 +825,31 @@ public async Task CanSendCompletionAndCompletionResolveRequest() Assert.Contains("Writes customized output to a host", updatedCompletionItem.Documentation.String); } + [Fact] + public async Task CanSendCompletionResolveWithModulePrefixRequest() + { + await LanguageClient.SendRequest( + "evaluate", + new EvaluateRequestArguments + { + Expression = "Import-Module Microsoft.PowerShell.Archive -Prefix Slow" + }); + + string filePath = NewTestFile("Expand-SlowArch"); + + CompletionList completionItems = await LanguageClient.TextDocument.Completions( + filePath, line: 0, column: 15); + + CompletionItem completionItem = Assert.Single(completionItems, + completionItem1 => completionItem1.Label == "Expand-SlowArchive"); + + CompletionItem updatedCompletionItem = await LanguageClient.SendRequest( + "completionItem/resolve", + completionItem); + + Assert.Contains("Extracts files from a specified archive", updatedCompletionItem.Documentation.String); + } + [Fact] public async Task CanSendHoverRequest() {