VS Code Markdown Language Server
raw JSON →The `vscode-markdown-languageserver` is a Node.js-based language server providing rich Markdown language support, including features like link completions, smart folding, document and workspace symbol navigation, document linking, renaming across files, code actions (e.g., organizing link definitions), and pull diagnostics for link validation. Currently at version `0.5.0-alpha.13`, it is actively developed, serving as the backend for VS Code's native Markdown capabilities. It operates as a standalone executable, communicating via the Language Server Protocol (LSP). The server leverages the `vscode-markdown-languageservice` for its core logic, which is recommended for developers needing a direct library for Markdown processing rather than a full LSP server. Its release cadence is tied to VS Code's development, with an 'alpha' tag signifying ongoing evolution and potential API changes.
Common errors
error Error: Connection got disposed. ↓
stdio, pipe). Verify node is available in the server's execution environment path. error No completion items / diagnostics / references found, even for valid Markdown. ↓
InitializeParams.initializationOptions.markdownFileExtensions is set to include all relevant file extensions (e.g., ['md', 'mdown']). Verify workspace/didChangeConfiguration notifications are sent with the markdown settings as described in the README (e.g., markdown.validate.enabled: true). error Cannot find module 'vscode-markdown-languageservice' or similar dependency error upon server startup. ↓
npm install (or yarn install) was run in the directory where vscode-markdown-languageserver is a dependency. If installing globally or linking, verify that the node_modules structure correctly allows the server to find its internal vscode-markdown-languageservice dependency. This typically implies a fresh npm install for the project using the language server. Warnings
breaking The package is currently in 'alpha' (`0.5.0-alpha.13`) and explicitly states 'This is still in development.' APIs are subject to change without strict adherence to semantic versioning until a stable 1.0 release. ↓
gotcha This package is a Language Server, designed to run as a separate process and communicate via LSP. It is not intended for direct use as a library to process Markdown files programmatically. For library-level Markdown functionality, use `vscode-markdown-languageservice`. ↓
gotcha The server has 'not yet been tested with other clients' besides VS Code. While it implements the standard LSP, full compatibility with non-VS Code clients (e.g., Neovim, Sublime Text) is not guaranteed and may require custom client-side configuration or workarounds. ↓
gotcha LSP servers, including this one, run in separate processes. While beneficial for performance isolation, this can lead to increased memory consumption if many language servers are active, even when files are not actively being edited. ↓
Install
npm install vscode-markdown-languageserver yarn add vscode-markdown-languageserver pnpm add vscode-markdown-languageserver Imports
- startServer wrong
import { startServer } from 'vscode-markdown-languageserver';correctimport { startServer } from 'vscode-markdown-languageserver/lib/node/server'; - Connection
import { Connection, createConnection, ProposedFeatures, TextDocuments } from 'vscode-languageserver/node'; - InitializeParams
import type { InitializeParams } from 'vscode-languageserver-protocol';
Quickstart
import { createConnection, ProposedFeatures, TextDocuments, Connection } from 'vscode-languageserver/node';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { startServer } from 'vscode-markdown-languageserver/lib/node/server';
// Create a connection for the server. The connection uses Node's IPC as a transport.
const connection: Connection = createConnection(ProposedFeatures.all);
// Create a simple text document manager.
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
connection.onInitialize((params) => {
console.log('Markdown Language Server Initialized', params);
// Client can send initialization options, e.g., for file extensions
if (params.initializationOptions) {
console.log('Received initialization options:', params.initializationOptions);
}
return {
capabilities: {
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: true },
documentSymbolProvider: true,
foldingRangeProvider: true,
documentLinkProvider: { resolveProvider: true },
referencesProvider: true,
definitionProvider: true,
renameProvider: { prepareProvider: true },
codeActionProvider: true,
// The server will pull diagnostics
diagnosticProvider: {
interFileDependencies: true,
workspaceDiagnostics: true,
},
// Custom messages are also supported
executeCommandProvider: {
commands: ['markdown/getReferencesToFileInWorkspace', 'markdown/getEditForFileRenames']
}
},
};
});
connection.onInitialized(() => {
console.log('Markdown Language Server Fully Initialized');
// Register for configuration changes if the client supports it
connection.client.register({
method: 'workspace/didChangeConfiguration'
});
});
// Listen for text document changes
documents.listen(connection);
// Start the actual Markdown language server logic
startServer(connection);
// Listen on the connection
connection.listen();
console.log('Markdown Language Server is listening...');