(ctx context.Context, snapshot *cache.Snapshot, uri protocol.DocumentURI, run func(invoke func(...string) (*bytes.Buffer, error)) error)
| 909 | } |
| 910 | |
| 911 | func (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. |
no test coverage detected