Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Language Server Project with implicit Environment-Resources(How can I run the language-server to include resources that are referenced by e.g. ENV-Vars?)
Language Server Project with implicit Environment-Resources [message #1832505] Sat, 19 September 2020 06:04 Go to next message
Jan Hermes is currently offline Jan HermesFriend
Messages: 27
Registered: September 2020
Junior Member
Hello Xtext community,

at the moment I'm running a language-server xtext project and it is doing very well. Thanks to the great starting-framework from items/xtext-languageserver-example.

Now I have one specific requirement that I would like to satisfy:

I would like to start the language server (RunServer) and implicitly include a resource (or several resources) that are specified e.g. in an environment variable (MY_DSL_HOME).

I was looking into the LanguageServerImpl and saw there are different components being used, and I found the WorkspaceManager which might have something to say in that sense. But I couldnt find any hook or service that allowed me to add this functionality without a better inside-knowledge of the underlying logic.

I also of course to include the resource to be accessible by the ClassLoader but that also did not implicitly make the resource contents available.

If someone could give me some direction or place where to add such functionality for the language-server it would be really great.

Thank you,
Jan
Re: Language Server Project with implicit Environment-Resources [message #1832506 is a reply to message #1832505] Sat, 19 September 2020 06:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
there is no ootb hook for that.
so for both classloader and workspacemanager your need to customize

e.g. here org.eclipse.xtext.ide.server.WorkspaceManager.initialize(List<WorkspaceFolder>, Procedure2<? super URI, ? super Iterable<Issue>>, CancelIndicator)

you may digg into concept of projects / ProjectDescription / ProjectDescription.getDependencies

or IFileSystemScanner


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 19 September 2020 06:22]

Report message to a moderator

Re: Language Server Project with implicit Environment-Resources [message #1832513 is a reply to message #1832506] Sat, 19 September 2020 10:47 Go to previous message
Jan Hermes is currently offline Jan HermesFriend
Messages: 27
Registered: September 2020
Junior Member
Yes thanks a lot! It is working now.

What I did is this (it is a little bit hacky because I desired a quick solution):

Create a custom WorkspaceManager:

I extended the WorkspaceManager overriding the initialize method so that it includes the desired workspacefolder by default

class CustomWorkspaceManager extends WorkspaceManager {
	static final Logger LOG = Logger::getLogger(typeof(CustomWorkspaceManager))
	@Inject UriExtensions uriExtensions

	override void initialize(List<WorkspaceFolder> workspaceFolders,
		Procedure2<? super URI, ? super Iterable<Issue>> issueAcceptor, CancelIndicator cancelIndicator) {
	
		val _workspaceFolders = new ArrayList(workspaceFolders)
		val mydslHome = System.getenv("MYDSL_HOME")

		if (mydslHome === null) {
			LOG.warn("the system env MYDSL_HOME is not set")
		} else {
		
			val mydslHomeDir = new File(mydslHome)
			val uri = uriExtensions.toUriString(mydslHomeDir.toURI)
			_workspaceFolders += new WorkspaceFolder(uri, "mydsllib")
		}
		
		super.initialize(_workspaceFolders, issueAcceptor, cancelIndicator)
	}
}


Create a custom ProjectDescriptionFactory:

Here I add the dependency to the library-project which is inside the workspace by default (see above).
The dependency is only added when it is not the library-project itself.

class MyDslProjectDescriptionFactory implements IProjectDescriptionFactory {
	
	override getProjectDescription(IProjectConfig config) {
		val result = new ProjectDescription();
		result.setName(config.getName());
	
		if (config.name != "mydsllib") {
			result.dependencies += "mydsllib"	
		}	
		
		return result;
	}
}


Create a custom ServerModule that binds the MyDslProjectDescriptionFactory and the CustomWorkspaceManager:

Here the custom ProjectDescriptionFactory instead of the Default one is bound.
And the CustomWorkspaceManager instead of the default one is bound

class MyDslServerModule extends AbstractModule {
	
	override protected configure() {
		
		binder.bind(ExecutorService).toProvider(ExecutorServiceProvider)
		
    	bind(LanguageServer).to(LanguageServerImpl)
        bind(IResourceServiceProvider.Registry).toProvider(ResourceServiceProviderServiceLoader)
        bind(IWorkspaceConfigFactory).to(ProjectWorkspaceConfigFactory)
        bind(ProjectWorkspaceConfigFactory).to(MultiRootWorkspaceConfigFactory)

		// custom factory for project descriptions as specified above
        bind(IProjectDescriptionFactory).to(MyDslProjectDescriptionFactory)

        bind(IContainer.Manager).to(ProjectDescriptionBasedContainerManager)

		// custom workspace manager for WorkspaceFolder initialization
		bind(WorkspaceManager).to(CustomWorkspaceManager)
	}
	
}


Load the custom ServerModule in the RunServer:

So the correct injections are used I need to load the new servermodule

public class RunServer {

	public static void main(String[] args) throws InterruptedException, IOException {
		
		Injector injector = Guice.createInjector(new MyDslServerModule());

		// ... rest stays as before
	}
	// ...
}


So thanks very much for the leading into the right direction. Everything works as desired now.

[Updated on: Sun, 20 September 2020 07:03]

Report message to a moderator

Previous Topic:Model-Transformation: How to resolve custom generated Proxy-Objects.
Next Topic:UI module generation with '-' sign in name
Goto Forum:
  


Current Time: Fri Apr 19 18:36:01 GMT 2024

Powered by FUDForum. Page generated in 0.03192 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top