@codingame/monaco-vscode-api ·
NPM module that implements the VSCode api and redirects calls to Monaco editor.
The VSCode api is composed of:
- A lot of classes and tools, which are exported the same way as in VSCode.
- Some features that are supported by Monaco (Language feature registrations...) which are just forwarded to it (with some transformations)
- Some features that are not supported by Monaco, and in such case:
- If it's an important feature: we let the user implement it as they wish.
- If it's some advanced features that don't make a lot of sense on Monaco (debug, tests...), it just throws an error when you try to use it.
To implement by hands the optional features (type hierarchy, call hierarchy...), you can use the Services
namespace from vscode/services
:
import { Services } from 'vscode/services'
Services.install({
languages: {
registerTypeHierarchyProvider (documentSelector, provider) {
...
}
}
})
Installation
npm install vscode@npm:@codingame/monaco-vscode-api
npm install -D @types/vscode
Usage
Just import it as if you were in a vscode extension:
import * as vscode from 'vscode'
const range = new new vscode.Range(...)
vscode.languages.registerCompletionItemProvider(...)
History
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:
- There is a lot of code to transform LSP objects into Monaco objects
- It's hard to follow the updates of VSCode and the language server protocol
- It doesn't behave exactly the same as in VSCode
With this library, it would be possible to plug vscode-languageclient directly on top of monaco, monaco-languageclient still helps to do so by:
- Adding some tweaks to the VSCode LanguageClient (Removing unsupported features...)
- Providing a default implementations of the required fallback services (
vscode/services
) - Providing some examples on how to build an app using it
- Adding some tools (DisposableCollection)