Skip to content

Commit

Permalink
Merge pull request #3068 from sfaqer/bugfix/sourceDefinedMethodCallRe…
Browse files Browse the repository at this point in the history
…adParams

Исправлена ошибка чтения параметров SourceDefinedMethodCallInlayHintSupplier
  • Loading branch information
nixel2007 authored Jun 15, 2023
2 parents fd25d3a + 5625cc4 commit 884c97c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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)));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,17 +35,22 @@
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";

@Autowired
private SourceDefinedMethodCallInlayHintSupplier supplier;

@Autowired
private LanguageServerConfiguration configuration;

@Test
void testDefaultInlayHints() {

Expand Down Expand Up @@ -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<InlayHint> 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**: ");
})
;
}


}
7 changes: 7 additions & 0 deletions src/test/resources/.partial-bsl-language-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"cyclomaticComplexity": false
}
},
"inlayHint": {
"parameters": {
"sourceDefinedMethodCall": {
"showParametersWithTheSameName": true
}
}
},
"diagnostics": {
"mode": "on"
}
Expand Down

0 comments on commit 884c97c

Please sign in to comment.