From 5625cc4a8632ee976e37dd48a73a159b62bceece Mon Sep 17 00:00:00 2001 From: sfaqer Date: Thu, 15 Jun 2023 18:01:14 +1000 Subject: [PATCH] =?UTF-8?q?1.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20SourceDefinedMethodCallI?= =?UTF-8?q?nlayHintSupplier=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=B8=D1=89=D0=B5=D1=82=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B8=20=D0=B2=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B0=D1=85=20inlayHint=20=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B5=20CodeLens=201.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20showParametersWith?= =?UTF-8?q?TheSameName=20=D0=B4=D0=BB=D1=8F=20SourceDefinedMethodCallInlay?= =?UTF-8?q?HintSupplier=203.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0=20=D1=87=D1=82?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2=20inlayHints=20=D0=B2=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rceDefinedMethodCallInlayHintSupplier.java | 4 +- .../LanguageServerConfigurationTest.java | 6 ++ ...efinedMethodCallInlayHintSupplierTest.java | 57 +++++++++++++++++++ .../.partial-bsl-language-server.json | 7 +++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplier.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplier.java index 6976c53a796..b3bce437605 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplier.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplier.java @@ -173,7 +173,7 @@ private static void setTooltip(InlayHint inlayHint, ParameterDefinition paramete private boolean showParametersWithTheSameName() { - var parameters = configuration.getCodeLensOptions().getParameters().getOrDefault(getId(), Either.forLeft(true)); + var parameters = configuration.getInlayHintOptions().getParameters().getOrDefault(getId(), Either.forLeft(true)); if (parameters.isLeft()) { return DEFAULT_SHOW_PARAMETERS_WITH_THE_SAME_NAME; } else { @@ -185,7 +185,7 @@ private boolean showParametersWithTheSameName() { } private boolean showDefaultValues() { - var parameters = configuration.getCodeLensOptions().getParameters().getOrDefault(getId(), Either.forLeft(true)); + var parameters = configuration.getInlayHintOptions().getParameters().getOrDefault(getId(), Either.forLeft(true)); if (parameters.isLeft()) { return DEFAULT_DEFAULT_VALUES; } else { diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/configuration/LanguageServerConfigurationTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/configuration/LanguageServerConfigurationTest.java index 51e3315111d..0dbb67436c4 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/configuration/LanguageServerConfigurationTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/configuration/LanguageServerConfigurationTest.java @@ -25,6 +25,7 @@ import com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions; import com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode; import com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport; +import com.github._1c_syntax.bsl.languageserver.configuration.inlayhints.InlayHintOptions; import com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod; import com.github._1c_syntax.utils.Absolute; import org.eclipse.lsp4j.jsonrpc.messages.Either; @@ -152,6 +153,7 @@ void testPartialInitialization() { // when CodeLensOptions codeLensOptions = configuration.getCodeLensOptions(); DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions(); + InlayHintOptions inlayHintOptions = configuration.getInlayHintOptions(); // then assertThat(codeLensOptions.getParameters().get("cognitiveComplexity")).isNull(); @@ -162,6 +164,10 @@ void testPartialInitialization() { assertThat(diagnosticsOptions.getMode()).isEqualTo(Mode.ON); assertThat(diagnosticsOptions.getSkipSupport()).isEqualTo(SkipSupport.NEVER); assertThat(diagnosticsOptions.getParameters()).isEmpty(); + + assertThat(inlayHintOptions.getParameters()) + .containsEntry("sourceDefinedMethodCall", Either.forRight(Map.of("showParametersWithTheSameName", true))); + } } \ No newline at end of file diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java index f62c122e191..d4dcfd89d26 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java @@ -21,7 +21,9 @@ */ package com.github._1c_syntax.bsl.languageserver.inlayhints; +import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration; import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol; +import com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod; import com.github._1c_syntax.bsl.languageserver.util.TestUtils; import org.eclipse.lsp4j.InlayHint; import org.eclipse.lsp4j.InlayHintKind; @@ -33,10 +35,12 @@ import org.springframework.boot.test.context.SpringBootTest; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest +@CleanupContextBeforeClassAndAfterEachTestMethod class SourceDefinedMethodCallInlayHintSupplierTest { private final static String FILE_PATH = "./src/test/resources/inlayhints/SourceDefinedMethodCallInlayHintSupplier.bsl"; @@ -44,6 +48,9 @@ class SourceDefinedMethodCallInlayHintSupplierTest { @Autowired private SourceDefinedMethodCallInlayHintSupplier supplier; + @Autowired + private LanguageServerConfiguration configuration; + @Test void testDefaultInlayHints() { @@ -80,4 +87,54 @@ void testDefaultInlayHints() { ; } + @Test + void testInlayHintsShowParametersWithTheSameName() { + + // given + configuration.getInlayHintOptions().getParameters().put( + supplier.getId(), + Either.forRight(Map.of("showParametersWithTheSameName", true)) + ); + + var documentContext = TestUtils.getDocumentContextFromFile(FILE_PATH); + MethodSymbol firstMethod = documentContext.getSymbolTree().getMethods().get(0); + + var textDocumentIdentifier = TestUtils.getTextDocumentIdentifier(documentContext.getUri()); + var range = firstMethod.getRange(); + var params = new InlayHintParams(textDocumentIdentifier, range); + + // when + List inlayHints = supplier.getInlayHints(documentContext, params); + + // then + assertThat(inlayHints) + .hasSize(3) + .anySatisfy(inlayHint -> { + assertThat(inlayHint.getLabel()).isEqualTo(Either.forLeft("Player:")); + assertThat(inlayHint.getKind()).isEqualTo(InlayHintKind.Parameter); + assertThat(inlayHint.getPosition()).isEqualTo(new Position(3, 14)); + assertThat(inlayHint.getPaddingRight()).isTrue(); + assertThat(inlayHint.getPaddingLeft()).isNull(); + assertThat(inlayHint.getTooltip().getRight().getValue()).isEqualTo("* **Player**: "); + }) + .anySatisfy(inlayHint -> { + assertThat(inlayHint.getLabel()).isEqualTo(Either.forLeft("PlayersHealth:")); + assertThat(inlayHint.getKind()).isEqualTo(InlayHintKind.Parameter); + assertThat(inlayHint.getPosition()).isEqualTo(new Position(3, 23)); + assertThat(inlayHint.getPaddingRight()).isTrue(); + assertThat(inlayHint.getPaddingLeft()).isNull(); + assertThat(inlayHint.getTooltip().getRight().getValue()).isEqualTo("* **PlayersHealth**: "); + }) + .anySatisfy(inlayHint -> { + assertThat(inlayHint.getLabel()).isEqualTo(Either.forLeft("Amount:")); + assertThat(inlayHint.getKind()).isEqualTo(InlayHintKind.Parameter); + assertThat(inlayHint.getPosition()).isEqualTo(new Position(3, 32)); + assertThat(inlayHint.getPaddingRight()).isTrue(); + assertThat(inlayHint.getPaddingLeft()).isNull(); + assertThat(inlayHint.getTooltip().getRight().getValue()).isEqualTo("* **Amount**: "); + }) + ; + } + + } diff --git a/src/test/resources/.partial-bsl-language-server.json b/src/test/resources/.partial-bsl-language-server.json index f3e3b85a302..070725801a3 100644 --- a/src/test/resources/.partial-bsl-language-server.json +++ b/src/test/resources/.partial-bsl-language-server.json @@ -4,6 +4,13 @@ "cyclomaticComplexity": false } }, + "inlayHint": { + "parameters": { + "sourceDefinedMethodCall": { + "showParametersWithTheSameName": true + } + } + }, "diagnostics": { "mode": "on" }