@@ -37,6 +37,23 @@ claudecode.nvim - A Neovim plugin that implements the same WebSocket-based MCP p
37
37
- ` nix develop ` - Enter development shell with all dependencies
38
38
- ` nix fmt ` - Format all files using nix formatter
39
39
40
+ ### Integration Testing with Fixtures
41
+
42
+ The ` fixtures/ ` directory contains test Neovim configurations for verifying plugin integrations:
43
+
44
+ - ` vv <config> ` - Start Neovim with a specific fixture configuration
45
+ - ` vve <config> ` - Start Neovim with a fixture config in edit mode
46
+ - ` list-configs ` - Show available fixture configurations
47
+ - Source ` fixtures/nvim-aliases.sh ` to enable these commands
48
+
49
+ ** Available Fixtures** :
50
+
51
+ - ` netrw ` - Tests with Neovim's built-in file explorer
52
+ - ` nvim-tree ` - Tests with nvim-tree.lua file explorer
53
+ - ` oil ` - Tests with oil.nvim file explorer
54
+
55
+ ** Usage** : ` source fixtures/nvim-aliases.sh && vv oil ` starts Neovim with oil.nvim configuration
56
+
40
57
## Architecture Overview
41
58
42
59
### Core Components
@@ -65,14 +82,28 @@ The WebSocket server implements secure authentication using:
65
82
- ** Lock File Discovery** : Tokens stored in ` ~/.claude/ide/[port].lock ` for Claude CLI
66
83
- ** MCP Compliance** : Follows official Claude Code IDE authentication protocol
67
84
68
- ### MCP Tools Architecture
85
+ ### MCP Tools Architecture (✅ FULLY COMPLIANT)
69
86
70
- Tools are registered with JSON schemas and handlers. MCP-exposed tools include:
87
+ ** Complete VS Code Extension Compatibility ** : All tools now implement identical behavior and output formats as the official VS Code extension.
71
88
72
- - ` openFile ` - Opens files with optional line/text selection
73
- - ` getCurrentSelection ` - Gets current text selection
74
- - ` getOpenEditors ` - Lists currently open files
89
+ ** MCP-Exposed Tools** (with JSON schemas):
90
+
91
+ - ` openFile ` - Opens files with optional line/text selection (startLine/endLine), preview mode, text pattern matching, and makeFrontmost flag
92
+ - ` getCurrentSelection ` - Gets current text selection from active editor
93
+ - ` getLatestSelection ` - Gets most recent text selection (even from inactive editors)
94
+ - ` getOpenEditors ` - Lists currently open files with VS Code-compatible ` tabs ` structure
75
95
- ` openDiff ` - Opens native Neovim diff views
96
+ - ` checkDocumentDirty ` - Checks if document has unsaved changes
97
+ - ` saveDocument ` - Saves document with detailed success/failure reporting
98
+ - ` getWorkspaceFolders ` - Gets workspace folder information
99
+ - ` closeAllDiffTabs ` - Closes all diff-related tabs and windows
100
+ - ` getDiagnostics ` - Gets language diagnostics (errors, warnings) from the editor
101
+
102
+ ** Internal Tools** (not exposed via MCP):
103
+
104
+ - ` close_tab ` - Internal-only tool for tab management (hardcoded in Claude Code)
105
+
106
+ ** Format Compliance** : All tools return MCP-compliant format: ` {content: [{type: "text", text: "JSON-stringified-data"}]} `
76
107
77
108
### Key File Locations
78
109
@@ -81,6 +112,33 @@ Tools are registered with JSON schemas and handlers. MCP-exposed tools include:
81
112
- ` plugin/claudecode.lua ` - Plugin loader with version checks
82
113
- ` tests/ ` - Comprehensive test suite with unit, component, and integration tests
83
114
115
+ ## MCP Protocol Compliance
116
+
117
+ ### Protocol Implementation Status
118
+
119
+ - ✅ ** WebSocket Server** : RFC 6455 compliant with MCP message format
120
+ - ✅ ** Tool Registration** : JSON Schema-based tool definitions
121
+ - ✅ ** Authentication** : UUID v4 token-based secure handshake
122
+ - ✅ ** Message Format** : JSON-RPC 2.0 with MCP content structure
123
+ - ✅ ** Error Handling** : Comprehensive JSON-RPC error responses
124
+
125
+ ### VS Code Extension Compatibility
126
+
127
+ claudecode.nvim implements ** 100% feature parity** with Anthropic's official VS Code extension:
128
+
129
+ - ** Identical Tool Set** : All 10 VS Code tools implemented
130
+ - ** Compatible Formats** : Output structures match VS Code extension exactly
131
+ - ** Behavioral Consistency** : Same parameter handling and response patterns
132
+ - ** Error Compatibility** : Matching error codes and messages
133
+
134
+ ### Protocol Validation
135
+
136
+ Run ` make test ` to verify MCP compliance:
137
+
138
+ - ** Tool Format Validation** : All tools return proper MCP structure
139
+ - ** Schema Compliance** : JSON schemas validated against VS Code specs
140
+ - ** Integration Testing** : End-to-end MCP message flow verification
141
+
84
142
## Testing Architecture
85
143
86
144
Tests are organized in three layers:
@@ -91,6 +149,33 @@ Tests are organized in three layers:
91
149
92
150
Test files follow the pattern ` *_spec.lua ` or ` *_test.lua ` and use the busted framework.
93
151
152
+ ### Test Infrastructure
153
+
154
+ ** JSON Handling** : Custom JSON encoder/decoder with support for:
155
+
156
+ - Nested objects and arrays
157
+ - Special Lua keywords as object keys (` ["end"] ` )
158
+ - MCP message format validation
159
+ - VS Code extension output compatibility
160
+
161
+ ** Test Pattern** : Run specific test files during development:
162
+
163
+ ``` bash
164
+ # Run specific tool tests with proper LUA_PATH
165
+ export LUA_PATH=" ./lua/?.lua;./lua/?/init.lua;./?.lua;./?/init.lua;$LUA_PATH "
166
+ busted tests/unit/tools/specific_tool_spec.lua --verbose
167
+
168
+ # Or use make for full validation
169
+ make test # Recommended for complete validation
170
+ ```
171
+
172
+ ** Coverage Metrics** :
173
+
174
+ - ** 320+ tests** covering all MCP tools and core functionality
175
+ - ** Unit Tests** : Individual tool behavior and error cases
176
+ - ** Integration Tests** : End-to-end MCP protocol flow
177
+ - ** Format Tests** : MCP compliance and VS Code compatibility
178
+
94
179
### Test Organization Principles
95
180
96
181
- ** Isolation** : Each test should be independent and not rely on external state
@@ -274,9 +359,103 @@ rg "0\.1\.0" . # Should only show CHANGELOG.md historical entries
274
359
4 . ** Document Changes** : Update relevant documentation (this file, PROTOCOL.md, etc.)
275
360
5 . ** Commit** : Only commit after successful ` make ` execution
276
361
362
+ ### Integration Development Guidelines
363
+
364
+ ** Adding New Integrations** (file explorers, terminals, etc.):
365
+
366
+ 1 . ** Implement Integration** : Add support in relevant modules (e.g., ` lua/claudecode/tools/ ` )
367
+ 2 . ** Create Fixture Configuration** : ** REQUIRED** - Add a complete Neovim config in ` fixtures/[integration-name]/ `
368
+ 3 . ** Test Integration** : Use fixture to verify functionality with ` vv [integration-name] `
369
+ 4 . ** Update Documentation** : Add integration to fixtures list and relevant tool documentation
370
+ 5 . ** Run Full Test Suite** : Ensure ` make ` passes with new integration
371
+
372
+ ** Fixture Requirements** :
373
+
374
+ - Complete Neovim configuration with plugin dependencies
375
+ - Include ` dev-claudecode.lua ` with development keybindings
376
+ - Test all relevant claudecode.nvim features with the integration
377
+ - Document any integration-specific behaviors or limitations
378
+
379
+ ### MCP Tool Development Guidelines
380
+
381
+ ** Adding New Tools** :
382
+
383
+ 1 . ** Study Existing Patterns** : Review ` lua/claudecode/tools/ ` for consistent structure
384
+ 2 . ** Implement Handler** : Return MCP format: ` {content: [{type: "text", text: JSON}]} `
385
+ 3 . ** Add JSON Schema** : Define parameters and expose via MCP (if needed)
386
+ 4 . ** Create Tests** : Both unit tests and integration tests required
387
+ 5 . ** Update Documentation** : Add to this file's MCP tools list
388
+
389
+ ** Tool Testing Pattern** :
390
+
391
+ ``` lua
392
+ -- All tools should return MCP-compliant format
393
+ local result = tool_handler (params )
394
+ expect (result ).to_be_table ()
395
+ expect (result .content ).to_be_table ()
396
+ expect (result .content [1 ].type ).to_be (" text" )
397
+ local parsed = json_decode (result .content [1 ].text )
398
+ -- Validate parsed structure matches VS Code extension
399
+ ```
400
+
401
+ ** Error Handling Standard** :
402
+
403
+ ``` lua
404
+ -- Use consistent JSON-RPC error format
405
+ error ({
406
+ code = - 32602 , -- Invalid params
407
+ message = " Description of the issue" ,
408
+ data = " Additional context"
409
+ })
410
+ ```
411
+
277
412
### Code Quality Standards
278
413
279
- - ** Test Coverage** : Maintain comprehensive test coverage (currently 314 + tests)
414
+ - ** Test Coverage** : Maintain comprehensive test coverage (currently ** 320 + tests** , 100% success rate )
280
415
- ** Zero Warnings** : All code must pass luacheck with 0 warnings/errors
416
+ - ** MCP Compliance** : All tools must return proper MCP format with JSON-stringified content
417
+ - ** VS Code Compatibility** : New tools must match VS Code extension behavior exactly
281
418
- ** Consistent Formatting** : Use ` nix fmt ` or ` stylua ` for consistent code style
282
419
- ** Documentation** : Update CLAUDE.md for architectural changes, PROTOCOL.md for protocol changes
420
+
421
+ ### Development Quality Gates
422
+
423
+ 1 . ** ` make check ` ** - Syntax and linting (0 warnings required)
424
+ 2 . ** ` make test ` ** - All tests passing (320/320 success rate required)
425
+ 3 . ** ` make format ` ** - Consistent code formatting
426
+ 4 . ** MCP Validation** - Tools return proper format structure
427
+ 5 . ** Integration Test** - End-to-end protocol flow verification
428
+
429
+ ## Development Troubleshooting
430
+
431
+ ### Common Issues
432
+
433
+ ** Test Failures with LUA_PATH** :
434
+
435
+ ``` bash
436
+ # Tests can't find modules - use proper LUA_PATH
437
+ export LUA_PATH=" ./lua/?.lua;./lua/?/init.lua;./?.lua;./?/init.lua;$LUA_PATH "
438
+ busted tests/unit/specific_test.lua
439
+ ```
440
+
441
+ ** JSON Format Issues** :
442
+
443
+ - Ensure all tools return: ` {content: [{type: "text", text: "JSON-string"}]} `
444
+ - Use ` vim.json.encode() ` for proper JSON stringification
445
+ - Test JSON parsing with custom test decoder in ` tests/busted_setup.lua `
446
+
447
+ ** MCP Tool Registration** :
448
+
449
+ - Tools with ` schema = nil ` are internal-only
450
+ - Tools with schema are exposed via MCP
451
+ - Check ` lua/claudecode/tools/init.lua ` for registration patterns
452
+
453
+ ** Authentication Testing** :
454
+
455
+ ``` bash
456
+ # Verify auth token generation
457
+ cat ~ /.claude/ide/* .lock | jq .authToken
458
+
459
+ # Test WebSocket connection
460
+ websocat ws://localhost:PORT --header " x-claude-code-ide-authorization: $( cat ~ /.claude/ide/* .lock | jq -r .authToken) "
461
+ ```
0 commit comments