Search in sources :

Example 11 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class LanguageServerImpl method initialize.

@Override
public CompletableFuture<InitializeResult> initialize(final InitializeParams params) {
    if ((this.params != null)) {
        throw new IllegalStateException("This language server has already been initialized.");
    }
    final URI baseDir = this.getBaseDir(params);
    boolean _isEmpty = this.languagesRegistry.getExtensionToFactoryMap().isEmpty();
    if (_isEmpty) {
        throw new IllegalStateException("No Xtext languages have been registered. Please make sure you have added the languages\'s setup class in \'/META-INF/services/org.eclipse.xtext.ISetup\'");
    }
    this.params = params;
    final InitializeResult result = new InitializeResult();
    ServerCapabilities _serverCapabilities = new ServerCapabilities();
    final Procedure1<ServerCapabilities> _function = (ServerCapabilities it) -> {
        it.setHoverProvider(Boolean.valueOf(true));
        it.setDefinitionProvider(Boolean.valueOf(true));
        it.setReferencesProvider(Boolean.valueOf(true));
        it.setDocumentSymbolProvider(Boolean.valueOf(true));
        it.setWorkspaceSymbolProvider(Boolean.valueOf(true));
        final Function1<IResourceServiceProvider, Boolean> _function_1 = (IResourceServiceProvider it_1) -> {
            ICodeLensService _get = it_1.<ICodeLensService>get(ICodeLensService.class);
            return Boolean.valueOf((_get != null));
        };
        boolean _exists = IterableExtensions.exists(this.getAllLanguages(), _function_1);
        if (_exists) {
            CodeLensOptions _codeLensOptions = new CodeLensOptions();
            final Procedure1<CodeLensOptions> _function_2 = (CodeLensOptions it_1) -> {
                final Function1<IResourceServiceProvider, Boolean> _function_3 = (IResourceServiceProvider it_2) -> {
                    ICodeLensResolver _get = it_2.<ICodeLensResolver>get(ICodeLensResolver.class);
                    return Boolean.valueOf((_get != null));
                };
                it_1.setResolveProvider(IterableExtensions.exists(this.getAllLanguages(), _function_3));
            };
            CodeLensOptions _doubleArrow = ObjectExtensions.<CodeLensOptions>operator_doubleArrow(_codeLensOptions, _function_2);
            it.setCodeLensProvider(_doubleArrow);
        }
        final Function1<IResourceServiceProvider, Boolean> _function_3 = (IResourceServiceProvider it_1) -> {
            ICodeActionService _get = it_1.<ICodeActionService>get(ICodeActionService.class);
            return Boolean.valueOf((_get != null));
        };
        it.setCodeActionProvider(Boolean.valueOf(IterableExtensions.exists(this.getAllLanguages(), _function_3)));
        SignatureHelpOptions _signatureHelpOptions = new SignatureHelpOptions(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("(", ",")));
        it.setSignatureHelpProvider(_signatureHelpOptions);
        it.setTextDocumentSync(TextDocumentSyncKind.Incremental);
        CompletionOptions _completionOptions = new CompletionOptions();
        final Procedure1<CompletionOptions> _function_4 = (CompletionOptions it_1) -> {
            it_1.setResolveProvider(Boolean.valueOf(false));
            it_1.setTriggerCharacters(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(".")));
        };
        CompletionOptions _doubleArrow_1 = ObjectExtensions.<CompletionOptions>operator_doubleArrow(_completionOptions, _function_4);
        it.setCompletionProvider(_doubleArrow_1);
        it.setDocumentFormattingProvider(Boolean.valueOf(true));
        it.setDocumentRangeFormattingProvider(Boolean.valueOf(true));
        it.setDocumentHighlightProvider(Boolean.valueOf(true));
        final Function1<IResourceServiceProvider, Boolean> _function_5 = (IResourceServiceProvider it_1) -> {
            IRenameService _get = it_1.<IRenameService>get(IRenameService.class);
            return Boolean.valueOf((_get != null));
        };
        it.setRenameProvider(Boolean.valueOf(IterableExtensions.exists(this.getAllLanguages(), _function_5)));
        ClientCapabilities _capabilities = params.getCapabilities();
        WorkspaceClientCapabilities _workspace = null;
        if (_capabilities != null) {
            _workspace = _capabilities.getWorkspace();
        }
        ExecuteCommandCapabilities _executeCommand = null;
        if (_workspace != null) {
            _executeCommand = _workspace.getExecuteCommand();
        }
        boolean _tripleNotEquals = (_executeCommand != null);
        if (_tripleNotEquals) {
            this.commandRegistry.initialize(this.getAllLanguages(), params.getCapabilities(), this.client);
            ExecuteCommandOptions _executeCommandOptions = new ExecuteCommandOptions();
            final Procedure1<ExecuteCommandOptions> _function_6 = (ExecuteCommandOptions it_1) -> {
                it_1.setCommands(this.commandRegistry.getCommands());
            };
            ExecuteCommandOptions _doubleArrow_2 = ObjectExtensions.<ExecuteCommandOptions>operator_doubleArrow(_executeCommandOptions, _function_6);
            it.setExecuteCommandProvider(_doubleArrow_2);
        }
    };
    ServerCapabilities capabilities = ObjectExtensions.<ServerCapabilities>operator_doubleArrow(_serverCapabilities, _function);
    Iterable<? extends IResourceServiceProvider> _allLanguages = this.getAllLanguages();
    for (final IResourceServiceProvider language : _allLanguages) {
        ICapabilitiesContributor _get = language.<ICapabilitiesContributor>get(ICapabilitiesContributor.class);
        if (_get != null) {
            _get.contribute(capabilities, params);
        }
    }
    result.setCapabilities(capabilities);
    this.access.addBuildListener(this);
    final Function0<Object> _function_1 = () -> {
        final Procedure2<URI, Iterable<Issue>> _function_2 = (URI $0, Iterable<Issue> $1) -> {
            this.publishDiagnostics($0, $1);
        };
        this.workspaceManager.initialize(baseDir, _function_2, CancelIndicator.NullImpl);
        return null;
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
        return null;
    };
    final Function<Object, InitializeResult> _function_3 = (Object it) -> {
        return result;
    };
    return this.requestManager.<Object, Object>runWrite(_function_1, _function_2).<InitializeResult>thenApply(_function_3);
}
Also used : ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) Issue(org.eclipse.xtext.validation.Issue) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ICapabilitiesContributor(org.eclipse.xtext.ide.server.ICapabilitiesContributor) ICodeActionService(org.eclipse.xtext.ide.server.codeActions.ICodeActionService) URI(org.eclipse.emf.common.util.URI) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IRenameService(org.eclipse.xtext.ide.server.rename.IRenameService) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) InitializeResult(org.eclipse.lsp4j.InitializeResult) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) ICodeLensService(org.eclipse.xtext.ide.server.codelens.ICodeLensService)

Example 12 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class LanguageServerImpl method didChangeWatchedFiles.

@Override
public void didChangeWatchedFiles(final DidChangeWatchedFilesParams params) {
    final Function0<BuildManager.Buildable> _function = () -> {
        BuildManager.Buildable _xblockexpression = null;
        {
            final ArrayList<URI> dirtyFiles = CollectionLiterals.<URI>newArrayList();
            final ArrayList<URI> deletedFiles = CollectionLiterals.<URI>newArrayList();
            List<FileEvent> _changes = params.getChanges();
            for (final FileEvent fileEvent : _changes) {
                FileChangeType _type = fileEvent.getType();
                boolean _tripleEquals = (_type == FileChangeType.Deleted);
                if (_tripleEquals) {
                    URI _uri = this._uriExtensions.toUri(fileEvent.getUri());
                    deletedFiles.add(_uri);
                } else {
                    URI _uri_1 = this._uriExtensions.toUri(fileEvent.getUri());
                    dirtyFiles.add(_uri_1);
                }
            }
            _xblockexpression = this.workspaceManager.didChangeFiles(dirtyFiles, deletedFiles);
        }
        return _xblockexpression;
    };
    final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
        return buildable.build(cancelIndicator);
    };
    this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FileChangeType(org.eclipse.lsp4j.FileChangeType) URI(org.eclipse.emf.common.util.URI) FileEvent(org.eclipse.lsp4j.FileEvent) BuildManager(org.eclipse.xtext.ide.server.BuildManager) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 13 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator 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 14 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class AbstractLanguageServerTest method getServerModule.

protected com.google.inject.Module getServerModule() {
    ServerModule _serverModule = new ServerModule();
    final com.google.inject.Module _function = (Binder it) -> {
        AnnotatedBindingBuilder<RequestManager> _bind = it.<RequestManager>bind(RequestManager.class);
        _bind.toInstance(new RequestManager() {

            @Override
            public <V extends Object> CompletableFuture<V> runRead(final Function1<? super CancelIndicator, ? extends V> request) {
                final CompletableFuture<V> result = new CompletableFuture<V>();
                try {
                    final CancelIndicator _function = () -> {
                        return false;
                    };
                    result.complete(request.apply(_function));
                } catch (final Throwable _t) {
                    if (_t instanceof Throwable) {
                        final Throwable e = (Throwable) _t;
                        result.completeExceptionally(e);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                return result;
            }

            @Override
            public <U extends Object, V extends Object> CompletableFuture<V> runWrite(final Function0<? extends U> nonCancellable, final Function2<? super CancelIndicator, ? super U, ? extends V> request) {
                final CompletableFuture<V> result = new CompletableFuture<V>();
                try {
                    final CancelIndicator _function = () -> {
                        return false;
                    };
                    result.complete(request.apply(_function, nonCancellable.apply()));
                } catch (final Throwable _t) {
                    if (_t instanceof Throwable) {
                        final Throwable e = (Throwable) _t;
                        result.completeExceptionally(e);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                return result;
            }
        });
    };
    return Modules2.mixin(_serverModule, _function);
}
Also used : Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Function0(org.eclipse.xtext.xbase.lib.Functions.Function0) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) ServerModule(org.eclipse.xtext.ide.server.ServerModule) Binder(com.google.inject.Binder) AnnotatedBindingBuilder(com.google.inject.binder.AnnotatedBindingBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 15 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class RequestManagerTest method testCancelRead.

@Test(timeout = 1000)
public void testCancelRead() {
    try {
        final AtomicBoolean isCanceled = new AtomicBoolean(false);
        final Function1<CancelIndicator, Object> _function = (CancelIndicator cancelIndicator) -> {
            try {
                try {
                    this.sharedState.incrementAndGet();
                    while ((!cancelIndicator.isCanceled())) {
                        Thread.sleep(10);
                    }
                } finally {
                    isCanceled.set(true);
                }
                return null;
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function);
        while ((this.sharedState.get() == 0)) {
            Thread.sleep(10);
        }
        future.cancel(true);
        while ((!isCanceled.get())) {
            Thread.sleep(10);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Test(org.junit.Test)

Aggregations

CancelIndicator (org.eclipse.xtext.util.CancelIndicator)18 URI (org.eclipse.emf.common.util.URI)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 BuildManager (org.eclipse.xtext.ide.server.BuildManager)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 ICodeLensResolver (org.eclipse.xtext.ide.server.codelens.ICodeLensResolver)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)2 Binder (com.google.inject.Binder)1 AnnotatedBindingBuilder (com.google.inject.binder.AnnotatedBindingBuilder)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1