# Zed Editor Setup

Learn how to setup Zed editor to work effectively with Tomba API using AI assistance and our comprehensive documentation.

## Quick Use

### Using Assistant Panel

In Zed's assistant panel, you can reference our documentation:

```
Please fetch the documentation from https://docs.tomba.io/llms.txt and help me create a Rust function for email verification using Tomba API
```

### Direct Web Context

```
Based on the Tomba API documentation at https://docs.tomba.io/llms.txt, generate a Go client for email finding with proper error handling
```

## Project-level Setup

### Method 1: Project Documentation

Create a documentation file in your project:

```bash
# Create docs directory
mkdir -p docs

# Download Tomba API documentation
curl -L https://docs.tomba.io/llms.txt -o docs/tomba-api.md
```

### Method 2: Workspace Configuration

Create a `.zed` directory with configuration:

```bash
mkdir -p .zed
```

Add this to `.zed/settings.json`:

```json
{
    "assistant": {
        "version": "2",
        "default_model": {
            "provider": "anthropic",
            "model": "claude-3-5-sonnet-20241022"
        },
        "custom_instructions": "When working with API code, prioritize Tomba API patterns from docs/tomba-api.md. Use proper authentication headers (X-Tomba-Key, X-Tomba-Secret) and handle rate limiting appropriately."
    },
    "context_servers": [
        {
            "id": "tomba-docs",
            "executable": {
                "command": "cat",
                "args": ["docs/tomba-api.md"]
            }
        }
    ]
}
```

## Zed-Specific Features

### 1. Language Server Integration

Configure language servers for better API development:

```json
{
    "lsp": {
        "rust-analyzer": {
            "cargo": {
                "features": ["tokio", "reqwest", "serde"]
            }
        },
        "typescript-language-server": {
            "settings": {
                "typescript": {
                    "preferences": {
                        "importModuleSpecifier": "relative"
                    }
                }
            }
        }
    }
}
```

### 2. Custom Snippets

Create Tomba API snippets in your language settings:

For JavaScript/TypeScript (`.zed/snippets/javascript.json`):

```json
{
    "tomba-email-finder": {
        "prefix": "tomba-finder",
        "body": [
            "async function findEmails(domain) {",
            "  const response = await fetch(`https://api.tomba.io/v1/domain-search?domain=${domain}`, {",
            "    headers: {",
            "      'X-Tomba-Key': process.env.TOMBA_API_KEY,",
            "      'X-Tomba-Secret': process.env.TOMBA_SECRET_KEY",
            "    }",
            "  });",
            "  ",
            "  if (!response.ok) {",
            "    throw new Error(`HTTP error! status: ${response.status}`);",
            "  }",
            "  ",
            "  return await response.json();",
            "}"
        ],
        "description": "Create a Tomba email finder function"
    },
    "tomba-email-verifier": {
        "prefix": "tomba-verify",
        "body": [
            "async function verifyEmail(email) {",
            "  const response = await fetch(`https://api.tomba.io/v1/email-verifier?email=${email}`, {",
            "    headers: {",
            "      'X-Tomba-Key': process.env.TOMBA_API_KEY,",
            "      'X-Tomba-Secret': process.env.TOMBA_SECRET_KEY",
            "    }",
            "  });",
            "  ",
            "  if (!response.ok) {",
            "    throw new Error(`HTTP error! status: ${response.status}`);",
            "  }",
            "  ",
            "  return await response.json();",
            "}"
        ],
        "description": "Create a Tomba email verifier function"
    }
}
```

For Rust (`.zed/snippets/rust.json`):

```json
{
    "tomba-client": {
        "prefix": "tomba-client",
        "body": [
            "use reqwest::Client;",
            "use serde_json::Value;",
            "use std::collections::HashMap;",
            "",
            "pub struct TombaClient {",
            "    client: Client,",
            "    api_key: String,",
            "    secret_key: String,",
            "}",
            "",
            "impl TombaClient {",
            "    pub fn new(api_key: String, secret_key: String) -> Self {",
            "        Self {",
            "            client: Client::new(),",
            "            api_key,",
            "            secret_key,",
            "        }",
            "    }",
            "",
            "    pub async fn domain_search(&self, domain: &str) -> Result<Value, reqwest::Error> {",
            "        let url = format!(\"https://api.tomba.io/v1/domain-search?domain={}\", domain);",
            "        ",
            "        let response = self.client",
            "            .get(&url)",
            "            .header(\"X-Tomba-Key\", &self.api_key)",
            "            .header(\"X-Tomba-Secret\", &self.secret_key)",
            "            .send()",
            "            .await?;",
            "        ",
            "        response.json().await",
            "    }",
            "}"
        ],
        "description": "Create a Tomba API client in Rust"
    }
}
```

## Configuration Examples

### Rust Development

For Rust projects, add this to your `Cargo.toml`:

```toml
[dependencies]
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
```

Then use the assistant:

```
Using the Tomba API documentation, create a complete Rust library for email finding and verification with proper error handling and async support
```

### Go Development

For Go projects, initialize modules:

```bash
go mod init tomba-client
go get github.com/go-resty/resty/v2
```

Assistant prompt:

```
Based on the Tomba API docs, create a Go package for email operations using the resty HTTP client with proper struct definitions and error handling
```

### Python Development

Setup virtual environment:

```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install requests aiohttp
```

Assistant prompt:

```
Using Tomba API documentation, create a Python async client class with both sync and async methods for all email operations
```

## Example Use Cases

### 1. Multi-language API Client

**Prompt:**

```
Based on docs/tomba-api.md, create API clients in Rust, Go, and Python that all follow the same interface pattern for email finding and verification
```

### 2. CLI Tool Development

**Prompt:**

```
Using the Tomba API documentation, create a CLI tool in Rust using clap that can:
- Find emails for a domain
- Verify single emails
- Bulk verify from a file
- Export results to JSON/CSV
```

### 3. Web Service Integration

**Prompt:**

```
Create a microservice using the Tomba API that provides:
- REST endpoints for email operations
- Rate limiting middleware
- Caching with Redis
- Proper logging and metrics
```

## Advanced Configuration

### Environment Variables

Create a `.env.example` file:

```bash
# Tomba API Configuration
TOMBA_API_KEY=your_api_key_here
TOMBA_SECRET_KEY=your_secret_key_here
TOMBA_BASE_URL=https://api.tomba.io/v1

# Optional Configuration
TOMBA_TIMEOUT=30
TOMBA_RATE_LIMIT=100
```

### Project Templates

Create project templates for common Tomba integrations:

```bash
# Create templates directory
mkdir -p .zed/templates

# Rust API client template
cat > .zed/templates/rust-tomba-client.rs << 'EOF'
// Tomba API Client Template
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[derive(Debug, Clone)]
pub struct TombaClient {
    client: Client,
    api_key: String,
    secret_key: String,
    base_url: String,
}

// Add your implementation here
EOF
```

### Task Configuration

Add build and test tasks to `.zed/tasks.json`:

```json
{
    "tasks": [
        {
            "label": "Build Tomba Client",
            "command": "cargo",
            "args": ["build", "--release"],
            "group": "build"
        },
        {
            "label": "Test Tomba Integration",
            "command": "cargo",
            "args": ["test", "--", "--nocapture"],
            "group": "test"
        },
        {
            "label": "Run Examples",
            "command": "cargo",
            "args": ["run", "--example", "email_finder"],
            "group": "build"
        }
    ]
}
```

## Best Practices

### 1. Structured Prompts

Use clear, structured prompts:

```
Context: Building a Rust application that processes user signups
Task: Integrate Tomba email verification
Requirements:
- Async/await pattern
- Proper error handling with custom error types
- Rate limiting with exponential backoff
- Comprehensive tests
```

### 2. Incremental Development

Build features incrementally:

```
Step 1: Create basic Tomba client struct
Step 2: Add email verification method
Step 3: Add error handling
Step 4: Add rate limiting
Step 5: Add caching layer
```

### 3. Code Review Integration

Use Zed's collaborative features:

```
Review this Tomba API integration for:
- Security best practices
- Error handling completeness
- Performance optimizations
- Code documentation
```

## Troubleshooting

### Assistant Not Responding

1. Check your API keys in Zed settings
2. Verify internet connection
3. Try restarting Zed
4. Clear assistant cache if available

### Documentation Not Found

1. Ensure `docs/tomba-api.md` exists in your project
2. Check file permissions
3. Verify the curl command downloaded the file correctly

### Build Issues

1. Check language server status in Zed
2. Verify dependencies are correctly installed
3. Review compiler/interpreter error messages

## Additional Resources

- [Zed Editor Documentation](https://zed.dev/docs)
- [Tomba API Reference](/api)
- [Authentication Guide](/authentication)
- [Rate Limits Documentation](/rate-limits)
