Search in sources :

Example 1 with LanguageClientExtensions

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

the class LanguageServerImpl method afterBuild.

@Override
public void afterBuild(final List<IResourceDescription.Delta> deltas) {
    if ((this.client instanceof LanguageClientExtensions)) {
        final Function1<IResourceDescription.Delta, Boolean> _function = (IResourceDescription.Delta it) -> {
            IResourceDescription _new = it.getNew();
            return Boolean.valueOf((_new != null));
        };
        final Function1<IResourceDescription.Delta, String> _function_1 = (IResourceDescription.Delta it) -> {
            return it.getUri().toString();
        };
        final Consumer<String> _function_2 = (String it) -> {
            final Function<ILanguageServerAccess.Context, Void> _function_3 = (ILanguageServerAccess.Context ctx) -> {
                boolean _isDocumentOpen = ctx.isDocumentOpen();
                if (_isDocumentOpen) {
                    Resource _resource = ctx.getResource();
                    if ((_resource instanceof XtextResource)) {
                        Resource _resource_1 = ctx.getResource();
                        final XtextResource resource = ((XtextResource) _resource_1);
                        final IResourceServiceProvider serviceProvider = this.languagesRegistry.getResourceServiceProvider(resource.getURI());
                        IColoringService _get = null;
                        if (serviceProvider != null) {
                            _get = serviceProvider.<IColoringService>get(IColoringService.class);
                        }
                        final IColoringService coloringService = _get;
                        if ((coloringService != null)) {
                            final Document doc = ctx.getDocument();
                            final List<? extends ColoringInformation> coloringInfos = coloringService.getColoring(resource, doc);
                            boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(coloringInfos);
                            boolean _not = (!_isNullOrEmpty);
                            if (_not) {
                                final String uri = resource.getURI().toString();
                                ColoringParams _coloringParams = new ColoringParams(uri, coloringInfos);
                                ((LanguageClientExtensions) this.client).updateColoring(_coloringParams);
                            }
                        }
                    }
                    return null;
                }
                return null;
            };
            this.access.<Void>doRead(it, _function_3);
        };
        IterableExtensions.<IResourceDescription.Delta, String>map(IterableExtensions.<IResourceDescription.Delta>filter(deltas, _function), _function_1).forEach(_function_2);
    }
}
Also used : LanguageClientExtensions(org.eclipse.lsp4j.services.LanguageClientExtensions) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextResource(org.eclipse.xtext.resource.XtextResource) ColoringParams(org.eclipse.lsp4j.ColoringParams) Document(org.eclipse.xtext.ide.server.Document) Function(java.util.function.Function) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IColoringService(org.eclipse.xtext.ide.server.coloring.IColoringService) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess)

Example 2 with LanguageClientExtensions

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

the class AbstractLanguageServerTest method setup.

@Before
public void setup() {
    try {
        final Injector injector = Guice.createInjector(this.getServerModule());
        injector.injectMembers(this);
        final Object resourceServiceProvider = this.resourceServerProviderRegistry.getExtensionToFactoryMap().get(this.fileExtension);
        if ((resourceServiceProvider instanceof IResourceServiceProvider)) {
            this.languageInfo = ((IResourceServiceProvider) resourceServiceProvider).<LanguageInfo>get(LanguageInfo.class);
        }
        this.languageServer.connect(ServiceEndpoints.<LanguageClientExtensions>toServiceObject(this, LanguageClientExtensions.class));
        this.languageServer.supportedMethods();
        File _absoluteFile = new File("").getAbsoluteFile();
        File _file = new File(_absoluteFile, "/test-data/test-project");
        this.root = _file;
        boolean _mkdirs = this.root.mkdirs();
        boolean _not = (!_mkdirs);
        if (_not) {
            Files.cleanFolder(this.root, null, true, false);
        }
        this.root.deleteOnExit();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : LanguageInfo(org.eclipse.xtext.LanguageInfo) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) LanguageClientExtensions(org.eclipse.lsp4j.services.LanguageClientExtensions) Injector(com.google.inject.Injector) File(java.io.File) Before(org.junit.Before)

Aggregations

LanguageClientExtensions (org.eclipse.lsp4j.services.LanguageClientExtensions)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 Injector (com.google.inject.Injector)1 File (java.io.File)1 Function (java.util.function.Function)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ColoringParams (org.eclipse.lsp4j.ColoringParams)1 LanguageInfo (org.eclipse.xtext.LanguageInfo)1 Document (org.eclipse.xtext.ide.server.Document)1 ILanguageServerAccess (org.eclipse.xtext.ide.server.ILanguageServerAccess)1 IColoringService (org.eclipse.xtext.ide.server.coloring.IColoringService)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 Before (org.junit.Before)1