mirror of
https://github.com/golang/go
synced 2024-11-18 19:24:39 -07:00
internal/lsp: ignore files that begin with underscores
Fixes golang/go#33540 Change-Id: I5b55c23ac8ff54db94387ed6b70ba39c61ba6108 Reviewed-on: https://go-review.googlesource.com/c/tools/+/189940 Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
89a01ca1a8
commit
1e8b33d652
12
internal/lsp/cache/session.go
vendored
12
internal/lsp/cache/session.go
vendored
@ -7,6 +7,7 @@ package cache
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -184,6 +185,17 @@ func (s *session) removeView(ctx context.Context, view *view) error {
|
||||
// TODO: Propagate the language ID through to the view.
|
||||
func (s *session) DidOpen(ctx context.Context, uri span.URI, _ source.FileKind, text []byte) {
|
||||
ctx = telemetry.File.With(ctx, uri)
|
||||
|
||||
// Files with _ prefixes are ignored.
|
||||
if strings.HasPrefix(filepath.Base(uri.Filename()), "_") {
|
||||
for _, view := range s.views {
|
||||
view.ignoredURIsMu.Lock()
|
||||
view.ignoredURIs[uri] = struct{}{}
|
||||
view.ignoredURIsMu.Unlock()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Mark the file as open.
|
||||
s.openFiles.Store(uri, true)
|
||||
|
||||
|
13
internal/lsp/cache/view.go
vendored
13
internal/lsp/cache/view.go
vendored
@ -84,7 +84,8 @@ type view struct {
|
||||
builtinPkg *ast.Package
|
||||
|
||||
// ignoredURIs is the set of URIs of files that we ignore.
|
||||
ignoredURIs map[span.URI]struct{}
|
||||
ignoredURIsMu sync.Mutex
|
||||
ignoredURIs map[span.URI]struct{}
|
||||
}
|
||||
|
||||
type metadataCache struct {
|
||||
@ -289,6 +290,9 @@ func (v *view) shutdown(context.Context) {
|
||||
// Ignore checks if the given URI is a URI we ignore.
|
||||
// As of right now, we only ignore files in the "builtin" package.
|
||||
func (v *view) Ignore(uri span.URI) bool {
|
||||
v.ignoredURIsMu.Lock()
|
||||
defer v.ignoredURIsMu.Unlock()
|
||||
|
||||
_, ok := v.ignoredURIs[uri]
|
||||
return ok
|
||||
}
|
||||
@ -326,7 +330,10 @@ func (v *view) buildBuiltinPkg(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
files[filename] = file
|
||||
|
||||
v.ignoredURIsMu.Lock()
|
||||
v.ignoredURIs[span.NewURI(filename)] = struct{}{}
|
||||
v.ignoredURIsMu.Unlock()
|
||||
}
|
||||
v.builtinPkg, _ = ast.NewPackage(cfg.Fset, files, nil, nil)
|
||||
}
|
||||
@ -341,7 +348,9 @@ func (v *view) SetContent(ctx context.Context, uri span.URI, content []byte) err
|
||||
v.cancel()
|
||||
v.backgroundCtx, v.cancel = context.WithCancel(v.baseCtx)
|
||||
|
||||
v.session.SetOverlay(uri, content)
|
||||
if !v.Ignore(uri) {
|
||||
v.session.SetOverlay(uri, content)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user