Commit 3a319f6
committed
Clear stale LSP diagnostics when a file is closed
When the user closed a file, the LSP server never published empty
diagnostics to clear the Problems panel. The root cause is that the
workspace's indexFiles path calls fileManager.Track for every file in
the module, incrementing the reference count beyond the editor's own
reference. When DidClose decrements the count, it rarely drops to zero,
so fileManager.Close never calls Reset and diagnostics were never cleared.
Fix this by handling the clear explicitly in DidClose: cancel in-flight
checks, publish empty diagnostics (while IsOpenInEditor is still true),
then set version=-1 to mark the file as no longer open in the editor so
subsequent RunChecks skip re-publishing lint diagnostics.
Also update Reset to be defensive: publish empty diagnostics if
IsOpenInEditor is still true at Reset time (e.g. for workspace-external
files whose ref count drops to zero without going through DidClose).
Extract the "buf lint" diagnostic source string into a named constant
lintSourceName alongside the existing serverName constant.
Add a regression test that opens a file with a known lint violation,
waits for diagnostics, sends DidClose, then asserts the Problems panel
is cleared.
Fixes bufbuild/vscode-buf#626.1 parent 7984e01 commit 3a319f6
4 files changed
Lines changed: 67 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
514 | 555 | | |
515 | 556 | | |
516 | 557 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
1080 | 1082 | | |
1081 | 1083 | | |
1082 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
1083 | 1105 | | |
1084 | 1106 | | |
1085 | 1107 | | |
| |||
1174 | 1196 | | |
1175 | 1197 | | |
1176 | 1198 | | |
1177 | | - | |
| 1199 | + | |
1178 | 1200 | | |
1179 | 1201 | | |
1180 | 1202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
0 commit comments