@@ -375,7 +375,7 @@ func (s *Snapshot) RunGoModUpdateCommands(ctx context.Context, modURI protocol.D
375
375
// TODO(rfindley): we must use ModFlag and ModFile here (rather than simply
376
376
// setting Args), because without knowing the verb, we can't know whether
377
377
// ModFlag is appropriate. Refactor so that args can be set by the caller.
378
- inv , cleanupInvocation , err := s .GoCommandInvocation (true , modURI .Dir (). Path (), "" , nil , "GOWORK=off" )
378
+ inv , cleanupInvocation , err := s .GoCommandInvocation (true , modURI .DirPath (), "" , nil , "GOWORK=off" )
379
379
if err != nil {
380
380
return nil , nil , err
381
381
}
@@ -807,7 +807,7 @@ func (s *Snapshot) fileWatchingGlobPatterns() map[protocol.RelativePattern]unit
807
807
var dirs []string
808
808
if s .view .typ .usesModules () {
809
809
if s .view .typ == GoWorkView {
810
- workVendorDir := filepath .Join (s .view .gowork .Dir (). Path (), "vendor" )
810
+ workVendorDir := filepath .Join (s .view .gowork .DirPath (), "vendor" )
811
811
workVendorURI := protocol .URIFromPath (workVendorDir )
812
812
patterns [protocol.RelativePattern {BaseURI : workVendorURI , Pattern : watchGoFiles }] = unit {}
813
813
}
@@ -818,8 +818,7 @@ func (s *Snapshot) fileWatchingGlobPatterns() map[protocol.RelativePattern]unit
818
818
// The assumption is that the user is not actively editing non-workspace
819
819
// modules, so don't pay the price of file watching.
820
820
for modFile := range s .view .workspaceModFiles {
821
- dir := filepath .Dir (modFile .Path ())
822
- dirs = append (dirs , dir )
821
+ dirs = append (dirs , modFile .DirPath ())
823
822
824
823
// TODO(golang/go#64724): thoroughly test these patterns, particularly on
825
824
// on Windows.
@@ -1059,15 +1058,6 @@ func moduleForURI(modFiles map[protocol.DocumentURI]struct{}, uri protocol.Docum
1059
1058
return match
1060
1059
}
1061
1060
1062
- // nearestModFile finds the nearest go.mod file contained in the directory
1063
- // containing uri, or a parent of that directory.
1064
- //
1065
- // The given uri must be a file, not a directory.
1066
- func nearestModFile (ctx context.Context , uri protocol.DocumentURI , fs file.Source ) (protocol.DocumentURI , error ) {
1067
- dir := filepath .Dir (uri .Path ())
1068
- return findRootPattern (ctx , protocol .URIFromPath (dir ), "go.mod" , fs )
1069
- }
1070
-
1071
1061
// Metadata returns the metadata for the specified package,
1072
1062
// or nil if it was not found.
1073
1063
func (s * Snapshot ) Metadata (id PackageID ) * metadata.Package {
@@ -1350,7 +1340,7 @@ searchOverlays:
1350
1340
)
1351
1341
if initialErr != nil {
1352
1342
msg = fmt .Sprintf ("initialization failed: %v" , initialErr .MainError )
1353
- } else if goMod , err := nearestModFile (ctx , fh .URI (), s ); err == nil && goMod != "" {
1343
+ } else if goMod , err := findRootPattern (ctx , fh .URI (). Dir (), "go.mod" , file . Source ( s ) ); err == nil && goMod != "" {
1354
1344
// Check if the file's module should be loadable by considering both
1355
1345
// loaded modules and workspace modules. The former covers cases where
1356
1346
// the file is outside of a workspace folder. The latter covers cases
@@ -1363,7 +1353,7 @@ searchOverlays:
1363
1353
// prescriptive diagnostic in the case that there is no go.mod file, but
1364
1354
// it is harder to be precise in that case, and less important.
1365
1355
if ! (loadedMod || workspaceMod ) {
1366
- modDir := filepath . Dir ( goMod .Path () )
1356
+ modDir := goMod .DirPath ( )
1367
1357
viewDir := s .view .folder .Dir .Path ()
1368
1358
1369
1359
// When the module is underneath the view dir, we offer
@@ -1664,7 +1654,7 @@ func (s *Snapshot) clone(ctx, bgCtx context.Context, changed StateChange, done f
1664
1654
continue // like with go.mod files, we only reinit when things change on disk
1665
1655
}
1666
1656
dir , base := filepath .Split (uri .Path ())
1667
- if base == "go.work.sum" && s .view .typ == GoWorkView && dir == filepath . Dir ( s .view .gowork .Path () ) {
1657
+ if base == "go.work.sum" && s .view .typ == GoWorkView && dir == s .view .gowork .DirPath ( ) {
1668
1658
reinit = true
1669
1659
}
1670
1660
if base == "go.sum" {
@@ -1947,7 +1937,7 @@ func deleteMostRelevantModFile(m *persistent.Map[protocol.DocumentURI, *memoize.
1947
1937
1948
1938
m .Range (func (modURI protocol.DocumentURI , _ * memoize.Promise ) {
1949
1939
if len (modURI ) > len (mostRelevant ) {
1950
- if pathutil .InDir (filepath . Dir ( modURI .Path () ), changedFile ) {
1940
+ if pathutil .InDir (modURI .DirPath ( ), changedFile ) {
1951
1941
mostRelevant = modURI
1952
1942
}
1953
1943
}
@@ -1999,12 +1989,12 @@ func invalidatedPackageIDs(uri protocol.DocumentURI, known map[protocol.Document
1999
1989
}{fi , err }
2000
1990
return fi , err
2001
1991
}
2002
- dir := filepath . Dir ( uri .Path () )
1992
+ dir := uri .DirPath ( )
2003
1993
fi , err := getInfo (dir )
2004
1994
if err == nil {
2005
1995
// Aggregate all possibly relevant package IDs.
2006
1996
for knownURI , ids := range known {
2007
- knownDir := filepath . Dir ( knownURI .Path () )
1997
+ knownDir := knownURI .DirPath ( )
2008
1998
knownFI , err := getInfo (knownDir )
2009
1999
if err != nil {
2010
2000
continue
0 commit comments