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

executeCommand api #2960

Merged
merged 12 commits into from
Apr 1, 2023
Merged

executeCommand api #2960

merged 12 commits into from
Apr 1, 2023

Conversation

nixel2007
Copy link
Member

@nixel2007 nixel2007 commented Dec 5, 2022

Описание

Вырезана часть с командами из #2672

Связанные задачи

Closes

Чеклист

Общие

  • Ветка PR обновлена из develop
  • Отладочные, закомментированные и прочие, не имеющие смысла участки кода удалены
  • Изменения покрыты тестами
  • Обязательные действия перед коммитом выполнены (запускал команду gradlew precommit)

Для диагностик

  • Описание диагностики заполнено для обоих языков (присутствуют файлы для обоих языков, для русского заполнено все подробно, перевод на английский можно опустить)

Дополнительно

@nixel2007 nixel2007 force-pushed the features/command-api branch 4 times, most recently from 12499ed to 3641719 Compare December 5, 2022 15:38
@nixel2007 nixel2007 force-pushed the features/command-api branch from 3641719 to ccc1c14 Compare December 5, 2022 15:44
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 12 Code Smells

47.4% 47.4% Coverage
0.0% 0.0% Duplication

@ghost
Copy link

ghost commented Mar 31, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@nixel2007 nixel2007 force-pushed the features/command-api branch from 45ce988 to 9698094 Compare March 31, 2023 08:53
@nixel2007 nixel2007 force-pushed the features/command-api branch from dd5e4eb to 237acce Compare March 31, 2023 13:00
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 1, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

82.1% 82.1% Coverage
0.0% 0.0% Duplication

@nixel2007 nixel2007 marked this pull request as ready for review April 1, 2023 05:47
@@ -308,4 +312,10 @@ private static Boolean getRenamePrepareSupport(InitializeParams params) {
.orElse(false);
}

private ExecuteCommandOptions getExecuteCommandProvider() {
var executeCommandOptions = new ExecuteCommandOptions();
executeCommandOptions.setCommands(commandProvider.getCommandIds());
Copy link
Member Author

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);
Copy link
Member Author

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;
Copy link
Member Author

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);
Copy link
Member Author

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)
Copy link
Member Author

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()) {
Copy link
Member Author

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> {
Copy link
Member Author

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")) {
Copy link
Member

Choose a reason for hiding this comment

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

@nixel2007, (придирка), а вот если была константа, скажем PREFIX_COMMAND_SUPPLIER, то было бы меньше усталости )

Copy link
Member Author

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() {
Copy link
Member

Choose a reason for hiding this comment

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

@nixel2007, почему не какой нибудь is или need?

Copy link
Member Author

Choose a reason for hiding this comment

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

Need - отличная идея! Я никак не мог слово подобрать

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@nixel2007 nixel2007 merged commit 8134504 into develop Apr 1, 2023
@nixel2007 nixel2007 deleted the features/command-api branch April 1, 2023 18:44
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