home / skills / plaited / agent-eval-harness / typescript-lsp@plaited_development-skills

typescript-lsp@plaited_development-skills skill

/.plaited/skills/typescript-lsp@plaited_development-skills

This skill enables type-aware TypeScript symbol exploration using LSP to quickly navigate, inspect types, and verify exports before editing.

This is most likely a fork of the typescript-lsp skill from plaited
npx playbooks add skill plaited/agent-eval-harness --skill typescript-lsp@plaited_development-skills

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
6.6 KB
---
name: typescript-lsp
description: Search TypeScript SYMBOLS (functions, types, classes) - NOT text. Use Glob to find files, Grep for text search, LSP for symbol search. Provides type-aware results that understand imports, exports, and relationships.
license: ISC
compatibility: Requires bun
allowed-tools: Bash
metadata:
  file-triggers: "*.ts,*.tsx,*.js,*.jsx"
---

# 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

| Tool | Purpose |
|------|---------|
| **Glob** | Find files by pattern |
| **Grep** | Search text content |
| **lsp-find** | Search TypeScript symbols |
| **lsp-hover** | Get type info + TSDoc documentation |
| **lsp-refs** | Find all references to a symbol |
| **lsp-analyze** | Batch analysis of file structure |

### LSP vs Grep/Glob

| Task | Use LSP | Use Grep/Glob |
|------|---------|---------------|
| Find all usages of a function/type | ✅ `lsp-refs` | ❌ Misses re-exports, aliases |
| Search for a symbol by name | ✅ `lsp-find` | ❌ Matches strings, comments |
| Get type signature + TSDoc | ✅ `lsp-hover` | ❌ Not possible |
| Understand file exports | ✅ `lsp-analyze --exports` | ❌ Doesn't resolve re-exports |
| Find files by pattern | ❌ | ✅ `Glob` |
| Search non-TS files (md, json) | ❌ | ✅ `Grep` |
| Search for text in comments/strings | ❌ | ✅ `Grep` |

## 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.

```bash
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:**
```bash
bunx @plaited/development-skills lsp-hover src/utils/parser.ts 42 10
```

#### lsp-symbols
List all symbols in a file.

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

**Example:**
```bash
bunx @plaited/development-skills lsp-symbols src/utils/parser.ts
```

#### lsp-references
Find all references to a symbol.

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

**Example:**
```bash
bunx @plaited/development-skills lsp-refs src/utils/parser.ts 42 10
```

#### lsp-find
Search for symbols across the workspace.

```bash
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:**
```bash
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.

```bash
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:**
```bash
# 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

```bash
# 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

```bash
# 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

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

### Pre-Implementation Verification

```bash
# 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:**
```json
{
  "contents": {
    "kind": "markdown",
    "value": "```typescript\nconst parseConfig: (options: Options) => Config\n```"
  },
  "range": { "start": {...}, "end": {...} }
}
```

**Symbols output:**
```json
[
  {
    "name": "symbolName",
    "kind": 13,
    "range": { "start": {...}, "end": {...} }
  }
]
```

**Analyze output:**
```json
{
  "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

Overview

This skill integrates the TypeScript Language Server Protocol to explore and understand TypeScript and JavaScript codebases. It prioritizes type-aware symbol searches over plain text search, giving accurate results that respect imports, exports, aliases, and type information. Use the included commands to jump to definitions, list symbols, inspect types, and find references across a project.

How this skill works

The skill combines three tools: Glob to locate files, Grep for plain-text searches, and LSP commands for symbol-aware queries. LSP commands (lsp-find, lsp-hover, lsp-refs, lsp-symbols, lsp-analyze) open the project with the TypeScript language server, query symbols or positions, and return JSON results that include signatures, ranges, and export metadata. For multiple queries in one session, lsp-analyze batches operations to avoid repeated server startup costs.

When to use it

  • Explore unfamiliar codebases and discover implementations of symbols
  • Find all usages of a function, type, or class before refactoring
  • Obtain exact type signatures and TSDoc documentation for APIs
  • Search for symbol names across a workspace where grep would miss re-exports or aliases
  • Use Glob/Grep when you need file-pattern results or plain-text search in non-TS files

Best practices

  • Prefer lsp-find and lsp-refs for symbol-oriented queries; they understand imports and re-exports
  • Use lsp-hover to verify types and TSDoc before making API changes
  • Batch repeated queries with lsp-analyze to reduce server startup overhead
  • Use package export paths for portability when referencing modules across projects
  • Fallback to Grep/Glob for non-TypeScript files or comment/string text searches

Example use cases

  • Before removing or renaming an exported function, run lsp-refs to list every call site
  • Locate all implementations of an interface or abstract class with lsp-find
  • Inspect a third-party API signature and docs using lsp-hover on the package export path
  • Generate a quick module overview with lsp-analyze --exports before adding new imports
  • Search the workspace for similar utilities or handler names with lsp-find

FAQ

What output format do commands produce?

All commands emit JSON to stdout; errors are written to stderr. Outputs include symbol names, kinds, ranges, and hover contents with type signatures.

When should I use lsp-analyze versus individual LSP commands?

Use lsp-analyze to run multiple symbol, hover, or refs queries in one session to avoid repeated TypeScript server startup. Use individual commands for ad-hoc single queries.