dx-forge 0.1.3

Production-ready VCS and orchestration engine for DX tools with Git-like versioning, dual-watcher architecture, traffic branch system, and component injection
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# DX-Forge LSP Integration Guide


## Overview


This guide explains how to integrate the DX-Forge LSP (Language Server Protocol) server with your development environment, specifically VSCode.

---

## Architecture


```
┌─────────────┐         JSON-RPC         ┌──────────────┐
│   VSCode    │ ◄────────────────────► │  forge-lsp   │
│  Extension  │      stdio/IPC/TCP      │    Server    │
└─────────────┘                          └──────────────┘
       │                                        │
       │                                        │
       ▼                                        ▼
┌─────────────┐                          ┌──────────────┐
│  Language   │                          │   Semantic   │
│   Client    │                          │   Analyzer   │
└─────────────┘                          └──────────────┘
```

---

## LSP Server Capabilities


The `forge-lsp` server provides:

- **Text Synchronization**: `textDocument/didOpen`, `didChange`, `didClose`
- **Code Completion**: `textDocument/completion` for DX components
- **Hover Information**: `textDocument/hover` for symbol information
- **Semantic Analysis**: AST-based symbol resolution using tree-sitter

---

## Installation


### 1. Build the LSP Server


```bash
cd /path/to/dx-forge

# Debug build (recommended for development)

cargo build --bin forge-lsp

# Release build (if linker works on your system)

cargo build --release --bin forge-lsp
```

**Output**: Binary at `target/debug/forge-lsp` or `target/release/forge-lsp`

### 2. Verify Installation


```bash
./target/debug/forge-lsp --version
```

---

## VSCode Integration


### Method 1: Using Language Client (Recommended)


#### Install Dependencies


```bash
cd vscode-forge
npm install vscode-languageclient
```

#### Create Language Client


**File**: `src/languageClient.ts`

```typescript
import * as path from 'path';
import * as vscode from 'vscode';
import {
    LanguageClient,
    LanguageClientOptions,
    ServerOptions,
    TransportKind
} from 'vscode-languageclient/node';

let client: LanguageClient;

export function activateLanguageClient(context: vscode.ExtensionContext) {
    // Path to LSP server binary
    const serverPath = findLSPBinary();
    
    if (!serverPath) {
        vscode.window.showErrorMessage('forge-lsp binary not found');
        return;
    }

    // Server options
    const serverOptions: ServerOptions = {
        run: { command: serverPath, transport: TransportKind.stdio },
        debug: { command: serverPath, transport: TransportKind.stdio }
    };

    // Client options
    const clientOptions: LanguageClientOptions = {
        documentSelector: [
            { scheme: 'file', language: 'rust' },
            { scheme: 'file', language: 'typescript' },
            { scheme: 'file', language: 'typescriptreact' }
        ],
        synchronize: {
            fileEvents: vscode.workspace.createFileSystemWatcher('**/*.{rs,ts,tsx}')
        }
    };

    // Create and start client
    client = new LanguageClient(
        'forgeLSP',
        'DX-Forge LSP Server',
        serverOptions,
        clientOptions
    );

    client.start();
    
    context.subscriptions.push({
        dispose: () => client.stop()
    });
}

function findLSPBinary(): string | null {
    const possiblePaths = [
        path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, 'target', 'debug', 'forge-lsp'),
        path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, 'target', 'release', 'forge-lsp'),
        'forge-lsp' // In PATH
    ];

    for (const binPath of possiblePaths) {
        if (require('fs').existsSync(binPath)) {
            return binPath;
        }
    }

    return null;
}
```

#### Update Extension Activation


**File**: `src/extension.ts`

```typescript
import { activateLanguageClient } from './languageClient';

export function activate(context: vscode.ExtensionContext) {
    // ... existing code ...
    
    // Activate LSP client
    activateLanguageClient(context);
}
```

#### Update package.json


```json
{
  "activationEvents": [
    "onLanguage:rust",
    "onLanguage:typescript",
    "onLanguage:typescriptreact"
  ],
  "contributes": {
    "configuration": {
      "type": "object",
      "title": "DX-Forge LSP",
      "properties": {
        "forge.lsp.enabled": {
          "type": "boolean",
          "default": true,
          "description": "Enable DX-Forge LSP server"
        },
        "forge.lsp.serverPath": {
          "type": "string",
          "default": "",
          "description": "Custom path to forge-lsp binary"
        }
      }
    }
  }
}
```

###Method 2: Manual Stdio Communication (Current Implementation)


The current `ForgeWatcher` in [`extension.ts`](file:///f:/Code/forge/vscode-forge/src/extension.ts) uses manual stdio communication. This works but is less robust than using the official Language Client.

---

## LSP Protocol Messages


### Initialize


**Request**:
```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "processId": 12345,
    "rootUri": "file:///path/to/workspace",
    "capabilities": {}
  }
}
```

**Response**:
```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "capabilities": {
      "textDocumentSync": 2,
      "completionProvider": {},
      "hoverProvider": true
    }
  }
}
```

### Text Document Sync


**didOpen**:
```json
{
  "jsonrpc": "2.0",
  "method": "textDocument/didOpen",
  "params": {
    "textDocument": {
      "uri": "file:///path/to/file.rs",
      "languageId": "rust",
      "version": 1,
      "text": "fn main() {}"
    }
  }
}
```

### Completion


**Request**:
```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "textDocument/completion",
  "params": {
    "textDocument": { "uri": "file:///path/to/file.tsx" },
    "position": { "line": 10, "character": 5 }
  }
}
```

**Response**:
```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": [
    {
      "label": "dxButton",
      "kind": 7,
      "detail": "DX Button Component",
      "documentation": "A customizable button component"
    }
  ]
}
```

---

## Configuration


### Environment Variables


```bash
# Logging level

export RUST_LOG=info

# LSP server port (if using TCP)

export FORGE_LSP_PORT=7878
```

### VSCode Settings


`.vscode/settings.json`:
```json
{
  "forge.lsp.enabled": true,
  "forge.lsp.serverPath": "${workspaceFolder}/target/debug/forge-lsp",
  "forge.lsp.trace.server": "verbose"
}
```

---

## Debugging


### LSP Server Logs


Add logging to `src/bin/lsp.rs`:

```rust
use tracing_subscriber;

fn main() {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();
    
    // ... rest of code
}
```

Run and check logs:
```bash
./target/debug/forge-lsp 2>&1 | tee lsp.log
```

### VSCode Client Logs


1. Open VSCode Output panel
2. Select "DX-Forge LSP" from dropdown
3. View client-server communication

### Test LSP Manually


```bash
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":null,"rootUri":"file:///tmp"}}' | ./target/debug/forge-lsp
```

---

## Extending LSP Capabilities


### Add New Capability


1. **Define in `src/server/lsp.rs`**:
   ```rust
   pub fn handle_goto_definition(&self, uri: &str, line: usize, col: usize) -> Option<Location> {
       // Implementation
   }
   ```

2. **Register in `src/bin/lsp.rs`**:
   ```rust
   "textDocument/definition" => {
       let result = server.handle_goto_definition(&uri, line, col);
       // Send response
   }
   ```

3. **Update capabilities in initialize response**:
   ```rust
   "definitionProvider": true
   ```

---

## Performance Optimization


### Incremental Parsing


Currently, the semantic analyzer re-parses the entire file on each change. Optimize with:

```rust
pub fn update_file_incremental(
    &mut self,
    file_path: &Path,
    old_tree: &Tree,
    source: &str,
    changes: &[TextEdit]
) -> Result<Tree> {
    self.parser.parse(source, Some(old_tree))
}
```

### Caching


Add caching for frequently accessed symbols:

```rust
use lru::LruCache;

pub struct SemanticAnalyzer {
    parser: Parser,
    symbol_table: HashMap<String, Vec<Symbol>>,
    cache: LruCache<String, Vec<Symbol>>, // NEW
}
```

---

## Troubleshooting


See [`docs/troubleshooting.md`](file:///f:/Code/forge/docs/troubleshooting.md) for common issues.

---

## Resources


- [LSP Specification]https://microsoft.github.io/language-server-protocol/
- [tree-sitter Documentation]https://tree-sitter.github.io/tree-sitter/
- [vscode-languageclient]https://www.npmjs.com/package/vscode-languageclient