use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class VariableSymbolMarkupContentBuilderTest method testFileVarContentFromDirectFile_OneCommentsStringFromRight.
@Test
void testFileVarContentFromDirectFile_OneCommentsStringFromRight() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
final var symbolTree = documentContext.getSymbolTree();
var varSymbol = symbolTree.getVariableSymbol("Имя_ОписаниеСправаОднойСтрокой", symbolTree.getModule()).orElseThrow();
// when
var content = markupContentBuilder.getContent(varSymbol).getValue();
assertThat(content).isNotEmpty();
var blocks = Arrays.asList(content.split("---\n?"));
assertThat(blocks).hasSize(3);
assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Перем Имя_ОписаниеСправаОднойСтрокой\n" + "```\n" + "\n");
assertThat(blocks.get(1)).matches("Переменная из file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl\n" + "\n");
assertThat(blocks.get(2)).matches("описание\n" + "\n");
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CallHierarchyProviderTest method testPrepareHierarchyLocalMethodCall.
@Test
void testPrepareHierarchyLocalMethodCall() {
// given
var textDocument = new TextDocumentIdentifier(documentContext.getUri().toString());
CallHierarchyPrepareParams params = new CallHierarchyPrepareParams();
params.setTextDocument(textDocument);
params.setPosition(firstFunctionCallPosition);
// when
List<CallHierarchyItem> items = provider.prepareCallHierarchy(documentContext, params);
// then
assertThat(items).hasSize(1).allMatch(callHierarchyItem -> callHierarchyItem.getName().equals("ПерваяФункция")).allMatch(callHierarchyItem -> callHierarchyItem.getKind().equals(SymbolKind.Method)).allMatch(callHierarchyItem -> callHierarchyItem.getTags().isEmpty());
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CodeActionProviderTest method testEmptyDiagnosticList.
@Test
void testEmptyDiagnosticList() {
// given
CodeActionParams params = new CodeActionParams();
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
CodeActionContext codeActionContext = new CodeActionContext();
codeActionContext.setDiagnostics(Collections.emptyList());
params.setRange(new Range());
params.setTextDocument(textDocumentIdentifier);
params.setContext(codeActionContext);
// when
List<Either<Command, CodeAction>> codeActions = codeActionProvider.getCodeActions(params, documentContext);
// then
assertThat(codeActions).filteredOn(codeAction -> codeAction.getRight().getKind().equals(CodeActionKind.QuickFix)).isEmpty();
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CodeActionProviderTest method testOnly.
@Test
void testOnly() {
// given
CodeActionParams params = new CodeActionParams();
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(CanonicalSpellingKeywordsDiagnostic.class, configuration);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream().filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode)).collect(Collectors.toList());
CodeActionContext codeActionContext = new CodeActionContext();
codeActionContext.setOnly(List.of(CodeActionKind.Refactor));
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).extracting(CodeAction::getKind).containsOnly(CodeActionKind.Refactor);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DefinitionProviderTest method testDefinitionOfLocalMethod.
@Test
void testDefinitionOfLocalMethod() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var methodSymbol = documentContext.getSymbolTree().getMethodSymbol("ИмяФункции").orElseThrow();
var params = new DefinitionParams();
params.setPosition(new Position(4, 10));
// when
var definitions = definitionProvider.getDefinition(documentContext, params);
// then
assertThat(definitions).hasSize(1);
var definition = definitions.get(0);
assertThat(definition.getTargetUri()).isEqualTo(documentContext.getUri().toString());
assertThat(definition.getTargetSelectionRange()).isEqualTo(methodSymbol.getSelectionRange());
assertThat(definition.getTargetRange()).isEqualTo(methodSymbol.getRange());
assertThat(definition.getOriginSelectionRange()).isEqualTo(Ranges.create(4, 0, 10));
}
Aggregations