use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CodeActionProviderTest method testGetCodeActions.
@Test
void testGetCodeActions() {
// given
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(CanonicalSpellingKeywordsDiagnostic.class, configuration);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream().filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode)).peek(diagnostic -> diagnostic.setTags(null)).collect(Collectors.toList());
CodeActionParams params = new CodeActionParams();
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
CodeActionContext codeActionContext = new CodeActionContext();
codeActionContext.setDiagnostics(diagnostics);
params.setRange(new Range());
params.setTextDocument(textDocumentIdentifier);
params.setContext(codeActionContext);
// when
List<Either<Command, CodeAction>> codeActions = codeActionProvider.getCodeActions(params, documentContext);
// then
assertThat(codeActions).extracting(Either::getRight).hasSizeGreaterThanOrEqualTo(3).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()));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CodeLensProviderTest method testGetCodeLens.
@Test
void testGetCodeLens() {
// given
String filePath = "./src/test/resources/providers/codeLens.bsl";
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(filePath);
// when
List<CodeLens> codeLenses = codeLensProvider.getCodeLens(documentContext);
// then
Map<MethodSymbol, Integer> methodsCognitiveComplexity = documentContext.getCognitiveComplexityData().getMethodsComplexity();
Map<MethodSymbol, Integer> methodsCyclomaticComplexity = documentContext.getCyclomaticComplexityData().getMethodsComplexity();
MethodSymbol firstMethod = documentContext.getSymbolTree().getMethods().get(0);
MethodSymbol secondMethod = documentContext.getSymbolTree().getMethods().get(1);
int cognitiveComplexityFirstMethod = methodsCognitiveComplexity.get(firstMethod);
int cognitiveComplexitySecondMethod = methodsCognitiveComplexity.get(secondMethod);
int cyclomaticComplexityFirstMethod = methodsCyclomaticComplexity.get(firstMethod);
int cyclomaticComplexitySecondMethod = methodsCyclomaticComplexity.get(secondMethod);
assertThat(codeLenses).hasSize(4).anyMatch(codeLens -> codeLens.getRange().equals(firstMethod.getSubNameRange())).anyMatch(codeLens -> codeLens.getCommand().getTitle().contains(String.valueOf(cognitiveComplexityFirstMethod))).anyMatch(codeLens -> codeLens.getCommand().getTitle().contains(String.valueOf(cyclomaticComplexityFirstMethod))).anyMatch(codeLens -> codeLens.getRange().equals(secondMethod.getSubNameRange())).anyMatch(codeLens -> codeLens.getCommand().getTitle().contains(String.valueOf(cognitiveComplexitySecondMethod))).anyMatch(codeLens -> codeLens.getCommand().getTitle().contains(String.valueOf(cyclomaticComplexitySecondMethod)));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DefinitionProviderTest method testDefinitionOfCommonModule.
@Test
void testDefinitionOfCommonModule() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var managerModule = serverContext.getDocument("Catalog.Справочник1", ModuleType.ManagerModule).orElseThrow();
var methodSymbol = managerModule.getSymbolTree().getMethodSymbol("ТестЭкспортная").orElseThrow();
var params = new DefinitionParams();
params.setPosition(new Position(6, 30));
// when
var definitions = definitionProvider.getDefinition(documentContext, params);
// then
assertThat(definitions).hasSize(1);
var definition = definitions.get(0);
assertThat(definition.getTargetUri()).isEqualTo(managerModule.getUri().toString());
assertThat(definition.getTargetSelectionRange()).isEqualTo(methodSymbol.getSelectionRange());
assertThat(definition.getTargetRange()).isEqualTo(methodSymbol.getRange());
assertThat(definition.getOriginSelectionRange()).isEqualTo(Ranges.create(6, 24, 38));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DiagnosticProviderTest method testComputeDiagnostics.
@Test
void testComputeDiagnostics() {
// given
// TODO: это тест на новый getDiagnostics, а не на DiagnosticProvider
final DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/providers/diagnosticProvider.bsl");
// when
final List<Diagnostic> diagnostics = documentContext.getDiagnostics();
// then
assertThat(diagnostics.size()).isPositive();
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class ReferenceIndexFillerTest method testFindCalledMethod.
@Test
void testFindCalledMethod() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/ReferenceIndexFillerTest.bsl");
referenceIndexFiller.fill(documentContext);
// when
Optional<Reference> referencedSymbol = referenceIndex.getReference(documentContext.getUri(), new Position(4, 0));
// then
assertThat(referencedSymbol).isPresent();
assertThat(referencedSymbol).get().extracting(Reference::getSymbol).extracting(Symbol::getName).isEqualTo("Локальная");
assertThat(referencedSymbol).get().extracting(Reference::getSelectionRange).isEqualTo(Ranges.create(4, 0, 4, 9));
}
Aggregations