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

Setting to Disable Pester Code Lens #1585

merged 5 commits into from
Oct 18, 2021

Conversation

JustinGrote
Copy link
Collaborator

@JustinGrote JustinGrote commented Oct 13, 2021

Allows the Pester Codelens to be disabled so as not to confuse users who want to use an alternate Pester Test Runner

Correlated vscode-powershell PR: PowerShell/vscode-powershell#3613

@JustinGrote
Copy link
Collaborator Author

@andschwa not sure why this is failing the test, something in the way you mock the settings maybe?

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

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

Is there a way to add a test checking that the provider is (and isn't) enabled via the flag? We might not actually have tests around settings yet, but I'm trying to be intentional about covering all new changes in tests.

@andyleejordan
Copy link
Member

@andschwa not sure why this is failing the test, something in the way you mock the settings maybe?

It looks like the actual test itself wasn't fixed. At a quick glance, there's an assertion failing. The input was changed, but not the tests on the output.

@JustinGrote
Copy link
Collaborator Author

@andschwa That's the thing though, by default it shouldn't be changing the behavior, I didn't write a new test yet, so I'm not sure why it thinks it's not registering the codelens.

@andyleejordan
Copy link
Member

andyleejordan commented Oct 13, 2021

Oh I see, we do have an existing test that asserts the code lens is there (yay!):

CodeLensContainer codeLenses = await PsesLanguageClient
.SendRequest<CodeLensParams>(
"textDocument/codeLens",
new CodeLensParams
{
TextDocument = new TextDocumentIdentifier
{
Uri = new Uri(filePath)
}
})
.Returning<CodeLensContainer>(CancellationToken.None).ConfigureAwait(false);
Assert.Collection(codeLenses,
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(1, range.Start.Line);
Assert.Equal(0, range.Start.Character);
Assert.Equal(7, range.End.Line);
Assert.Equal(1, range.End.Character);
Assert.Equal("Run tests", codeLens.Command.Title);
},
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(1, range.Start.Line);
Assert.Equal(0, range.Start.Character);
Assert.Equal(7, range.End.Line);
Assert.Equal(1, range.End.Character);
Assert.Equal("Debug tests", codeLens.Command.Title);
},
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(2, range.Start.Line);
Assert.Equal(4, range.Start.Character);
Assert.Equal(6, range.End.Line);
Assert.Equal(5, range.End.Character);
Assert.Equal("Run tests", codeLens.Command.Title);
},
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(2, range.Start.Line);
Assert.Equal(4, range.Start.Character);
Assert.Equal(6, range.End.Line);
Assert.Equal(5, range.End.Character);
Assert.Equal("Debug tests", codeLens.Command.Title);
},
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(3, range.Start.Line);
Assert.Equal(8, range.Start.Character);
Assert.Equal(5, range.End.Line);
Assert.Equal(9, range.End.Character);
Assert.Equal("Run test", codeLens.Command.Title);
},
codeLens =>
{
Range range = codeLens.Range;
Assert.Equal(3, range.Start.Line);
Assert.Equal(8, range.Start.Character);
Assert.Equal(5, range.End.Line);
Assert.Equal(9, range.End.Character);
Assert.Equal("Debug test", codeLens.Command.Title);
});

And it looks like the way its written is making for a really bad failure message, but in short from here:

I think the collection is empty, which means that this failed:

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

@JustinGrote
Copy link
Collaborator Author

Thanks for eyeballing it, I'll investigate but again it shouldn't have changed the default behavior so either I goofed or something wrong in the test.

@andyleejordan
Copy link
Member

Looking at the rest of the settings file, the Pester class is weird:

public class PesterSettings
{
public PesterSettings()
{
}

This should be:

    internal class PesterSettings
    {

That is, none of the others are public just internal, and this empty constructor is useless. Probably not breaking anything but want to change it while we're in this code?

@andyleejordan
Copy link
Member

Two other things to note is that in the tests, the test you're having to touch is unnecessarily (I think?) parsing JSON in a string into a Settings object, but there are other places in these tests that are just creating the Settings directly. That would at least help make the test more readable if you wanted to mirror that way of doing it:

PsesLanguageClient.SendNotification("workspace/didChangeConfiguration",
new DidChangeConfigurationParams
{
Settings = JToken.FromObject(new LanguageServerSettingsWrapper
{
Files = new EditorFileSettings(),
Search = new EditorSearchSettings(),
Powershell = new LanguageServerSettings
{
ScriptAnalysis = new ScriptAnalysisSettings
{
Enable = false
}
}
})
});

The other thing in here is that the test I just linked is explicitly sending a workspace/didChangeConfiguration notification (and then waiting a bit) instead of calling PsesLanguageClient.Workspace.DidChangeConfiguration. I actually think the latter makes more sense because it removes having to wait, but it's two avenues to dig into and see what's happening to the failing test.

@JustinGrote
Copy link
Collaborator Author

Looking at the rest of the settings file, the Pester class is weird:

public class PesterSettings
{
public PesterSettings()
{
}

This should be:

    internal class PesterSettings
    {

That is, none of the others are public just internal, and this empty constructor is useless. Probably not breaking anything but want to change it while we're in this code?

I agree I thought this was super bizarre but with lack of comments as to why it was this way I assumed there was a good reason.

@andyleejordan
Copy link
Member

I agree I thought this was super bizarre but with lack of comments as to why it was this way I assumed there was a good reason.

I checked the Git blame and saw no good reason. Looked like the code was added in a community PR and so was probably just checked as thoroughly as we're doing now.

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

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

Looks like it's working now. Can we add a simple test that asserts thing work as expected with Pester.CodeLens = false? Also would be happy to have included the change to the Pester settings class that has a dummy constructor and is for some reason public.

@JustinGrote
Copy link
Collaborator Author

@andschwa I'll try to work on this tonight or tomorrow, no guarantees though :)

@JustinGrote
Copy link
Collaborator Author

@andschwa banged on this for a while, everything looks fine after making some additional adjustments, but the Pester Code lens test fails for me even on master with the same error, can you confirm it fails on master for you too?

image

@andyleejordan
Copy link
Member

@andschwa banged on this for a while, everything looks fine after making some additional adjustments, but the Pester Code lens test fails for me even on master with the same error, can you confirm it fails on master for you too?

It certainly shouldn't be! Here's the most recent master CI run and it's passing: https://dev.azure.com/powershell/PowerShellEditorServices/_build/results?buildId=87315&view=ms.vss-test-web.build-test-results-tab&runId=1676954&resultId=100001&paneView=debug

Sounds like an environment issue?

@JustinGrote
Copy link
Collaborator Author

@andschwa OK now that I've got both-sides debugging working, it looks like the config change via DidChangeConfiguration is not taking effect and that's why the legacyCodeLens test is failing
image

@JustinGrote
Copy link
Collaborator Author

@andschwa should pass but it's in "awaiting approval" status for the MacOS build.

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

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

Hey, this looks fantastic, I'm excited to get this into a preview. @rjmholt Do you have a moment to review?

@rjmholt rjmholt enabled auto-merge (squash) October 18, 2021 21:34
@rjmholt rjmholt merged commit 8cda531 into PowerShell:master Oct 18, 2021
@JustinGrote
Copy link
Collaborator Author

@rjmholt @andschwa thank you! And thanks for putting up with my low level of C# experience.

@JustinGrote JustinGrote deleted the justingrote/disablePesterCodeLens branch October 18, 2021 21:50

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants