diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProvider.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProvider.java index fc9c8d91120..e4dca5e0282 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProvider.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProvider.java @@ -73,6 +73,9 @@ public static List createCodeActions( codeAction.setDiagnostics(diagnostics); codeAction.setEdit(edit); codeAction.setKind(CodeActionKind.QuickFix); + if (diagnostics.size() == 1) { + codeAction.setIsPreferred(Boolean.TRUE); + } return Collections.singletonList(codeAction); diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProviderTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProviderTest.java index 9e8581d60bb..36ae7ae92a9 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProviderTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/providers/CodeActionProviderTest.java @@ -42,6 +42,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import javax.annotation.CheckForNull; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -102,6 +103,7 @@ void testGetCodeActions() { .anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(0))) .anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(1))) .anyMatch(codeAction -> codeAction.getKind().equals(CodeActionKind.QuickFix)) + .allMatch(codeAction -> (codeAction.getDiagnostics().size() == 1) == toBoolean(codeAction.getIsPreferred())) ; } @@ -163,4 +165,11 @@ void testOnly() { .containsOnly(CodeActionKind.Refactor) ; } + + private static boolean toBoolean(@CheckForNull Boolean value) { + if (value == null) { + return false; + } + return value; + } } \ No newline at end of file