You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@codingame/monaco-vscode-editor-api` is installed as an alias to `monaco-editor` because it provides the same api as the official `monaco-editor`
19
19
20
20
# Usage
21
+
21
22
If you are just starting with `monaco-editor` and `monaco-vscode-api` you may find helpful the [Getting Started Guide](https://github.com/CodinGame/monaco-vscode-api/wiki/Getting-started-guide) in the wiki.
23
+
22
24
## Monaco service override
23
25
24
-
Most of VSCode functionality implemented as "services", e.g.
26
+
Most of VSCode functionality implemented as "services", e.g.
27
+
25
28
- theme service, providing support for VSCode themes
26
29
- languages service, providing support for different language features.
27
30
28
-
By default, Monaco uses a simplified versions of the VSCode services, called `standalone` services.
29
-
This package allows to
30
-
1) override them with fully-functional alternatives from VSCode
31
-
2) add new services that were not included in Monaco
31
+
By default, Monaco uses a simplified versions of the VSCode services, called `standalone` services.
32
+
This package allows to
33
+
34
+
1. override them with fully-functional alternatives from VSCode
35
+
2. add new services that were not included in Monaco
32
36
33
37
Here is an example usage that overrides Monaco default configuration with VSCode json-based settings:
- Provides workspace search functionality for both Command Palette file search (Ctrl+P) and Search panel (Ctrl+Shift+F)
98
+
- Enables searching through files and text content within your workspace
87
99
88
100
However, most of the services are separated into different modules, so they can be imported as required. You can find a full list of services in the [corresponding wiki page](https://github.com/CodinGame/monaco-vscode-api/wiki/List-of-service-overrides).
89
101
90
-
91
102
### Default vscode extensions
92
103
93
104
VSCode uses a bunch of default extensions. Most of them are used to load the default languages and grammars (see <https://github.com/microsoft/vscode/tree/main/extensions>).
@@ -104,31 +115,31 @@ Here is an example of usage of default VSCode theme extension with theme service
See [the full list of ported default extensions](https://www.npmjs.com/search?q=%40codingame%2Fmonaco-vscode-*-default-extension)
@@ -176,7 +187,6 @@ This library also offers the possibility to localize vscode and the extensions i
176
187
177
188
⚠️ The language pack should be imported and loaded BEFORE anything else from this library is loaded. Otherwise, some translations would be missing and an error would be displayed in the console. ⚠️
178
189
179
-
180
190
## Model creation
181
191
182
192
The official `monaco-editor` package provides a function to create models: `monaco.editor.createModel`.
@@ -192,6 +202,7 @@ It has some pros:
192
202
- It is possible to call the method multiple times on the same file to get multiple references. The model is disposed when there is no reference left
193
203
194
204
To work, it needs the file to exist on the virtual filesystem. It can be achieved either by:
205
+
195
206
- using the `registerFileSystemOverlay` from the files service override, which can be cleaned when not needed anymore (recommended)
196
207
- by using the second argument of the `createModelReference` function, which writes the file content to the virtual filesystem before creating the model
197
208
@@ -286,6 +297,7 @@ Try it out on <https://monaco-vscode-api.netlify.app/>
286
297
287
298
There is a demo that showcases the service-override features.
288
299
It includes:
300
+
289
301
- Languages
290
302
- VSCode themes
291
303
- Textmate grammars (requires VSCode themes)
@@ -330,6 +342,7 @@ The library supports shadow-dom.
330
342
⚠️ VSCode itself doesn't support shadow dom, and there are multiple parts that needed to be patched in order for it to work.
331
343
332
344
There are multiple benefits of using it:
345
+
333
346
- Your custom global style won't impact the VSCode workbench style (for instance if you did override the default [box-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing))
334
347
- The VSCode styles won't impact other parts of your app
335
348
- You page head won't be polluted with dozen of css files from VSCode
@@ -406,19 +419,20 @@ To still be able to do it, a possibility is to run all VSCode code inside an ifr
406
419
To better integrate it, it's also possible to run the code in the iframe, but make the code interact with the main page dom.
407
420
408
421
This library supports that mode. To enable that, you should
422
+
409
423
- have a secondary html entrypoint, that initialize the services
410
424
- load that secondary html in an iframe
411
425
- in the iframe, set `window.vscodeWindow` to the parent window, also initialize the service with a container mounted in that window
412
426
- do not import any monaco-vscode-library from the top window, but you can declare functions on the iframe window to get objects to the top window
413
427
414
428
To "unload" the workbench, you should:
429
+
415
430
- remove the iframe element from the top frame
416
431
- remove or empty the workbench container
417
432
- cleanup the elements that VSCode has injected in the page head: `document.querySelectorAll('[data-vscode]').forEach((el) => el.remove())`
418
433
419
434
⚠️ `window.vscodeWindow` should be set BEFORE any VSCode code is loaded
420
435
421
-
422
436
Note: it can be used in combination with shadow dom
423
437
424
438
It's demonstrated in the demo, by adding `?sandbox` query parameter to the demo url
0 commit comments