Debian Codegraph @

gopls/internal/test/marker/testdata/codeaction/extract_variable_resolve.txt

raw
1 This test checks the behavior of the 'extract variable/constant' code action, with resolve support.
2 See extract_variable.txt for the same test without resolve support.
3
4 -- flags --
5 -ignore_extra_diags
6
7 -- basic_lit.go --
8 package extract
9
10 func _() {
11 var _ = 1 + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1)
12 var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2)
13 }
14
15 -- @basic_lit1/basic_lit.go --
16 @@ -4 +4,2 @@
17 - var _ = 1 + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1)
18 + const newConst = 1
19 + var _ = newConst + 2 //@codeaction("1", "refactor.extract.constant", edit=basic_lit1)
20 -- @basic_lit2/basic_lit.go --
21 @@ -5 +5,2 @@
22 - var _ = 3 + 4 //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2)
23 + const newConst = 3 + 4
24 + var _ = newConst //@codeaction("3 + 4", "refactor.extract.constant", edit=basic_lit2)
25 -- func_call.go --
26 package extract
27
28 import "strconv"
29
30 func _() {
31 x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1)
32 str := "1"
33 b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2)
34 }
35
36 -- @func_call1/func_call.go --
37 @@ -6 +6,2 @@
38 - x0 := append([]int{}, 1) //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1)
39 + newVar := append([]int{}, 1)
40 + x0 := newVar //@codeaction("append([]int{}, 1)", "refactor.extract.variable", edit=func_call1)
41 -- @func_call2/func_call.go --
42 @@ -8 +8,2 @@
43 - b, err := strconv.Atoi(str) //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2)
44 + newVar, newVar1 := strconv.Atoi(str)
45 + b, err := newVar, newVar1 //@codeaction("strconv.Atoi(str)", "refactor.extract.variable", edit=func_call2)
46 -- scope.go --
47 package extract
48
49 import "go/ast"
50
51 func _() {
52 x0 := 0
53 if true {
54 y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1)
55 }
56 if true {
57 x := !false //@codeaction("!false", "refactor.extract.constant", edit=scope2)
58 }
59 }
60
61 -- @scope1/scope.go --
62 @@ -8 +8,2 @@
63 - y := ast.CompositeLit{} //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1)
64 + newVar := ast.CompositeLit{}
65 + y := newVar //@codeaction("ast.CompositeLit{}", "refactor.extract.variable", edit=scope1)
66 -- @scope2/scope.go --
67 @@ -11 +11,2 @@
68 - x := !false //@codeaction("!false", "refactor.extract.constant", edit=scope2)
69 + const newConst = !false
70 + x := newConst //@codeaction("!false", "refactor.extract.constant", edit=scope2)