mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[lsp] USer JDK service loader to find ISetups
This commit is contained in:
parent
40e3cf6e9f
commit
41be0aa99f
6 changed files with 56 additions and 19 deletions
|
@ -9,7 +9,7 @@ package org.eclipse.xtext.ide.server
|
|||
|
||||
import com.google.inject.AbstractModule
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl
|
||||
import org.eclipse.xtext.resource.ResourceServiceProviderServiceLoader
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -17,7 +17,7 @@ import org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl
|
|||
class ServerModule extends AbstractModule {
|
||||
|
||||
override protected configure() {
|
||||
bind(IResourceServiceProvider.Registry).toInstance(new ResourceServiceProviderRegistryImpl)
|
||||
bind(IResourceServiceProvider.Registry).toProvider(ResourceServiceProviderServiceLoader)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.resource
|
||||
|
||||
import com.google.inject.Provider
|
||||
import java.util.ServiceLoader
|
||||
import org.eclipse.xtext.ISetup
|
||||
import org.eclipse.xtext.resource.FileExtensionProvider
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl
|
||||
import com.google.inject.Singleton
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
@Singleton
|
||||
class ResourceServiceProviderServiceLoader implements Provider<IResourceServiceProvider.Registry> {
|
||||
|
||||
private static ServiceLoader<ISetup> setupLoader = ServiceLoader.load(ISetup)
|
||||
|
||||
private def static IResourceServiceProvider.Registry loadRegistry() {
|
||||
val registry = new ResourceServiceProviderRegistryImpl()
|
||||
for (ISetup cp : setupLoader) {
|
||||
val injector = cp.createInjectorAndDoEMFRegistration();
|
||||
val resourceServiceProvider = injector.getInstance(IResourceServiceProvider)
|
||||
val extensionProvider = injector.getInstance(FileExtensionProvider)
|
||||
for (ext : extensionProvider.fileExtensions) {
|
||||
if (registry.extensionToFactoryMap.containsKey(ext)) {
|
||||
if (extensionProvider.primaryFileExtension == ext) {
|
||||
registry.extensionToFactoryMap.put(ext, resourceServiceProvider)
|
||||
}
|
||||
} else {
|
||||
registry.extensionToFactoryMap.put(ext, resourceServiceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
private static IResourceServiceProvider.Registry registry = loadRegistry
|
||||
|
||||
override get() {
|
||||
return registry
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
|
@ -0,0 +1 @@
|
|||
org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
|
@ -18,9 +18,6 @@ import java.util.List
|
|||
import java.util.Map
|
||||
import org.eclipse.xtext.ide.server.LanguageServerImpl
|
||||
import org.eclipse.xtext.ide.server.ServerModule
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.resource.FileExtensionProvider
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.util.Files
|
||||
import org.junit.Before
|
||||
|
||||
|
@ -64,8 +61,4 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
diagnostics.put(t.uri, t.diagnostics)
|
||||
}
|
||||
|
||||
@Inject def voidRegisterTestLanguage(IResourceServiceProvider.Registry registry) {
|
||||
val injector = new TestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration
|
||||
registry.extensionToFactoryMap.put(injector.getInstance(FileExtensionProvider).primaryFileExtension, injector.getInstance(IResourceServiceProvider))
|
||||
}
|
||||
}
|
|
@ -16,14 +16,11 @@ import java.util.Map
|
|||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtext.ide.server.ServerModule
|
||||
import org.eclipse.xtext.ide.server.WorkspaceManager
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.resource.FileExtensionProvider
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.util.Files
|
||||
import org.eclipse.xtext.validation.Issue
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.Assert
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -80,10 +77,4 @@ class WorkspaceManagerTest {
|
|||
return URI.createFileURI(file.absolutePath)
|
||||
}
|
||||
|
||||
@Inject def voidRegisterTestLanguage(IResourceServiceProvider.Registry registry) {
|
||||
val injector = new TestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration
|
||||
registry.extensionToFactoryMap.put(injector.getInstance(FileExtensionProvider).primaryFileExtension,
|
||||
injector.getInstance(IResourceServiceProvider))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue