Skip to content

Setting to Disable Pester Code Lens #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 18, 2021
Merged
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
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.Symbols;
Expand Down Expand Up @@ -101,6 +101,12 @@ private static CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, Scri
/// <returns>All Pester CodeLenses for the given script file.</returns>
public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
{
// Don't return anything if codelens setting is disabled
if (!this._configurationService.CurrentSettings.Pester.CodeLens)
{
return Array.Empty<CodeLens>();
}

var lenses = new List<CodeLens>();
foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public SymbolsService(
var codeLensProviders = new ICodeLensProvider[]
{
new ReferencesCodeLensProvider(_workspaceService, this),
new PesterCodeLensProvider(configurationService),
new PesterCodeLensProvider(configurationService)
};

foreach (ICodeLensProvider codeLensProvider in codeLensProviders)
{
_codeLensProviders.TryAdd(codeLensProvider.ProviderId, codeLensProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Update(
logger);
this.CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
this.CodeFolding.Update(settings.CodeFolding, logger);
this.Pester = new PesterSettings(settings.Pester);
this.Pester.Update(settings.Pester, logger);
this.Cwd = settings.Cwd;
}
}
Expand Down Expand Up @@ -384,19 +384,39 @@ public void Update(
/// </summary>
public class PesterSettings
{
public PesterSettings()
{
}

public PesterSettings(PesterSettings settings)
{
UseLegacyCodeLens = settings.UseLegacyCodeLens;
}
/// <summary>
/// If specified, the lenses "run tests" and "debug tests" will appear above all Pester tests
/// </summary>
public bool CodeLens { get; set; } = true;

/// <summary>
/// Whether integration features specific to Pester v5 are enabled
/// </summary>
public bool UseLegacyCodeLens { get; set; }
public bool UseLegacyCodeLens { get; set; } = false;

/// <summary>
/// Update these settings from another settings object
/// </summary>
public void Update(
PesterSettings settings,
ILogger logger)
{
if (settings is null) {
return;
}

if (this.CodeLens != settings.CodeLens)
{
this.CodeLens = settings.CodeLens;
logger.LogTrace(string.Format("Using Pester Code Lens - {0}", this.CodeLens));
}

if (this.UseLegacyCodeLens != settings.UseLegacyCodeLens)
{
this.UseLegacyCodeLens = settings.UseLegacyCodeLens;
logger.LogTrace(string.Format("Using Pester Legacy Code Lens - {0}", this.UseLegacyCodeLens));
}
}
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion test/PowerShellEditorServices.Test.E2E/LSPTestsFixures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public class LSPTestsFixture : IAsyncLifetime
public ITestOutputHelper Output { get; set; }

protected PsesStdioProcess _psesProcess;
public int ProcessId => _psesProcess.Id;

public async Task InitializeAsync()
{
var factory = new LoggerFactory();
_psesProcess = new PsesStdioProcess(factory, IsDebugAdapterTests);
await _psesProcess.Start().ConfigureAwait(false);

Console.WriteLine("PowerShell Editor Services Server started with PID {0}", ProcessId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm late back to this, but I thought it looked fishy when I reviewed it...

I think we want to use ITestOutputHelper for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to have a indicator for when I breakpoint right past this which process to attach to for dual-debugging, would the ITestOutputHelper still output that to the vscode debug console at that point?

// TIP: Add Breakpoint here and attach debugger using the PID from the above message
Diagnostics = new List<Diagnostic>();
TelemetryEvents = new List<PsesTelemetryEvent>();
DirectoryInfo testdir =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ public async Task CanSendPesterLegacyCodeLensRequestAsync()
{
""powershell"": {
""pester"": {
""useLegacyCodeLens"": true
""useLegacyCodeLens"": true,
""codeLens"": true
}
}
}
Expand Down Expand Up @@ -727,7 +728,8 @@ public async Task CanSendPesterCodeLensRequestAsync()
{
""powershell"": {
""pester"": {
""useLegacyCodeLens"": false
""useLegacyCodeLens"": false,
""codeLens"": true
}
}
}
Expand Down Expand Up @@ -825,6 +827,50 @@ public async Task CanSendPesterCodeLensRequestAsync()
});
}

[Trait("Category", "LSP")]
[Fact]
public async Task NoMessageIfPesterCodeLensDisabled()
{
// Make sure Pester legacy CodeLens is disabled because we'll need it in this test.
PsesLanguageClient.Workspace.DidChangeConfiguration(
new DidChangeConfigurationParams
{
Settings = JObject.Parse(@"
{
""powershell"": {
""pester"": {
""codeLens"": false
}
}
}
")
});

string filePath = NewTestFile(@"
Describe 'DescribeName' {
Context 'ContextName' {
It 'ItName' {
1 | Should - Be 1
}
}
}
", isPester: true);

CodeLensContainer codeLenses = await PsesLanguageClient
.SendRequest<CodeLensParams>(
"textDocument/codeLens",
new CodeLensParams
{
TextDocument = new TextDocumentIdentifier
{
Uri = new Uri(filePath)
}
})
.Returning<CodeLensContainer>(CancellationToken.None).ConfigureAwait(false);

Assert.Empty(codeLenses);
}

[Trait("Category", "LSP")]
[Fact]
public async Task CanSendReferencesCodeLensRequestAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public StdioServerProcess(ILoggerFactory loggerFactory, ProcessStartInfo serverS
_serverStartInfo = serverStartInfo;
}

/// <summary>
/// The process ID of the server process, useful for attaching a debugger.
/// </summary>
public int Id
{
get {
return _serverProcess.Id;
}
}

/// <summary>
/// Dispose of resources being used by the launcher.
/// </summary>
Expand Down