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

Experimental client-side command executions #596

Merged
merged 5 commits into from
Mar 23, 2018

Conversation

kdvolder
Copy link
Contributor

This is one half of a proposed protocol extension that allows language server to execute commands on the server.

It requires another PR to implement support for handling the new workspace/executeCommand message on the client side.

This fits in with in the discussion at #595


public interface ExecuteCommandProposedClient {

@JsonRequest("workspace/executeCommand")
Copy link
Contributor

Choose a reason for hiding this comment

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

there's already a "workspace/executeCommand" command on the server side, so I suggest using a different name

Copy link
Contributor Author

@kdvolder kdvolder Mar 20, 2018

Choose a reason for hiding this comment

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

I thought it logical to use the same name as it actually does exactly the same thing just the message are flowing in the opposite direction. But sure... could change it to 'workspace/executeClientCommand' or maybe 'client/executeCommand'? What is more logical?

Copy link
Contributor

Choose a reason for hiding this comment

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

either one is fine I guess, I have no strong opinion for one or the other

Change it to `workspace/executeClientCommand` to
distinguish it from existing `workspace/executeCommand`
on the server side.
Follow through on renaming protocol message "workspace/executeCommand". Java methods involved in
handling this message now also renamed.
@fbricon
Copy link
Contributor

fbricon commented Mar 23, 2018

So @tsmaeder and I agreed we'll go on with the approach in this PR rather than #575.

Can you please add some tests before we can proceed? Take a look at https://github.com/eclipse/eclipse.jdt.ls/pull/575/files#diff-1514fea0a7698e4d85f57581474c7cd7R37 for inspiration.

public interface ExecuteCommandProposedClient {

@JsonRequest("workspace/executeClientCommand")
CompletableFuture<Object> executeClientCommand(ExecuteCommandParams params);
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 actually need to wait for the client to respond?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is a good idea yes. One possible and useful scenario is an error results because the command was deregistered. If command is a kind of 'callback' as in our case, then this may be a good way to trigger cleanup of the callback table.

I've experimented with a more 'proper' cleanup. But as this tends to happen around the same time as server is in the process of shutting down... its not very reliable (messages no longer able to send etc.).

Anyhow... callers wanting to catch errors and responding to them seems to be a good enough reason. And I could also imagine that the command could return useful information (not in our use case, but if it used in a more 'request -> response fashion, rather than a callback it could be).

@@ -56,6 +61,10 @@ public JavaClientConnection(JavaLanguageClient client) {
logHandler.install(this);
}

public Object executeClientCommand(String id, Object... params) {
return this.client.executeClientCommand(new ExecuteCommandParams(id, ImmutableList.copyOf(params))).join();
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably add a timeout

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 raises the question... how long should the timeout be? Or should we change this api and return the CompletableFuture? Then the caller can decide how long they want to wait... or if they want to continue with an async composition instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm... returning CompletableFuture seems a bit 'out of style' with the rest of the api in the same class. I called join because I as trying to follow similar pattern as other stuff in the same class. E.g. like here:

https://github.com/kdvolder/eclipse.jdt.ls/blob/66aa25d44cea30d2fdf90b30058508772b990b48/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaClientConnection.java#L107

@kdvolder
Copy link
Contributor Author

@fbricon Added some tests and also an alternate api that allows passing a Duration for timeout.
I still kept the api without timeout as well.

* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

That'd be Pivotal :-)

* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

Pivotal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... yeah. The headers were all added automagically by Eclipse (you must have configured it that way in the projects). And I didn't pay attention so I didn't notice.

I'll make pass through all the copyright headers of all the changed files.

@fbricon fbricon merged commit b5f383f into eclipse-jdtls:master Mar 23, 2018
tsmaeder pushed a commit to bdshadow/eclipse.jdt.ls that referenced this pull request Apr 6, 2018
Experimental execute client-side command protocol extension

Signed-off-by: Kris De Volder <[email protected]>
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.

2 participants