gopls/internal/server: modify checkGoModDeps condition
- Use slices.IndexFunc to check if a file has been created or modified
once.
diff --git a/gopls/internal/server/text_synchronization.go b/gopls/internal/server/text_synchronization.go
index 6c73800..8fbef8b 100644
--- a/gopls/internal/server/text_synchronization.go
+++ b/gopls/internal/server/text_synchronization.go
@@ -10,6 +10,7 @@
"errors"
"fmt"
"path/filepath"
+ "slices"
"strings"
"sync"
@@ -254,13 +255,11 @@
// to their files.
modifications = s.session.ExpandModificationsToDirectories(ctx, modifications)
- for _, m := range modifications {
- // TODO: also handle go.work changes as well.
- if strings.HasSuffix(m.URI.Path(), "go.mod") {
- if m.Action == file.Create || m.Action == file.Change {
- s.checkGoModDeps(ctx, m.URI)
- }
- }
+ // TODO: also handle go.work changes as well.
+ if idx := slices.IndexFunc(modifications, func(m file.Modification) bool {
+ return strings.HasSuffix(m.URI.Path(), "go.mod") && (m.Action == file.Create || m.Action == file.Change)
+ }); idx != -1 {
+ s.checkGoModDeps(ctx, modifications[idx].URI)
}
viewsToDiagnose, err := s.session.DidModifyFiles(ctx, modifications)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if idx := slices.IndexFunc(modifications, func(m file.Modification) bool {I'm very sorry I was wrong about it previously. I forgot the fact that you have to run `s.checkGoModDeps()` with the URI.
In this case, we can keep using the for loop
```
var uris map[protocol.URI]struct{}
for ... {
if isModeFile && (isCreate or isChange) {
uris[uri] = struct{}
}
}
for .. := range uri {
s.checkGoModDeps(ctx, uri)
}
```This would de-duplicate.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
if idx := slices.IndexFunc(modifications, func(m file.Modification) bool {I'm very sorry I was wrong about it previously. I forgot the fact that you have to run `s.checkGoModDeps()` with the URI.
In this case, we can keep using the for loop
```
var uris map[protocol.URI]struct{}
for ... {
if isModeFile && (isCreate or isChange) {
uris[uri] = struct{}
}
}for .. := range uri {
s.checkGoModDeps(ctx, uri)
}
```This would de-duplicate.
Sure, that would handle the scenario in which there are multiple go.mod files in the workspace that have changed.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |