Search in sources :

Example 1 with CodeLens

use of org.eclipse.lsp4j.CodeLens 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 2 with CodeLens

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

the class AbstractLanguageServerTest method testCodeLens.

protected void testCodeLens(final Procedure1<? super AbstractLanguageServerTest.TestCodeLensConfiguration> configurator) {
    try {
        @Extension final AbstractLanguageServerTest.TestCodeLensConfiguration configuration = new AbstractLanguageServerTest.TestCodeLensConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CodeLensParams _codeLensParams = new CodeLensParams();
        final Procedure1<CodeLensParams> _function = (CodeLensParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
        };
        CodeLensParams _doubleArrow = ObjectExtensions.<CodeLensParams>operator_doubleArrow(_codeLensParams, _function);
        final CompletableFuture<List<? extends CodeLens>> codeLenses = this.languageServer.codeLens(_doubleArrow);
        final Function1<CodeLens, CodeLens> _function_1 = (CodeLens it) -> {
            try {
                return this.languageServer.resolveCodeLens(it).get();
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        final List<CodeLens> result = IterableExtensions.<CodeLens>toList(ListExtensions.map(codeLenses.get(), _function_1));
        if ((configuration.assertCodeLenses != null)) {
            configuration.assertCodeLenses.apply(result);
        } else {
            this.assertEquals(configuration.expectedCodeLensItems, this.toExpectation(result));
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 3 with CodeLens

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

the class LanguageServerImpl method resolveCodeLens.

@Override
public CompletableFuture<CodeLens> resolveCodeLens(final CodeLens unresolved) {
    final URI uri = this.uninstallURI(unresolved);
    if ((uri == null)) {
        return CompletableFuture.<CodeLens>completedFuture(unresolved);
    }
    final Function1<CancelIndicator, CodeLens> _function = (CancelIndicator cancelIndicator) -> {
        final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
        ICodeLensResolver _get = null;
        if (resourceServiceProvider != null) {
            _get = resourceServiceProvider.<ICodeLensResolver>get(ICodeLensResolver.class);
        }
        final ICodeLensResolver resolver = _get;
        if ((resolver == null)) {
            return unresolved;
        }
        final Function2<Document, XtextResource, CodeLens> _function_1 = (Document document, XtextResource resource) -> {
            final CodeLens result = resolver.resolveCodeLens(document, resource, unresolved, cancelIndicator);
            return result;
        };
        return this.workspaceManager.<CodeLens>doRead(uri, _function_1);
    };
    return this.requestManager.<CodeLens>runRead(_function);
}
Also used : ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) CodeLens(org.eclipse.lsp4j.CodeLens) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI)

Example 4 with CodeLens

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

the class LanguageServerImpl method installURI.

private void installURI(final List<? extends CodeLens> codeLenses, final String uri) {
    for (final CodeLens lens : codeLenses) {
        Object _data = lens.getData();
        boolean _tripleNotEquals = (_data != null);
        if (_tripleNotEquals) {
            lens.setData(CollectionLiterals.<Object>newArrayList(uri, lens.getData()));
        } else {
            lens.setData(uri);
        }
    }
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens)

Example 5 with CodeLens

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

the class CodeLensTest method testCodeLens.

@Test
public void testCodeLens() {
    final Procedure1<AbstractLanguageServerTest.TestCodeLensConfiguration> _function = (AbstractLanguageServerTest.TestCodeLensConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo {}");
        _builder.newLine();
        _builder.append("type Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Foo foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setModel(_builder.toString());
        final Procedure1<List<? extends CodeLens>> _function_1 = (List<? extends CodeLens> it_1) -> {
            this.assertEquals("Do Awesome Stuff(RESOLVED)", IterableExtensions.head(it_1).getCommand().getTitle());
            Object _data = IterableExtensions.head(it_1).getData();
            Assert.assertEquals(1, ((Position) _data).getLine());
        };
        it.setAssertCodeLenses(_function_1);
    };
    this.testCodeLens(_function);
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Aggregations

CodeLens (org.eclipse.lsp4j.CodeLens)5 List (java.util.List)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 URI (org.eclipse.emf.common.util.URI)1 CodeLensParams (org.eclipse.lsp4j.CodeLensParams)1 Command (org.eclipse.lsp4j.Command)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Position (org.eclipse.lsp4j.Position)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Document (org.eclipse.xtext.ide.server.Document)1 ICodeLensResolver (org.eclipse.xtext.ide.server.codelens.ICodeLensResolver)1 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 AbstractLanguageServerTest (org.eclipse.xtext.testing.AbstractLanguageServerTest)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)1 Test (org.junit.Test)1