Search in sources :

Example 6 with Position

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

the class DocumentExtensions method newPosition.

public Position newPosition(final Resource resource, final int offset) {
    if ((resource instanceof XtextResource)) {
        final ICompositeNode rootNode = ((XtextResource) resource).getParseResult().getRootNode();
        final LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(rootNode, offset);
        int _line = lineAndColumn.getLine();
        int _minus = (_line - 1);
        int _column = lineAndColumn.getColumn();
        int _minus_1 = (_column - 1);
        return new Position(_minus, _minus_1);
    }
    return null;
}
Also used : Position(org.eclipse.lsp4j.Position) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) LineAndColumn(org.eclipse.xtext.util.LineAndColumn)

Example 7 with Position

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

the class ContentAssistService method toCompletionItem.

protected CompletionItem toCompletionItem(final ContentAssistEntry entry, final int caretOffset, final Position caretPosition, final Document document) {
    final CompletionItem completionItem = new CompletionItem();
    String _elvis = null;
    String _label = entry.getLabel();
    if (_label != null) {
        _elvis = _label;
    } else {
        String _proposal = entry.getProposal();
        _elvis = _proposal;
    }
    completionItem.setLabel(_elvis);
    completionItem.setDetail(entry.getDescription());
    completionItem.setDocumentation(entry.getDocumentation());
    String _elvis_1 = null;
    String _prefix = entry.getPrefix();
    if (_prefix != null) {
        _elvis_1 = _prefix;
    } else {
        _elvis_1 = "";
    }
    int _length = _elvis_1.length();
    final int prefixOffset = (caretOffset - _length);
    final Position prefixPosition = document.getPosition(prefixOffset);
    Range _range = new Range(prefixPosition, caretPosition);
    String _proposal_1 = entry.getProposal();
    TextEdit _textEdit = new TextEdit(_range, _proposal_1);
    completionItem.setTextEdit(_textEdit);
    completionItem.setKind(this.translateKind(entry));
    return completionItem;
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) Position(org.eclipse.lsp4j.Position) TextEdit(org.eclipse.lsp4j.TextEdit) Range(org.eclipse.lsp4j.Range)

Example 8 with Position

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

the class ContentAssistService method createCompletionList.

public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
    try {
        final CompletionList result = new CompletionList();
        result.setIsIncomplete(true);
        final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
        final int caretOffset = document.getOffSet(params.getPosition());
        final Position caretPosition = params.getPosition();
        final TextRegion position = new TextRegion(caretOffset, 0);
        try {
            this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
        } catch (final Throwable _t) {
            if (_t instanceof Throwable) {
                final Throwable t = (Throwable) _t;
                boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
                boolean _not = (!_isOperationCanceledException);
                if (_not) {
                    throw t;
                }
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
        final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
            final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
            item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
            List<CompletionItem> _items = result.getItems();
            _items.add(item);
        };
        IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) TextRegion(org.eclipse.xtext.util.TextRegion) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) CompletionList(org.eclipse.lsp4j.CompletionList) List(java.util.List) IdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)

Example 9 with Position

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

the class DocumentTest method position.

private Position position(final int l, final int c) {
    Position _position = new Position();
    final Procedure1<Position> _function = (Position it) -> {
        it.setLine(l);
        it.setCharacter(c);
    };
    return ObjectExtensions.<Position>operator_doubleArrow(_position, _function);
}
Also used : Position(org.eclipse.lsp4j.Position)

Example 10 with Position

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

the class RenameTest2 method testRenameContainer.

@Test
public void testRenameContainer() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("element Foo {");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("element Bar {");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("}");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("ref foo.Foo.Bar");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("ref Foo.Bar");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("ref Bar");
        _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, "Baz");
        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 : Baz [[2, 8] .. [2, 11]]");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("Bar [[5, 5] .. [5, 16]]");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("Bar [[6, 5] .. [6, 12]]");
        _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)

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