@@ -16,6 +16,11 @@ import (
16
16
17
17
func TestPackageSymbols (t * testing.T ) {
18
18
const files = `
19
+ -- go.mod --
20
+ module example.com
21
+
22
+ go 1.20
23
+
19
24
-- a.go --
20
25
package a
21
26
@@ -33,68 +38,74 @@ func (s *S) M2() {}
33
38
func (s *S) M3() {}
34
39
35
40
func F() {}
41
+ -- unloaded.go --
42
+ //go:build unloaded
43
+
44
+ package a
45
+
46
+ var Unloaded int
36
47
`
37
48
integration .Run (t , files , func (t * testing.T , env * integration.Env ) {
38
- a_uri := env .Sandbox .Workdir .URI ("a.go" )
39
- b_uri := env .Sandbox .Workdir .URI ("b.go" )
49
+ aURI := env .Sandbox .Workdir .URI ("a.go" )
50
+ bURI := env .Sandbox .Workdir .URI ("b.go" )
40
51
args , err := command .MarshalArgs (command.PackageSymbolsArgs {
41
- URI : a_uri ,
52
+ URI : aURI ,
42
53
})
43
54
if err != nil {
44
- t .Fatalf ( "failed to MarshalArgs: %v" , err )
55
+ t .Fatal ( err )
45
56
}
46
57
47
58
var res command.PackageSymbolsResult
48
59
env .ExecuteCommand (& protocol.ExecuteCommandParams {
49
- Command : "gopls.package_symbols" ,
60
+ Command : command . PackageSymbols . String () ,
50
61
Arguments : args ,
51
62
}, & res )
52
63
53
64
want := command.PackageSymbolsResult {
54
65
PackageName : "a" ,
55
- Files : []protocol.DocumentURI {a_uri , b_uri },
66
+ Files : []protocol.DocumentURI {aURI , bURI },
56
67
Symbols : []command.PackageSymbol {
57
- {
58
- Name : "A" ,
59
- Kind : protocol .Variable ,
60
- File : 0 ,
61
- },
62
- {
63
- Name : "F" ,
64
- Kind : protocol .Function ,
65
- File : 1 ,
66
- },
67
- {
68
- Name : "S" ,
69
- Kind : protocol .Struct ,
70
- File : 0 ,
71
- Children : []command.PackageSymbol {
72
- {
73
- Name : "M1" ,
74
- Kind : protocol .Method ,
75
- File : 0 ,
76
- },
77
- {
78
- Name : "M2" ,
79
- Kind : protocol .Method ,
80
- File : 1 ,
81
- },
82
- {
83
- Name : "M3" ,
84
- Kind : protocol .Method ,
85
- File : 1 ,
86
- },
87
- },
88
- },
89
- {
90
- Name : "b" ,
91
- Kind : protocol .Variable ,
92
- File : 1 ,
93
- },
68
+ {Name : "A" , Kind : protocol .Variable , File : 0 },
69
+ {Name : "F" , Kind : protocol .Function , File : 1 },
70
+ {Name : "S" , Kind : protocol .Struct , File : 0 , Children : []command.PackageSymbol {
71
+ {Name : "M1" , Kind : protocol .Method , File : 0 },
72
+ {Name : "M2" , Kind : protocol .Method , File : 1 },
73
+ {Name : "M3" , Kind : protocol .Method , File : 1 },
74
+ }},
75
+ {Name : "b" , Kind : protocol .Variable , File : 1 },
94
76
},
95
77
}
96
- if diff := cmp .Diff (want , res , cmpopts .IgnoreFields (command.PackageSymbol {}, "Range" , "SelectionRange" , "Detail" )); diff != "" {
97
- t .Errorf ("gopls.package_symbols returned unexpected diff (-want +got):\n %s" , diff )
78
+ ignore := cmpopts .IgnoreFields (command.PackageSymbol {}, "Range" , "SelectionRange" , "Detail" )
79
+ if diff := cmp .Diff (want , res , ignore ); diff != "" {
80
+ t .Errorf ("package_symbols returned unexpected diff (-want +got):\n %s" , diff )
81
+ }
82
+
83
+ for file , want := range map [string ]command.PackageSymbolsResult {
84
+ "go.mod" : {},
85
+ "unloaded.go" : {
86
+ PackageName : "a" ,
87
+ Files : []protocol.DocumentURI {env .Sandbox .Workdir .URI ("unloaded.go" )},
88
+ Symbols : []command.PackageSymbol {
89
+ {Name : "Unloaded" , Kind : protocol .Variable , File : 0 },
90
+ },
91
+ },
92
+ } {
93
+ uri := env .Sandbox .Workdir .URI (file )
94
+ args , err := command .MarshalArgs (command.PackageSymbolsArgs {
95
+ URI : uri ,
96
+ })
97
+ if err != nil {
98
+ t .Fatal (err )
99
+ }
100
+ var res command.PackageSymbolsResult
101
+ env .ExecuteCommand (& protocol.ExecuteCommandParams {
102
+ Command : command .PackageSymbols .String (),
103
+ Arguments : args ,
104
+ }, & res )
105
+
106
+ if diff := cmp .Diff (want , res , ignore ); diff != "" {
107
+ t .Errorf ("package_symbols returned unexpected diff (-want +got):\n %s" , diff )
108
+ }
98
109
}
99
110
})
100
111
}
0 commit comments