use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.
the class LanguageServerImpl method publishDiagnostics.
private void publishDiagnostics(final URI uri, final Iterable<? extends Issue> issues) {
PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams();
final Procedure1<PublishDiagnosticsParams> _function = (PublishDiagnosticsParams it) -> {
it.setUri(this._uriExtensions.toUriString(uri));
final Function1<Issue, Boolean> _function_1 = (Issue it_1) -> {
Severity _severity = it_1.getSeverity();
return Boolean.valueOf((_severity != Severity.IGNORE));
};
final Function1<Issue, Diagnostic> _function_2 = (Issue it_1) -> {
return this.toDiagnostic(it_1);
};
it.setDiagnostics(IterableExtensions.<Diagnostic>toList(IterableExtensions.map(IterableExtensions.filter(issues, _function_1), _function_2)));
};
final PublishDiagnosticsParams diagnostics = ObjectExtensions.<PublishDiagnosticsParams>operator_doubleArrow(_publishDiagnosticsParams, _function);
this.client.publishDiagnostics(diagnostics);
}
use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.
the class LanguageServerImpl method toDiagnostic.
private Diagnostic toDiagnostic(final Issue issue) {
Diagnostic _diagnostic = new Diagnostic();
final Procedure1<Diagnostic> _function = (Diagnostic it) -> {
it.setCode(issue.getCode());
DiagnosticSeverity _switchResult = null;
Severity _severity = issue.getSeverity();
if (_severity != null) {
switch(_severity) {
case ERROR:
_switchResult = DiagnosticSeverity.Error;
break;
case WARNING:
_switchResult = DiagnosticSeverity.Warning;
break;
case INFO:
_switchResult = DiagnosticSeverity.Information;
break;
default:
_switchResult = DiagnosticSeverity.Hint;
break;
}
} else {
_switchResult = DiagnosticSeverity.Hint;
}
it.setSeverity(_switchResult);
it.setMessage(issue.getMessage());
Integer _elvis = null;
Integer _lineNumber = issue.getLineNumber();
if (_lineNumber != null) {
_elvis = _lineNumber;
} else {
_elvis = Integer.valueOf(1);
}
final int lineNumber = ((_elvis).intValue() - 1);
Integer _elvis_1 = null;
Integer _column = issue.getColumn();
if (_column != null) {
_elvis_1 = _column;
} else {
_elvis_1 = Integer.valueOf(1);
}
final int column = ((_elvis_1).intValue() - 1);
Integer _elvis_2 = null;
Integer _length = issue.getLength();
if (_length != null) {
_elvis_2 = _length;
} else {
_elvis_2 = Integer.valueOf(0);
}
final Integer length = _elvis_2;
Position _position = new Position(lineNumber, column);
Position _position_1 = new Position(lineNumber, (column + (length).intValue()));
Range _range = new Range(_position, _position_1);
it.setRange(_range);
};
return ObjectExtensions.<Diagnostic>operator_doubleArrow(_diagnostic, _function);
}
use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.
the class OpenDocumentTest method testDidChange.
@Test
public void testDidChange() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String firstFile = this.writeFile("MyType1.testlang", _builder);
this.initialize();
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Test {");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("NonExisting foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this.open(firstFile, _builder_1.toString());
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
DidChangeTextDocumentParams _didChangeTextDocumentParams = new DidChangeTextDocumentParams();
final Procedure1<DidChangeTextDocumentParams> _function = (DidChangeTextDocumentParams it) -> {
VersionedTextDocumentIdentifier _versionedTextDocumentIdentifier = new VersionedTextDocumentIdentifier();
final Procedure1<VersionedTextDocumentIdentifier> _function_1 = (VersionedTextDocumentIdentifier it_1) -> {
it_1.setUri(firstFile);
it_1.setVersion(2);
};
VersionedTextDocumentIdentifier _doubleArrow = ObjectExtensions.<VersionedTextDocumentIdentifier>operator_doubleArrow(_versionedTextDocumentIdentifier, _function_1);
it.setTextDocument(_doubleArrow);
TextDocumentContentChangeEvent _textDocumentContentChangeEvent = new TextDocumentContentChangeEvent();
final Procedure1<TextDocumentContentChangeEvent> _function_2 = (TextDocumentContentChangeEvent it_1) -> {
Position _position = new Position(1, 4);
Position _position_1 = new Position(1, 15);
Range _range = new Range(_position, _position_1);
it_1.setRange(_range);
it_1.setText("Test");
};
TextDocumentContentChangeEvent _doubleArrow_1 = ObjectExtensions.<TextDocumentContentChangeEvent>operator_doubleArrow(_textDocumentContentChangeEvent, _function_2);
it.setContentChanges(Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_doubleArrow_1)));
};
DidChangeTextDocumentParams _doubleArrow = ObjectExtensions.<DidChangeTextDocumentParams>operator_doubleArrow(_didChangeTextDocumentParams, _function);
this.languageServer.didChange(_doubleArrow);
Assert.assertNull(IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)));
}
use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.
the class ServerTest method testInitializeBuildWithError.
@Test
public void testInitializeBuildWithError() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.writeFile("MyType1.testlang", _builder);
this.initialize();
Diagnostic _head = IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()));
String _message = null;
if (_head != null) {
_message = _head.getMessage();
}
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", _message);
Assert.assertEquals(1, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getLine());
Assert.assertEquals(4, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getCharacter());
Assert.assertEquals(1, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getLine());
Assert.assertEquals(15, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getCharacter());
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method assertNewProblemReported.
private void assertNewProblemReported(ExpectedProblemReport... expectedReports) {
List<PublishDiagnosticsParams> diags = getClientRequests("publishDiagnostics");
assertEquals(expectedReports.length, diags.size());
for (int i = 0; i < expectedReports.length; i++) {
PublishDiagnosticsParams diag = diags.get(i);
ExpectedProblemReport expected = expectedReports[i];
assertEquals(JDTUtils.toURI(expected.cu), diag.getUri());
if (expected.problemCount != diag.getDiagnostics().size()) {
String message = "";
for (Diagnostic d : diag.getDiagnostics()) {
message += d.getMessage() + ", ";
}
assertEquals(message, expected.problemCount, diag.getDiagnostics().size());
}
}
diags.clear();
}
Aggregations