Search in sources :

Example 36 with Diagnostic

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);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Severity(org.eclipse.xtext.diagnostics.Severity)

Example 37 with Diagnostic

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);
}
Also used : DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Severity(org.eclipse.xtext.diagnostics.Severity) Range(org.eclipse.lsp4j.Range)

Example 38 with Diagnostic

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)));
}
Also used : DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 39 with Diagnostic

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());
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Diagnostic(org.eclipse.lsp4j.Diagnostic) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 40 with Diagnostic

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();
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Aggregations

Diagnostic (org.eclipse.lsp4j.Diagnostic)56 Test (org.junit.Test)31 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)22 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)11 List (java.util.List)8 Position (org.eclipse.lsp4j.Position)8 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)7 URI (java.net.URI)5 Path (java.nio.file.Path)5 Map (java.util.Map)5 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)5 Command (org.eclipse.lsp4j.Command)5 MarkedString (org.eclipse.lsp4j.MarkedString)5 CodeAction (org.springframework.ide.vscode.languageserver.testharness.CodeAction)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3