-
Notifications
You must be signed in to change notification settings - Fork 109
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
executeCommand api #2960
executeCommand api #2960
Conversation
12499ed
to
3641719
Compare
3641719
to
ccc1c14
Compare
SonarCloud Quality Gate failed. |
45ce988
to
9698094
Compare
dd5e4eb
to
237acce
Compare
Kudos, SonarCloud Quality Gate passed! |
@@ -308,4 +312,10 @@ private static Boolean getRenamePrepareSupport(InitializeParams params) { | |||
.orElse(false); | |||
} | |||
|
|||
private ExecuteCommandOptions getExecuteCommandProvider() { | |||
var executeCommandOptions = new ExecuteCommandOptions(); | |||
executeCommandOptions.setCommands(commandProvider.getCommandIds()); |
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.
Идентификаторы известных команд отдаются нижестоящим провайдером
|
||
@Override | ||
public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) { | ||
var arguments = commandProvider.extractArguments(params); |
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.
Аргументы входящего запроса приходят в виде JsonElement. Здесь мы их преобразуем к типизированному dto
@RequiredArgsConstructor | ||
public class CommandProvider { | ||
|
||
private final Map<String, CommandSupplier<CommandArguments>> commandSuppliersById; |
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.
В конструктор внедряется мапа сапплаеров по их идентификаторам
public Object executeCommand(CommandArguments arguments) { | ||
var commandId = arguments.getId(); | ||
|
||
var commandSupplier = commandSuppliersById.get(commandId); |
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.
Выбирается нужный сапплаер...
} | ||
|
||
var result = commandSupplier | ||
.execute(arguments) |
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.
И ему передаётся вызов команды.
.orElse(null); | ||
|
||
CompletableFuture.runAsync(() -> { | ||
if (commandSupplier.refreshCodeLensesAfterExecuteCommand()) { |
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.
Команда может декларировать, что после её выполнения нужно обновлять code lenses
* @param <T> Конкретный тип для аргументов команды. | ||
*/ | ||
|
||
public interface CommandSupplier<T extends CommandArguments> { |
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.
По аналогии с CodeLensSupplier, каждый CommandSupplier деклариует свои аргументы (интерфейс, который можно реализовать в виде dto)
*/ | ||
default String getId() { | ||
String simpleName = getClass().getSimpleName(); | ||
if (simpleName.endsWith("CommandSupplier")) { |
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.
@nixel2007, (придирка), а вот если была константа, скажем PREFIX_COMMAND_SUPPLIER
, то было бы меньше усталости )
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.
done
* | ||
* @return Флаг, показывающий необходимость обновить линзы после выполнения команды. | ||
*/ | ||
default boolean refreshCodeLensesAfterExecuteCommand() { |
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.
@nixel2007, почему не какой нибудь is или need?
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.
Need - отличная идея! Я никак не мог слово подобрать
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.
done
Описание
Вырезана часть с командами из #2672
Связанные задачи
Closes
Чеклист
Общие
gradlew precommit
)Для диагностик
Дополнительно