| 1 | #!/usr/bin/expect -f |
| 2 | |
| 3 | # Test real-time LSP diagnostics with textDocument/didChange notifications |
| 4 | # This test verifies that: |
| 5 | # 1. Initial diagnostics are received when opening a file |
| 6 | # 2. Diagnostics update in real-time as the user types |
| 7 | # 3. The diagnostics panel displays and updates correctly |
| 8 | |
| 9 | set timeout 10 |
| 10 | spawn ./fac tests/lsp/sample_errors.c |
| 11 | |
| 12 | # Wait for editor to load and LSP to initialize |
| 13 | expect { |
| 14 | "LSP server initialized" { puts "✓ LSP server started" } |
| 15 | timeout { puts "✗ LSP server did not initialize"; exit 1 } |
| 16 | } |
| 17 | |
| 18 | # Give LSP time to analyze the file and send initial diagnostics |
| 19 | sleep 3 |
| 20 | |
| 21 | # Press Ctrl+Shift+D to open diagnostics panel |
| 22 | send "\033\[68;6u" |
| 23 | sleep 1 |
| 24 | |
| 25 | # Check that we see error diagnostics in the panel |
| 26 | expect { |
| 27 | "expected" { puts "✓ Initial diagnostics received" } |
| 28 | "syntax" { puts "✓ Initial diagnostics received" } |
| 29 | "error" { puts "✓ Initial diagnostics received" } |
| 30 | "2 diagnostic" { puts "✓ Found 2 diagnostics" } |
| 31 | timeout { puts "⚠ No initial diagnostics found (server may need more time)" } |
| 32 | } |
| 33 | |
| 34 | # Go to line 4 (the first missing semicolon) |
| 35 | send "\007" ;# Ctrl+G for goto |
| 36 | expect "Go to line:" |
| 37 | send "4\r" |
| 38 | sleep 0.5 |
| 39 | |
| 40 | # Move to end of line |
| 41 | send "\005" ;# Ctrl+E |
| 42 | sleep 0.5 |
| 43 | |
| 44 | # Add the missing semicolon |
| 45 | send ";" |
| 46 | sleep 2 ;# Wait for debounce delay (500ms) + processing time |
| 47 | |
| 48 | # Refresh diagnostics panel to see updated count |
| 49 | send "\033\[68;6u" ;# Toggle panel off and on |
| 50 | sleep 0.5 |
| 51 | send "\033\[68;6u" |
| 52 | sleep 0.5 |
| 53 | |
| 54 | # Look for updated diagnostic count (should be 1 now) |
| 55 | expect { |
| 56 | "1 diagnostic" { puts "✓ Diagnostics updated after first fix" } |
| 57 | "line 8" { puts "✓ Remaining error on line 8 shown" } |
| 58 | timeout { puts "⚠ Could not verify diagnostic update" } |
| 59 | } |
| 60 | |
| 61 | # Fix the second error - go to line 8 |
| 62 | send "\007" ;# Ctrl+G |
| 63 | expect "Go to line:" |
| 64 | send "8\r" |
| 65 | sleep 0.5 |
| 66 | |
| 67 | # Move to end of line and add semicolon |
| 68 | send "\005" ;# Ctrl+E |
| 69 | send ";" |
| 70 | sleep 2 ;# Wait for debounce + processing |
| 71 | |
| 72 | # Refresh panel again |
| 73 | send "\033\[68;6u" ;# Toggle off |
| 74 | sleep 0.5 |
| 75 | send "\033\[68;6u" ;# Toggle on |
| 76 | sleep 0.5 |
| 77 | |
| 78 | # Check if all diagnostics cleared |
| 79 | expect { |
| 80 | "No diagnostics" { puts "✓ All diagnostics cleared after fixes" } |
| 81 | "0 diagnostic" { puts "✓ No errors remaining" } |
| 82 | timeout { puts "⚠ Diagnostics may not have fully cleared" } |
| 83 | } |
| 84 | |
| 85 | # Quit without saving |
| 86 | send "\030" ;# Ctrl+X |
| 87 | expect { |
| 88 | "Save modified" { |
| 89 | send "n" |
| 90 | puts "✓ Editor detected modifications" |
| 91 | } |
| 92 | eof { puts "✓ Editor exited cleanly" } |
| 93 | timeout { send "\030" } ;# Try again |
| 94 | } |
| 95 | |
| 96 | wait |
| 97 | puts "\n=== Real-time diagnostics test complete ===\n" |