Gathering detailed insights and metrics for @codingame/monaco-vscode-language-pack-es
Gathering detailed insights and metrics for @codingame/monaco-vscode-language-pack-es
Gathering detailed insights and metrics for @codingame/monaco-vscode-language-pack-es
Gathering detailed insights and metrics for @codingame/monaco-vscode-language-pack-es
VSCode public API plugged on the monaco editor
npm install @codingame/monaco-vscode-language-pack-es
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
255 Stars
1,896 Commits
34 Forks
12 Watching
7 Branches
11 Contributors
Updated on 28 Nov 2024
TypeScript (89.81%)
HTML (9.33%)
Shell (0.68%)
JavaScript (0.13%)
Dockerfile (0.05%)
Cumulative downloads
Total Downloads
Last day
9.9%
1,189
Compared to previous day
Last week
18.3%
5,897
Compared to previous week
Last month
19%
21,372
Compared to previous month
Last year
6,837.5%
81,585
Compared to previous year
1
This NPM module allows to integrate full VSCode functionality into your monaco-editor
.
For more information, please checkout the project's wiki.
1npm install vscode@npm:@codingame/monaco-vscode-api 2npm install monaco-editor@npm:@codingame/monaco-vscode-editor-api 3npm install -D @types/vscode
@codingame/monaco-vscode-api
is installed as an alias to vscode
to be able to run import * as vscode from 'vscode'
, similar to what is done inside a VSCode extension
@codingame/monaco-vscode-editor-api
is installed as an alias to monaco-editor
because it provides the same api as the official monaco-editor
If you are just starting with monaco-editor
and monaco-vscode-api
you may find helpful the Getting Started Guide in the wiki.
Most of VSCode functionality implemented as "services", e.g.
By default, Monaco uses a simplified versions of the VSCode services, called standalone
services.
This package allows to
Here is an example usage that overrides Monaco default configuration with VSCode json-based settings:
1// default monaco-editor imports 2import * as monaco from 'monaco-editor'; 3import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; 4 5// utilities to override Monaco services 6import { initialize } from 'vscode/services' 7import getConfigurationServiceOverride, { updateUserConfiguration } from '@codingame/monaco-vscode-configuration-service-override' 8 9window.MonacoEnvironment = { 10 getWorker: (_moduleId, _label) => new editorWorker() 11} 12 13// overriding Monaco service with VSCode 14await initialize({ 15 ...getConfigurationServiceOverride(), 16}); 17 18// json config like in vscode settings.json 19updateUserConfiguration(`{ 20 "editor.fontSize": 30, 21 "editor.lineHeight": 30, 22 "editor.fontFamily": "monospace", 23 "editor.fontWeight": "bold", 24 "editor.letterSpacing": 0, 25}`) 26 27// creating an editor with VSCode configuration 28monaco.editor.create(document.getElementById('editor')!, { 29 value: "Editor with VSCode config and large bold fonts", 30});
[!NOTE]
initialize
can only be called once (and it should be called BEFORE creating your first editor).
Each get<service-name>ServiceOverride
contains the service and some glue to make VSCode service work with Monaco.
Some basic service overrides are coming with this package as dependencies:
@codingame/monaco-vscode-base-service-override
@codingame/monaco-vscode-host-service-override
@codingame/monaco-vscode-extensions-service-override
@codingame/monaco-vscode-files-service-override
file://
files, but also adds the support for lazy loaded extension files. It adds separate memory user files (e.g. config, keybindings), cache files and log filesfile://
files@codingame/monaco-vscode-quickaccess-service-override
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.
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).
This library bundles and publishes them as separate packages, which allows to use the ones you want. To use an extension, just install the corresponding package and import it in the beginning of the file:
1import '@codingame/monaco-vscode-javascript-default-extension' 2import '@codingame/monaco-vscode-json-default-extension' 3...
Here is an example of usage of default VSCode theme extension with theme service override:
1// importing default VSCode theme extension 2import "@codingame/monaco-vscode-theme-defaults-default-extension"; 3 4// default monaco-editor imports 5import * as monaco from 'monaco-editor'; 6import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; 7 8// utilities to override Monaco services 9import { initialize } from 'vscode/services' 10import getThemeServiceOverride from "@codingame/monaco-vscode-theme-service-override"; 11 12window.MonacoEnvironment = { 13 getWorker: function (_moduleId, _label) { 14 return new editorWorker(); 15 } 16} 17 18// overriding Monaco service with VSCode 19await initialize({ 20 ...getThemeServiceOverride(), 21}); 22 23// creating an editor with VSCode theme 24monaco.editor.create(document.getElementById('editor')!, { 25 value: "Editor with VSCode Theme Support", 26});
See the full list of ported default extensions
VSCode extensions are bundled as vsix files. This library publishes a rollup plugin (vite-compatible) that allows to load a vsix file.
1import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin' 2... 3plugins: [ 4 ..., 5 vsixPlugin() 6]
1import './extension.vsix'
This library also offers the possibility to localize vscode and the extensions in the supported languages. To do so, import one of the following packages before anything else:
@codingame/monaco-vscode-language-pack-cs
@codingame/monaco-vscode-language-pack-de
@codingame/monaco-vscode-language-pack-es
@codingame/monaco-vscode-language-pack-fr
@codingame/monaco-vscode-language-pack-it
@codingame/monaco-vscode-language-pack-ja
@codingame/monaco-vscode-language-pack-ko
@codingame/monaco-vscode-language-pack-pl
@codingame/monaco-vscode-language-pack-pt-br
@codingame/monaco-vscode-language-pack-qps-ploc
@codingame/monaco-vscode-language-pack-ru
@codingame/monaco-vscode-language-pack-tr
@codingame/monaco-vscode-language-pack-zh-hans
@codingame/monaco-vscode-language-pack-zh-hant
⚠️ 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. ⚠️
The official monaco-editor
package provides a function to create models: monaco.editor.createModel
.
This method creates a standalone model that cannot be found or used by any VSCode services.
The recommended way is to used the createModelReference
method instead (added on top of the official monaco-editor api) which returns instead a reference to a model.
It has some pros:
To work, it needs the file to exist on the virtual filesystem. It can be achieved either by:
registerFileSystemOverlay
from the files service override, which can be cleaned when not needed anymore (recommended)createModelReference
function, which writes the file content to the virtual filesystem before creating the modelbefore:
1import * as monaco from 'monaco-editor' 2const model = monaco.editor.createModel(...) 3const editor = monaco.editor.create({ model, ... }) 4 5... 6 7model.dispose() 8editor.dispose() 9
after:
1import * as monaco from 'monaco-editor' 2import { RegisteredFileSystemProvider, RegisteredMemoryFile, registerFileSystemOverlay } from '@codingame/monaco-vscode-files-service-override' 3 4const fileUri = monaco.Uri.file(<file uri>); 5 6const fileSystemProvider = new RegisteredFileSystemProvider(false) 7fileSystemProvider.registerFile(new RegisteredMemoryFile(fileUri, <file content>)) 8const overlayDisposable = registerFileSystemOverlay(1, fileSystemProvider) 9 10const modelRef = await monaco.editor.createModelReference(fileUri) 11 12const editor = monaco.editor.create({ model: modelRef.object.textEditorModel }) 13 14... 15 16await modelRef.object.save() 17 18... 19 20modelRef.dispose() 21editor.dispose() 22overlayDisposable.dispose() 23
createModelReference
return a reference to a model. The value is fetched from the memory filesystem.
The reference can then be disposed, the model will only be disposed if there is no remaining references.
To be able to use the VSCode api directly from your code, you need to import vscode/localExtensionHost
and wait for the services to be initialized.
You will then be able to import it as if you were in a VSCode extension:
1import * as vscode from 'vscode' 2import 'vscode/localExtensionHost' 3 4const range = new vscode.Range(...) 5vscode.languages.registerCompletionItemProvider(...)
You can also register a new extension from its manifest:
1import { registerExtension, initialize, ExtensionHostKind } from 'vscode/extensions' 2 3await initialize() 4 5const { registerFileUrl, getApi } = registerExtension({ 6 name: 'my-extension', 7 publisher: 'someone', 8 version: '1.0.0', 9 engines: { 10 vscode: '*' 11 }, 12 contributes: { 13 } 14}, ExtensionHostKind.LocalProcess) 15 16registerFileUrl('/file-extension-path.json', new URL('./file-real-path.json', import.meta.url).toString()) 17 18const vscode = await getApi() 19 20vscode.languages.registerCompletionItemProvider(...) 21
Try it out on https://monaco-vscode-api.netlify.app/
There is a demo that showcases the service-override features. It includes:
From CLI run:
1# build monaco-vscode-api (the demo use it as a local dependency) 2npm ci 3npm run build 4# start demo 5cd demo 6npm ci 7npm start 8# OR: for vite debug output 9npm run start:debug
For the debug feature, also run:
1npm run start:debugServer
⚠️ Building monaco-vscode-api is only supported on Linux or Mac. It you use Windows, have a look at WSL ⚠️
See the VSCode Server wiki page.
If something doesn't work, make sure to check out the Troubleshooting wiki page.
This project was mainly created to make the implementation of monaco-languageclient more robust and maintainable.
monaco-languageclient uses vscode-languageclient which was built to run inside a VSCode extension. VSCode extensions communicate with the editor via an API they can import into their code.
The VSCode api exports:
The first implementations of monaco-languageclient were using a fake VSCode api implementation. The vscode-languageclient was hacked so the VSCode<->protocol object converters were mainly bypassed, so the fake VSCode api was receiving Language Server Protocol objects. Then the objects were transformed using custom transformers into Monaco objects to communicate with the monaco api.
This approach has some disadvantages:
With this library, it would be possible to plug vscode-languageclient directly on top of monaco, monaco-languageclient still helps to do so by:
No vulnerabilities found.
No security vulnerabilities found.