From 8b2b8cf54a6a1ee11911d31b72c90e3f92054cfc Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 18 Jun 2019 18:25:22 -0400 Subject: [PATCH] internal/lsp: add a field on the package to store diagnostics So we can surface their code actions later. Change-Id: I735e5d025a1250861d49db227f5a79453f599140 Reviewed-on: https://go-review.googlesource.com/c/tools/+/182837 Run-TryBot: Michael Matloob Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cache/pkg.go | 15 +++++++++++++++ internal/lsp/source/diagnostics.go | 1 + internal/lsp/source/view.go | 2 ++ 3 files changed, 18 insertions(+) diff --git a/internal/lsp/cache/pkg.go b/internal/lsp/cache/pkg.go index b50011bf..9728c31d 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 bf6c2f54..bd70ee88 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 4bdbc940..83e1de12 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.