---
name: definition
description: Go to definition using LSP. Find where a function, class, or variable is defined.
---

# Go to Definition Skill

## Description

This skill uses Language Server Protocol (LSP) to find the definition location of symbols. It provides accurate "go to definition" functionality like an IDE.

## Prerequisites

Requires LSP servers to be installed:
- **Python**: `pip install python-lsp-server`
- **JavaScript/TypeScript**: `npm install -g typescript-language-server typescript`
- **C/C++**: Install clangd from LLVM

Use `check_lsp_servers` to verify installation.

## When to Use

- When the user asks "where is X defined?"
- When navigating to function/class definitions
- When exploring unfamiliar code
- When the user clicks on a symbol and wants to see its definition

## How to Use

### Step 1: Identify the Symbol Location

Get the file path, line number (0-indexed), and character position of the symbol.

### Step 2: Query Definition

Use the `lsp_get_definition` tool:

```python
lsp_get_definition(
    file_path="src/main.py",
    line=25,  # 0-indexed
    character=10,  # 0-indexed position in line
    workspace="."  # Optional workspace root
)
```

### Step 3: Show Results

Present the definition location(s) with file path and line number.

## Examples

### Example 1: Find Function Definition

**User Request:** "Where is `process_data` defined?"

**Approach:**
1. First find a reference to `process_data` using grep
2. Get its position (line, character)
3. Call `lsp_get_definition` with that position
4. Show the definition file and line number

### Example 2: Navigate to Class Definition

**User Request:** "Show me where the User class is defined"

**Approach:**
1. Find a usage of `User` in the code
2. Get its exact position
3. Call `lsp_get_definition`
4. Read and show the class definition

## Output Format

```json
{
  "success": true,
  "definitions": [
    {
      "file": "/path/to/module.py",
      "line": 42,
      "character": 0
    }
  ]
}
```

## Troubleshooting

### Server Not Installed
```json
{"success": false, "error": "No server available for python"}
```
**Solution**: Install the required LSP server.

### Symbol Not Found
```json
{"success": true, "definitions": []}
```
**Solution**: Verify the position is on the symbol name, not whitespace.

## Notes

- Line and character positions are 0-indexed
- Multiple definitions may be returned (e.g., overloaded functions)
- For built-in symbols, definition may point to stubs
- Works best with type-annotated code
