Search in sources :

Example 26 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class FragmentTestLanguageStandaloneSetupGenerated method register.

public void register(Injector injector) {
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fragmenttestlanguage", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("fragmenttestlanguage", serviceProvider);
    if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2015/tmf/xtext/fragments")) {
        EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2015/tmf/xtext/fragments", FragmentTestLanguagePackage.eINSTANCE);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 27 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class UnassignedTextTestLanguageStandaloneSetupGenerated method register.

public void register(Injector injector) {
    IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
    IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("unassignedtexttestlanguage", resourceFactory);
    IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("unassignedtexttestlanguage", serviceProvider);
    if (!EPackage.Registry.INSTANCE.containsKey("http://simple/unassignedtext")) {
        EPackage.Registry.INSTANCE.put("http://simple/unassignedtext", UnassignedtextPackage.eINSTANCE);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory)

Example 28 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class XtextGenerator method initializeEncoding.

protected void initializeEncoding() {
    IResourceServiceProvider.Registry serviceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
    IResourceServiceProvider serviceProvider = (IResourceServiceProvider) serviceProviderRegistry.getExtensionToFactoryMap().get("xtext");
    String encoding = null;
    if (grammarEncoding != null) {
        encoding = grammarEncoding;
    } else {
        encoding = configuration.getCode().getEncoding();
    }
    if (serviceProvider != null && encoding != null) {
        IEncodingProvider encodingProvider = serviceProvider.get(IEncodingProvider.class);
        if (encodingProvider instanceof IEncodingProvider.Runtime) {
            ((IEncodingProvider.Runtime) encodingProvider).setDefaultEncoding(encoding);
        }
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider)

Example 29 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class LanguageServerImpl method codeAction.

/**
 * Compute the code action commands. Executed in a read request.
 * @since 2.20
 */
protected List<Either<Command, CodeAction>> codeAction(CodeActionParams params, CancelIndicator cancelIndicator) {
    URI uri = getURI(params.getTextDocument());
    IResourceServiceProvider serviceProvider = getResourceServiceProvider(uri);
    ICodeActionService2 service2 = getService(serviceProvider, ICodeActionService2.class);
    if (service2 == null) {
        return Collections.emptyList();
    }
    return workspaceManager.doRead(uri, (doc, resource) -> {
        List<Either<Command, CodeAction>> result = new ArrayList<>();
        if (service2 != null) {
            ICodeActionService2.Options options = new ICodeActionService2.Options();
            options.setDocument(doc);
            options.setResource(resource);
            options.setLanguageServerAccess(access);
            options.setCodeActionParams(params);
            options.setCancelIndicator(cancelIndicator);
            List<Either<Command, CodeAction>> actions = service2.getCodeActions(options);
            if (actions != null) {
                result.addAll(actions);
            }
        }
        return result;
    });
}
Also used : CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) RenameOptions(org.eclipse.lsp4j.RenameOptions) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) URI(org.eclipse.emf.common.util.URI)

Example 30 with IResourceServiceProvider

use of org.eclipse.xtext.resource.IResourceServiceProvider in project xtext-core by eclipse.

the class LanguageServerImpl method supportedMethods.

@Override
public Map<String, JsonRpcMethod> supportedMethods() {
    if (supportedMethods != null) {
        return supportedMethods;
    }
    synchronized (extensionProviders) {
        Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(getClass()));
        Map<String, JsonRpcMethod> extensions = new LinkedHashMap<>();
        for (IResourceServiceProvider resourceServiceProvider : getAllLanguages()) {
            ILanguageServerExtension ext = resourceServiceProvider.get(ILanguageServerExtension.class);
            if (ext != null) {
                ext.initialize(access);
                Map<String, JsonRpcMethod> supportedExtensions = ext instanceof JsonRpcMethodProvider ? ((JsonRpcMethodProvider) ext).supportedMethods() : ServiceEndpoints.getSupportedMethods(ext.getClass());
                for (Map.Entry<String, JsonRpcMethod> entry : supportedExtensions.entrySet()) {
                    if (supportedMethods.containsKey(entry.getKey())) {
                        LOG.error("The json rpc method \'" + entry.getKey() + "\' can not be an extension as it is already defined in the LSP standard.");
                    } else {
                        JsonRpcMethod existing = extensions.put(entry.getKey(), entry.getValue());
                        if (existing != null && !Objects.equal(existing, entry.getValue())) {
                            LOG.error("An incompatible LSP extension \'" + entry.getKey() + "\' has already been registered. Using 1 ignoring 2. \n1 : " + existing + " \n2 : " + entry.getValue());
                            extensions.put(entry.getKey(), existing);
                        } else {
                            Endpoint endpoint = ServiceEndpoints.toEndpoint(ext);
                            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) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)267 IResourceFactory (org.eclipse.xtext.resource.IResourceFactory)190 URI (org.eclipse.emf.common.util.URI)25 Resource (org.eclipse.emf.ecore.resource.Resource)21 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)20 XtextResource (org.eclipse.xtext.resource.XtextResource)13 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)5 IResource (org.eclipse.core.resources.IResource)5 EObject (org.eclipse.emf.ecore.EObject)5 Manager (org.eclipse.xtext.resource.IResourceDescription.Manager)5 Issue (org.eclipse.xtext.validation.Issue)5 Injector (com.google.inject.Injector)4 IProject (org.eclipse.core.resources.IProject)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)4