Registry / web-framework / monaco-languageserver-types

monaco-languageserver-types

JSON →
library0.4.0jsnpmunverified

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-types
INSTALL
IMPORT
SIG · MONACO-LANGUAGESER
M
monaco-languageserver-types
web-frameworkjavascriptv0.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toMonaco
import * as toMonaco from 'monaco-languageserver-types/lib/toMonaco'
import { toMonaco } from 'monaco-languageserver-types'
Conversion functions are organized into 'toMonaco' and 'fromMonaco' submodules for clarity. Use named imports from the specific path.
fromMonaco
import * as fromMonaco from 'monaco-languageserver-types/lib/fromMonaco'
import fromMonaco from 'monaco-languageserver-types'
Conversion functions are organized into 'toMonaco' and 'fromMonaco' submodules for clarity. Use named imports from the specific path.
toCodeAction
import { toCodeAction } from 'monaco-languageserver-types/lib/toMonaco'
import { toCodeAction } from 'monaco-languageserver-types'
Specific conversion utilities like `toCodeAction` are available as named exports within their respective submodules (`toMonaco` or `fromMonaco`).

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.

import * as monaco from 'monaco-editor'; import type * as lsp from 'vscode-languageserver-types'; import { toMonaco, fromMonaco } from 'monaco-languageserver-types'; // Assume 'monaco' is globally available or correctly imported if using ESM // This example simulates converting LSP Diagnostics to Monaco Markers const lspDiagnostic: lsp.Diagnostic = { range: { start: { line: 0, character: 7 }, end: { line: 0, character: 10 } }, message: "'foo' is undefined", severity: 1, // lsp.DiagnosticSeverity.Error code: "TS2304", source: "typescript" }; const monacoMarker: monaco.editor.IMarkerData = toMonaco.toMarkerData(lspDiagnostic, monaco.Uri.parse('file:///main.ts')); console.log('LSP Diagnostic:', lspDiagnostic); console.log('Monaco Marker:', monacoMarker); // Example of converting Monaco Position back to LSP Position const monacoPosition: monaco.Position = new monaco.Position(1, 5); const lspPosition: lsp.Position = fromMonaco.fromPosition(monacoPosition); console.log('Monaco Position:', monacoPosition.toString()); console.log('LSP Position:', lspPosition); /* Output will be similar to: LSP Diagnostic: { range: { start: [Object], end: [Object] }, message: "'foo' is undefined", severity: 1, code: "TS2304", source: "typescript" } Monaco Marker: { startLineNumber: 1, startColumn: 8, endLineNumber: 1, endColumn: 11, message: "'foo' is undefined", severity: 8, code: "TS2304", source: "typescript" } Monaco Position: (1,5) LSP Position: { line: 0, character: 4 } */
Debug
Known issues
breakingThe `setMonaco()` function was removed in v0.3.0. Previously, it was used to configure the Monaco editor module globally. Now, the `monaco` object (or relevant `Uri` utilities) must be passed directly to conversion functions where needed.
fix
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`.
affects: >=0.3.0
breakingThe deprecated singular `selectionRange` APIs were removed in v0.4.0. Functions handling single selection ranges are no longer available.
fix
If you were using singular `selectionRange` conversion, migrate to the plural `selectionRanges` APIs, which are typically used for converting multiple selection ranges.
affects: >=0.4.0
breakingThe `defaultSeverity` options for `toCodeAction` and `toMarkerData` were removed in v0.4.0. Additionally, the default severity for markers changed to `error` if no explicit severity is provided.
fix
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.
affects: >=0.4.0
gotchaWhen converting LSP `Position` and `Range` types to Monaco types, be mindful of the 0-based vs 1-based indexing. LSP uses 0-based for both lines and characters, while Monaco uses 1-based for lines and 1-based for columns. This library handles the conversion automatically, but incorrect manual manipulation can lead to off-by-one errors.
fix
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.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'Uri')
Attempting to use a conversion function like `toMarkerData` that requires `monaco.Uri` without providing the `monaco` object or `Uri` utility.
fix
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'))`.
Error: named export 'toCodeAction' not found. (hint: from 'monaco-languageserver-types')
Incorrect import path for specific conversion utilities. The library uses submodules for 'toMonaco' and 'fromMonaco' functions.
fix
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'`.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
monaco-editorrequiredProvides the target types for conversion; typically consumed as a peer dependency or external type.
vscode-languageserver-typesrequiredProvides the source types for conversion (LSP types); typically consumed as a peer dependency or external type.
Agent activity
6 hits · last 30 days
node
6
Resources