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

Question:executeCommand #470

Open
pl0301 opened this issue Aug 23, 2024 · 12 comments
Open

Question:executeCommand #470

pl0301 opened this issue Aug 23, 2024 · 12 comments
Labels
api-customization documentation Improvements or additions to documentation

Comments

@pl0301
Copy link

pl0301 commented Aug 23, 2024

Hello, I'm in the process of integrating LSP4IJ and would like to create a window for interacting with LSP commands. I have a question: how can I obtain the server within my custom window class?

image

@angelozerr
Copy link
Contributor

Badly it doesn't exists a clean API which get LanguageServerItem form a given language server id.

We need to provide it.

@pl0301
Copy link
Author

pl0301 commented Aug 23, 2024

Badly it doesn't exists a clean API which get LanguageServerItem form a given language server id.

We need to provide it.

Okay, currently I've achieved my goal by using LanguageServiceAccessor, but I see in the comments that it's not recommended to use it this way. However, it nicely fulfills my needs. Is it possible to expose this interface officially?
image

@angelozerr
Copy link
Contributor

Badly it doesn't exists a clean API which get LanguageServerItem form a given language server id.
We need to provide it.

Okay, currently I've achieved my goal by using LanguageServiceAccessor, but I see in the comments that it's not recommended to use it this way. However, it nicely fulfills my needs. Is it possible to expose this interface officially?

We want to avoid doing that because as soon as we say that LanguageServiceAccessor is an API we will not able to do refactoring. And we prefer providing high level API like https://github.com/redhat-developer/lsp4ij/blob/main/docs/DeveloperGuide.md#language-server-manager

Pay attention with your code:

@pl0301
Copy link
Author

pl0301 commented Aug 24, 2024

fine, hope you can develop an API that can be called from other actions or windows.

@angelozerr
Copy link
Contributor

angelozerr commented Aug 24, 2024

fine, hope you can develop an API that can be called from other actions or windows.

Our mail goal is to have a relevant and clean API. That's why we prefer developping API according the issues like you have written instead of trying to imagine non concrete usecases.

When I will find time I will develop something.

@angelozerr angelozerr added documentation Improvements or additions to documentation api-customization labels Aug 27, 2024
@angelozerr
Copy link
Contributor

@pl0301 please see this discussion #558

0.7.0 will break API from this class, so please don't use it.

@angelozerr
Copy link
Contributor

@pl0301 I have managed your use case in #543 (you can read the DeveloperGuide), but the idea is that you can write that:

Command command= new Command("My command", "command.from.your.ls");
LSPCommandContext commandContext = new LSPCommandContext(command, project);
commandContext.setPreferredLanguageServerId("myLanguageServerId");
CommandExecutor.executeCommand(commandContext);

@pl0301
Copy link
Author

pl0301 commented Oct 3, 2024

@pl0301 I have managed your use case in #543 (you can read the DeveloperGuide), but the idea is that you can write that:

Command command= new Command("My command", "command.from.your.ls");
LSPCommandContext commandContext = new LSPCommandContext(command, project);
commandContext.setPreferredLanguageServerId("myLanguageServerId");
CommandExecutor.executeCommand(commandContext);

Thank you! Your work is extremely valuable.

@angelozerr
Copy link
Contributor

@fbricon said me that in your sample you get the result and executeCommand return just a boolean.

I need to investigate if it is possible to return something.

But My PR provides LanguageServerManager.getInstance(project).getLanguageServer("myLanguageServerId")

which returns a CompletableFuture<LanguageServerItem>,

LanguageServerManager.getInstance(project)
        .getLanguageServer("myLanguageServerId")
        .thenAccept(languageServerItem -> {
            if (languageServerItem != null) {
                // Language server item exists here...

                // Get the LSPJ LanguageServer
                org.eclipse.lsp4j.services.LanguageServer ls = languageServerItem.getServer();

                // Do something with the language server

            }});

so you could manage you usecase with this new API,but let me try to improve again the executeCommand.

@pl0301
Copy link
Author

pl0301 commented Oct 3, 2024

ok

@angelozerr
Copy link
Contributor

Ok, I manage that now,here a sample:

Command command = new Command("My command", "command.from.your.ls");
LSPCommandContext commandContext = new LSPCommandContext(command, project);
commandContext.setPreferredLanguageServerId("myLanguageServerId");
CommandExecutor.executeCommand(commandContext)
        .response()
        .thenAccept(r -> {
            // Do something with the workspace/executeCommand Object response
        });

@angelozerr
Copy link
Contributor

@pl0301 please try installing nightly-builds, read doc at https://github.com/redhat-developer/lsp4ij/blob/main/docs/DeveloperGuide.md#execute-a-command

For more information ,see #561

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-customization documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants