[tools] gopls/internal/golang: resolve todo to find decl using slices.Index

1 view
Skip to first unread message

Runqian Chen (Gerrit)

unread,
Dec 24, 2025, 12:44:27 AM (yesterday) Dec 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Runqian Chen has uploaded the change for review

Commit message

gopls/internal/golang: resolve todo to find decl using slices.Index

Resolve the todo comments in `findDecl` using `slices.Index` which is
available now.
Change-Id: If0346cb1e115036e702ed9806cf640e24bf45994

Change diff

diff --git a/gopls/internal/golang/change_signature.go b/gopls/internal/golang/change_signature.go
index 97cefcf..fc8c1f0 100644
--- a/gopls/internal/golang/change_signature.go
+++ b/gopls/internal/golang/change_signature.go
@@ -14,6 +14,7 @@
"go/token"
"go/types"
"regexp"
+ "slices"

goastutil "golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/cache"
@@ -793,13 +794,6 @@
}

// findDecl finds the index of decl in file.Decls.
-//
-// TODO: use slices.Index when it is available.
func findDecl(file *ast.File, decl ast.Decl) int {
- for i, d := range file.Decls {
- if d == decl {
- return i
- }
- }
- return -1
+ return slices.Index(file.Decls, decl)
}

Change information

Files:
  • M gopls/internal/golang/change_signature.go
Change size: S
Delta: 1 file changed, 2 insertions(+), 8 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: If0346cb1e115036e702ed9806cf640e24bf45994
Gerrit-Change-Number: 732520
Gerrit-PatchSet: 1
Gerrit-Owner: Runqian Chen <runqian...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages