Skip to content

Fix: Multiple Monaco editor issue #666

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

Merged
merged 2 commits into from
May 28, 2024
Merged

Fix: Multiple Monaco editor issue #666

merged 2 commits into from
May 28, 2024

Conversation

kaisalmen
Copy link
Collaborator

This fixes #620 It actually didn't require a code change. You only create one language client and the other editor re-uses the globally installed for the registered language (= statemachine in this case). This may have not been as easily configurable in the past.

In addition the PR contains the update to monaco-vscode-api version 5.2.0

@kaisalmen kaisalmen requested a review from CGNonofr as a code owner May 27, 2024 08:25
Copy link
Collaborator

@CGNonofr CGNonofr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kaisalmen kaisalmen merged commit 369834a into main May 28, 2024
2 checks passed
@kaisalmen kaisalmen deleted the issue-620 branch May 28, 2024 08:14
@wa8f7192
Copy link

wa8f7192 commented Jun 3, 2024

Thanks for resolving this and updating the examples

@cdietrich
Copy link
Contributor

@kaisalmen is there also the option to have the react component twice and have them completely isolated from each other?
(two workers, each editor talking to one?)

@kaisalmen
Copy link
Collaborator Author

@cdietrich each editor for a different LS/language?

@cdietrich
Copy link
Contributor

cdietrich commented Jul 8, 2024

for the same language.

see this branch:
https://github.com/cdietrich/my-monaco-editor-react-example/tree/cd/otherFilesExperiments_createModelReference_multi-newer-componentTwice

currently both workers seem to see the files from the other.
(also happens when i useMonacoEditorReactComp instead of my MonacoEditorReactCompExtended

@CGNonofr
Copy link
Collaborator

CGNonofr commented Jul 8, 2024

I don't think it will be able, monaco/VSCode don't support having multiple isolated "instances" in parallel

The closer you can get is having 2 workspace folders. You can configure a language client to match only a single workspace folder.

@kaisalmen
Copy link
Collaborator Author

The closer you can get is having 2 workspace folders. You can configure a language client to match only a single workspace folder.

We should add that to our Troubleshooting section

@cdietrich
Copy link
Contributor

hmm ok. so this is why monaco dispatches all events to all clients.
as we have tabs inside our react app, we are looking into how can unmount when tab is not visible

@CGNonofr
Copy link
Collaborator

CGNonofr commented Jul 8, 2024

An alternative can be to use Iframes also of course

@kaisalmen
Copy link
Collaborator Author

kaisalmen commented Jul 8, 2024

@cdietrich and @CGNonofr btw, you can use MessageChannels to communicate in between IFrames or to channel the communication between main and worker or between workers. You can configure this already: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/langium/statemachine/main.ts#L35-L62

Idea: You could have logic either on client or the worker or both to disable communication to silence one LS.

@cdietrich
Copy link
Contributor

yeah but we basically would need very heavy rewrite to isolate on the server side

@kaisalmen
Copy link
Collaborator Author

@cdietrich disconnecting and re-connecting the languageclient on tab change is not an option? You don't have to dispose the worker. This should be fast.

@cdietrich
Copy link
Contributor

we need to check

@kaisalmen
Copy link
Collaborator Author

If something is missing, let us know.

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

Successfully merging this pull request may close these issues.

Multiple Monaco editor issue
4 participants