Search in sources :

Example 11 with Position

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

the class RenameTest2 method testRenameSelfRef.

@Test
public void testRenameSelfRef() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("element Foo {");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("ref Foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String model = _builder.toString();
        final String file = this.writeFile("foo/Foo.fileawaretestlanguage", model);
        this.initialize();
        TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(file);
        Position _position = new Position(2, 9);
        final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Bar");
        final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("changes :");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("Foo.fileawaretestlanguage : Bar [[2, 8] .. [2, 11]]");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("Bar [[3, 5] .. [3, 8]]");
        _builder_1.newLine();
        _builder_1.append("documentChanges : ");
        _builder_1.newLine();
        this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) RenameParams(org.eclipse.lsp4j.RenameParams) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 12 with Position

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

the class UnknownProjectConfigTest method checkCompletion.

protected void checkCompletion(final String uri) {
    try {
        TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
        final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
            it.setTextDocument(_textDocumentIdentifier);
            Position _position = new Position(0, 10);
            it.setPosition(_position);
        };
        TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
        final CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = this.languageServer.completion(_doubleArrow);
        final Either<List<CompletionItem>, CompletionList> result = completionItems.get();
        List<CompletionItem> _xifexpression = null;
        boolean _isLeft = result.isLeft();
        if (_isLeft) {
            _xifexpression = result.getLeft();
        } else {
            _xifexpression = result.getRight().getItems();
        }
        final List<CompletionItem> items = _xifexpression;
        final String actualCompletionItems = this.toExpectation(items);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("boolean -> boolean [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("int -> int [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("op -> op [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("string -> string [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("void -> void [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("} -> } [[0, 10] .. [0, 10]]");
        _builder.newLine();
        _builder.append("{ -> { [[0, 9] .. [0, 10]]");
        _builder.newLine();
        final String expectedCompletionItems = _builder.toString();
        this.assertEquals(expectedCompletionItems, actualCompletionItems);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 13 with Position

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

the class CodeActionService method recordWorkspaceEdit.

private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
    try {
        final XtextResourceSet rs = new XtextResourceSet();
        final Resource copy = rs.createResource(resource.getURI());
        String _text = resource.getParseResult().getRootNode().getText();
        StringInputStream _stringInputStream = new StringInputStream(_text);
        copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
        this.serializer.<Resource>addModification(copy, mod);
        final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
        this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
            Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
            for (final ITextDocumentChange documentchange : _filter) {
                {
                    final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
                        TextEdit _textEdit = new TextEdit();
                        final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
                            it_1.setNewText(replacement.getReplacementText());
                            Position _position = doc.getPosition(replacement.getOffset());
                            Position _position_1 = doc.getPosition(replacement.getEndOffset());
                            Range _range = new Range(_position, _position_1);
                            it_1.setRange(_range);
                        };
                        return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
                    };
                    final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
                    it.getChanges().put(documentchange.getNewURI().toString(), edits);
                }
            }
        };
        return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) Range(org.eclipse.lsp4j.Range) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange)

Example 14 with Position

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

the class CodeLensService method computeCodeLenses.

@Override
public List<? extends CodeLens> computeCodeLenses(final Document document, final XtextResource resource, final CodeLensParams params, final CancelIndicator indicator) {
    CodeLens _codeLens = new CodeLens();
    final Procedure1<CodeLens> _function = (CodeLens it) -> {
        Command _command = new Command();
        final Procedure1<Command> _function_1 = (Command it_1) -> {
            it_1.setCommand("do.this");
            it_1.setTitle("Do Awesome Stuff");
            it_1.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true))));
        };
        Command _doubleArrow = ObjectExtensions.<Command>operator_doubleArrow(_command, _function_1);
        it.setCommand(_doubleArrow);
        Position _position = new Position(1, 2);
        it.setData(_position);
    };
    CodeLens _doubleArrow = ObjectExtensions.<CodeLens>operator_doubleArrow(_codeLens, _function);
    return Collections.<CodeLens>unmodifiableList(CollectionLiterals.<CodeLens>newArrayList(_doubleArrow));
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) Position(org.eclipse.lsp4j.Position) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1)

Example 15 with Position

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

the class PositionComparatorTest method withNull.

@Test
public void withNull() {
    Position _position = new Position(2, 2);
    Position _position_1 = new Position(1, 1);
    final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, null, _position_1));
    Assert.assertEquals(1, input.get(0).getLine());
    Assert.assertEquals(1, input.get(0).getCharacter());
    Assert.assertEquals(2, input.get(1).getLine());
    Assert.assertEquals(2, input.get(1).getCharacter());
    Assert.assertNull(IterableExtensions.last(input));
}
Also used : Position(org.eclipse.lsp4j.Position) Test(org.junit.Test)

Aggregations

Position (org.eclipse.lsp4j.Position)37 Range (org.eclipse.lsp4j.Range)18 Test (org.junit.Test)10 List (java.util.List)9 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 CompletionList (org.eclipse.lsp4j.CompletionList)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)6 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)6 Extension (org.eclipse.xtext.xbase.lib.Extension)6 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)4 Diagnostic (org.eclipse.lsp4j.Diagnostic)4 Location (org.eclipse.lsp4j.Location)4 TextEdit (org.eclipse.lsp4j.TextEdit)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 StringReader (java.io.StringReader)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 Path (java.nio.file.Path)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2