diff --git a/internal/lsp/cache/pkg.go b/internal/lsp/cache/pkg.go index b50011bf24..9728c31d9b 100644 --- a/internal/lsp/cache/pkg.go +++ b/internal/lsp/cache/pkg.go @@ -36,6 +36,9 @@ type pkg struct { // and analysis-to-analysis (horizontal) dependencies. mu sync.Mutex analyses map[*analysis.Analyzer]*analysisEntry + + diagMu sync.Mutex + diagnostics []analysis.Diagnostic } // packageID is a type that abstracts a package ID. @@ -184,3 +187,15 @@ func (pkg *pkg) GetImport(pkgPath string) source.Package { // Don't return a nil pointer because that still satisfies the interface. return nil } + +func (pkg *pkg) SetDiagnostics(diags []analysis.Diagnostic) { + pkg.diagMu.Lock() + defer pkg.diagMu.Unlock() + pkg.diagnostics = diags +} + +func (pkg *pkg) GetDiagnostics() []analysis.Diagnostic { + pkg.diagMu.Lock() + defer pkg.diagMu.Unlock() + return pkg.diagnostics +} diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index bf6c2f547e..bd70ee886a 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -303,6 +303,7 @@ func runAnalyses(ctx context.Context, v View, pkg Package, disabledAnalyses map[ return err } } + pkg.SetDiagnostics(r.diagnostics) } return nil } diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go index 4bdbc940fd..83e1de12c7 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go @@ -248,6 +248,8 @@ type Package interface { IsIllTyped() bool GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*Action, error) GetImport(pkgPath string) Package + GetDiagnostics() []analysis.Diagnostic + SetDiagnostics(diags []analysis.Diagnostic) } // TextEdit represents a change to a section of a document.