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

wrap command return type #452

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft

wrap command return type #452

wants to merge 60 commits into from

Conversation

jurgenvinju
Copy link
Member

@jurgenvinju jurgenvinju commented Sep 19, 2024

The current CommandExecutor definition is value (Command _command), so it can return anything
including true and 1.

However, if we do that the JSON-RPC bridge breaks. The LSP4J method to implement is:
public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {

But Object must not be primitive or become primitive.

Therefore the current code in Rascal language servers (repeated for every language times every command) wraps every result in a map like so:
return ("result" : true)

This PR changes that such that we can write:
return true;

And for backward compatibility it wraps the result before sending it over the bridge:
return vf.map().put(vf.string("result"), result);

This way the Rascal type-checker can completely check the validity of the CommandExecutor again,
and the JSON-RPC bridge can not accidentally fail anymore.

If there exists code that wraps CommandExecutor results differently, e.g. like so:
return [result];

then this PR breaks those language servers. Therefore it would be good for @DavyLandman to have a close
look at this before we merge it.

…tic messages can carry a list of quickfixes. Only for DSLs though
…toring the CompletableFuture/Stream code for code actions
CodeActions.

Commands were the simplest way of creating this interaction, but
the LSP provides more configurability and smoother UI interactions
via the concept of a "CodeAction". A CodeAction optionally wraps
a Command and/or a DocumentEdit. The edit is always executed
first and may involve preview(s) of the different alternative
commands. The command is just the command to execute when the option
is chosen, just as before.

Command titles are lifted to CodeAction titles if none are present.

CodeActions may be "categorized" via the CodeActionKind enum. This
enum is open for users to extend. The current definition lists the
currently known list in lsp4j.

If a command calls a IDEServices.registerTextEdits, then this has
the same effect on the files and editor content as providing the edits
in the CodeAction immediately. However, UI interactions like previews
and OK/Cancel pop-ups may be different.
@jurgenvinju jurgenvinju self-assigned this Sep 19, 2024
@jurgenvinju jurgenvinju added the enhancement New feature or request label Sep 19, 2024
@jurgenvinju
Copy link
Member Author

Also after this PR, if we don't replace return ("result": true) by return true; then the code also breaks on the client side that processes command results.

@jurgenvinju
Copy link
Member Author

So this seems like a small change, but it breaks the API of every command executor. I do think it is necessary for the future of util::LanguageServer to clean this up.

@jurgenvinju
Copy link
Member Author

There is a big TODO in this code that would break the client code on the TypeScript side even more. So let's push that into the future. It is also not strictly necessary.

@DavyLandman
Copy link
Member

I think something went wrong with this PR, it has a lot of commits in here? I think from the code-actions branch?

@jurgenvinju
Copy link
Member Author

jurgenvinju commented Sep 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants