Search in sources :

Example 11 with DocumentContext

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");
}
Also used : DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with DocumentContext

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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SymbolKind(org.eclipse.lsp4j.SymbolKind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) CallHierarchyIncomingCall(org.eclipse.lsp4j.CallHierarchyIncomingCall) Test(org.junit.jupiter.api.Test) SymbolTag(org.eclipse.lsp4j.SymbolTag) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CallHierarchyOutgoingCallsParams(org.eclipse.lsp4j.CallHierarchyOutgoingCallsParams) CallHierarchyOutgoingCall(org.eclipse.lsp4j.CallHierarchyOutgoingCall) Position(org.eclipse.lsp4j.Position) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) CallHierarchyIncomingCallsParams(org.eclipse.lsp4j.CallHierarchyIncomingCallsParams) CallHierarchyPrepareParams(org.eclipse.lsp4j.CallHierarchyPrepareParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CallHierarchyPrepareParams(org.eclipse.lsp4j.CallHierarchyPrepareParams) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with DocumentContext

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();
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) CodeAction(org.eclipse.lsp4j.CodeAction) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) CanonicalSpellingKeywordsDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.CanonicalSpellingKeywordsDiagnostic) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Command(org.eclipse.lsp4j.Command) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with DocumentContext

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);
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) CodeAction(org.eclipse.lsp4j.CodeAction) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) CanonicalSpellingKeywordsDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.CanonicalSpellingKeywordsDiagnostic) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Command(org.eclipse.lsp4j.Command) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Diagnostic(org.eclipse.lsp4j.Diagnostic) CanonicalSpellingKeywordsDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.CanonicalSpellingKeywordsDiagnostic) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with DocumentContext

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));
}
Also used : Position(org.eclipse.lsp4j.Position) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)86 Test (org.junit.jupiter.api.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)57 Diagnostic (org.eclipse.lsp4j.Diagnostic)36 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)21 SneakyThrows (lombok.SneakyThrows)17 Path (java.nio.file.Path)16 CodeAction (org.eclipse.lsp4j.CodeAction)16 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Collectors (java.util.stream.Collectors)14 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)12 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)12 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)11 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)10 MDCommonModule (com.github._1c_syntax.mdclasses.mdo.MDCommonModule)10