Get the FREE Ultimate OpenClaw Setup Guide →

typescript-lsp

Scanned
npx machina-cli add skill plaited/development-skills/typescript-lsp --openclaw
Files (1)
SKILL.md
6.6 KB

TypeScript LSP Skill

Purpose

This skill provides TypeScript Language Server Protocol integration for exploring and understanding TypeScript/JavaScript codebases.

IMPORTANT: Prefer LSP tools over Grep/Glob when working with *.ts, *.tsx, *.js, *.jsx files. LSP provides type-aware results that understand imports, exports, and symbol relationships.

Use these tools to:

  • Explore codebases - Find symbols, understand module structure, discover implementations
  • Find references - Type-aware search across the entire codebase (better than grep for symbols)
  • Understand types - Get full type signatures, generics, and documentation
  • Verify before editing - Check all usages before modifying or deleting exports
  • Navigate code - Jump to definitions, find implementations

When to Use Each Tool

ToolPurpose
GlobFind files by pattern
GrepSearch text content
lsp-findSearch TypeScript symbols
lsp-hoverGet type info + TSDoc documentation
lsp-refsFind all references to a symbol
lsp-analyzeBatch analysis of file structure

LSP vs Grep/Glob

TaskUse LSPUse Grep/Glob
Find all usages of a function/typelsp-refs❌ Misses re-exports, aliases
Search for a symbol by namelsp-find❌ Matches strings, comments
Get type signature + TSDoclsp-hover❌ Not possible
Understand file exportslsp-analyze --exports❌ Doesn't resolve re-exports
Find files by patternGlob
Search non-TS files (md, json)Grep
Search for text in comments/stringsGrep

When to Use

Exploring code (prefer LSP):

  • Run lsp-find to search for symbols across the workspace
  • Run lsp-symbols to get an overview of file structure
  • Run lsp-analyze --exports to see what a module provides

Before editing code:

  • Run lsp-references to find all usages of a symbol you plan to modify
  • Run lsp-hover to verify current type signatures

Before writing code:

  • Run lsp-find to search for similar patterns or related symbols
  • Run lsp-hover on APIs you plan to use

Path Resolution

All scripts accept three types of file paths:

  • Absolute paths: /Users/name/project/src/file.ts
  • Relative paths: ./src/file.ts or ../other/file.ts
  • Package export paths: my-package/src/module.ts (resolved via Bun.resolve())

Package export paths are recommended for portability and consistency with the package's exports field.

Scripts

Individual Scripts

lsp-hover

Get type information at a specific position.

bunx @plaited/development-skills lsp-hover <file> <line> <char>

Arguments:

  • file: Path to TypeScript/JavaScript file
  • line: Line number (0-indexed)
  • char: Character position (0-indexed)

Example:

bunx @plaited/development-skills lsp-hover src/utils/parser.ts 42 10

lsp-symbols

List all symbols in a file.

bunx @plaited/development-skills lsp-symbols <file>

Example:

bunx @plaited/development-skills lsp-symbols src/utils/parser.ts

lsp-references

Find all references to a symbol.

bunx @plaited/development-skills lsp-refs <file> <line> <char>

Example:

bunx @plaited/development-skills lsp-refs src/utils/parser.ts 42 10

lsp-find

Search for symbols across the workspace.

bunx @plaited/development-skills lsp-find <query> [context-file]

Arguments:

  • query: Symbol name or partial name
  • context-file: Optional file to open for project context

Example:

bunx @plaited/development-skills lsp-find parseConfig
bunx @plaited/development-skills lsp-find validateInput src/lib/validator.ts

Batch Script

lsp-analyze

Perform multiple analyses in a single session for efficiency.

bunx @plaited/development-skills lsp-analyze <file> [options]

Options:

  • --symbols, -s: List all symbols
  • --exports, -e: List only exported symbols
  • --hover <line:char>: Get type info (repeatable)
  • --refs <line:char>: Find references (repeatable)
  • --all: Run symbols + exports analysis

Examples:

# Get file overview
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --all

# Check multiple positions
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --hover 50:10 --hover 75:5

# Before refactoring: find all references
bunx @plaited/development-skills lsp-analyze src/utils/parser.ts --refs 42:10

Common Workflows

Understanding a File

# 1. Get exports overview
bunx @plaited/development-skills lsp-analyze path/to/file.ts --exports

# 2. For specific type info, hover on interesting symbols
bunx @plaited/development-skills lsp-hover path/to/file.ts <line> <char>

Before Modifying an Export

# 1. Find all references first
bunx @plaited/development-skills lsp-refs path/to/file.ts <line> <char>

# 2. Check what depends on it
# Review the output to understand impact

Finding Patterns

# Search for similar implementations
bunx @plaited/development-skills lsp-find handleRequest
bunx @plaited/development-skills lsp-find parseConfig

Pre-Implementation Verification

# Before writing code that uses an API, verify its signature
bunx @plaited/development-skills lsp-hover path/to/api.ts <line> <char>

Output Format

All scripts output JSON to stdout. Errors go to stderr.

Hover output:

{
  "contents": {
    "kind": "markdown",
    "value": "```typescript\nconst parseConfig: (options: Options) => Config\n```"
  },
  "range": { "start": {...}, "end": {...} }
}

Symbols output:

[
  {
    "name": "symbolName",
    "kind": 13,
    "range": { "start": {...}, "end": {...} }
  }
]

Analyze output:

{
  "file": "path/to/file.ts",
  "exports": [
    { "name": "exportName", "kind": "Constant", "line": 139 }
  ]
}

Performance

Each script invocation:

  1. Starts TypeScript Language Server (~300-500ms)
  2. Initializes LSP connection
  3. Opens document
  4. Performs query
  5. Closes and stops

For multiple queries on the same file, use lsp-analyze to batch operations in a single session.

Related Skills

  • code-documentation: TSDoc standards for documentation

Source

git clone https://github.com/plaited/development-skills/blob/main/skills/typescript-lsp/SKILL.mdView on GitHub

Overview

This skill provides TypeScript Language Server Protocol integration to explore and understand TS/JS codebases. It prioritizes LSP-based symbol search over Grep or Glob to yield type-aware results that respect imports, exports, and symbol relationships.

How This Skill Works

File discovery can be done with Glob and quick text checks with Grep when needed, but symbol search is driven by LSP commands such as lsp-find, lsp-refs, lsp-hover, and lsp-analyze. These LSP tools return type-aware results that understand imports, exports, and relationships across the workspace.

When to Use It

  • Explore codebases to locate definitions, understand module structures, and discover implementations.
  • Find all references to a symbol across the project, including re-exports and aliases.
  • Understand full type signatures, generics, and documentation with lsp-hover.
  • Verify before editing by checking all usages and exports to avoid breaking changes.
  • Navigate code by jumping to definitions and implementations across files.

Quick Start

  1. Step 1: Run lsp-find <query> to search for a symbol by name.
  2. Step 2: Use lsp-refs <file> <line> <char> to see all usages across the workspace.
  3. Step 3: Run lsp-hover <file> <line> <char> to view type signatures and TSDoc.

Best Practices

  • Prioritize LSP tools (lsp-find, lsp-refs, lsp-hover) over Grep for TS/JS symbol work.
  • Use lsp-symbols to get an overview of a file's structure and symbols.
  • Run lsp-analyze --exports to understand module exports and track re-exports.
  • Use lsp-refs to gather all usages before making edits to a symbol.
  • For non-TS content, use Glob/Grep as needed; keep LSP for TS/JS symbol accuracy.

Example Use Cases

  • Find where a function is implemented across the workspace using lsp-find and lsp-refs.
  • Inspect a type's signature and documentation via lsp-hover on a symbol.
  • List all exports for a module with lsp-analyze --exports to understand its surface.
  • Locate all references to a symbol, including re-exports and aliases, with lsp-refs.
  • Get a quick symbol overview in a TS file with lsp-symbols.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers