Skip to content

Commit

Permalink
Skip packages with the 'ignore' build tag when searching for generate…
Browse files Browse the repository at this point in the history
…d code
  • Loading branch information
kralicky committed Sep 21, 2024
1 parent 627e559 commit 4f2bbad
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/lsp/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/fs"
"log/slog"
"maps"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -246,6 +247,25 @@ func (s *GoLanguageDriver) SynthesizeFromGoSource(importName string, res GoModul
if err != nil {
return nil, fmt.Errorf("%w: %s", os.ErrNotExist, err)
}
if len(packages) > 1 {
maps.DeleteFunc(packages, func(k string, v *goast.Package) bool {
filesIgnored := 0
for _, f := range v.Files {
if len(f.Comments) == 0 {
continue
}
// only check the first comment group
for _, comment := range f.Comments[0].List {
if strings.HasPrefix(comment.Text, "//go:build ignore") ||
strings.HasPrefix(comment.Text, "// +build ignore") {
filesIgnored++
break
}
}
}
return filesIgnored == len(v.Files)
})
}
if len(packages) != 1 {
return nil, fmt.Errorf("wrong number of packages found: %d", len(packages))
}
Expand Down

0 comments on commit 4f2bbad

Please sign in to comment.