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

Invoke arbitrary action from vscode #3843

Merged
merged 1 commit into from
Mar 25, 2022
Merged

Conversation

jhorvath
Copy link
Contributor

@jhorvath jhorvath commented Mar 23, 2022

Adding possibility to invoke arbitrary action from vscode. Any action registered in java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/layer.xml can be called as a vscode command:
vscode.commands.executeCommand('nbls:<Category>:<actionId>', <context>);. Context will be converted to Action type defined in layer.

Copy link

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Can you document (at least in the PR or in some arch.xml) how one invokes such action?

private CompletableFuture<Object> invokeAction(NbCodeLanguageClient client, String category, String aid, List<Object> arguments) {
String path = "Actions/" + category + "/" + aid.replace('.', '-') + ".instance"; //NOI18N
FileObject config = FileUtil.getConfigFile(path);
String contextType = (String) config.getAttribute("type"); //NOI18N

Choose a reason for hiding this comment

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

Please write a test for this new API/behavior.

String contextType = (String) config.getAttribute("type"); //NOI18N
try {
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(contextType);
Object context = gson.fromJson(gson.toJson(arguments.get(0)), clazz);
Copy link
Member

Choose a reason for hiding this comment

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

Q: this deserializes the 1st argument, which was deserialized at line ~97 as JSONObject, in an attempt to read inputs like { data : { id: <nodeId> } }. Does the code that deserializes a JSONObject / id behave "well" when it is fed with a typed parameter (other node-based actions) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case the new method invokeAction() is called the first argument doesn't contain input you mention above (data) as it is not called from tree view. It is expected to contain fields for a action type to deserialise properly

@jhorvath jhorvath merged commit a9dfd9e into apache:master Mar 25, 2022
@jhorvath jhorvath deleted the invoke-action branch March 25, 2022 15: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

3 participants