Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I pass cutom Launcher for LanguageServerDefinition? #1187

Open
yanshudan opened this issue Jan 16, 2025 · 8 comments
Open

How do I pass cutom Launcher for LanguageServerDefinition? #1187

yanshudan opened this issue Jan 16, 2025 · 8 comments

Comments

@yanshudan
Copy link

context: I need to custom a type adapter to handle responses from language server eclipse-lsp4j/lsp4j#865, and it turned out I need to pass a custom gson builder to a launcher builder like below:

var launcher = new Launcher.Builder<LanguageClient>()
          .setLocalService(myserver)
          .setRemoteInterface(LanguageClient.class)
          .setInput(System.in)
          .setOutput(System.out)
          .configureGson(gsonBuilder -> gsonBuilder
              .registerTypeAdapterFactory(new MyProgressParamsAdapter())) //register custom adapter
          .create();

      launcher.startListening();

But in

Launcher<LanguageServer> launcher = serverDefinition.createLauncherBuilder() //
.setLocalService(languageClient)//
.setRemoteInterface(serverDefinition.getServerInterface())//
.setInput(lspStreamProvider.getInputStream())//
.setOutput(lspStreamProvider.getOutputStream())//
.setExecutorService(listener)//
.wrapMessages(wrapper)//
.create();
lsp4e creates a launcher already, and I suppose I need to pass my custom launcher to make it work.

serverDefinition.createLauncherBuilder() //returns my custom builder

But the class is abstract static &private, I cannot override createLauncherBuilder by extending the class or using dynamic proxy.

public <S extends LanguageServer> Launcher.Builder<S> createLauncherBuilder() {

How could I resolve this?

@rubenporras
Copy link
Contributor

@mickaelistria,

I assume the analysis is correct so far and that @yanshudan needs a custom Gson configurator.

What do you think of adding

				.configureGson(serverDefinition.getConfigureGson())

to

Launcher<LanguageServer> launcher = serverDefinition.createLauncherBuilder() //
.setLocalService(languageClient)//
.setRemoteInterface(serverDefinition.getServerInterface())//
.setInput(lspStreamProvider.getInputStream())//
.setOutput(lspStreamProvider.getOutputStream())//
.setExecutorService(listener)//
.wrapMessages(wrapper)//
.create();

and then the corresponding extension point to languageServer.xsd? The configureGson would by default do nothing to be backwards compatible.

Or do you have a better idea?

@mickaelistria
Copy link
Contributor

I don't have a better idea, this proposal seems good.

@rubenporras
Copy link
Contributor

@yanshudan , would you like to prepare a PR for the proposal?

@yanshudan
Copy link
Author

@rubenporras Yes, sure. Will get back to you when the PR is ready.

@yanshudan
Copy link
Author

Hi @rubenporras , I'm working on the PR and I'm wondering how I could pass a custom gson builder in my code once the PR gets merged.

@yanshudan
Copy link
Author

yanshudan commented Jan 17, 2025

I noticed

new Launcher.Builder<LanguageClient>()
          .setLocalService(myserver)
          .setRemoteInterface(LanguageClient.class)
          .setInput(System.in)
          .setOutput(System.out)
          .configureGson(gsonBuilder -> gsonBuilder
              .registerTypeAdapterFactory(new MyProgressParamsAdapter()))

returns a Launcher.Builder and lsp4e provides extesion point for that

public <S extends LanguageServer> Launcher.Builder<S> createLauncherBuilder() {
if I understand correctly, I can just provide my launcher in some way. Looks like the proposed solution also leverages the extension point mechanism to customize a gson builder, why not just customize a launcher?

@mickaelistria
Copy link
Contributor

@yanshudan good finding. Indeed it looks like you can try to define your own launcher builder, and get this particular class setting the appropriate gson configuration during that .build() method.

@rubenporras
Copy link
Contributor

Agree, if that works, that is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants