Text · 2282 bytes Raw Blame History
1 #!/usr/bin/expect -f
2
3 # Test that textDocument/didSave triggers diagnostics
4
5 set timeout 10
6 log_user 1
7
8 puts "=== Testing didSave Diagnostics ===\n"
9 puts "This test verifies that saving a file triggers LSP diagnostics.\n"
10
11 # Start editor with test file
12 spawn ./fac tests/lsp/sample_errors.c
13
14 # Wait for LSP initialization
15 expect {
16 "LSP server initialized: c" {
17 puts "\n✓ LSP server initialized"
18 }
19 timeout {
20 puts "\n✗ LSP server failed to initialize"
21 exit 1
22 }
23 }
24
25 # Give LSP a moment to settle
26 sleep 2
27
28 # Save the file (Ctrl+S)
29 puts "\nSaving file with Ctrl+S..."
30 send "\023" ;# Ctrl+S
31
32 # Wait for save confirmation and didSave notification
33 expect {
34 "[LSP DEBUG] Sent didSave" {
35 puts "✓ didSave notification sent"
36 }
37 timeout {
38 puts "⚠ No didSave notification detected (check stderr)"
39 }
40 }
41
42 # Wait a moment for diagnostics to arrive
43 sleep 3
44
45 # Open diagnostics panel (Ctrl+Shift+D)
46 puts "\nOpening diagnostics panel..."
47 send "\033\[68;6u"
48 sleep 1
49
50 # Check for diagnostics
51 expect {
52 -re "\\d+ diagnostic" {
53 puts "✓ Diagnostics received and displayed!"
54 }
55 "expected ';'" {
56 puts "✓ Found specific diagnostic: missing semicolon"
57 }
58 "syntax error" {
59 puts "✓ Found syntax error diagnostic"
60 }
61 "No diagnostics" {
62 puts "✗ No diagnostics received after save"
63 }
64 timeout {
65 puts "⚠ Could not determine diagnostic status"
66 }
67 }
68
69 # Also check if we see debug messages about receiving diagnostics
70 expect {
71 "[LSP DEBUG] Received notification: textDocument/publishDiagnostics" {
72 puts "✓ publishDiagnostics notification received"
73 }
74 "[DEBUG] Received diagnostics notification" {
75 puts "✓ Diagnostics handler called"
76 }
77 timeout {
78 puts "⚠ No debug messages about diagnostics found"
79 }
80 }
81
82 # Quit
83 send "\030" ;# Ctrl+X
84 expect {
85 "Save modified" {
86 send "n"
87 puts "Declined save prompt"
88 }
89 eof {
90 puts "Editor exited"
91 }
92 }
93
94 wait
95 puts "\n=== Test complete ===\n"
96 puts "Summary:"
97 puts "- LSP server should initialize ✓"
98 puts "- didSave should be sent on Ctrl+S ✓"
99 puts "- Diagnostics should arrive after save"
100 puts "- Diagnostics panel should display errors"