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

fix(codecatalyst): menu command fails after using tree node #4870

Merged
merged 1 commit into from May 23, 2024

Conversation

justinmk3
Copy link
Contributor

Problem:

The codecatalyst commands:

"Open Dev Environment"
"Clone Repository"

fail if their menu forms are used AFTER the treenode forms.

Steps to reproduce:

  1. click the "Open Dev Environment" tree node in the codecatalyst panel.
  2. close the wizard.
  3. in the codecatalyst panel, expand the "..." root menu and choose "Open CodeCatalyst Dev Environment"
  4. it fails because the TreeNode from step (1) is passed as the first arg, which breaks openDevEnv().

Solution:

Follow the instructions from the VsCodeCommandArg docstring:

/**
* HACK
*
* If a command matches the following conditions:
* - Is registered with VS Code
* - Has args for the execution of the command
* - Can be executed through a package.json contribution (eg: ellipsis menu in View)
*
* Then unexpected args will be passed to the command.
* - Currently it sets arg[0] to an object or undefined, depending on the context.
* - And the rest of the args will be undefined do not exist.
* ---
* **So as a workaround**, commands who meet the above criteria should
* - have this type as their first arg as a placeholder
* - When executing the command from within the code, pass in {@link placeholder} as the first arg.
* - In the command check if the first arg !== {@link placeholder}, and if so you will need to
* set values for the other args since they will not exist.
*/
export type VsCodeCommandArg = typeof placeholder

TODO:

Note that the bug does NOT occur if you use the "..." menu command FIRST. It seems like the TreeNode is stored as state on the CommandResource; is that actually necessary?

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@justinmk3 justinmk3 requested a review from a team as a code owner April 28, 2024 22:12
@justinmk3 justinmk3 marked this pull request as draft April 28, 2024 22:12
@justinmk3 justinmk3 marked this pull request as ready for review May 23, 2024 22:20
Problem:
The codecatalyst commands:

    "Open Dev Environment"
    "Clone Repository"

fail if their menu forms are used AFTER the treenode forms.

Steps to reproduce:
1. click the "Open Dev Environment" tree node in the codecatalyst panel.
2. close the wizard.
3. in the codecatalyst panel, expand the "..." root menu and choose "Open CodeCatalyst Dev Environment"
4. it fails because the TreeNode from step (1) is passed as the first arg, which breaks `openDevEnv()`.

Solution:
Follow the instructions from the `VsCodeCommandArg` docstring:
https://github.com/aws/aws-toolkit-vscode/blob/4decdf6341a38c58db0e9f778ba57b5514434b0b/packages/core/src/shared/vscode/commands2.ts#L23-L41

TODO:
Note that the bug does NOT occur if you use the "..." menu command
FIRST. It seems like the TreeNode is stored as state on the
`CommandResource`; is that actually necessary?
@justinmk3 justinmk3 merged commit afe1a39 into master May 23, 2024
17 checks passed
@justinmk3 justinmk3 deleted the fixcodecatalystcommands branch May 23, 2024 22:51
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.

None yet

1 participant