Reputation: 16354
I'm building a page that contains multiple monaco editors. I currently control the libraries I want to use by using:
monaco.languages.typescript.javascriptDefaults.addExtraLib(`
interface Product {
foo: String;
}
declare const product: Product;
`, 'global.d.ts')
By using this, all the editors are forced to have exactly the same libraries available.
Is it possible to control that behavior by editor instance and not globally?
Upvotes: 2
Views: 1599
Reputation: 3442
Long story short: no.
The problem is that the IStandaloneCodeEditor
you create by calling monaco.editor.create ()
has no idea of any of the monaco.languages
that are currently available and registered.
The parsing is done by monaco.worker
s, which get - for Java- and TypeScript - configured through monaco.languages.typescript
and are static and not instance-specific, so that one worker serves many instances.
I believe this design decision was made in favour of efficiency and performance - having may WebWorker
s for many instances with (probably) many different libraries is not very efficient.
Also note that this is not the only thing that is not configurable instance-wise: everything which is configurable via any monaco.languages
language definition is global.
I do not know how this is exactly implemented, but if you are willing to understand what is happening, the Type- and JavaScript implementation is on GitHub (as well as Monaco's base).
Though it would be (probably) somewhat performance-heavy, this is something which may be suitable to be discussed in an GitHub issue. In the end, if this is declined, you might as well just have got an impression on the implementation of Monaco by the contributors.
Upvotes: 4