Skip to content

Commit 021ff06

Browse files
nohwndTylerLeonhardt
authored andcommitted
Add opt-in for Pester v5 code lens
1 parent 6765616 commit 021ff06

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs

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

6+
using System;
67
using System.Collections.Generic;
8+
using Microsoft.PowerShell.EditorServices.Services;
79
using Microsoft.PowerShell.EditorServices.Services.Symbols;
810
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
911
using Microsoft.PowerShell.EditorServices.Utility;
@@ -14,6 +16,7 @@ namespace Microsoft.PowerShell.EditorServices.CodeLenses
1416
{
1517
internal class PesterCodeLensProvider : ICodeLensProvider
1618
{
19+
private readonly ConfigurationService _configurationService;
1720

1821
/// <summary>
1922
/// The symbol provider to get symbols from to build code lenses with.
@@ -29,8 +32,9 @@ internal class PesterCodeLensProvider : ICodeLensProvider
2932
/// <summary>
3033
/// Create a new Pester CodeLens provider for a given editor session.
3134
/// </summary>
32-
public PesterCodeLensProvider()
35+
public PesterCodeLensProvider(ConfigurationService configurationService)
3336
{
37+
_configurationService = configurationService;
3438
_symbolProvider = new PesterDocumentSymbolProvider();
3539
}
3640

@@ -100,7 +104,11 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
100104
{
101105
if (symbol is PesterSymbolReference pesterSymbol)
102106
{
103-
lenses.AddRange(GetPesterLens(pesterSymbol, scriptFile));
107+
if (_configurationService.CurrentSettings.Pester.Pester5CodeLens
108+
|| pesterSymbol.Command == PesterCommandType.Describe)
109+
{
110+
lenses.AddRange(GetPesterLens(pesterSymbol, scriptFile));
111+
}
104112
}
105113
}
106114

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ internal class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler
2727
private readonly ILogger _logger;
2828
private readonly SymbolsService _symbolsService;
2929
private readonly WorkspaceService _workspaceService;
30+
private readonly ConfigurationService _configurationService;
3031

3132
private CodeLensCapability _capability;
3233

33-
public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService)
34+
public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService, ConfigurationService configurationService)
3435
{
3536
_logger = factory.CreateLogger<FoldingRangeHandler>();
3637
_workspaceService = workspaceService;
3738
_symbolsService = symbolsService;
39+
_configurationService = configurationService;
3840
}
3941

4042
CodeLensRegistrationOptions IRegistration<CodeLensRegistrationOptions>.GetRegistrationOptions()

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ internal class LanguageServerSettings
2626

2727
public CodeFoldingSettings CodeFolding { get; set; }
2828

29+
public PesterSettings Pester { get; set; }
30+
2931
public LanguageServerSettings()
3032
{
3133
this.ScriptAnalysis = new ScriptAnalysisSettings();
3234
this.CodeFormatting = new CodeFormattingSettings();
3335
this.CodeFolding = new CodeFoldingSettings();
36+
this.Pester = new PesterSettings();
3437
}
3538

3639
public void Update(
@@ -49,6 +52,7 @@ public void Update(
4952
logger);
5053
this.CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
5154
this.CodeFolding.Update(settings.CodeFolding, logger);
55+
this.Pester = new PesterSettings(settings.Pester);
5256
}
5357
}
5458
}
@@ -356,6 +360,27 @@ public void Update(
356360
}
357361
}
358362

363+
/// <summary>
364+
/// Pester settings
365+
/// </summary>
366+
public class PesterSettings
367+
{
368+
public PesterSettings()
369+
{
370+
371+
}
372+
373+
public PesterSettings(PesterSettings settings)
374+
{
375+
Pester5CodeLens = settings.Pester5CodeLens;
376+
}
377+
378+
/// <summary>
379+
/// Whether integration features specific to Pester v5 are enabled
380+
/// </summary>
381+
public bool Pester5CodeLens { get; set; } = false;
382+
}
383+
359384
/// <summary>
360385
/// Additional settings from the Language Client that affect Language Server operations but
361386
/// do not exist under the 'powershell' section

0 commit comments

Comments
 (0)