npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@valtown/codemirror-ls

v0.2.4

Published

Val Town editor Codemirror LSP client

Readme

Codemirror Client library

codemirror-ls is a Codemirror client library for connecting a Codemirror editor to a language server.

The library is designed to make it easy to use arbitrary "renderer"s to actually display language server widgets like tooltips or context menus, so you can use your favorite libraries, like React, to render components.

To use codemirror-ls, you have to:

  1. Set up a Transport. This is an implementation of LSITransport that contains methods for registering message callbacks and sending messages to a language server. We provide a simple reference implementation of a WebSocket transport that assumes WebSocket input messages are raw output from stdout of an LSP process. This is a bit unique from other Codemirror language server clients out there -- our reference WebSocket transport needs to receive the raw output including Content-Length and all. It should be simple to change this behavior in a custom transport.
  2. Create a LSClient. The LSClient wraps the transport and provides utility methods that are internally used by plugins but also exposed. It is useful if you want to add your own additional extensions or also make LSP calls. You can reuuse an LSClient and memoize it if you want to share a language server between editors.
  3. Create actual extensions. There is a utility languageServerWithClient function to easily construct a large array of all language server extensions and configure everything at once. Under the hood, it is just constructing the extensions using the extensions "getters" this library exports, and then passing along your parameters. Importantly, if you decide to NOT use this helper, make sure that you provide a LSClient before any language server Codemirror extensions in your Codemirror extensions array.

A simple example that uses React to render components may look like

import { LSContents } from "./components/LSContents";
import { useMemo, useCallback, useState } from "react";
import ReactDOM from "react-dom/client";
import { LSContextMenu } from "./components/LSContextMenu";
import { LSSignatureHelp } from "./components/LSSignatureHelp";
import { LSGoTo } from "./components/LSGoTo";
import { LSWindow } from "./components/LSWindow";
import type * as LSP from "vscode-languageserver-protocol";
import { languageServerWithClient, LSClient } from "codemirror-ls";
import { LSWebSocketTransport } from "codemirror-ls/transport";
    
const wsTransport = new LSWebSocketTransport(url);

const lsClient = new LSClient({
  transport: newTransport,
  workspaceFolders: [{ uri: "file:///demo", name: "Demo" }],
});

const lspExtensions = languageServerWithClient({
  client: lsClient,
  documentUri: `file://${path}`,
  languageId: "typescript",
  sendIncrementalChanges: false,
  sendDidOpen: true,
  features: {
    signatureHelp: {
      render: async (dom, data, activeSignature, activeParameter) => {
        const root = ReactDOM.createRoot(dom);
        root.render(
          <LSSignatureHelp
            data={data}
            activeParameter={activeParameter}
            activeSignature={activeSignature}
          />,
        );
      },
    },
    linting: {
      render: async (dom, message) => {
        const root = ReactDOM.createRoot(dom);
        root.render(<LSContents contents={message} />);
      },
    },
    references: {
      render: async (dom, references, goToReference, onClose, kind) => {
        const root = ReactDOM.createRoot(dom);
        root.render(
          <LSGoTo
            onClose={onClose}
            locations={references}
            goTo={goToReference}
            kind={kind}
          />,
        );
      },
      modClickForDefinition: true,
      onExternalReference: (uri) => {
        console.log("Go to external reference", uri);
      },
      goToDefinitionShortcuts: ["F12"],
      modClickForDefinition: true,
    },
  },
});

const editorView = new EditorView({
  extensions: [
    basicSetup,
    javascript(),
    ...lspExtensions,
  ],
  parent: document.body,
});

Currently, our library provides the following extensions:

  • Completions: These are the list of editor suggestions you get as you type.
  • Renames: Symbol renaming. This is, for example, useful for when you want to rename a variable or function.
  • Signatures: Method or function signatures that pop up as you type out a function call.
  • Hovers: Hover tooltips that you receive when you hover over symbols.
  • Context Menu: A context menu that is triggered by right clicking a symbol. This hijacks the native context menu.
  • Linting: Red, gray, or yellow squiggles under "bad code." May also include associated code action buttons.
  • References: For viewing a list of places a symbol is referenced, or for go to definition.
  • Window: For warning messages from the LSP.

Renderers

Many of the extensions take a "renderer" as a parameter. A Renderer is just a callback that takes a dom, followed by some useful metadata, and is expected to append children to the dom to display the metadata's content.