| 1 |
This test checks the behavior of the 'extract variable/constant' code action. |
| 2 |
See extract_variable_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 |
| 19 |
|
| 20 |
func _() { |
| 21 |
var _ = 1 + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1) |
| 22 |
var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2) |
| 23 |
} |
| 24 |
|
| 25 |
-- @basic_lit1/basic_lit.go -- |
| 26 |
@@ -4 +4,2 @@ |
| 27 |
- var _ = 1 + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1) |
| 28 |
+ const newConst = 1 |
| 29 |
+ var _ = newConst + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1) |
| 30 |
-- @basic_lit2/basic_lit.go -- |
| 31 |
@@ -5 +5,2 @@ |
| 32 |
- var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2) |
| 33 |
+ const newConst = 3 + 4 |
| 34 |
+ var _ = newConst //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2) |
| 35 |
-- func_call.go -- |
| 36 |
package extract |
| 37 |
|
| 38 |
import "strconv" |
| 39 |
|
| 40 |
func _() { |
| 41 |
x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| 42 |
str := "1" |
| 43 |
b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| 44 |
} |
| 45 |
|
| 46 |
-- @func_call1/func_call.go -- |
| 47 |
@@ -6 +6,2 @@ |
| 48 |
- x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| 49 |
+ newVar := append([]int{}, 1) |
| 50 |
+ x0 := newVar //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| 51 |
-- @func_call2/func_call.go -- |
| 52 |
@@ -8 +8,2 @@ |
| 53 |
- b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| 54 |
+ newVar, newVar1 := strconv.Atoi(str) |
| 55 |
+ b, err := newVar, newVar1 //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| 56 |
-- scope.go -- |
| 57 |
package extract |
| 58 |
|
| 59 |
import "go/ast" |
| 60 |
|
| 61 |
func _() { |
| 62 |
x0 := 0 |
| 63 |
if true { |
| 64 |
y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| 65 |
} |
| 66 |
if true { |
| 67 |
x := !false //@codeaction("!false", "refactor.extract.constant", edit=scope2) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
-- @scope1/scope.go -- |
| 72 |
@@ -8 +8,2 @@ |
| 73 |
- y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| 74 |
+ newVar := ast.CompositeLit{} |
| 75 |
+ y := newVar //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| 76 |
-- @scope2/scope.go -- |
| 77 |
@@ -11 +11,2 @@ |
| 78 |
- x := !false //@codeaction("!false", "refactor.extract.constant", edit=scope2) |
| 79 |
+ const newConst = !false |
| 80 |
+ x := newConst //@codeaction("!false", "refactor.extract.constant", edit=scope2) |