The `vscode-languageserver-textdocument` package provides a lightweight and immutable in-memory representation of a text document, specifically designed for use within Node.js-based Language Server Protocol (LSP) servers. It abstracts away the complexities of file system interactions, offering a consistent model for document content, versioning, and change tracking. This is a foundational utility within the larger `vscode-languageserver-node` monorepo, which is actively maintained by Microsoft. While the monorepo sees frequent `next` releases (e.g., `10.0.0-next.x` for server components), `vscode-languageserver-textdocument` itself is currently stable at version `1.0.12`, indicating a mature and less frequently changing API for its core document management functions. It is written in TypeScript and ships with comprehensive type definitions, making it well-suited for TypeScript-first development environments. Its primary differentiator is its focus on being a simple, efficient, and reliable document model optimized for LSP server operations like diagnostics, completions, and refactoring.
npm install vscode-languageserver-textdocumentVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a `TextDocument`, applying simulated text edits to generate a new document version, and retrieving document content and position/offset information. Note that `vscode-languageserver-types` is a peer dependency for `Position`, `Range`, `TextEdit`.
Ensure your Node.js runtime is updated to a version that fully supports ES2020 (Node.js 14+ recommended) or configure your build pipeline to transpile down to an older ECMAScript target if necessary.
Always capture the return value of methods that modify document content (e.g., `let newDoc = TextDocument.applyEdits(oldDoc, edits);`) and update your internal state to reference the new document.
When using multiple packages from the `vscode-languageserver-node` family, ensure they are compatible versions. Prefer stable releases unless actively testing new features, and consult the monorepo's changelog for specific compatibility notes, especially when using 'next' channel packages.
Ensure you are using ESM named imports: `import { TextDocument } from 'vscode-languageserver-textdocument';` if your environment supports it. If strictly in CJS, try `const TextDocument = require('vscode-languageserver-textdocument').TextDocument;` or `const { TextDocument } = require('vscode-languageserver-textdocument');` if the package provides CJS interop.Verify that `TextDocument.create` successfully returned a document instance and that your logic correctly handles the lifecycle of document objects, ensuring they are always valid when accessed. Check for missing input parameters to `create` or incorrect logic flow.
No dependency data recorded yet.