Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ internal class PsesDocumentSymbolHandler : DocumentSymbolHandlerBase
private static readonly SymbolInformationOrDocumentSymbolContainer s_emptySymbolInformationOrDocumentSymbolContainer = new();
private readonly ILogger _logger;
private readonly WorkspaceService _workspaceService;
private readonly ConfigurationService _configurationService;
private readonly IDocumentSymbolProvider[] _providers;

public PsesDocumentSymbolHandler(ILoggerFactory factory, WorkspaceService workspaceService)
public PsesDocumentSymbolHandler(
ILoggerFactory factory,
WorkspaceService workspaceService,
ConfigurationService configurationService)
{
_logger = factory.CreateLogger<PsesDocumentSymbolHandler>();
_workspaceService = workspaceService;
_configurationService = configurationService;
_providers = new IDocumentSymbolProvider[]
{
new ScriptDocumentSymbolProvider(),
Expand Down Expand Up @@ -166,7 +171,13 @@ public override async Task<SymbolInformationOrDocumentSymbolContainer> Handle(Do
//
// TODO: We should also include function invocations that are part of DSLs (like
// Invoke-Build etc.).
if (!symbolReference.IsDeclaration || symbolReference.Type is SymbolType.Parameter)
if (!symbolReference.IsDeclaration)
{
continue;
}

if (symbolReference.Type is SymbolType.Parameter &&
!_configurationService.CurrentSettings.EnableParameterOutline)
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class LanguageServerSettings
public string Cwd { get; set; }
public bool EnableReferencesCodeLens { get; set; } = true;
public bool AnalyzeOpenDocumentsOnly { get; set; }

public bool EnableParameterOutline { get; set; }
public LanguageServerSettings()
{
ScriptAnalysis = new ScriptAnalysisSettings();
Expand All @@ -50,6 +50,7 @@ public void Update(
Cwd = settings.Cwd;
EnableReferencesCodeLens = settings.EnableReferencesCodeLens;
AnalyzeOpenDocumentsOnly = settings.AnalyzeOpenDocumentsOnly;
EnableParameterOutline = settings.EnableParameterOutline;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function New-MyFunc {
param(
[string]$MyString,
$MyLooselyTypedParam
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Test.Shared;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Xunit;

namespace PowerShellEditorServices.Test.Language
{
[Trait("Category", "Symbols")]
public class DocumentSymbolHandlerTests
{
private readonly WorkspaceService workspace;
private readonly ConfigurationService configuration;
private readonly PsesDocumentSymbolHandler documentSymbolHandler;

public DocumentSymbolHandlerTests()
{
workspace = new WorkspaceService(NullLoggerFactory.Instance);
configuration = new ConfigurationService();
documentSymbolHandler = new PsesDocumentSymbolHandler(
NullLoggerFactory.Instance,
workspace,
configuration);
}

[Fact]
public async Task ExcludesParametersWhenParameterOutlineIsDisabled()
{
configuration.CurrentSettings.EnableParameterOutline = false;

string filePath = TestUtilities.GetSharedPath(
"Symbols/DocumentSymbolParameters.ps1");

SymbolInformationOrDocumentSymbolContainer result =
await documentSymbolHandler.Handle(
new DocumentSymbolParams
{
TextDocument = new TextDocumentIdentifier(
DocumentUri.FromFileSystemPath(filePath))
},
CancellationToken.None);

DocumentSymbol function = result
.Select(symbol => symbol.DocumentSymbol)
.Single(symbol => symbol.Name.Contains("New-MyFunc"));

Assert.DoesNotContain(
function.Children,
symbol => symbol.Name.Contains("$MyString"));

Assert.DoesNotContain(
function.Children,
symbol => symbol.Name.Contains("$MyLooselyTypedParam"));
}

[Fact]
public async Task IncludesParametersWhenParameterOutlineIsEnabled()
{
configuration.CurrentSettings.EnableParameterOutline = true;

string filePath = TestUtilities.GetSharedPath(
"Symbols/DocumentSymbolParameters.ps1");

SymbolInformationOrDocumentSymbolContainer result =
await documentSymbolHandler.Handle(
new DocumentSymbolParams
{
TextDocument = new TextDocumentIdentifier(
DocumentUri.FromFileSystemPath(filePath))
},
CancellationToken.None);

DocumentSymbol function = result
.Select(symbol => symbol.DocumentSymbol)
.Single(symbol => symbol.Name.Contains("New-MyFunc"));

Assert.Contains(
function.Children,
symbol => symbol.Name.Contains("$MyString"));

Assert.Contains(
function.Children,
symbol => symbol.Name.Contains("$MyLooselyTypedParam"));
}
}
}