use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CommonModuleAssignDiagnosticTest method test.
@SneakyThrows
@Test
void test() {
Path path = Absolute.path(PATH_TO_METADATA);
initServerContext(path);
Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
DocumentContext documentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
List<Diagnostic> diagnostics = diagnosticInstance.getDiagnostics(documentContext);
assertThat(diagnostics).hasSize(1);
assertThat(diagnostics, true).hasRange(3, 0, 3, 17);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CommonModuleNameClientDiagnosticTest method getDocumentContextFromFile.
@SneakyThrows
void getDocumentContextFromFile() {
Path path = Absolute.path(PATH_TO_METADATA);
Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
initServerContext(path);
var configuration = context.getConfiguration();
documentContext = spy(TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context));
module = spy((MDCommonModule) configuration.getModulesByObject().get(documentContext.getUri()));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CanonicalSpellingKeywordsDiagnosticTest method testQuickFix.
@Test
void testQuickFix() {
final DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = getDiagnostics();
final Diagnostic firstDiagnostic = diagnostics.get(0);
List<CodeAction> quickFixes = getQuickFixes(firstDiagnostic);
assertThat(quickFixes).hasSize(1);
final CodeAction quickFix = quickFixes.get(0);
assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(firstDiagnostic);
assertThat(quickFix).in(documentContext).hasChanges(1);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DiagnosticsTest method testCompatibilityMode.
@Test
void testCompatibilityMode() {
// given
documentContext = spy(TestUtils.getDocumentContext(""));
var serverContext = spy(context);
var bslConfiguration = spy(serverContext.getConfiguration());
doReturn(serverContext).when(documentContext).getServerContext();
doReturn(bslConfiguration).when(serverContext).getConfiguration();
configuration.getDiagnosticsOptions().setMode(Mode.ON);
// when-then pairs
doReturn(new CompatibilityMode(3, 10)).when(bslConfiguration).getCompatibilityMode();
assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
doReturn(new CompatibilityMode(3, 6)).when(bslConfiguration).getCompatibilityMode();
assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
doReturn(new CompatibilityMode(2, 16)).when(bslConfiguration).getCompatibilityMode();
assertThat(diagnosticsConfiguration.diagnostics(documentContext)).noneMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class EmptyRegionDiagnosticTest method testQuickFix.
@Test
void testQuickFix() {
final DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = getDiagnostics();
final Diagnostic externalRegionDiagnostic = diagnostics.get(2);
final Diagnostic internalRegionDiagnostic = diagnostics.get(1);
List<CodeAction> quickFixes = getQuickFixes(externalRegionDiagnostic);
assertThat(quickFixes).hasSize(1);
final CodeAction quickFix = quickFixes.get(0);
assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(externalRegionDiagnostic);
assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(internalRegionDiagnostic);
assertThat(quickFix).in(documentContext).hasChanges(1).hasNewText("");
}
Aggregations