Skip to content

Commit f4e6125

Browse files
Filter LSP diagnostics to file (#4098)
1 parent 88b3687 commit f4e6125

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Fix LSP published diagnostics to filter to the opened file.
56
- Add `textDocument/documentSymbol` support for `buf lsp serve`.
67

78
## [v1.59.0] - 2025-10-20

private/buf/buflsp/file.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func (f *file) RefreshIR(ctx context.Context) {
459459
Session: session,
460460
}
461461
})
462-
results, report, err := incremental.Run(
462+
results, diagnosticReport, err := incremental.Run(
463463
ctx,
464464
f.lsp.queryExecutor,
465465
queries...,
@@ -480,8 +480,12 @@ func (f *file) RefreshIR(ctx context.Context) {
480480
file.IndexSymbols(ctx)
481481
}
482482
}
483+
// Only hold on to diagnostics where the primary span is for this path.
484+
fileDiagnostics := xslices.Filter(diagnosticReport.Diagnostics, func(d report.Diagnostic) bool {
485+
return d.Primary().Path() == f.objectInfo.Path()
486+
})
483487
diagnostics, err := xslices.MapError(
484-
report.Diagnostics,
488+
fileDiagnostics,
485489
reportDiagnosticToProtocolDiagnostic,
486490
)
487491
if err != nil {

0 commit comments

Comments
 (0)