| This test checks the behavior of the 'extract variable' code action. |
| See extract_variable_resolve.txt for the same test with resolve support. |
| |
| -- flags -- |
| -ignore_extra_diags |
| |
| -- basic_lit.go -- |
| package extract |
| |
| func _() { |
| var _ = 1 + 2 //@codeaction("1", "refactor.extract.variable", edit=basic_lit1) |
| var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.variable", edit=basic_lit2) |
| } |
| |
| -- @basic_lit1/basic_lit.go -- |
| @@ -4 +4,2 @@ |
| - var _ = 1 + 2 //@codeaction("1", "refactor.extract.variable", edit=basic_lit1) |
| + x := 1 |
| + var _ = x + 2 //@codeaction("1", "refactor.extract.variable", edit=basic_lit1) |
| -- @basic_lit2/basic_lit.go -- |
| @@ -5 +5,2 @@ |
| - var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.variable", edit=basic_lit2) |
| + x := 3 + 4 |
| + var _ = x //@codeaction("3 + 4", "refactor.extract.variable", edit=basic_lit2) |
| -- func_call.go -- |
| package extract |
| |
| import "strconv" |
| |
| func _() { |
| x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| str := "1" |
| b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| } |
| |
| -- @func_call1/func_call.go -- |
| @@ -6 +6,2 @@ |
| - x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| + x := append([]int{}, 1) |
| + x0 := x //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1) |
| -- @func_call2/func_call.go -- |
| @@ -8 +8,2 @@ |
| - b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| + x, x1 := strconv.Atoi(str) |
| + b, err := x, x1 //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2) |
| -- scope.go -- |
| package extract |
| |
| import "go/ast" |
| |
| func _() { |
| x0 := 0 |
| if true { |
| y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| } |
| if true { |
| x1 := !false //@codeaction("!false", "refactor.extract.variable", edit=scope2) |
| } |
| } |
| |
| -- @scope1/scope.go -- |
| @@ -8 +8,2 @@ |
| - y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| + x := ast.CompositeLit{} |
| + y := x //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1) |
| -- @scope2/scope.go -- |
| @@ -11 +11,2 @@ |
| - x1 := !false //@codeaction("!false", "refactor.extract.variable", edit=scope2) |
| + x := !false |
| + x1 := x //@codeaction("!false", "refactor.extract.variable", edit=scope2) |