This test checks the behavior of the 'extract variable/constant' code action at top level (outside any function). See issue #70665. -- a.go -- package a const Length = len("hello") + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) var Slice = append([]int{}, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) type SHA256 [32]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) func F([2]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) -- @lenhello/a.go -- @@ -3 +3,2 @@ -const Length = len("hello") + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) +const newConst = len("hello") +const Length = newConst + 2 //@codeaction(`len("hello")`, "refactor.extract.constant", edit=lenhello) -- @sliceliteral/a.go -- @@ -5 +5,2 @@ -var Slice = append([]int{}, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) +var newVar = []int{} +var Slice = append(newVar, 1, 2, 3) //@codeaction("[]int{}", "refactor.extract.variable", edit=sliceliteral) -- @arraylen/a.go -- @@ -7 +7,2 @@ -type SHA256 [32]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) +const newConst = 32 +type SHA256 [newConst]byte //@codeaction("32", "refactor.extract.constant", edit=arraylen) -- @paramtypearraylen/a.go -- @@ -9 +9,2 @@ -func F([2]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) +const newConst = 2 +func F([newConst]int) {} //@codeaction("2", "refactor.extract.constant", edit=paramtypearraylen) -- b/b.go -- package b // Check that package- and file-level name collisions are avoided. import newVar3 "errors" var newVar, newVar1, newVar2 any // these names are taken already var _ = newVar3.New("") var a, b int var C = a + b //@codeaction("a + b", "refactor.extract.variable", edit=fresh) -- @fresh/b/b.go -- @@ -10 +10,2 @@ -var C = a + b //@codeaction("a + b", "refactor.extract.variable", edit=fresh) +var newVar4 = a + b +var C = newVar4 //@codeaction("a + b", "refactor.extract.variable", edit=fresh)