{"id":11355,"library":"monaco-languageserver-types","title":"Monaco Language Server Types Converter","description":"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.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/remcohaszing/monaco-languageserver-types","tags":["javascript","monaco","monaco-editor","lsp","language-server-protocol","vscode-languageserver-types","typescript"],"install":[{"cmd":"npm install monaco-languageserver-types","lang":"bash","label":"npm"},{"cmd":"yarn add monaco-languageserver-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add monaco-languageserver-types","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the target types for conversion; typically consumed as a peer dependency or external type.","package":"monaco-editor","optional":false},{"reason":"Provides the source types for conversion (LSP types); typically consumed as a peer dependency or external type.","package":"vscode-languageserver-types","optional":false}],"imports":[{"note":"Conversion functions are organized into 'toMonaco' and 'fromMonaco' submodules for clarity. Use named imports from the specific path.","wrong":"import { toMonaco } from 'monaco-languageserver-types'","symbol":"toMonaco","correct":"import * as toMonaco from 'monaco-languageserver-types/lib/toMonaco'"},{"note":"Conversion functions are organized into 'toMonaco' and 'fromMonaco' submodules for clarity. Use named imports from the specific path.","wrong":"import fromMonaco from 'monaco-languageserver-types'","symbol":"fromMonaco","correct":"import * as fromMonaco from 'monaco-languageserver-types/lib/fromMonaco'"},{"note":"Specific conversion utilities like `toCodeAction` are available as named exports within their respective submodules (`toMonaco` or `fromMonaco`).","wrong":"import { toCodeAction } from 'monaco-languageserver-types'","symbol":"toCodeAction","correct":"import { toCodeAction } from 'monaco-languageserver-types/lib/toMonaco'"}],"quickstart":{"code":"import * as monaco from 'monaco-editor';\nimport type * as lsp from 'vscode-languageserver-types';\nimport { toMonaco, fromMonaco } from 'monaco-languageserver-types';\n\n// Assume 'monaco' is globally available or correctly imported if using ESM\n// This example simulates converting LSP Diagnostics to Monaco Markers\n\nconst lspDiagnostic: lsp.Diagnostic = {\n  range: {\n    start: { line: 0, character: 7 },\n    end: { line: 0, character: 10 }\n  },\n  message: \"'foo' is undefined\",\n  severity: 1, // lsp.DiagnosticSeverity.Error\n  code: \"TS2304\",\n  source: \"typescript\"\n};\n\nconst monacoMarker: monaco.editor.IMarkerData = toMonaco.toMarkerData(lspDiagnostic, monaco.Uri.parse('file:///main.ts'));\n\nconsole.log('LSP Diagnostic:', lspDiagnostic);\nconsole.log('Monaco Marker:', monacoMarker);\n\n// Example of converting Monaco Position back to LSP Position\nconst monacoPosition: monaco.Position = new monaco.Position(1, 5);\nconst lspPosition: lsp.Position = fromMonaco.fromPosition(monacoPosition);\n\nconsole.log('Monaco Position:', monacoPosition.toString());\nconsole.log('LSP Position:', lspPosition);\n\n/* Output will be similar to:\nLSP Diagnostic: { range: { start: [Object], end: [Object] }, message: \"'foo' is undefined\", severity: 1, code: \"TS2304\", source: \"typescript\" }\nMonaco Marker: { startLineNumber: 1, startColumn: 8, endLineNumber: 1, endColumn: 11, message: \"'foo' is undefined\", severity: 8, code: \"TS2304\", source: \"typescript\" }\nMonaco Position: (1,5)\nLSP Position: { line: 0, character: 4 }\n*/","lang":"typescript","description":"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."},"warnings":[{"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`.","message":"The `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.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"If you were using singular `selectionRange` conversion, migrate to the plural `selectionRanges` APIs, which are typically used for converting multiple selection ranges.","message":"The deprecated singular `selectionRange` APIs were removed in v0.4.0. Functions handling single selection ranges are no longer available.","severity":"breaking","affected_versions":">=0.4.0"},{"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.","message":"The `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.","severity":"breaking","affected_versions":">=0.4.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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'))`.","cause":"Attempting to use a conversion function like `toMarkerData` that requires `monaco.Uri` without providing the `monaco` object or `Uri` utility.","error":"TypeError: Cannot read properties of undefined (reading 'Uri')"},{"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'`.","cause":"Incorrect import path for specific conversion utilities. The library uses submodules for 'toMonaco' and 'fromMonaco' functions.","error":"Error: named export 'toCodeAction' not found. (hint: from 'monaco-languageserver-types')"}],"ecosystem":"npm"}