Search in sources :

Example 1 with ILanguageServerExtension

use of org.eclipse.xtext.ide.server.ILanguageServerExtension in project xtext-core by eclipse.

the class LanguageServerImpl method supportedMethods.

@Override
public Map<String, JsonRpcMethod> supportedMethods() {
    if ((this.supportedMethods != null)) {
        return this.supportedMethods;
    }
    synchronized (this.extensionProviders) {
        final LinkedHashMap<String, JsonRpcMethod> supportedMethods = CollectionLiterals.<String, JsonRpcMethod>newLinkedHashMap();
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(this.getClass()));
        final LinkedHashMap<String, JsonRpcMethod> extensions = CollectionLiterals.<String, JsonRpcMethod>newLinkedHashMap();
        Iterable<IResourceServiceProvider> _filter = Iterables.<IResourceServiceProvider>filter(IterableExtensions.<Object>toSet(this.languagesRegistry.getExtensionToFactoryMap().values()), IResourceServiceProvider.class);
        for (final IResourceServiceProvider resourceServiceProvider : _filter) {
            {
                final ILanguageServerExtension ext = resourceServiceProvider.<ILanguageServerExtension>get(ILanguageServerExtension.class);
                if ((ext != null)) {
                    ext.initialize(this.access);
                    Map<String, JsonRpcMethod> _xifexpression = null;
                    if ((ext instanceof JsonRpcMethodProvider)) {
                        _xifexpression = ((JsonRpcMethodProvider) ext).supportedMethods();
                    } else {
                        _xifexpression = ServiceEndpoints.getSupportedMethods(ext.getClass());
                    }
                    final Map<String, JsonRpcMethod> supportedExtensions = _xifexpression;
                    Set<Map.Entry<String, JsonRpcMethod>> _entrySet = supportedExtensions.entrySet();
                    for (final Map.Entry<String, JsonRpcMethod> entry : _entrySet) {
                        boolean _containsKey = supportedMethods.containsKey(entry.getKey());
                        if (_containsKey) {
                            String _key = entry.getKey();
                            String _plus = ("The json rpc method \'" + _key);
                            String _plus_1 = (_plus + "\' can not be an extension as it is already defined in the LSP standard.");
                            LanguageServerImpl.LOG.error(_plus_1);
                        } else {
                            final JsonRpcMethod existing = extensions.put(entry.getKey(), entry.getValue());
                            if (((existing != null) && (!Objects.equal(existing, entry.getValue())))) {
                                String _key_1 = entry.getKey();
                                String _plus_2 = ("An incompatible LSP extension \'" + _key_1);
                                String _plus_3 = (_plus_2 + "\' has already been registered. Using 1 ignoring 2. \n1 : ");
                                String _plus_4 = (_plus_3 + existing);
                                String _plus_5 = (_plus_4 + " \n2 : ");
                                JsonRpcMethod _value = entry.getValue();
                                String _plus_6 = (_plus_5 + _value);
                                LanguageServerImpl.LOG.error(_plus_6);
                                extensions.put(entry.getKey(), existing);
                            } else {
                                final Endpoint endpoint = ServiceEndpoints.toEndpoint(ext);
                                this.extensionProviders.put(entry.getKey(), endpoint);
                                supportedMethods.put(entry.getKey(), entry.getValue());
                            }
                        }
                    }
                }
            }
        }
        this.supportedMethods = supportedMethods;
        return supportedMethods;
    }
}
Also used : JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Set(java.util.Set) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ILanguageServerExtension(org.eclipse.xtext.ide.server.ILanguageServerExtension)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Endpoint (org.eclipse.lsp4j.jsonrpc.Endpoint)1 JsonRpcMethod (org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod)1 JsonRpcMethodProvider (org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider)1 ILanguageServerExtension (org.eclipse.xtext.ide.server.ILanguageServerExtension)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1