Search in sources :

Example 56 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class ValidatorTest method testMultilineDiagnostic.

@Test
public void testMultilineDiagnostic() {
    String model = "type Multiline_Demo {\n" + "}\n";
    writeFile("MyType1.testlang", model);
    initialize();
    List<Diagnostic> problems = problems();
    Assert.assertEquals("problems found:\n" + Joiner.on("\n").join(problems), 1, problems.size());
    Diagnostic problem = Iterables.getFirst(problems, null);
    assertEquals("Test Validation to mark the whole type", problem.getMessage());
    Assert.assertEquals(TestLanguageValidator.MULTILINE_PROBLEM, problem.getCode().get());
    Range range = problem.getRange();
    Assert.assertEquals(0, range.getStart().getLine());
    Assert.assertEquals(0, range.getStart().getCharacter());
    Assert.assertEquals(1, range.getEnd().getLine());
    Assert.assertEquals(1, range.getEnd().getCharacter());
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 57 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class CodeLensService method computeCodeLenses.

@Override
public List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, CancelIndicator indicator) {
    CodeLens codeLens = new CodeLens();
    Command command = new Command();
    command.setCommand("do.this");
    command.setTitle("Do Awesome Stuff");
    command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)));
    codeLens.setCommand(command);
    codeLens.setData(new Position(1, 2));
    codeLens.setRange(new Range(new Position(1, 1), new Position(1, 2)));
    return Lists.newArrayList(codeLens);
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 58 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class DocumentExtensions method newLocation.

public Location newLocation(Resource resource, ITextRegion textRegion) {
    Range range = newRange(resource, textRegion);
    if (range == null) {
        return null;
    }
    String uri = uriExtensions.toUriString(resource.getURI());
    return new Location(uri, range);
}
Also used : Range(org.eclipse.lsp4j.Range) Location(org.eclipse.lsp4j.Location)

Example 59 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class DocumentExtensions method newRange.

public Range newRange(Resource resource, int startOffset, int endOffset) {
    Position startPosition = newPosition(resource, startOffset);
    if (startPosition == null) {
        return null;
    }
    Position endPosition = newPosition(resource, endOffset);
    if (endPosition == null) {
        return null;
    }
    return new Range(startPosition, endPosition);
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 60 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class ChangeConverter2 method _handleReplacements.

protected void _handleReplacements(ITextDocumentChange change) {
    try {
        if (change.getReplacements().size() > 0) {
            String uri = uriExtensions.toUriString(change.getNewURI());
            access.doRead(uri, (ILanguageServerAccess.Context context) -> {
                Document document = context.getDocument();
                List<TextEdit> textEdits = Lists.transform(change.getReplacements(), (ITextReplacement replacement) -> {
                    Position start = document.getPosition(replacement.getOffset());
                    Position end = document.getPosition(replacement.getOffset() + replacement.getLength());
                    Range range = new Range(start, end);
                    return new TextEdit(range, replacement.getReplacementText());
                });
                return addTextEdit(uri, document, textEdits.toArray(new TextEdit[textEdits.size()]));
            }).get();
        }
    } catch (InterruptedException | ExecutionException e) {
        throw Exceptions.sneakyThrow(e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) TextEdit(org.eclipse.lsp4j.TextEdit) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.eclipse.xtext.ide.server.Document) Range(org.eclipse.lsp4j.Range) ExecutionException(java.util.concurrent.ExecutionException) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess)

Aggregations

Range (org.eclipse.lsp4j.Range)126 Position (org.eclipse.lsp4j.Position)59 Test (org.junit.Test)38 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)23 TextEdit (org.eclipse.lsp4j.TextEdit)23 ArrayList (java.util.ArrayList)22 List (java.util.List)17 Location (org.eclipse.lsp4j.Location)16 Document (org.eclipse.xtext.ide.server.Document)16 Diagnostic (org.eclipse.lsp4j.Diagnostic)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)13 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)12 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)12 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)9 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)9 Command (org.eclipse.lsp4j.Command)9 CompletionList (org.eclipse.lsp4j.CompletionList)9 RenameParams (org.eclipse.lsp4j.RenameParams)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)8