-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support click on inlayhint label parts #923
Support click on inlayhint label parts #923
Conversation
What do you think of this PR @mickaelistria @rubenporras ? I wasn't able to write a proper unit test for the multi part label... However, testing it manually with multi part label from LS each part with its own command - worked very well for me. |
0491869
to
2c036c4
Compare
if(command != null && command.getCommand() != null && !command.getCommand().isEmpty()) { | ||
ExecuteCommandOptions provider = wrapper.getServerCapabilities().getExecuteCommandProvider(); | ||
if (provider != null && provider.getCommands().contains(command.getCommand())) { | ||
wrapper.execute(ls -> ls.getWorkspaceService() |
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.
should we not use LanguageServerDocumentExecutor.LanguageServerDocumentExecutor(IDocument) and execute the command through it so that we ensure the order of the executions for the given document?
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.
Shall I change it to:
public final Consumer<MouseEvent> getAction() {
return me -> {
String title= getLabel();
if (title != null && !title.isEmpty()) {
findLabelPart(me).ifPresent(labelPart -> {
final Command command = labelPart.getCommand();
if(command != null && command.getCommand() != null && !command.getCommand().isEmpty()) {
ExecuteCommandOptions provider = wrapper.getServerCapabilities().getExecuteCommandProvider();
if (provider != null && provider.getCommands().contains(command.getCommand())) {
LanguageServerDocumentExecutor.forDocument(document).computeAll((wrapper, ls) -> {
if (wrapper == this.wrapper) {
return ls.getWorkspaceService()
.executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments()));
}
return CompletableFuture.completedFuture(null);
});
} else {
CommandExecutor.executeCommandClientSide(command, document);
}
}
});
}
};
}
Would this be the recommended way you had in mind @rubenporras ?
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.
Sorry for having missed your comment. Yes, I think something like that is good. Maybe use just (w, ls)
instead of (wrapper, ls)
, as I think that is the commonly used abbreviation in the codebase.
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.
IMO, explicit names that one can read out of a context are always better than abbreviation which require deep knowledge of the overall code. I think we should avoid mandating such "shortening" of names in general and most often stick with the contributor's style. I find project that welcome and handle more diverse style are more comfortable to work with than the ones that force a style (Maven is my worst experience in OSS contribution because of that)
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.
Yes, I agree that they are usually better. Only this context, wrapper
already exists as a class field, so I would tend to give a different name if possible. In any case, it was only a suggestion, not a requirement :)
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.
Only this context, wrapper already exists as a class field,
Ah OK, I had missed that point.
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.
Thank you! Updated as requested :-)
Any update on this PR? Shall I indeed use |
9d09f63
to
9d6f799
Compare
@mickaelistria @rubenporras am I okay to merge this PR? I see the build is failing but if i run it locally on master it is the same failure :-\ |
@BoykoAlex , if you rebase, it should build again. |
9d6f799
to
e9eddd8
Compare
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.
I only have minor comments. Would you like to merge as it is or would you like to modify the PR a little bit?
return me -> { | ||
String title= getLabel(); | ||
if (title != null && !title.isEmpty()) { | ||
findLabelPart(me).ifPresent(labelPart -> { |
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.
would that be a bit more readable by reducing the number of nested ifs?
findLabelPart(me).ifPresent(labelPart -> { | |
findLabelPart(me).map(InlayHintLabelPart::getCommand).map(Command::getCommand).ifPresent(command -> { |
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.
Sounds good, but simplified it up to map(InlayHintLabelPart::getCommand)
since both commandId
, i.e. command.getCommand()
and the command
itself are required in the black below.
font = new Font(display, fontData); | ||
gc.setFont(font); | ||
Point origin = new Point(0, 0); | ||
for (InlayHintLabelPart l : inlayHint.getLabel().getRight()) { |
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.
for (InlayHintLabelPart l : inlayHint.getLabel().getRight()) { | |
for (InlayHintLabelPart labelPart : inlayHint.getLabel().getRight()) { |
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.
Sounds good, did this.
|
||
private Optional<InlayHintLabelPart> findLabelPart(MouseEvent me) { | ||
if (inlayHint.getLabel().isRight()) { | ||
if (inlayHint.getLabel().getRight().size() == 1) { |
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.
Could we extract inlayHint.getLabel().getRight() to a local variable and replace the three accesses in this method?
if (inlayHint.getLabel().getRight().size() == 1) { | |
if (inlayHint.getLabel().getRight().size() == 1) { |
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.
Sounds good, did this.
InlayHint
may have a number ofInlayHintLabelPart
s. This is necessary support to determine which label part has been clicked on to execute the command corresponding to the clicked label part.Includes a test for a single label part