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);
}
}
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);
}
}
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);
}
}
}
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;
});
}
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;
}
}
Aggregations