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