Search in sources :

Example 81 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class DiagnosticsConfiguration method diagnostics.

@Bean
@Scope("prototype")
public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {
    Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfos();
    DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
    if (needToComputeDiagnostics(documentContext, diagnosticsOptions)) {
        FileType fileType = documentContext.getFileType();
        CompatibilityMode compatibilityMode = documentContext.getServerContext().getConfiguration().getCompatibilityMode();
        ModuleType moduleType = documentContext.getModuleType();
        return diagnosticInfos.stream().filter(diagnosticInfo -> isEnabled(diagnosticInfo, diagnosticsOptions)).filter(info -> inScope(info, fileType)).filter(info -> correctModuleType(info, moduleType, fileType)).filter(info -> passedCompatibilityMode(info, compatibilityMode)).map(DiagnosticInfo::getDiagnosticClass).map(diagnosticObjectProvider::get).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
Also used : SupportConfiguration(com.github._1c_syntax.mdclasses.supportconf.SupportConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Scope(org.springframework.context.annotation.Scope) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) Map(java.util.Map) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Mode(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode) SupportVariant(com.github._1c_syntax.mdclasses.supportconf.SupportVariant) Collection(java.util.Collection) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) BSLDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) SkipSupport(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport) Lookup(org.springframework.beans.factory.annotation.Lookup) Bean(org.springframework.context.annotation.Bean) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) Comparator(java.util.Comparator) Collections(java.util.Collections) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Scope(org.springframework.context.annotation.Scope) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) Bean(org.springframework.context.annotation.Bean)

Example 82 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_NoComments.

@Test
void testFileVarContentFromDirectFile_NoComments() {
    // 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(2);
    assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Перем ИмяБезОписания\n" + "```\n" + "\n");
    assertThat(blocks.get(1)).matches("Переменная из file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl\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 83 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class VariableSymbolMarkupContentBuilderTest method testMethodVarContentFromDirectFile_3_comments_strings.

@Test
void testMethodVarContentFromDirectFile_3_comments_strings() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    final var symbolTree = documentContext.getSymbolTree();
    var methodSymbol = symbolTree.getMethodSymbol("ИмяФункции").orElseThrow();
    var varSymbol = symbolTree.getVariableSymbol("Имя_ОписаниеСверхуТриСтрокиПоследняяПустая_Функция", methodSymbol).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("описание 1 строка\n2 строка\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 84 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class CallHierarchyProviderTest method testPrepareHierarchyOnDeclaration.

@Test
void testPrepareHierarchyOnDeclaration() {
    // given
    var textDocument = new TextDocumentIdentifier(documentContext.getUri().toString());
    CallHierarchyPrepareParams params = new CallHierarchyPrepareParams();
    params.setTextDocument(textDocument);
    params.setPosition(firstProcedureDeclarationPosition);
    // 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 85 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class CallHierarchyProviderTest method testPrepareHierarchyLocalDeprecatedMethodCall.

@Test
void testPrepareHierarchyLocalDeprecatedMethodCall() {
    // given
    var textDocument = new TextDocumentIdentifier(documentContext.getUri().toString());
    CallHierarchyPrepareParams params = new CallHierarchyPrepareParams();
    params.setTextDocument(textDocument);
    params.setPosition(secondFunctionCallPosition);
    // 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().contains(SymbolTag.Deprecated));
}
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)

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