use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class JUnitReporterTest method report.
@Test
void report() throws IOException {
// given
List<Diagnostic> diagnostics = new ArrayList<>();
diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test"));
diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
diagnostics.add(new Diagnostic(Ranges.create(3, 1, 4, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
DocumentContext documentContext = TestUtils.getDocumentContext(Paths.get("./src/test/java/diagnostics/CanonicalSpellingKeywordsDiagnostic.bsl").toUri(), "");
String sourceDir = ".";
FileInfo fileInfo = new FileInfo(sourceDir, documentContext, diagnostics);
AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
DiagnosticReporter reporter = new JUnitReporter();
// when
reporter.report(analysisInfo, Path.of(sourceDir));
// then
ObjectMapper mapper = new XmlMapper();
JUnitTestSuites report = mapper.readValue(file, JUnitTestSuites.class);
assertThat(report).isNotNull();
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class CodeActionAssert method fixes.
public CodeActionAssert fixes(Diagnostic diagnostic) {
// check that actual value we want to make assertions on is not null.
isNotNull();
// saving original state
String cachedContent = documentContext.getContent();
// apply edits from quick fix
final List<TextEdit> textEdits = getTextEdits();
String[] contentList = documentContext.getContentList();
textEdits.forEach(textEdit -> {
final String newText = textEdit.getNewText();
final Range range = textEdit.getRange();
final Position start = range.getStart();
int startLine = 0;
int startChar = 0;
int endLine = start.getLine();
int endChar = 0;
if (start.getCharacter() > 0) {
endChar = start.getCharacter() - 1;
}
Range startRange = Ranges.create(startLine, startChar, endLine, endChar);
final String startText = documentContext.getText(startRange);
final Position end = range.getEnd();
startLine = end.getLine();
startChar = end.getCharacter();
endLine = contentList.length - 1;
endChar = max(contentList[endLine].length() - 1, 0);
Range endRange = Ranges.create(startLine, startChar, endLine, endChar);
final String endText = documentContext.getText(endRange);
// TODO: does not work for several textedits changing content length (missed semicolon ie.)
String content = startText + newText + endText;
documentContext.rebuild(content, documentContext.getVersion() + 1);
});
// get diagnostics from fixed document
final List<Diagnostic> diagnostics = bslDiagnostic.getDiagnostics(documentContext);
// check if expected diagnostic is not present in new diagnostic list
Assertions.assertThat(diagnostics).doesNotContain(diagnostic);
// returning to original state
documentContext.rebuild(cachedContent, documentContext.getVersion() + 1);
return this;
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class InvalidCharacterInFileDiagnostic method getQuickFixes.
@Override
public List<CodeAction> getQuickFixes(List<Diagnostic> diagnostics, CodeActionParams params, DocumentContext documentContext) {
List<TextEdit> textEdits = new ArrayList<>();
diagnostics.stream().filter(diagnostic -> diagnostic.getMessage().equals(diagnosticMessageSpace)).forEach((Diagnostic diagnostic) -> {
Range range = diagnostic.getRange();
TextEdit textEdit = new TextEdit(range, ILLEGAL_SPACE_PATTERN.matcher(documentContext.getText(range)).replaceAll(" "));
textEdits.add(textEdit);
});
diagnostics.stream().filter(diagnostic -> diagnostic.getMessage().equals(diagnosticMessageDash)).forEach((Diagnostic diagnostic) -> {
Range range = diagnostic.getRange();
TextEdit textEdit = new TextEdit(range, ILLEGAL_PATTERN.matcher(documentContext.getText(range)).replaceAll("-"));
textEdits.add(textEdit);
});
return CodeActionProvider.createCodeActions(textEdits, info.getResourceString("quickFixMessage"), documentContext.getUri(), diagnostics);
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics 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.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class TimeoutsInExternalResourcesDiagnosticTest method testCompatibilityMode836.
@SneakyThrows
@Test
void testCompatibilityMode836() {
// when
FileUtils.writeStringToFile(Paths.get(tempDir.toAbsolutePath().toString(), "Configuration.xml").toFile(), FileUtils.readFileToString(CONFIGURATION_FILE_PATH, StandardCharsets.UTF_8).replace("Version8_3_10", "Version8_3_6"), StandardCharsets.UTF_8);
Path testFile = Paths.get("./src/test/resources/diagnostics/TimeoutsInExternalResourcesDiagnostic836.bsl").toAbsolutePath();
initServerContext(tempDir.toAbsolutePath());
DocumentContext newDocumentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
List<Diagnostic> diagnostics = getDiagnostics(newDocumentContext);
// then
assertThat(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode()).isNotNull();
assertThat(CompatibilityMode.compareTo(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode(), DiagnosticCompatibilityMode.COMPATIBILITY_MODE_8_3_6.getCompatibilityMode())).isZero();
assertThat(diagnostics).hasSize(9);
// check ranges
assertThat(diagnostics, true).hasRange(3, 20, 3, 75).hasRange(5, 20, 5, 92).hasRange(9, 18, 9, 72).hasRange(13, 16, 13, 80).hasRange(21, 21, 21, 65).hasRange(34, 14, 34, 43).hasRange(71, 26, 71, 114).hasRange(78, 10, 78, 39).hasRange(80, 47, 80, 76);
}
Aggregations