Skip to content

@adecore/lsp ​

A client for the Language Server Protocol 3.17, without a DOM and without Node or Bun APIs, so it runs in a backend process, a utility process or a page. It also defines LanguageService, the interface @adecore/editor-react asks its features through. Starting a server is the app's: the package takes a transport and speaks the protocol over it.

ts
import { LspSession, pathToFileUri } from '@adecore/lsp';

const session = new LspSession(transport, { rootUri: pathToFileUri('/work') });
await session.initialize();

const document = session.openDocument({ uri: pathToFileUri('/work/example.ts'), languageId: 'typescript', text });
const hover = await document.hover({ line: 0, character: 6 });
sh
bun add @adecore/lsp

What is in it ​

  • Sessions and transports: LspSession, the handshake, capabilities, configuration and shutdown, over stdio, a WebSocket or memory.
  • Documents and edits: LspDocument and its versions, the requests, stale answers, the edit helpers, workspace edits, watched files and renames.
  • Language service: the interface between editor features and the servers of a project, and a Vue and TypeScript pair.
  • Testing: FakeLanguageServer and a memory transport.

Positions are the protocol's: zero-based lines and UTF-16 characters. The edit helpers end a line at \n, \r\n or a lone \r; @adecore/editor-core does not count a lone \r as a line break, so text that holds one gets different line numbers in the two.

Limits ​

  • Only the UTF-16 position encoding is offered. A server that picks another one fails to initialize.
  • Diagnostics without a version cannot be proven fresh and are passed on while their document is open.
  • The package applies no workspace edit and touches no file. It declares only renames as resource operations.
  • A server that negotiated no document changes cannot follow an edit; applyChanges rejects.
  • A session does not reconnect. After the transport closes, start a new session and open the documents again.

The package is FSL-1.1-MIT.

Licenses and third-party notices are listed in each package.