Skip to content
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

[vscode] Support TestMessage#contextValue #13176

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

rschnekenbu
Copy link
Contributor

What it does

Provides support for 1.84 vscode API TestMessage#contextValue optional property. This also adds one introduced menu using this API (testing/message/context). See https://code.visualstudio.com/updates/v1_84#_finalized-testmessagecontextvalue-api
The other menu is not relevant currently, as the test API implementation is not as advanced as the vscode one (no diff editor with actual and expected compared for example).

Fixes #13144

Contributed on behalf of STMicroelectronics

How to test

The test can be done installing the following extension:

This adds a test controller that required the creation of a test run profile before being used (Command palette > Create Test Run Profile). Once the test has run, the results are shown. On the test results, there is a new context menu action that displays a message information with the arguments passed to this command. The expected arguments are described in the comment of TestMessage#contextValue (see theia.d.ts - line to be added once commited)

issue-13144

Note that since the testing/message/content extension menu is not yet implemented, the extension will show a warning at startup.

Follow-ups

Support of the testing/message/content extension menu. This is tracked under #13145

Review checklist

Reminder for reviewers

@rschnekenbu
Copy link
Contributor Author

@tsmaeder, as you worked on the test API, could you have a look to this one?

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

Just two remarks.

@@ -131,3 +132,23 @@ export namespace TestItemReference {
}
}

export interface TestMessageArg {
typeTag: '$type_test_message_arg',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this or can we just send an array of [TestItemReference, TestMessageDTO]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was easier to detect the kind of message, as we send an array of 2 elements with one optional and the other with almost everything optional except 1 property. But this is definitely not mandatory.
That can be removed and we can have the following code for TestMessageArg.is():

Suggested change
typeTag: '$type_test_message_arg',
export interface TestMessageArg {
testItemReference: TestItemReference | undefined,
testMessage: TestMessageDTO
}
export namespace TestMessageArg {
export function is(arg: unknown): arg is TestMessageArg {
return isObject<TestMessageArg>(arg)
&& isObject<TestMessageDTO>(arg.testMessage)
&& typeof arg.testMessage.message === 'string';
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I was more thinking of making the argument transformer method recursive: we are already detecting if it's an array, but the assumption is that the contents can only be TestItemReferences

@@ -216,6 +218,12 @@ export class TestRunTreeWidget extends TreeWidget {
onDidAddTestOutput: Event.map(node.parent.run.onDidChangeTestOutput, evt => evt.filter(item => item[0] === node.item).map(item => item[1]))
};
this.uiModel.selectedTestState = node.parent.run.getTestState(node.item);
if (this.uiModel.selectedTestState && TestFailure.is(this.uiModel.selectedTestState.state)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this code live in the uiModel as it's the owner of the selectedTestState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing! Indeed, that should happen in the uiModel. I will update the code and move this part of the code on the selectedTestState mutator.

@tsmaeder
Copy link
Contributor

When testing, I never get anything in the info popup for the message context except: Message Context with args: [object Object]. In instance, I got a stack overflow:

4rpc-message-encoder.ts:151 Uncaught (in promise) Error: Error during encoding: 'Maximum call stack size exceeded'
    at MsgPackMessageEncoder.encode (rpc-message-encoder.ts:151:23)
    at MsgPackMessageEncoder.request (rpc-message-encoder.ts:137:14)
    at RpcProtocol.sendRequest (rpc-protocol.ts:161:22)
    at proxy-handler.ts:74:45

This happened when doing this:

  1. left-click "sample-child 1" in the Test Explorer view
  2. right-click "sample-child 1" in the Test Run view and select "Message Context" from the context menu

Not sure whether that is due to the test plugin or the PR code.

@rschnekenbu
Copy link
Contributor Author

When testing, I never get anything in the info popup for the message context except: Message Context with args: [object Object]. In instance, I got a stack overflow:

4rpc-message-encoder.ts:151 Uncaught (in promise) Error: Error during encoding: 'Maximum call stack size exceeded'
    at MsgPackMessageEncoder.encode (rpc-message-encoder.ts:151:23)
    at MsgPackMessageEncoder.request (rpc-message-encoder.ts:137:14)
    at RpcProtocol.sendRequest (rpc-protocol.ts:161:22)
    at proxy-handler.ts:74:45

This happened when doing this:

  1. left-click "sample-child 1" in the Test Explorer view
  2. right-click "sample-child 1" in the Test Run view and select "Message Context" from the context menu

Not sure whether that is due to the test plugin or the PR code.

I tried again, using the extension provided in the PR and with latest version, I do not get these stack error messages on sample-child1. I tested on both browser and electron version. I see the difference with your message information text, I will push a new version of the extension with pretty printed objects.

I can see however a call stack error while right clicking on the Test Run root object. I will fix that.

@rschnekenbu
Copy link
Contributor Author

I updated the PR with more checks on arguments processing. Element tree in Test Run widget can also be TestRun, which was not caught in argument processor and forwarded as such without cleaning.

Here is the version of the test extension with stringified argument:
zip:
test-extension-sample-0.0.3.zip
src:
test-extension-sample-0.0.3-src.zip

@tsmaeder
Copy link
Contributor

With the latest plugin, I always get "Message Context with args: undefined" when I click the context menu. What gives?

@rschnekenbu
Copy link
Contributor Author

rschnekenbu commented Dec 20, 2023

With the latest plugin, I always get "Message Context with args: undefined" when I click the context menu. What gives?

Sorry for that, @tsmaeder! I am pretty sure I had check thoroughly the changes :/ In certain cases, TestMessage.is() was returning false despite the element passed being one. I updated the PR so this should not happen anymore.
In the case the test items are not in failure or the selected element in the tree is not a TestItem, the command shall return the kind of message that you have, as the expected arguments cannot be computed. In fact, TestMessage is only available in case of test failures. I assume there it is up to the extension to check the enablement of the command.
I will squash and resolve conflicts once the PR is approved if it is OK for you.

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

I think your original code was correct as far as the typing goes: the "location" field in TestMessage should probably be optional. But that's another problem. Lgtm now.

@rschnekenbu
Copy link
Contributor Author

Thanks a lot, @tsmaeder! I will rebase and resolve conflicts then.

Also adds the menu mapping for testing/message/context vscode menu extension.

contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <[email protected]>

review comments

review comments

- avoid passing TestRun in the plugin menu command adapter

review comments

TestMessage location can be undefined, so the TestMessage.is() was returning false despite being one.
@JonasHelming
Copy link
Contributor

@tsmaeder Is this approved?

@JonasHelming JonasHelming merged commit 7dcce3e into eclipse-theia:master Dec 20, 2023
14 checks passed
@vince-fugnitto vince-fugnitto added this to the 1.45.0 milestone Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[vscode] Support TestMessage#contextValue optional property
4 participants