---
title: "LSP Code Intelligence"
source: https://docs.autohand.ai/guides/lsp-code-intelligence
---

# LSP Code Intelligence

Give Autohand IDE-level understanding of your codebase using the Language Server Protocol (LSP).

## Overview

The LSP tool provides Autohand with semantic code intelligence capabilities that go far beyond text search. Instead of just matching strings, Autohand can understand your code's structure, types, and relationships.

**What you get:**

-   Navigate to function and class definitions instantly
-   Find all references before making changes
-   Understand type signatures and documentation
-   Map file structure and symbol hierarchies
-   Trace call chains for debugging
-   Works across TypeScript, Python, Go, Rust, and more

## Why LSP?

Text search is useful, but it can't tell you:

-   Which `fetchUser` is the *definition* vs. a *call site*
-   What parameters a function expects
-   Which classes implement an interface
-   What functions call or are called by a given function

LSP provides semantic understanding. When Autohand uses LSP, it can:

| Use Case | LSP Operation | Benefit |
|---|---|---|
| Navigate codebase | goToDefinition | Jump directly to where functions/classes are defined |
| Understand impact | findReferences | See all places that use a symbol before changing it |
| Get type info | hover | Understand function signatures, types, and docs |
| Map file structure | documentSymbol | Get all functions/classes in a file for context |
| Find implementations | goToImplementation | Find concrete implementations of interfaces |
| Trace call chains | incomingCalls / outgoingCalls | Understand execution flow for debugging |
| Search workspace | workspaceSymbol | Find symbols by name across entire project |

## Prerequisites

Before using LSP features, install the appropriate language server for your project:

### TypeScript / JavaScript

``` bash
npm install -g typescript-language-server typescript
```

### Python

``` bash
pip install python-lsp-server
```

### Go

``` bash
go install golang.org/x/tools/gopls@latest
```

### Rust

``` bash
rustup component add rust-analyzer
```

**Tip:** Autohand auto-detects installed language servers. Once installed, LSP features work automatically for supported file types.

## LSP Operations

### goToDefinition

Find where a symbol is defined.

``` text
Prompt: "Where is the createUser function defined?"

Autohand: I'll look up the definition of createUser...

Result: Definition found at src/services/userService.ts:112:1
```

### findReferences

Find all places where a symbol is used.

``` text
Prompt: "Find all places where the User type is referenced"

Autohand: Looking up references...

Result: Found 47 references across 12 files:
  src/types/user.ts:5:10
  src/services/userService.ts:8:15
  src/components/UserProfile.tsx:12:20
  ...
```

### hover

Get type signature and documentation for a symbol.

``` text
Prompt: "What are the parameters for the fetchData function?"

Autohand: Getting type information...

Result:
function fetchData<T>(
  url: string,
  options?: RequestOptions
): Promise<ApiResponse<T>>

Fetches data from the specified URL.
@param url - The endpoint to fetch from
@param options - Optional request configuration
@returns A promise that resolves to the API response
```

### documentSymbol

List all symbols in a file.

``` text
Prompt: "What functions are defined in src/core/engine.ts?"

Autohand: Getting document symbols...

Result:
Class Engine (lines 15-450)
  Method constructor (lines 17-25)
  Method initialize (lines 27-45)
  Method start (lines 47-89)
  Method stop (lines 91-120)
  Property config (line 16)
Function createEngine (lines 455-470)
```

### incomingCalls / outgoingCalls

Trace the call hierarchy of a function.

``` text
Prompt: "What functions call processPayment?"

Autohand: Finding incoming calls...

Result: Found 3 incoming calls:
  Function handleCheckout in src/checkout/handler.ts
    Called at lines: 45, 78
  Method PaymentForm.submit in src/components/PaymentForm.tsx
    Called at line: 112
  Function retryPayment in src/payments/retry.ts
    Called at line: 23
```

## Configuration

Configure LSP behavior in `~/.autohand/config.json`:

``` json
{
  "lsp": {
    "enabled": true,
    "connectionTimeout": 10000,
    "requestTimeout": 30000,
    "servers": {
      "typescript": {
        "command": "typescript-language-server",
        "args": ["--stdio"]
      },
      "python": {
        "command": "pylsp",
        "args": []
      }
    },
    "externalServers": [
      {
        "languageId": "rust",
        "host": "127.0.0.1",
        "port": 9257
      }
    ]
  }
}
```

### Configuration options

| Option | Type | Default | Description |
|---|---|---|---|
| enabled | boolean | true | Enable/disable LSP features |
| connectionTimeout | number | 10000 | Server connection timeout in milliseconds |
| requestTimeout | number | 30000 | Request timeout in milliseconds |
| servers | object | - | Custom server configurations per language |
| externalServers | array | - | Pre-running external language servers |

### Managed vs. External servers

Autohand supports two modes for language servers:

-   **Managed servers** (default): Autohand spawns and manages the language server process. Just install the server and Autohand handles the rest.
-   **External servers**: Connect to a language server that's already running. Useful for servers that are slow to start or shared across tools.

## Real-world examples

### Refactoring safely

Before renaming a function, find all its usages:

``` text
You: I want to rename the validateEmail function to validateEmailAddress.
     Where is it used?

Autohand: Let me find all references to validateEmail...

[Uses findReferences on validateEmail]

Found 15 references across 8 files. Here's a summary:
- src/utils/validation.ts:45 (definition)
- src/forms/signup.ts:23, 67
- src/forms/profile.ts:89
- src/api/users.ts:34, 78, 112
- tests/validation.test.ts:12, 45, 67, 89, 102
...
```

### Understanding unfamiliar code

Navigate a codebase you didn't write:

``` text
You: I'm looking at handleRequest in src/server.ts.
     What functions does it call?

Autohand: Let me trace the outgoing calls...

[Uses outgoingCalls on handleRequest]

handleRequest makes 5 function calls:
1. parseRequest (src/parsing/request.ts:23)
2. authenticateUser (src/auth/authenticate.ts:45)
3. validatePayload (src/validation/payload.ts:12)
4. processRequest (src/processing/main.ts:89)
5. sendResponse (src/response/send.ts:34)
```

### Debugging with call traces

Find where a bug might originate:

``` text
You: There's a null pointer error in saveUser.
     What calls saveUser?

Autohand: Let me find the incoming calls...

[Uses incomingCalls on saveUser]

saveUser is called from 3 places:
1. UserForm.handleSubmit (src/components/UserForm.tsx:78)
2. importUsers (src/admin/import.ts:145)
3. syncFromLDAP (src/integrations/ldap.ts:234)

The importUsers function doesn't check for null values
before calling saveUser. That's likely the source.
```

## Troubleshooting

### Server not available

**Symptom:** "No language server available for \[language\]"

**Solution:** Install the required language server for your language. See [Prerequisites](#prerequisites).

### Server times out

**Symptom:** "LSP request timed out"

**Solution:** Increase timeout in config:

``` json
{
  "lsp": {
    "connectionTimeout": 30000,
    "requestTimeout": 60000
  }
}
```

### No results returned

**Symptom:** "No definition found" or "No references found"

**Possible causes:**

-   The symbol is not indexed yet (wait for server to finish initial indexing)
-   The file is not saved (LSP works with saved files)
-   The cursor position doesn't point to a valid symbol
-   The language server doesn't support this operation

### Server crashes

**Symptom:** LSP operations fail repeatedly

**Solution:**

1.  Check that your project compiles/type-checks correctly
2.  Update the language server to the latest version
3.  Restart the Autohand session

## Supported languages

| Language | File Extensions | Server |
|---|---|---|
| TypeScript | .ts, .tsx, .mts, .cts | typescript-language-server |
| JavaScript | .js, .jsx, .mjs, .cjs | typescript-language-server |
| Python | .py, .pyw, .pyi | pylsp |
| Go | .go | gopls |
| Rust | .rs | rust-analyzer |

## Next steps

[Configuration](/docs/working-with-autohand-code/configuration.html) - Advanced Autohand CLI configuration options

[Code Refactoring](/docs/guides/code-refactoring.html) - Use Autohand for safe, comprehensive refactoring

[Zed Integration](/docs/guides/zed-integration.html) - Use Autohand as an AI agent in Zed editor

[Tools Reference](/docs/working-with-autohand-code/tools.html) - Complete reference for all Autohand tools