@codemirror/lsp-client

中文文档
6.3.0发布于 2026/09/17MITTypeScriptES Module近 30 天下载 13.2万

Language server protocol client for CodeMirror

原始使用文档

@codemirror/lsp-client NPM version

[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]

This package implements a language server protocol (LSP) client for the CodeMirror code editor.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

Usage

There are various ways to run a language server and connect it to a web page. You can run it on the server and proxy it through a web socket, or, if it is written in JavaScript or can be compiled to WASM, run it directly in the client. The @codemirror/lsp-client package talks to the server through a (Transport) object, which exposes a small interface for sending and receiving JSON messages.

Responsibility for how to actually talk to the server, how to connect and to handle disconnects are left to the code that implements the transport.

This example uses a crude transport that doesn't handle errors at all.

import {Transport, LSPClient, languageServerExtensions} from "@codemirror/lsp-client"
import {basicSetup, EditorView} from "codemirror"
import {typescriptLanguage} from "@codemirror/lang-javascript"

function simpleWebSocketTransport(uri: string): Promise<Transport> {
  let handlers: ((value: string) => void)[] = []
  let sock = new WebSocket(uri)
  sock.onmessage = e => { for (let h of handlers) h(e.data.toString()) }
  return new Promise(resolve => {
    sock.onopen = () => resolve({
      send(message: string) { sock.send(message) },
      subscribe(handler: (value: string) => void) { handlers.push(handler) },
      unsubscribe(handler: (value: string) => void) { handlers = handlers.filter(h => h != handler) }
    })
  })
}

let transport = await simpleWebSocketTransport("ws://host:port")
let client = new LSPClient({extensions: languageServerExtensions()}).connect(transport)

new EditorView({
  extensions: [
    basicSetup,
    typescriptLanguage,
    client.plugin("file:///some/file.ts"),
  ],
  parent: document.body
})

版本与发布记录

@codemirror/lsp-client 共发布 12 个版本,首次发布于 2025/07/02;过去 12 个月发布了 6 个版本。

版本发布日期距今
6.3.0latest2026/09/171 个月前
6.2.52026/06/095 个月前
6.2.42026/05/155 个月前
6.2.32026/04/156 个月前
6.2.22026/03/028 个月前
6.2.12025/11/2011 个月前

关于 @codemirror/lsp-client 的常见问题

@codemirror/lsp-client 是什么?

Language server protocol client for CodeMirror

如何安装 @codemirror/lsp-client?

在项目目录运行 npm install @codemirror/lsp-client,或使用 pnpm add / yarn add / bun add。

@codemirror/lsp-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codemirror/lsp-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codemirror/lsp-client 可以商用吗?

@codemirror/lsp-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codemirror/lsp-client 的下载量有多少?

根据 npm 官方下载统计,@codemirror/lsp-client 在 2026/10/10 – 2026/11/08 这 30 天内被下载 132,360 次,日均约 4,412 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codemirror/lsp-client 还在维护吗?

最新版本 6.3.0 发布于 2026/09/17(1 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 6 个;首次发布于 2025/07/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。