1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

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 <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Michael Matloob 2019-06-18 18:25:22 -04:00
parent c152035a7b
commit 8b2b8cf54a
3 changed files with 18 additions and 0 deletions

View File

@ -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
}

View File

@ -303,6 +303,7 @@ func runAnalyses(ctx context.Context, v View, pkg Package, disabledAnalyses map[
return err
}
}
pkg.SetDiagnostics(r.diagnostics)
}
return nil
}

View File

@ -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.