| 1 |
This test checks the behavior of the 'replace all occurrences of expression' code action, with resolve support. |
| 2 |
See extract_variable_all_resolve.txt for the same test with resolve support. |
| 3 |
|
| 4 |
-- capabilities.json -- |
| 5 |
{ |
| 6 |
"textDocument": { |
| 7 |
"codeAction": { |
| 8 |
"dataSupport": false, |
| 9 |
"resolveSupport": {} |
| 10 |
} |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
-- flags -- |
| 15 |
-ignore_extra_diags |
| 16 |
|
| 17 |
-- basic_lit.go -- |
| 18 |
package extract_all |
| 19 |
|
| 20 |
func _() { |
| 21 |
var _ = 1 + 2 + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 22 |
var _ = 1 + 2 + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 23 |
} |
| 24 |
-- @basic_lit/basic_lit.go -- |
| 25 |
@@ -4,2 +4,3 @@ |
| 26 |
- var _ = 1 + 2 + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 27 |
- var _ = 1 + 2 + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 28 |
+ const newConst = 1 + 2 |
| 29 |
+ var _ = newConst + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 30 |
+ var _ = newConst + 3 //@codeaction("1 + 2", "refactor.extract.constant-all", edit=basic_lit) |
| 31 |
-- nested_scope.go -- |
| 32 |
package extract_all |
| 33 |
|
| 34 |
func _() { |
| 35 |
newConst1 := 0 |
| 36 |
if true { |
| 37 |
x := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 38 |
} |
| 39 |
if true { |
| 40 |
newConst := 0 |
| 41 |
if false { |
| 42 |
y := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 43 |
} |
| 44 |
} |
| 45 |
z := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 46 |
} |
| 47 |
-- @nested_scope/nested_scope.go -- |
| 48 |
@@ -5 +5 @@ |
| 49 |
+ const newConst2 = 1 + 2 + 3 |
| 50 |
@@ -6 +7 @@ |
| 51 |
- x := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 52 |
+ x := newConst2 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 53 |
@@ -11 +12 @@ |
| 54 |
- y := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 55 |
+ y := newConst2 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 56 |
@@ -14 +15 @@ |
| 57 |
- z := 1 + 2 + 3 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 58 |
+ z := newConst2 //@codeaction("1 + 2 + 3", "refactor.extract.constant-all", edit=nested_scope) |
| 59 |
-- function_call.go -- |
| 60 |
package extract_all |
| 61 |
|
| 62 |
import "fmt" |
| 63 |
|
| 64 |
func _() { |
| 65 |
result := fmt.Sprintf("%d", 42) //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 66 |
if result != "" { |
| 67 |
anotherResult := fmt.Sprintf("%d", 42) //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 68 |
_ = anotherResult |
| 69 |
} |
| 70 |
} |
| 71 |
-- @replace_func_call/function_call.go -- |
| 72 |
@@ -6 +6,2 @@ |
| 73 |
- result := fmt.Sprintf("%d", 42) //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 74 |
+ newVar := fmt.Sprintf("%d", 42) |
| 75 |
+ result := newVar //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 76 |
@@ -8 +9 @@ |
| 77 |
- anotherResult := fmt.Sprintf("%d", 42) //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 78 |
+ anotherResult := newVar //@codeaction(`fmt.Sprintf("%d", 42)`, "refactor.extract.variable-all", edit=replace_func_call) |
| 79 |
-- composite_literals.go -- |
| 80 |
package extract_all |
| 81 |
|
| 82 |
func _() { |
| 83 |
data := []int{1, 2, 3} //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 84 |
processData(data) |
| 85 |
moreData := []int{1, 2, 3} //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 86 |
processData(moreData) |
| 87 |
} |
| 88 |
|
| 89 |
func processData(d []int) {} |
| 90 |
-- @composite/composite_literals.go -- |
| 91 |
@@ -4 +4,2 @@ |
| 92 |
- data := []int{1, 2, 3} //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 93 |
+ newVar := []int{1, 2, 3} |
| 94 |
+ data := newVar //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 95 |
@@ -6 +7 @@ |
| 96 |
- moreData := []int{1, 2, 3} //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 97 |
+ moreData := newVar //@codeaction("[]int{1, 2, 3}", "refactor.extract.variable-all", edit=composite) |
| 98 |
-- selector.go -- |
| 99 |
package extract_all |
| 100 |
|
| 101 |
type MyStruct struct { |
| 102 |
Value int |
| 103 |
} |
| 104 |
|
| 105 |
func _() { |
| 106 |
s := MyStruct{Value: 10} |
| 107 |
v := s.Value //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 108 |
if v > 0 { |
| 109 |
w := s.Value //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 110 |
_ = w |
| 111 |
} |
| 112 |
} |
| 113 |
-- @sel/selector.go -- |
| 114 |
@@ -9 +9,2 @@ |
| 115 |
- v := s.Value //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 116 |
+ newVar := s.Value |
| 117 |
+ v := newVar //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 118 |
@@ -11 +12 @@ |
| 119 |
- w := s.Value //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 120 |
+ w := newVar //@codeaction("s.Value", "refactor.extract.variable-all", edit=sel) |
| 121 |
-- index.go -- |
| 122 |
package extract_all |
| 123 |
|
| 124 |
func _() { |
| 125 |
arr := []int{1, 2, 3} |
| 126 |
val := arr[0] //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 127 |
val2 := arr[0] //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 128 |
} |
| 129 |
-- @index/index.go -- |
| 130 |
@@ -5,2 +5,3 @@ |
| 131 |
- val := arr[0] //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 132 |
- val2 := arr[0] //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 133 |
+ newVar := arr[0] |
| 134 |
+ val := newVar //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 135 |
+ val2 := newVar //@codeaction("arr[0]", "refactor.extract.variable-all", edit=index) |
| 136 |
-- slice_expr.go -- |
| 137 |
package extract_all |
| 138 |
|
| 139 |
func _() { |
| 140 |
data := []int{1, 2, 3, 4, 5} |
| 141 |
part := data[1:3] //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 142 |
anotherPart := data[1:3] //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 143 |
} |
| 144 |
-- @slice/slice_expr.go -- |
| 145 |
@@ -5,2 +5,3 @@ |
| 146 |
- part := data[1:3] //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 147 |
- anotherPart := data[1:3] //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 148 |
+ newVar := data[1:3] |
| 149 |
+ part := newVar //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 150 |
+ anotherPart := newVar //@codeaction("data[1:3]", "refactor.extract.variable-all", edit=slice) |
| 151 |
-- nested_func.go -- |
| 152 |
package extract_all |
| 153 |
|
| 154 |
func outer() { |
| 155 |
inner := func() { |
| 156 |
val := 100 + 200 //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 157 |
_ = val |
| 158 |
} |
| 159 |
inner() |
| 160 |
val := 100 + 200 //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 161 |
_ = val |
| 162 |
} |
| 163 |
-- @nested/nested_func.go -- |
| 164 |
@@ -4 +4 @@ |
| 165 |
+ const newConst = 100 + 200 |
| 166 |
@@ -5 +6 @@ |
| 167 |
- val := 100 + 200 //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 168 |
+ val := newConst //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 169 |
@@ -9 +10 @@ |
| 170 |
- val := 100 + 200 //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 171 |
+ val := newConst //@codeaction("100 + 200", "refactor.extract.constant-all", edit=nested) |
| 172 |
-- switch.go -- |
| 173 |
package extract_all |
| 174 |
|
| 175 |
func _() { |
| 176 |
value := 2 |
| 177 |
switch value { |
| 178 |
case 1: |
| 179 |
result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 180 |
_ = result |
| 181 |
case 2: |
| 182 |
result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 183 |
_ = result |
| 184 |
default: |
| 185 |
result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 186 |
_ = result |
| 187 |
} |
| 188 |
} |
| 189 |
-- @switch/switch.go -- |
| 190 |
@@ -5 +5 @@ |
| 191 |
+ newVar := value * 10 |
| 192 |
@@ -7 +8 @@ |
| 193 |
- result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 194 |
+ result := newVar //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 195 |
@@ -10 +11 @@ |
| 196 |
- result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 197 |
+ result := newVar //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 198 |
@@ -13 +14 @@ |
| 199 |
- result := value * 10 //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 200 |
+ result := newVar //@codeaction("value * 10", "refactor.extract.variable-all", edit=switch) |
| 201 |
-- switch_single.go -- |
| 202 |
package extract_all |
| 203 |
|
| 204 |
func _() { |
| 205 |
value := 2 |
| 206 |
switch value { |
| 207 |
case 1: |
| 208 |
result := value * 10 |
| 209 |
_ = result |
| 210 |
case 2: |
| 211 |
result := value * 10 |
| 212 |
_ = result |
| 213 |
default: |
| 214 |
result := value * 10 //@codeaction("value * 10", "refactor.extract.variable", edit=switch_single) |
| 215 |
_ = result |
| 216 |
} |
| 217 |
} |
| 218 |
-- @switch_single/switch_single.go -- |
| 219 |
@@ -13 +13,2 @@ |
| 220 |
- result := value * 10 //@codeaction("value * 10", "refactor.extract.variable", edit=switch_single) |
| 221 |
+ newVar := value * 10 |
| 222 |
+ result := newVar //@codeaction("value * 10", "refactor.extract.variable", edit=switch_single) |
| 223 |
-- func_list.go -- |
| 224 |
package extract_all |
| 225 |
|
| 226 |
func _() { |
| 227 |
x := func(a int) int { //@codeaction("func", "refactor.extract.variable-all", end=closeBracket1, edit=func_list) |
| 228 |
b := 1 |
| 229 |
return b + a |
| 230 |
} //@loc(closeBracket1, "}") |
| 231 |
y := func(a int) int { //@codeaction("func", "refactor.extract.variable-all", end=closeBracket2, edit=func_list) |
| 232 |
b := 1 |
| 233 |
return b + a |
| 234 |
}//@loc(closeBracket2, "}") |
| 235 |
} |
| 236 |
-- @func_list/func_list.go -- |
| 237 |
@@ -4 +4 @@ |
| 238 |
- x := func(a int) int { //@codeaction("func", "refactor.extract.variable-all", end=closeBracket1, edit=func_list) |
| 239 |
+ newVar := func(a int) int { |
| 240 |
@@ -7,5 +7,3 @@ |
| 241 |
- } //@loc(closeBracket1, "}") |
| 242 |
- y := func(a int) int { //@codeaction("func", "refactor.extract.variable-all", end=closeBracket2, edit=func_list) |
| 243 |
- b := 1 |
| 244 |
- return b + a |
| 245 |
- }//@loc(closeBracket2, "}") |
| 246 |
+ } |
| 247 |
+ x := newVar //@loc(closeBracket1, "}") |
| 248 |
+ y := newVar//@loc(closeBracket2, "}") |