diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/CodeOutOfRegionDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/CodeOutOfRegionDiagnostic.java index f4f5b8dbe16..eaea745416b 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/CodeOutOfRegionDiagnostic.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/CodeOutOfRegionDiagnostic.java @@ -117,10 +117,7 @@ private void addChildrenToRelatedInformation( Integer... ruleIndex ) { Trees.getChildren(ctx, ruleIndex).stream() - .filter(node -> - node.getStart() != null - && node.getStop() != null - && (node.getStart().getLine() <= node.getStop().getLine())) // todo исправить костыль + .filter(node -> !node.getTokens().isEmpty()) .map(node -> RelatedInformation.create( documentContext.getUri(), diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/SmokyTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/SmokyTest.java index 64b92e2ed2f..b301987309b 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/SmokyTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/SmokyTest.java @@ -23,8 +23,18 @@ import com.ginsberg.junit.exit.ExpectSystemExitWithStatus; import com.github._1c_syntax.bsl.languageserver.BSLLSPLauncher; +import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration; +import com.github._1c_syntax.bsl.languageserver.providers.DiagnosticProvider; +import com.github._1c_syntax.bsl.languageserver.util.TestUtils; +import org.apache.commons.io.FileUtils; +import org.eclipse.lsp4j.Diagnostic; import org.junit.jupiter.api.Test; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import static org.assertj.core.api.Assertions.assertThat; public class SmokyTest { @@ -38,6 +48,33 @@ void test() { BSLLSPLauncher.main(args); assertThat(true).isTrue(); // TODO что проверять? + } + + @Test + void testIdenticalRanges() { + + var configuration = LanguageServerConfiguration.create(); + var diagnosticSupplier = new DiagnosticSupplier(configuration); + var srcDir = "./src/test/resources/"; + List diagnostics = new ArrayList<>(); + FileUtils.listFiles(Paths.get(srcDir).toAbsolutePath().toFile(), new String[]{"bsl", "os"}, true) + .forEach(filePath -> { + var documentContext = TestUtils.getDocumentContextFromFile(filePath.toString()); + var diagnosticProvider = new DiagnosticProvider(diagnosticSupplier); + diagnosticProvider.computeDiagnostics(documentContext).stream() + .filter(diagnostic -> + (diagnostic.getRange() != null + && diagnostic.getRange().getEnd().equals(diagnostic.getRange().getStart())) + || (diagnostic.getRelatedInformation() != null + && diagnostic.getRelatedInformation().stream() + .anyMatch(relation -> relation.getLocation() != null + && relation.getLocation().getRange() != null + && relation.getLocation().getRange().getEnd().equals(relation.getLocation().getRange().getStart()))) + ) + .collect(Collectors.toCollection(() -> diagnostics)); + }); + assertThat(diagnostics).isEmpty(); } + }