monaco-languageserver-types provides a utility layer for converting data structures between the Language Server Protocol (LSP) types and the Monaco Editor's native types. This is crucial for integrating language servers, which typically communicate using LSP, with the Monaco Editor frontend. The current stable version is 0.4.0, with a release cadence that appears to be driven by feature additions and bug fixes, often addressing compatibility with newer LSP specifications or Monaco Editor versions. Its key differentiator is providing a comprehensive, idiomatic TypeScript API for bidirectional type mapping, simplifying the development of language features within Monaco by abstracting away manual type transformations and reducing boilerplate code for common LSP operations like diagnostics, completion, and hover information.
npm install monaco-languageserver-typesVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting an LSP Diagnostic to a Monaco Editor Marker and a Monaco Position back to an LSP Position using the library's utility functions.
Remove calls to `setMonaco()`. Ensure that `monaco.Uri.parse` or other `monaco` specific objects are passed as arguments to conversion functions that require them, such as `toMarkerData`.
If you were using singular `selectionRange` conversion, migrate to the plural `selectionRanges` APIs, which are typically used for converting multiple selection ranges.
Remove any `defaultSeverity` options from calls to `toCodeAction` or `toMarkerData`. If custom severity is required, ensure the LSP `Diagnostic` or similar input explicitly sets the desired severity.
Always use the provided `toMonaco.toPosition`, `fromMonaco.fromPosition`, `toMonaco.toRange`, and `fromMonaco.fromRange` utilities. Avoid manual adjustments to line or character numbers when crossing between LSP and Monaco contexts.
Ensure you are passing the `monaco` global object (or `monaco.Uri`) as an argument to conversion functions that expect it, especially after the removal of `setMonaco()` in v0.3.0. For example: `toMonaco.toMarkerData(lspDiagnostic, monaco.Uri.parse('file:///main.ts'))`.Adjust your import statement to target the correct submodule. For example, change `import { toCodeAction } from 'monaco-languageserver-types'` to `import { toCodeAction } from 'monaco-languageserver-types/lib/toMonaco'`.