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

Get LanguageClient of LSP running in WebExtension #750

Open
P422L opened this issue Sep 24, 2024 · 3 comments
Open

Get LanguageClient of LSP running in WebExtension #750

P422L opened this issue Sep 24, 2024 · 3 comments

Comments

@P422L
Copy link

P422L commented Sep 24, 2024

Description

I have created a MonacoEditorReactComp with the following userConfig:

import getEditorServiceOverride from '@codingame/monaco-vscode-editor-service-override';
import './custom-lsp-1.0.0.vsix';
import { useOpenEditorStub } from 'monaco-editor-wrapper/vscode/services';
import { UserConfig } from 'monaco-editor-wrapper';

export const setupExtended = async (test?: string): Promise<UserConfig> => {
    let main = {
        text: text || "",
        fileExt: 'test'
    };
    let original = {
        text: text || "",
        fileExt: 'test'
    };

    return {
        wrapperConfig: {
            serviceConfig: {
                userServices: {
                    ...getEditorServiceOverride(useOpenEditorStub),
                },
                enableExtHostWorker: true,
                debugLogging: true
            },
            editorAppConfig: {
                $type: 'extended',
                codeResources: {
                    main,
                    original
                },
                useDiffEditor: false,
                userConfiguration: {
                    json: JSON.stringify({
                        'workbench.colorTheme': 'Custom Dark',
                    })
                }
            }
        }
    }
}

The LSP functionalities work as expected, meaning my Monaco editor is definitely connected to the LanguageClient from the .vsix file, and this LanguageClient is also connected to the LanguageServer running in the extension.

Use Case

I need to react to a custom state of the LanguageClient, meaning I need a way to communicate between the LanguageClient and my editor. Currently, I only see options to access the LanguageClient and the connection when I create it in the config, but not when I want to access a LanguageClient in an extension.

Question

How can I obtain the connection details for a LanguageClient that is running in an extension, so I can communicate with it from my editor? Is there no way I can access it via the id?

@P422L
Copy link
Author

P422L commented Sep 24, 2024

In addition, I execute custom commands with:

monacoEditorRef.current?.executeCommand(...)

...which throw intial error messages because the LanguageServer has not yet started. So it would also be nice for this use case to be able to communicate explicitly with the LanguageClient to be informed when the LanguageServer is fully ready

@kaisalmen
Copy link
Collaborator

@P422L is this web extension created by you? You need to communicate with that extension somehow, because it runs isolated from your editor code above. A MessageChannel would be a way to achieve that or something like this: https://github.com/TypeFox/vscode-messenger

@P422L
Copy link
Author

P422L commented Sep 25, 2024

@kaisalmen Thank you for your quick reply. Yes it is my extension and I have tried both the MessageChannel and vscode-messenger approach but to no avail.

I lack a bit of understanding of how to connect my React component with my Monaco Editor (running in a worker) to the LanguageClient (running in a worker in a WebExtension). The approach with the MessageChannel sounds good, but as far as I understand it I have to pass it, otherwise I can't communicate on the same channel.

Do you have a short example?

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

2 participants