MCPcopy
hub / github.com/golang/tools / runGoModUpdateCommands

Method runGoModUpdateCommands

gopls/internal/server/command.go:911–940  ·  view source on GitHub ↗
(ctx context.Context, snapshot *cache.Snapshot, uri protocol.DocumentURI, run func(invoke func(...string) (*bytes.Buffer, error)) error)

Source from the content-addressed store, hash-verified

909}
910
911func (s *server) runGoModUpdateCommands(ctx context.Context, snapshot *cache.Snapshot, uri protocol.DocumentURI, run func(invoke func(...string) (*bytes.Buffer, error)) error) error {
912 // TODO(rfindley): can/should this use findRootPattern?
913 modURI := snapshot.GoModForFile(uri)
914 if modURI == "" {
915 return fmt.Errorf("no go.mod file found for %s", uri.Path())
916 }
917 newModBytes, newSumBytes, err := snapshot.RunGoModUpdateCommands(ctx, modURI, run)
918 if err != nil {
919 return err
920 }
921 sumURI := protocol.URIFromPath(strings.TrimSuffix(modURI.Path(), ".mod") + ".sum")
922
923 modChange, err := computeEditChange(ctx, snapshot, modURI, newModBytes)
924 if err != nil {
925 return err
926 }
927 sumChange, err := computeEditChange(ctx, snapshot, sumURI, newSumBytes)
928 if err != nil {
929 return err
930 }
931
932 var changes []protocol.DocumentChange
933 if modChange.Valid() {
934 changes = append(changes, modChange)
935 }
936 if sumChange.Valid() {
937 changes = append(changes, sumChange)
938 }
939 return applyChanges(ctx, s.client, changes)
940}
941
942// computeEditChange computes the edit change required to transform the
943// snapshot file specified by uri to the provided new content.

Callers 6

GoGetModuleMethod · 0.80
UpdateGoSumMethod · 0.80
TidyMethod · 0.80
EditGoDirectiveMethod · 0.80
RemoveDependencyMethod · 0.80
GoGetPackageMethod · 0.80

Calls 9

URIFromPathFunction · 0.92
computeEditChangeFunction · 0.85
appendFunction · 0.85
applyChangesFunction · 0.85
GoModForFileMethod · 0.80
PathMethod · 0.80
ErrorfMethod · 0.65
ValidMethod · 0.65

Tested by

no test coverage detected