@@ -375,7 +375,7 @@ func (s *Snapshot) RunGoModUpdateCommands(ctx context.Context, modURI protocol.D
375375 // TODO(rfindley): we must use ModFlag and ModFile here (rather than simply
376376 // setting Args), because without knowing the verb, we can't know whether
377377 // 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" )
379379 if err != nil {
380380 return nil , nil , err
381381 }
@@ -807,7 +807,7 @@ func (s *Snapshot) fileWatchingGlobPatterns() map[protocol.RelativePattern]unit
807807 var dirs []string
808808 if s .view .typ .usesModules () {
809809 if s .view .typ == GoWorkView {
810- workVendorDir := filepath .Join (s .view .gowork .Dir (). Path (), "vendor" )
810+ workVendorDir := filepath .Join (s .view .gowork .DirPath (), "vendor" )
811811 workVendorURI := protocol .URIFromPath (workVendorDir )
812812 patterns [protocol.RelativePattern {BaseURI : workVendorURI , Pattern : watchGoFiles }] = unit {}
813813 }
@@ -818,8 +818,7 @@ func (s *Snapshot) fileWatchingGlobPatterns() map[protocol.RelativePattern]unit
818818 // The assumption is that the user is not actively editing non-workspace
819819 // modules, so don't pay the price of file watching.
820820 for modFile := range s .view .workspaceModFiles {
821- dir := filepath .Dir (modFile .Path ())
822- dirs = append (dirs , dir )
821+ dirs = append (dirs , modFile .DirPath ())
823822
824823 // TODO(golang/go#64724): thoroughly test these patterns, particularly on
825824 // on Windows.
@@ -1059,15 +1058,6 @@ func moduleForURI(modFiles map[protocol.DocumentURI]struct{}, uri protocol.Docum
10591058 return match
10601059}
10611060
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-
10711061// Metadata returns the metadata for the specified package,
10721062// or nil if it was not found.
10731063func (s * Snapshot ) Metadata (id PackageID ) * metadata.Package {
@@ -1350,7 +1340,7 @@ searchOverlays:
13501340 )
13511341 if initialErr != nil {
13521342 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 != "" {
13541344 // Check if the file's module should be loadable by considering both
13551345 // loaded modules and workspace modules. The former covers cases where
13561346 // the file is outside of a workspace folder. The latter covers cases
@@ -1363,7 +1353,7 @@ searchOverlays:
13631353 // prescriptive diagnostic in the case that there is no go.mod file, but
13641354 // it is harder to be precise in that case, and less important.
13651355 if ! (loadedMod || workspaceMod ) {
1366- modDir := filepath . Dir ( goMod .Path () )
1356+ modDir := goMod .DirPath ( )
13671357 viewDir := s .view .folder .Dir .Path ()
13681358
13691359 // 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
16641654 continue // like with go.mod files, we only reinit when things change on disk
16651655 }
16661656 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 ( ) {
16681658 reinit = true
16691659 }
16701660 if base == "go.sum" {
@@ -1947,7 +1937,7 @@ func deleteMostRelevantModFile(m *persistent.Map[protocol.DocumentURI, *memoize.
19471937
19481938 m .Range (func (modURI protocol.DocumentURI , _ * memoize.Promise ) {
19491939 if len (modURI ) > len (mostRelevant ) {
1950- if pathutil .InDir (filepath . Dir ( modURI .Path () ), changedFile ) {
1940+ if pathutil .InDir (modURI .DirPath ( ), changedFile ) {
19511941 mostRelevant = modURI
19521942 }
19531943 }
@@ -1999,12 +1989,12 @@ func invalidatedPackageIDs(uri protocol.DocumentURI, known map[protocol.Document
19991989 }{fi , err }
20001990 return fi , err
20011991 }
2002- dir := filepath . Dir ( uri .Path () )
1992+ dir := uri .DirPath ( )
20031993 fi , err := getInfo (dir )
20041994 if err == nil {
20051995 // Aggregate all possibly relevant package IDs.
20061996 for knownURI , ids := range known {
2007- knownDir := filepath . Dir ( knownURI .Path () )
1997+ knownDir := knownURI .DirPath ( )
20081998 knownFI , err := getInfo (knownDir )
20091999 if err != nil {
20102000 continue
0 commit comments