@@ -585,11 +585,11 @@ func (v *View) contains(uri protocol.DocumentURI) bool {
585
585
// directoryFilters.
586
586
func (v * View ) filterFunc () func (protocol.DocumentURI ) bool {
587
587
folderDir := v .folder .Dir .Path ()
588
- filterer := buildFilterer (folderDir , v .gomodcache , v .folder .Options )
588
+ filterer := buildFilterer (folderDir , v .gomodcache , v .folder .Options . DirectoryFilters )
589
589
return func (uri protocol.DocumentURI ) bool {
590
590
// Only filter relative to the configured root directory.
591
591
if pathutil .InDir (folderDir , uri .Path ()) {
592
- return pathExcludedByFilter (strings .TrimPrefix (uri .Path (), folderDir ), filterer )
592
+ return relPathExcludedByFilter (strings .TrimPrefix (uri .Path (), folderDir ), filterer )
593
593
}
594
594
return false
595
595
}
@@ -971,7 +971,7 @@ func getViewDefinition(ctx context.Context, runner *gocommand.Runner, fs file.So
971
971
972
972
// filterFunc is the path filter function for this workspace folder. Notably,
973
973
// it is relative to folder (which is specified by the user), not root.
974
- filterFunc := pathExcludedByFilterFunc (folder .Dir .Path (), def .gomodcache , folder .Options )
974
+ filterFunc := relPathExcludedByFilterFunc (folder .Dir .Path (), def .gomodcache , folder .Options . DirectoryFilters )
975
975
def .gomod , err = findWorkspaceModFile (ctx , folder .Dir , fs , filterFunc )
976
976
if err != nil {
977
977
return nil , err
@@ -1197,6 +1197,8 @@ var modFlagRegexp = regexp.MustCompile(`-mod[ =](\w+)`)
1197
1197
// after we have a version of the workspace go.mod file on disk. Getting a
1198
1198
// FileHandle from the cache for temporary files is problematic, since we
1199
1199
// cannot delete it.
1200
+ //
1201
+ // TODO(rfindley): move this to snapshot.go.
1200
1202
func (s * Snapshot ) vendorEnabled (ctx context.Context , modURI protocol.DocumentURI , modContent []byte ) (bool , error ) {
1201
1203
// Legacy GOPATH workspace?
1202
1204
if len (s .view .workspaceModFiles ) == 0 {
@@ -1244,27 +1246,26 @@ func allFilesExcluded(files []string, filterFunc func(protocol.DocumentURI) bool
1244
1246
return true
1245
1247
}
1246
1248
1247
- func pathExcludedByFilterFunc (folder , gomodcache string , opts * settings.Options ) func (string ) bool {
1248
- filterer := buildFilterer (folder , gomodcache , opts )
1249
+ // relPathExcludedByFilterFunc returns a func that filters paths relative to the
1250
+ // given folder according the given GOMODCACHE value and directory filters (see
1251
+ // settings.BuildOptions.DirectoryFilters).
1252
+ //
1253
+ // The resulting func returns true if the directory should be skipped.
1254
+ func relPathExcludedByFilterFunc (folder , gomodcache string , directoryFilters []string ) func (string ) bool {
1255
+ filterer := buildFilterer (folder , gomodcache , directoryFilters )
1249
1256
return func (path string ) bool {
1250
- return pathExcludedByFilter (path , filterer )
1257
+ return relPathExcludedByFilter (path , filterer )
1251
1258
}
1252
1259
}
1253
1260
1254
- // pathExcludedByFilter reports whether the path (relative to the workspace
1255
- // folder) should be excluded by the configured directory filters.
1256
- //
1257
- // TODO(rfindley): passing root and gomodcache here makes it confusing whether
1258
- // path should be absolute or relative, and has already caused at least one
1259
- // bug.
1260
- func pathExcludedByFilter (path string , filterer * Filterer ) bool {
1261
+ func relPathExcludedByFilter (path string , filterer * Filterer ) bool {
1261
1262
path = strings .TrimPrefix (filepath .ToSlash (path ), "/" )
1262
1263
return filterer .Disallow (path )
1263
1264
}
1264
1265
1265
- func buildFilterer (folder , gomodcache string , opts * settings. Options ) * Filterer {
1266
- filters := opts . DirectoryFilters
1267
-
1266
+ func buildFilterer (folder , gomodcache string , directoryFilters [] string ) * Filterer {
1267
+ var filters [] string
1268
+ filters = append ( filters , directoryFilters ... )
1268
1269
if pref := strings .TrimPrefix (gomodcache , folder ); pref != gomodcache {
1269
1270
modcacheFilter := "-" + strings .TrimPrefix (filepath .ToSlash (pref ), "/" )
1270
1271
filters = append (filters , modcacheFilter )
0 commit comments