PitchHut logo
Bridge Neovim's LSP client with TypeScript's tsserver.
Pitch

ts-bridge is a TypeScript language-server shim designed for seamless integration between Neovim and tsserver. Written in Rust, it transforms LSP requests into TypeScript server protocol without reinventing the wheel. With its modular architecture, it provides a clean and efficient path for Neovim users to enhance their development experience, leveraging the power of TypeScript.

Description

ts-bridge is a robust TypeScript language-server shim developed in Rust, designed to seamlessly connect Neovim's built-in LSP client with the well-known tsserver. By acting as a bridge, it efficiently facilitates communication between the Language Server Protocol (LSP) and the TypeScript server, allowing for enhanced development capabilities within the Neovim environment.

Key Features

  • Modular Architecture: The design is organized into distinct components such as config, provider, process, and protocol, aligning with modern JavaScript and TypeScript tooling pipelines.
  • Stand-Alone Operation: The project provides a single Rust binary that manages the Neovim aspect of communication, eliminating the need for additional Lua or Node.js integrations. This setup focuses on performance while maintaining reliance on the official TypeScript installation (tsc and tsserver) for all type-checking and completion tasks.
  • Supported LSP Features: ts-bridge includes support for a variety of LSP functionalities including:
    • Initialization and server capabilities handling
    • Document management (didOpen, didChange, and didClose)
    • Diagnostics handling and streaming
    • Various document-related features such as hover, definition, completion, renaming, and formatting
    • Semantic tokens and inlay hints

How daemon mode works

At a high level, the daemon accepts many LSP connections and routes each project's requests through a shared tsserver service keyed by project root.

             ┌─────────────────────────────────────────────────┐
             │                 ts-bridge daemon                │
             │                                                 │
LSP client 1 ─┤ session (per client) ─┐                        │
LSP client 2 ─┤ session (per client) ─┼── Project registry ─┐   │
LSP client 3 ─┤ session (per client) ─┘                      │  │
             │                                               │  │
             │               project root A ── tsserver (A)  │  │
             │               project root B ── tsserver (B)  │  │
             └─────────────────────────────────────────────────┘

Installation & Setup

While ready for use out-of-the-box, ts-bridge allows for easy configuration within Neovim using lspconfig. A minimal configuration snippet is available:

local configs = require("lspconfig.configs")
local util = require("lspconfig.util")

if not configs.ts_bridge then
  configs.ts_bridge = {
    default_config = {
      cmd = { "ts-bridge" },
      filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
      root_dir = util.root_pattern("tsconfig.json", "jsconfig.json", "package.json", ".git"),
    },
  }
end

local lspconfig = require("lspconfig")

lspconfig.ts_bridge.setup({
  cmd = { "ts-bridge" },
  settings = {
    ["ts-bridge"] = {
      separate_diagnostic_server = true,
      publish_diagnostic_on = "insert_leave",
      enable_inlay_hints = true,
    },
  },
})

Daemon Mode

ts-bridge supports a daemon mode that keeps a single ts-bridge process alive, which can handle multiple LSP clients. This mode enhances responsiveness by reusing warm tsserver instances across different project sessions. Users can easily configure the daemon to run directly from Neovim or manually through the command line.

For more detailed information regarding configuration options and advanced setups, refer to the GitHub Releases page as well as the available installation scripts for differing platforms.

Contributions and issue reporting are encouraged, fostering a collaborative environment for further enhancements and bug fixes.

0 comments

No comments yet.

Sign in to be the first to comment.