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

I can't understant this parameter #845

Open
wudicom520 opened this issue Feb 7, 2025 · 12 comments
Open

I can't understant this parameter #845

wudicom520 opened this issue Feb 7, 2025 · 12 comments

Comments

@wudicom520
Copy link

Hi
Now, Every time I initialize for the second time, Even browsers will report errors.
The report errors message is as follows:
Image
My code 38line and 39line is as follows:
Image
I hope you can provide the meaning and guidance of these parameters. Thank you!

@kaisalmen
Copy link
Collaborator

Hi @wudicom520 yes the example code does not check if the command oyright.restartServer was already registered. This is stored globally. The error ist not a problem, but we should fix it at one point.

@wudicom520
Copy link
Author

wudicom520 commented Feb 8, 2025

Thank you for your feedback @kaisalmen
My logic is that every time I click on a file, an editor is generated and initialized, but I found that when I click on another file, the previous editor is not destroyed.
Image
My code is as follows:
Image
Image

@wudicom520
Copy link
Author

Image
After I repeatedly open it, many prompt words will also appear.

@kaisalmen
Copy link
Collaborator

@wudicom520 then the best way out is to not configure the language clients in your wrapper, but to start and dispose them independently of your editor. The language registration is done globally (monaco-editor, vscode do it like that) and this is beyond our control.

Another approach is to either just update the editor model or use something like this to show a file:
https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/appPlayground/common.ts#L24

@wudicom520
Copy link
Author

Thank you for your feedback @kaisalmen . Your suggestion is every good, but I how to cerate and use this independent language wrapper. Do you have an example?

@kaisalmen
Copy link
Collaborator

@wudicom520 we have unit tests 🎉 https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper/test/languageClientWrapper.test.ts

@wudicom520
Copy link
Author

Hi @kaisalmen good morning.
I read unit tests, I have a lot of confusion.
In test file, this do not use the languageClient

test('Constructor: no config', async () => {

only this test fun, introducing how to init LanguageClientWrapper object, but I can't how to use.
other test examples, mainly tell me how to configure wrapper. create wrapper and configure wrapper json.
now, I have new a LanguageClientWrapper, and if I were to use it by MonacoEditorLanguageClientWrapper.

    const url = createUrl(({
        secured: false,
        host: 'localhost',
        port: 21007,
        path: 'pyright',
        extraParams: {
            authorization: 'UserAuth'
        }
    }));
    const webSocket = new WebSocket(url);
    const iWebSocket = toSocket(webSocket);
    const reader = new WebSocketMessageReader(iWebSocket);
    const writer = new WebSocketMessageWriter(iWebSocket);
    ideInfo.value.languageClient = new LanguageClientWrapper({
      languageClientConfig: {
        name: 'Python',
        connection: {
          options: {
            $type: 'WebSocketDirect',
            webSocket: webSocket,
          },
          messageTransports: { reader, writer }
        },
        clientOptions: {
          documentSelector: ['python'],
        }
      }
    })

@kaisalmen
Copy link
Collaborator

kaisalmen commented Feb 11, 2025

@wudicom520 you need to start them as well. Then they register.

We have a bit more complex example that allows that allows to use the language clients in an integrate and independent way:
https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/multi/twoLanguageClients.ts

@wudicom520
Copy link
Author

wudicom520 commented Feb 11, 2025

Thank your for you reply @kaisalmen .
I have seen your examples, but they were all configured from the beginning, and so are the file.
I need to dynamically write the content now, and I want to directly change the code inside

editorAppConfig: {
      codeResources: {
          modified: {
              text: code, // I want to directly change this
              fileExt: 'py'
          }
      },
      monacoWorkerFactory: configureMonacoWorkers
  }

like this, I can avoid to repeatedly new MonacoEditorLanguageClientWrapper().
Why do we do this, that because I don't need your built-in file system, I only need to change code.

@kaisalmen
Copy link
Collaborator

@wudicom520 if you want to dynamically update the editor content, then just do it. Once the wrapper runs, you can use all the means available via its api. I showed you that you can losen the coupling between editor and language client(s). so you can independently manage them. Now you have to define your application logic. All building blocks are there.

@wudicom520
Copy link
Author

Hi @kaisalmen
I have encounted a problem. No matter how much languageClients are used, it should only be configured during initialization. But if have a languageClient conntion fail(mean is websocket connecting fail), it means init fail.
There is a situation now, user maybe disconnected from the internet, but local env have code file, so editor need to show code, but if disconnection, MonacoEditorLanguageClientWrapper will init fail.
so I think MonacoEditorLanguageClientWrapper class need to add setLanguageClient function, in order to be flexible in set it up.

@kaisalmen
Copy link
Collaborator

@wudicom520 do you want to open a PR and add this function? A unit test that deals with this error case could helpful.

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