-
Notifications
You must be signed in to change notification settings - Fork 822
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) ?
There was a problem hiding this comment.
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
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.