2018-11-12 12:15:47 -07:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-24 08:14:25 -07:00
|
|
|
"fmt"
|
|
|
|
"go/ast"
|
|
|
|
"strconv"
|
2020-01-06 15:31:24 -07:00
|
|
|
"strings"
|
2019-02-07 15:27:10 -07:00
|
|
|
|
2020-01-24 08:14:25 -07:00
|
|
|
"golang.org/x/mod/modfile"
|
2019-02-06 16:47:00 -07:00
|
|
|
"golang.org/x/tools/go/analysis"
|
2019-08-14 18:12:18 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
2019-07-14 21:08:10 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
2019-02-19 19:11:15 -07:00
|
|
|
"golang.org/x/tools/internal/span"
|
2019-08-13 13:07:39 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/log"
|
|
|
|
"golang.org/x/tools/internal/telemetry/trace"
|
2019-11-21 13:14:48 -07:00
|
|
|
errors "golang.org/x/xerrors"
|
2018-11-12 12:15:47 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type Diagnostic struct {
|
2019-08-14 18:12:18 -06:00
|
|
|
Range protocol.Range
|
2019-02-27 16:08:04 -07:00
|
|
|
Message string
|
|
|
|
Source string
|
2019-09-24 22:46:57 -06:00
|
|
|
Severity protocol.DiagnosticSeverity
|
2019-09-24 14:28:59 -06:00
|
|
|
Tags []protocol.DiagnosticTag
|
2019-06-20 14:57:45 -06:00
|
|
|
|
2019-09-06 12:55:14 -06:00
|
|
|
SuggestedFixes []SuggestedFix
|
2019-10-11 03:39:09 -06:00
|
|
|
Related []RelatedInformation
|
|
|
|
}
|
|
|
|
|
2019-10-21 15:25:09 -06:00
|
|
|
type SuggestedFix struct {
|
|
|
|
Title string
|
|
|
|
Edits map[span.URI][]protocol.TextEdit
|
|
|
|
}
|
|
|
|
|
2019-10-11 03:39:09 -06:00
|
|
|
type RelatedInformation struct {
|
|
|
|
URI span.URI
|
|
|
|
Range protocol.Range
|
|
|
|
Message string
|
2019-06-20 14:57:45 -06:00
|
|
|
}
|
|
|
|
|
2020-01-24 08:14:25 -07:00
|
|
|
func Diagnostics(ctx context.Context, snapshot Snapshot, ph PackageHandle, missingModules map[string]*modfile.Require, withAnalysis bool) (map[FileIdentity][]Diagnostic, bool, error) {
|
2019-09-23 18:19:50 -06:00
|
|
|
// If we are missing dependencies, it may because the user's workspace is
|
|
|
|
// not correctly configured. Report errors, if possible.
|
2020-01-23 23:36:46 -07:00
|
|
|
var warn bool
|
2019-11-29 23:17:57 -07:00
|
|
|
if len(ph.MissingDependencies()) > 0 {
|
2020-01-11 21:59:57 -07:00
|
|
|
warn = true
|
2020-01-07 16:00:43 -07:00
|
|
|
}
|
2019-11-29 23:17:57 -07:00
|
|
|
pkg, err := ph.Check(ctx)
|
2019-07-09 15:52:23 -06:00
|
|
|
if err != nil {
|
2020-01-23 23:36:46 -07:00
|
|
|
return nil, false, err
|
2019-03-13 17:31:41 -06:00
|
|
|
}
|
2020-01-06 15:31:24 -07:00
|
|
|
// If we have a package with a single file and errors about "undeclared" symbols,
|
|
|
|
// we may have an ad-hoc package with multiple files. Show a warning message.
|
|
|
|
// TODO(golang/go#36416): Remove this when golang.org/cl/202277 is merged.
|
2020-01-07 16:00:43 -07:00
|
|
|
if len(pkg.CompiledGoFiles()) == 1 && hasUndeclaredErrors(pkg) {
|
2020-01-11 21:59:57 -07:00
|
|
|
warn = true
|
|
|
|
}
|
2020-01-24 08:14:25 -07:00
|
|
|
|
|
|
|
isMissingModule := false
|
|
|
|
for _, imp := range pkg.Imports() {
|
|
|
|
if _, ok := missingModules[imp.PkgPath()]; ok {
|
|
|
|
isMissingModule = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for dep, req := range missingModules {
|
|
|
|
// If the import is a package of the dependency, then add the package to the map, this will
|
|
|
|
// eliminate the need to do this prefix package search on each import for each file.
|
|
|
|
// Example:
|
|
|
|
// import (
|
|
|
|
// "golang.org/x/tools/go/expect"
|
|
|
|
// "golang.org/x/tools/go/packages"
|
|
|
|
// )
|
|
|
|
// They both are related to the same module: "golang.org/x/tools"
|
|
|
|
if req != nil && strings.HasPrefix(imp.PkgPath(), dep) {
|
|
|
|
missingModules[imp.PkgPath()] = req
|
|
|
|
isMissingModule = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 12:59:35 -06:00
|
|
|
// Prepare the reports we will send for the files in this package.
|
2019-11-20 22:08:58 -07:00
|
|
|
reports := make(map[FileIdentity][]Diagnostic)
|
2019-11-20 14:15:00 -07:00
|
|
|
for _, fh := range pkg.CompiledGoFiles() {
|
2020-01-21 12:45:11 -07:00
|
|
|
if err := clearReports(snapshot, reports, fh.File().Identity().URI); err != nil {
|
2020-01-23 23:36:46 -07:00
|
|
|
return nil, warn, err
|
2020-01-21 12:45:11 -07:00
|
|
|
}
|
2020-01-24 08:14:25 -07:00
|
|
|
if isMissingModule {
|
|
|
|
if err := missingModulesDiagnostics(ctx, snapshot, reports, missingModules, fh.File().Identity().URI); err != nil {
|
|
|
|
return nil, warn, err
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 12:15:47 -07:00
|
|
|
}
|
2019-05-29 12:59:35 -06:00
|
|
|
// Prepare any additional reports for the errors in this package.
|
2019-11-20 22:08:58 -07:00
|
|
|
for _, e := range pkg.GetErrors() {
|
2019-12-04 10:56:52 -07:00
|
|
|
// We only need to handle lower-level errors.
|
2019-12-19 08:01:26 -07:00
|
|
|
if e.Kind != ListError {
|
2019-06-14 12:23:47 -06:00
|
|
|
continue
|
|
|
|
}
|
2020-01-07 16:00:43 -07:00
|
|
|
// If no file is associated with the error, pick an open file from the package.
|
2020-01-13 17:43:43 -07:00
|
|
|
if e.URI.Filename() == "" {
|
2020-01-07 16:00:43 -07:00
|
|
|
for _, ph := range pkg.CompiledGoFiles() {
|
2020-02-06 14:20:50 -07:00
|
|
|
if snapshot.IsOpen(ph.File().Identity().URI) {
|
2020-01-13 17:43:43 -07:00
|
|
|
e.URI = ph.File().Identity().URI
|
2020-01-07 16:00:43 -07:00
|
|
|
}
|
|
|
|
}
|
2019-12-04 10:56:52 -07:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
if err := clearReports(snapshot, reports, e.URI); err != nil {
|
2020-01-23 23:36:46 -07:00
|
|
|
return nil, warn, err
|
2020-01-13 17:43:43 -07:00
|
|
|
}
|
2019-05-17 11:45:50 -06:00
|
|
|
}
|
2019-05-01 20:46:07 -06:00
|
|
|
// Run diagnostics for the package that this URI belongs to.
|
2020-01-25 17:58:28 -07:00
|
|
|
hadDiagnostics, err := diagnostics(ctx, snapshot, reports, pkg, len(ph.MissingDependencies()) > 0)
|
2020-01-13 17:43:43 -07:00
|
|
|
if err != nil {
|
2020-01-23 23:36:46 -07:00
|
|
|
return nil, warn, err
|
2020-01-13 17:43:43 -07:00
|
|
|
}
|
|
|
|
if !hadDiagnostics && withAnalysis {
|
2020-01-29 12:56:25 -07:00
|
|
|
// Exit early if the context has been canceled. This also protects us
|
|
|
|
// from a race on Options, see golang/go#36699.
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
return nil, warn, ctx.Err()
|
|
|
|
}
|
2019-05-01 20:46:07 -06:00
|
|
|
// If we don't have any list, parse, or type errors, run analyses.
|
2020-01-11 21:59:57 -07:00
|
|
|
if err := analyses(ctx, snapshot, reports, ph, snapshot.View().Options().DisabledAnalyses); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
2020-01-23 23:36:46 -07:00
|
|
|
return nil, warn, ctx.Err()
|
2019-12-05 14:37:47 -07:00
|
|
|
}
|
2020-01-07 16:00:43 -07:00
|
|
|
log.Error(ctx, "failed to run analyses", err, telemetry.Package.Of(ph.ID()))
|
2019-05-01 20:46:07 -06:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 23:36:46 -07:00
|
|
|
return reports, warn, nil
|
2020-01-11 21:59:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func FileDiagnostics(ctx context.Context, snapshot Snapshot, uri span.URI) (FileIdentity, []Diagnostic, error) {
|
|
|
|
fh, err := snapshot.GetFile(uri)
|
2019-12-19 12:31:39 -07:00
|
|
|
if err != nil {
|
2020-01-11 21:59:57 -07:00
|
|
|
return FileIdentity{}, nil, err
|
2019-12-19 12:31:39 -07:00
|
|
|
}
|
2020-01-11 21:59:57 -07:00
|
|
|
phs, err := snapshot.PackageHandles(ctx, fh)
|
|
|
|
if err != nil {
|
|
|
|
return FileIdentity{}, nil, err
|
2019-05-01 20:46:07 -06:00
|
|
|
}
|
2020-01-11 21:59:57 -07:00
|
|
|
ph, err := NarrowestPackageHandle(phs)
|
|
|
|
if err != nil {
|
|
|
|
return FileIdentity{}, nil, err
|
|
|
|
}
|
2020-01-24 08:14:25 -07:00
|
|
|
reports, _, err := Diagnostics(ctx, snapshot, ph, nil, true)
|
2020-01-11 21:59:57 -07:00
|
|
|
if err != nil {
|
|
|
|
return FileIdentity{}, nil, err
|
|
|
|
}
|
|
|
|
diagnostics, ok := reports[fh.Identity()]
|
|
|
|
if !ok {
|
|
|
|
return FileIdentity{}, nil, errors.Errorf("no diagnostics for %s", uri)
|
|
|
|
}
|
|
|
|
return fh.Identity(), diagnostics, nil
|
2019-05-01 20:46:07 -06:00
|
|
|
}
|
|
|
|
|
2019-06-14 15:16:26 -06:00
|
|
|
type diagnosticSet struct {
|
2019-08-14 18:12:18 -06:00
|
|
|
listErrors, parseErrors, typeErrors []*Diagnostic
|
2019-06-14 15:16:26 -06:00
|
|
|
}
|
|
|
|
|
2020-01-25 17:58:28 -07:00
|
|
|
func diagnostics(ctx context.Context, snapshot Snapshot, reports map[FileIdentity][]Diagnostic, pkg Package, hasMissingDeps bool) (bool, error) {
|
2019-07-09 18:16:21 -06:00
|
|
|
ctx, done := trace.StartSpan(ctx, "source.diagnostics", telemetry.Package.Of(pkg.ID()))
|
2019-11-12 15:58:37 -07:00
|
|
|
_ = ctx // circumvent SA4006
|
2019-07-09 18:16:21 -06:00
|
|
|
defer done()
|
2019-08-02 17:45:56 -06:00
|
|
|
|
2020-01-21 12:45:11 -07:00
|
|
|
diagSets := make(map[span.URI]*diagnosticSet)
|
2019-11-20 22:08:58 -07:00
|
|
|
for _, e := range pkg.GetErrors() {
|
2019-08-14 18:12:18 -06:00
|
|
|
diag := &Diagnostic{
|
2019-11-20 22:08:58 -07:00
|
|
|
Message: e.Message,
|
|
|
|
Range: e.Range,
|
2019-09-24 22:46:57 -06:00
|
|
|
Severity: protocol.SeverityError,
|
2019-06-14 15:16:26 -06:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
set, ok := diagSets[e.URI]
|
2019-06-14 15:16:26 -06:00
|
|
|
if !ok {
|
|
|
|
set = &diagnosticSet{}
|
2020-01-21 12:45:11 -07:00
|
|
|
diagSets[e.URI] = set
|
2019-06-14 15:16:26 -06:00
|
|
|
}
|
2019-11-20 22:08:58 -07:00
|
|
|
switch e.Kind {
|
2019-10-21 15:25:09 -06:00
|
|
|
case ParseError:
|
2019-06-14 15:16:26 -06:00
|
|
|
set.parseErrors = append(set.parseErrors, diag)
|
2019-10-20 17:57:03 -06:00
|
|
|
diag.Source = "syntax"
|
2019-10-21 15:25:09 -06:00
|
|
|
case TypeError:
|
2019-06-14 15:16:26 -06:00
|
|
|
set.typeErrors = append(set.typeErrors, diag)
|
2019-10-20 17:57:03 -06:00
|
|
|
diag.Source = "compiler"
|
2019-12-19 08:01:26 -07:00
|
|
|
case ListError:
|
2019-06-14 15:16:26 -06:00
|
|
|
set.listErrors = append(set.listErrors, diag)
|
2019-10-20 17:57:03 -06:00
|
|
|
diag.Source = "go list"
|
2018-11-12 12:15:47 -07:00
|
|
|
}
|
|
|
|
}
|
2019-06-14 15:16:26 -06:00
|
|
|
var nonEmptyDiagnostics bool // track if we actually send non-empty diagnostics
|
2020-01-21 12:45:11 -07:00
|
|
|
for uri, set := range diagSets {
|
2019-06-14 15:16:26 -06:00
|
|
|
// Don't report type errors if there are parse errors or list errors.
|
|
|
|
diags := set.typeErrors
|
|
|
|
if len(set.parseErrors) > 0 {
|
|
|
|
diags = set.parseErrors
|
|
|
|
} else if len(set.listErrors) > 0 {
|
2020-01-25 17:58:28 -07:00
|
|
|
// Only show list errors if the package has missing dependencies.
|
|
|
|
if hasMissingDeps {
|
|
|
|
diags = set.listErrors
|
|
|
|
}
|
2018-12-20 15:31:55 -07:00
|
|
|
}
|
2019-06-14 15:16:26 -06:00
|
|
|
if len(diags) > 0 {
|
|
|
|
nonEmptyDiagnostics = true
|
2018-11-12 12:15:47 -07:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
if err := addReports(ctx, snapshot, reports, uri, diags...); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2018-11-12 12:15:47 -07:00
|
|
|
}
|
2020-01-13 17:43:43 -07:00
|
|
|
return nonEmptyDiagnostics, nil
|
2019-05-01 20:46:07 -06:00
|
|
|
}
|
|
|
|
|
2020-01-24 08:14:25 -07:00
|
|
|
func missingModulesDiagnostics(ctx context.Context, snapshot Snapshot, reports map[FileIdentity][]Diagnostic, missingModules map[string]*modfile.Require, uri span.URI) error {
|
|
|
|
if snapshot.View().Ignore(uri) || len(missingModules) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
fh, err := snapshot.GetFile(uri)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
file, m, _, err := snapshot.View().Session().Cache().ParseGoHandle(fh, ParseHeader).Parse(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(ctx, "could not parse go file when checking for missing modules", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Make a dependency->import map to improve performance when finding missing dependencies.
|
|
|
|
imports := make(map[string]*ast.ImportSpec)
|
|
|
|
for _, imp := range file.Imports {
|
|
|
|
if imp.Path == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if target, err := strconv.Unquote(imp.Path.Value); err == nil {
|
|
|
|
imports[target] = imp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the go file has 0 imports, then we do not need to check for missing dependencies.
|
|
|
|
if len(imports) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if reports[fh.Identity()] == nil {
|
|
|
|
reports[fh.Identity()] = []Diagnostic{}
|
|
|
|
}
|
|
|
|
for mod, req := range missingModules {
|
|
|
|
if req.Syntax == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
imp, ok := imports[mod]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
spn, err := span.NewRange(snapshot.View().Session().Cache().FileSet(), imp.Path.Pos(), imp.Path.End()).Span()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rng, err := m.Range(spn)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reports[fh.Identity()] = append(reports[fh.Identity()], Diagnostic{
|
|
|
|
Message: fmt.Sprintf("%s is not in your go.mod file.", req.Mod.Path),
|
|
|
|
Range: rng,
|
|
|
|
Source: "go mod tidy",
|
|
|
|
Severity: protocol.SeverityWarning,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-13 17:43:43 -07:00
|
|
|
func analyses(ctx context.Context, snapshot Snapshot, reports map[FileIdentity][]Diagnostic, ph PackageHandle, disabledAnalyses map[string]struct{}) error {
|
2019-10-21 15:25:09 -06:00
|
|
|
var analyzers []*analysis.Analyzer
|
|
|
|
for _, a := range snapshot.View().Options().Analyzers {
|
|
|
|
if _, ok := disabledAnalyses[a.Name]; ok {
|
|
|
|
continue
|
2019-03-15 11:19:43 -06:00
|
|
|
}
|
2019-10-21 15:25:09 -06:00
|
|
|
analyzers = append(analyzers, a)
|
2019-10-11 03:39:09 -06:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:17:57 -07:00
|
|
|
diagnostics, err := snapshot.Analyze(ctx, ph.ID(), analyzers)
|
2019-06-20 14:57:45 -06:00
|
|
|
if err != nil {
|
2019-10-21 15:25:09 -06:00
|
|
|
return err
|
2019-06-20 14:57:45 -06:00
|
|
|
}
|
2019-10-11 03:39:09 -06:00
|
|
|
|
2019-10-21 15:25:09 -06:00
|
|
|
// Report diagnostics and errors from root analyzers.
|
2019-10-24 16:15:23 -06:00
|
|
|
for _, e := range diagnostics {
|
|
|
|
// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
|
|
|
|
// If we are deleting code as part of all of our suggested fixes, assume that this is dead code.
|
|
|
|
// TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
|
|
|
|
var tags []protocol.DiagnosticTag
|
|
|
|
if onlyDeletions(e.SuggestedFixes) {
|
|
|
|
tags = append(tags, protocol.Unnecessary)
|
2019-10-21 13:10:19 -06:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
if err := addReports(ctx, snapshot, reports, e.URI, &Diagnostic{
|
2019-10-24 16:15:23 -06:00
|
|
|
Range: e.Range,
|
|
|
|
Message: e.Message,
|
|
|
|
Source: e.Category,
|
|
|
|
Severity: protocol.SeverityWarning,
|
|
|
|
Tags: tags,
|
|
|
|
SuggestedFixes: e.SuggestedFixes,
|
|
|
|
Related: e.Related,
|
2020-01-21 12:45:11 -07:00
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-21 13:10:19 -06:00
|
|
|
}
|
2019-10-21 15:25:09 -06:00
|
|
|
return nil
|
2019-10-21 13:10:19 -06:00
|
|
|
}
|
|
|
|
|
2020-01-21 12:45:11 -07:00
|
|
|
func clearReports(snapshot Snapshot, reports map[FileIdentity][]Diagnostic, uri span.URI) error {
|
|
|
|
if snapshot.View().Ignore(uri) {
|
|
|
|
return nil
|
2019-05-31 22:08:57 -06:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
fh, err := snapshot.GetFile(uri)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reports[fh.Identity()] = []Diagnostic{}
|
|
|
|
return nil
|
2019-06-20 14:57:45 -06:00
|
|
|
}
|
|
|
|
|
2020-01-21 12:45:11 -07:00
|
|
|
func addReports(ctx context.Context, snapshot Snapshot, reports map[FileIdentity][]Diagnostic, uri span.URI, diagnostics ...*Diagnostic) error {
|
|
|
|
if snapshot.View().Ignore(uri) {
|
2019-11-20 22:08:58 -07:00
|
|
|
return nil
|
2019-05-31 22:08:57 -06:00
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
fh, err := snapshot.GetFile(uri)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, ok := reports[fh.Identity()]; !ok {
|
|
|
|
return errors.Errorf("diagnostics for unexpected file %s", uri)
|
2019-11-21 13:14:48 -07:00
|
|
|
}
|
|
|
|
for _, diag := range diagnostics {
|
|
|
|
if diag == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-01-21 12:45:11 -07:00
|
|
|
reports[fh.Identity()] = append(reports[fh.Identity()], *diag)
|
2019-08-14 18:12:18 -06:00
|
|
|
}
|
2019-11-20 22:08:58 -07:00
|
|
|
return nil
|
2019-05-31 22:08:57 -06:00
|
|
|
}
|
|
|
|
|
2019-10-21 15:25:09 -06:00
|
|
|
// onlyDeletions returns true if all of the suggested fixes are deletions.
|
|
|
|
func onlyDeletions(fixes []SuggestedFix) bool {
|
|
|
|
for _, fix := range fixes {
|
|
|
|
for _, edits := range fix.Edits {
|
|
|
|
for _, edit := range edits {
|
|
|
|
if edit.NewText != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if protocol.ComparePosition(edit.Range.Start, edit.Range.End) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
2019-06-20 14:57:45 -06:00
|
|
|
}
|
2019-07-09 15:52:23 -06:00
|
|
|
}
|
2019-02-06 09:24:10 -07:00
|
|
|
}
|
2019-10-21 15:25:09 -06:00
|
|
|
return true
|
2019-02-06 09:24:10 -07:00
|
|
|
}
|
2020-01-06 15:31:24 -07:00
|
|
|
|
|
|
|
// hasUndeclaredErrors returns true if a package has a type error
|
|
|
|
// about an undeclared symbol.
|
|
|
|
func hasUndeclaredErrors(pkg Package) bool {
|
|
|
|
for _, err := range pkg.GetErrors() {
|
|
|
|
if err.Kind != TypeError {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.Contains(err.Message, "undeclared name:") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|