Search in sources :

Example 41 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.

the class CompletionHandlerTest method testCompletion_setter.

@Test
public void testCompletion_setter() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + "    private String strField;\n" + "    set" + "}\n");
    int[] loc = findCompletionLocation(unit, "set");
    CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
    assertNotNull(list);
    CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("setStrField(String strField) : void")).findFirst().orElse(null);
    assertNotNull(ci);
    assertEquals("setStrField", ci.getInsertText());
    assertEquals(CompletionItemKind.Function, ci.getKind());
    assertEquals("999999979", ci.getSortText());
    assertNull(ci.getTextEdit());
    CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
    assertNotNull(resolvedItem.getTextEdit());
    assertTextEdit(2, 4, 7, "/**\n" + " * @param strField the strField to set\n" + " */\n" + "public void setStrField(String strField) {\n" + "	this.strField = strField;\n" + "}", resolvedItem.getTextEdit());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompletionList(org.eclipse.lsp4j.CompletionList) CompletionItem(org.eclipse.lsp4j.CompletionItem) Test(org.junit.Test)

Example 42 with CompletionList

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

the class AbstractLanguageServerTest method testCompletion.

protected void testCompletion(final Procedure1<? super TestCompletionConfiguration> configurator) {
    try {
        @Extension final TestCompletionConfiguration configuration = new TestCompletionConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CompletionParams _completionParams = new CompletionParams();
        final Procedure1<CompletionParams> _function = (CompletionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        CompletionParams _doubleArrow = ObjectExtensions.<CompletionParams>operator_doubleArrow(_completionParams, _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 Function1<CompletionItem, String> _function_1 = (CompletionItem it) -> {
            return it.getSortText();
        };
        Assert.assertEquals(items, IterableExtensions.<CompletionItem>toList(IterableExtensions.<CompletionItem, String>sortBy(items, _function_1)));
        Procedure1<? super CompletionList> _assertCompletionList = configuration.getAssertCompletionList();
        boolean _tripleNotEquals = (_assertCompletionList != null);
        if (_tripleNotEquals) {
            configuration.getAssertCompletionList().apply(result.getRight());
        } else {
            final String actualCompletionItems = this.toExpectation(items);
            this.assertEquals(configuration.getExpectedCompletionItems(), actualCompletionItems);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) CompletionParams(org.eclipse.lsp4j.CompletionParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 43 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project sts4 by spring-projects.

the class Editor method getCompletions.

public List<CompletionItem> getCompletions() throws Exception {
    CompletionList cl = harness.getCompletions(this.doc, this.getCursor());
    ArrayList<CompletionItem> items = new ArrayList<>(cl.getItems());
    Collections.sort(items, new Comparator<CompletionItem>() {

        @Override
        public int compare(CompletionItem o1, CompletionItem o2) {
            return sortKey(o1).compareTo(sortKey(o2));
        }

        private String sortKey(CompletionItem item) {
            String k = item.getSortText();
            if (k == null) {
                k = item.getLabel();
            }
            return k;
        }
    });
    return items;
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 44 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project sts4 by spring-projects.

the class LanguageServerHarness method getCompletions.

public CompletionList getCompletions(TextDocumentInfo doc, Position cursor) throws Exception {
    TextDocumentPositionParams params = new TextDocumentPositionParams();
    params.setPosition(cursor);
    params.setTextDocument(doc.getId());
    waitForReconcile();
    Either<List<CompletionItem>, CompletionList> completions = getServer().getTextDocumentService().completion(params).get();
    if (completions.isLeft()) {
        List<CompletionItem> list = completions.getLeft();
        return new CompletionList(false, list);
    } else /* sompletions.isRight() */
    {
        return completions.getRight();
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Aggregations

CompletionList (org.eclipse.lsp4j.CompletionList)44 CompletionItem (org.eclipse.lsp4j.CompletionItem)36 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)33 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)11 TextEdit (org.eclipse.lsp4j.TextEdit)11 List (java.util.List)10 Lsp4jAssertions.assertTextEdit (org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertTextEdit)10 Range (org.eclipse.lsp4j.Range)9 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)7 Map (java.util.Map)6 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)6 Collections (java.util.Collections)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Path (org.eclipse.core.runtime.Path)5 IJavaProject (org.eclipse.jdt.core.IJavaProject)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)5 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)5 DidChangeTextDocumentParams (org.eclipse.lsp4j.DidChangeTextDocumentParams)5 Comparator (java.util.Comparator)4