@@ -54,6 +54,7 @@ import (
54
54
"path"
55
55
"path/filepath"
56
56
"regexp"
57
+ "slices"
57
58
"sort"
58
59
"strconv"
59
60
"strings"
@@ -169,13 +170,7 @@ func PrepareRename(ctx context.Context, snapshot *cache.Snapshot, f file.Handle,
169
170
170
171
func prepareRenamePackageName (ctx context.Context , snapshot * cache.Snapshot , pgf * parsego.File ) (* PrepareItem , error ) {
171
172
// Does the client support file renaming?
172
- fileRenameSupported := false
173
- for _ , op := range snapshot .Options ().SupportedResourceOperations {
174
- if op == protocol .Rename {
175
- fileRenameSupported = true
176
- break
177
- }
178
- }
173
+ fileRenameSupported := slices .Contains (snapshot .Options ().SupportedResourceOperations , protocol .Rename )
179
174
if ! fileRenameSupported {
180
175
return nil , errors .New ("can't rename package: LSP client does not support file renaming" )
181
176
}
@@ -438,13 +433,7 @@ func Rename(ctx context.Context, snapshot *cache.Snapshot, f file.Handle, pp pro
438
433
// become reordered) and that are either identical or
439
434
// non-overlapping.
440
435
diff .SortEdits (edits )
441
- filtered := edits [:0 ]
442
- for i , edit := range edits {
443
- if i == 0 || edit != filtered [len (filtered )- 1 ] {
444
- filtered = append (filtered , edit )
445
- }
446
- }
447
- edits = filtered
436
+ edits = slices .Compact (edits )
448
437
449
438
// TODO(adonovan): the logic above handles repeat edits to the
450
439
// same file URI (e.g. as a member of package p and p_test) but
@@ -541,15 +530,15 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle
541
530
//
542
531
// Note that unlike Funcs, TypeNames are always canonical (they are "left"
543
532
// of the type parameters, unlike methods).
544
- switch obj .(type ) { // avoid "obj :=" since cases reassign the var
533
+ switch obj0 := obj .(type ) { // avoid "obj :=" since cases reassign the var
545
534
case * types.TypeName :
546
535
if _ , ok := types .Unalias (obj .Type ()).(* types.TypeParam ); ok {
547
536
// As with capitalized function parameters below, type parameters are
548
537
// local.
549
538
goto skipObjectPath
550
539
}
551
540
case * types.Func :
552
- obj = obj .( * types. Func ) .Origin ()
541
+ obj = obj0 .Origin ()
553
542
case * types.Var :
554
543
// TODO(adonovan): do vars need the origin treatment too? (issue #58462)
555
544
@@ -563,7 +552,7 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle
563
552
// objectpath, the classifies them as local vars, but as
564
553
// they came from export data they lack syntax and the
565
554
// correct scope tree (issue #61294).
566
- if ! obj .( * types. Var ) .IsField () && ! typesinternal .IsPackageLevel (obj ) {
555
+ if ! obj0 .IsField () && ! typesinternal .IsPackageLevel (obj ) {
567
556
goto skipObjectPath
568
557
}
569
558
}
0 commit comments