This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
langserver_test.go
2100 lines (1956 loc) · 73.8 KB
/
langserver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package langserver
import (
"context"
"encoding/json"
"errors"
"fmt"
"go/build"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
"testing"
"github.com/sourcegraph/ctxvfs"
"github.com/sourcegraph/go-langserver/langserver/util"
"github.com/sourcegraph/go-langserver/pkg/lsp"
"github.com/sourcegraph/go-langserver/pkg/lspext"
"github.com/sourcegraph/jsonrpc2"
)
type serverTestCase struct {
skip bool
rootURI lsp.DocumentURI
fs map[string]string
mountFS map[string]map[string]string // mount dir -> map VFS
cases lspTestCases
}
var serverTestCases = map[string]serverTestCase{
"go basic": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; func A() { A() }",
"b.go": "package p; func B() { A() }",
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
//"a.go:1:9": "package p", // TODO(slimsag): sub-optimal "no declaration found for p"
"a.go:1:17": "func A()",
"a.go:1:23": "func A()",
"b.go:1:17": "func B()",
"b.go:1:23": "func A()",
},
wantHover: map[string]string{
"a.go:1:9": "package p",
"a.go:1:17": "func A()",
"a.go:1:23": "func A()",
"b.go:1:17": "func B()",
"b.go:1:23": "func A()",
},
wantDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/a.go:1:17-1:18",
"a.go:1:23": "/src/test/pkg/a.go:1:17-1:18",
"b.go:1:17": "/src/test/pkg/b.go:1:17-1:18",
"b.go:1:23": "/src/test/pkg/a.go:1:17-1:18",
},
wantXDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/a.go:1:17 id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
"a.go:1:23": "/src/test/pkg/a.go:1:17 id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
"b.go:1:17": "/src/test/pkg/b.go:1:17 id:test/pkg/-/B name:B package:test/pkg packageName:p recv: vendor:false",
"b.go:1:23": "/src/test/pkg/a.go:1:17 id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
},
wantCompletion: map[string]string{
//"a.go:1:24": "1:23-1:24 A function func()", // returns empty list for unknown reason. Works if the two statements are in separate lines
"b.go:1:24": "1:23-1:24 A function func()",
},
wantReferences: map[string][]string{
"a.go:1:17": {
"/src/test/pkg/a.go:1:17",
"/src/test/pkg/a.go:1:23",
"/src/test/pkg/b.go:1:23",
},
"a.go:1:23": {
"/src/test/pkg/a.go:1:17",
"/src/test/pkg/a.go:1:23",
"/src/test/pkg/b.go:1:23",
},
"b.go:1:17": {"/src/test/pkg/b.go:1:17"},
"b.go:1:23": {
"/src/test/pkg/a.go:1:17",
"/src/test/pkg/a.go:1:23",
"/src/test/pkg/b.go:1:23",
},
},
wantSymbols: map[string][]string{
"a.go": {"/src/test/pkg/a.go:function:A:1:17"},
"b.go": {"/src/test/pkg/b.go:function:B:1:17"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Query: "A"}: {"/src/test/pkg/a.go:function:A:1:17"},
{Query: "B"}: {"/src/test/pkg/b.go:function:B:1:17"},
{Query: "is:exported"}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Query: "dir:/"}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Query: "dir:/ A"}: {"/src/test/pkg/a.go:function:A:1:17"},
{Query: "dir:/ B"}: {"/src/test/pkg/b.go:function:B:1:17"},
// non-nil SymbolDescriptor + no keys.
{Symbol: make(lspext.SymbolDescriptor)}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
// Individual filter fields.
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg"}}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"name": "A"}}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"name": "B"}}: {"/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"packageName": "p"}}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"recv": ""}}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"vendor": false}}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
// Combined filter fields.
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg"}}: {"/src/test/pkg/a.go:function:A:1:17", "/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "A"}}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "A", "packageName": "p"}}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "A", "packageName": "p", "recv": ""}}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "A", "packageName": "p", "recv": "", "vendor": false}}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "B"}}: {"/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "B", "packageName": "p"}}: {"/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "B", "packageName": "p", "recv": ""}}: {"/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "B", "packageName": "p", "recv": "", "vendor": false}}: {"/src/test/pkg/b.go:function:B:1:17"},
// By ID.
{Symbol: lspext.SymbolDescriptor{"id": "test/pkg/-/B"}}: {"/src/test/pkg/b.go:function:B:1:17"},
{Symbol: lspext.SymbolDescriptor{"id": "test/pkg/-/A"}}: {"/src/test/pkg/a.go:function:A:1:17"},
},
wantFormatting: map[string]map[string]string{
"a.go": map[string]string{
"0:0-1:0": "package p\n\nfunc A() { A() }\n",
},
},
},
},
"go detailed": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; type T struct { F string }",
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
// "a.go:1:28": "(T).F string", // TODO(sqs): see golang/hover.go; this is the output we want
"a.go:1:28": "struct field F string",
"a.go:1:17": `type T struct; struct{ F string }`,
},
wantHover: map[string]string{
// "a.go:1:28": "(T).F string", // TODO(sqs): see golang/hover.go; this is the output we want
"a.go:1:28": "struct field F string",
"a.go:1:17": `type T struct; struct {
F string
}`,
},
wantSymbols: map[string][]string{
"a.go": {"/src/test/pkg/a.go:field:T.F:1:28", "/src/test/pkg/a.go:class:T:1:17"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/a.go:class:T:1:17", "/src/test/pkg/a.go:field:T.F:1:28"},
{Query: "T"}: {"/src/test/pkg/a.go:class:T:1:17", "/src/test/pkg/a.go:field:T.F:1:28"},
{Query: "F"}: {"/src/test/pkg/a.go:field:T.F:1:28"},
{Query: "is:exported"}: {"/src/test/pkg/a.go:class:T:1:17", "/src/test/pkg/a.go:field:T.F:1:28"},
},
},
},
"exported defs unexported type": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; type t struct { F string }",
},
cases: lspTestCases{
wantSymbols: map[string][]string{
"a.go": {"/src/test/pkg/a.go:field:t.F:1:28", "/src/test/pkg/a.go:class:t:1:17"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: "is:exported"}: {},
},
},
},
"go xtest": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; var A int",
"x_test.go": `package p_test; import "test/pkg"; var X = p.A`,
"y_test.go": "package p_test; func Y() int { return X }",
// non xtest to ensure we don't mix up xtest and test.
"a_test.go": `package p; var X = A`,
"b_test.go": "package p; func Y() int { return X }",
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
"a.go:1:16": "var A int",
"x_test.go:1:40": "var X = p.A",
"x_test.go:1:46": "var A int",
"a_test.go:1:16": "var X = A",
"a_test.go:1:20": "var A int",
},
wantHover: map[string]string{
"a.go:1:16": "var A int",
"x_test.go:1:40": "var X int",
"x_test.go:1:46": "var A int",
"a_test.go:1:16": "var X int",
"a_test.go:1:20": "var A int",
},
wantCompletion: map[string]string{
"x_test.go:1:45": "1:44-1:45 panic function func(v interface{}), print function func(args ...Type), println function func(args ...Type), p module ",
"x_test.go:1:46": "1:46-1:46 A variable int",
"b_test.go:1:35": "1:34-1:35 X variable int",
},
wantSymbols: map[string][]string{
"y_test.go": {"/src/test/pkg/y_test.go:function:Y:1:22"},
"b_test.go": {"/src/test/pkg/b_test.go:function:Y:1:17"},
},
wantReferences: map[string][]string{
"a.go:1:16": {
"/src/test/pkg/a.go:1:16",
"/src/test/pkg/a_test.go:1:20",
"/src/test/pkg/x_test.go:1:46",
},
"x_test.go:1:46": {
"/src/test/pkg/a.go:1:16",
"/src/test/pkg/a_test.go:1:20",
"/src/test/pkg/x_test.go:1:46",
},
"x_test.go:1:40": {
"/src/test/pkg/x_test.go:1:40",
"/src/test/pkg/y_test.go:1:39",
},
// The same as the xtest references above, but in the normal test pkg.
"a_test.go:1:20": {
"/src/test/pkg/a.go:1:16",
"/src/test/pkg/a_test.go:1:20",
"/src/test/pkg/x_test.go:1:46",
},
"a_test.go:1:16": {
"/src/test/pkg/a_test.go:1:16",
"/src/test/pkg/b_test.go:1:34",
},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/x_test.go:1:24-1:34 -> id:test/pkg name: package:test/pkg packageName:p recv: vendor:false",
"/src/test/pkg/x_test.go:1:46-1:47 -> id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
},
},
},
},
"go test": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; var A int",
"a_test.go": `package p; import "test/pkg/b"; var X = b.B; func TestB() {}`,
"b/b.go": "package b; var B int; func C() int { return B };",
"c/c.go": `package c; import "test/pkg/b"; var X = b.B;`,
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
"a_test.go:1:37": "var X = b.B",
"a_test.go:1:43": "var B int",
},
wantHover: map[string]string{
"a_test.go:1:37": "var X int",
"a_test.go:1:43": "var B int",
},
wantReferences: map[string][]string{
"a_test.go:1:43": {
"/src/test/pkg/a_test.go:1:43",
"/src/test/pkg/b/b.go:1:16",
"/src/test/pkg/b/b.go:1:45",
"/src/test/pkg/c/c.go:1:43",
},
"a_test.go:1:41": {
"/src/test/pkg/a_test.go:1:19",
"/src/test/pkg/a_test.go:1:41",
},
"a_test.go:1:51": {
"/src/test/pkg/a_test.go:1:51",
},
},
},
},
"go subdirectory in repo": {
rootURI: "file:///src/test/pkg/d",
fs: map[string]string{
"a.go": "package d; func A() { A() }",
"d2/b.go": `package d2; import "test/pkg/d"; func B() { d.A(); B() }`,
},
cases: lspTestCases{
wantHover: map[string]string{
"a.go:1:17": "func A()",
"a.go:1:23": "func A()",
"d2/b.go:1:39": "func B()",
"d2/b.go:1:47": "func A()",
"d2/b.go:1:52": "func B()",
},
wantDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/d/a.go:1:17-1:18",
"a.go:1:23": "/src/test/pkg/d/a.go:1:17-1:18",
"d2/b.go:1:39": "/src/test/pkg/d/d2/b.go:1:39-1:40",
"d2/b.go:1:47": "/src/test/pkg/d/a.go:1:17-1:18",
"d2/b.go:1:52": "/src/test/pkg/d/d2/b.go:1:39-1:40",
},
wantXDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/d/a.go:1:17 id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
"a.go:1:23": "/src/test/pkg/d/a.go:1:17 id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
"d2/b.go:1:39": "/src/test/pkg/d/d2/b.go:1:39 id:test/pkg/d/d2/-/B name:B package:test/pkg/d/d2 packageName:d2 recv: vendor:false",
"d2/b.go:1:47": "/src/test/pkg/d/a.go:1:17 id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
"d2/b.go:1:52": "/src/test/pkg/d/d2/b.go:1:39 id:test/pkg/d/d2/-/B name:B package:test/pkg/d/d2 packageName:d2 recv: vendor:false",
},
wantCompletion: map[string]string{
"d2/b.go:1:47": "1:47-1:47 A function func()",
//"d2/b.go:1:52": "1:52-1:52 d module , B function func()", // B not presented, see test case "go simple"
},
wantSymbols: map[string][]string{
"a.go": {"/src/test/pkg/d/a.go:function:A:1:17"},
"d2/b.go": {"/src/test/pkg/d/d2/b.go:function:B:1:39"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/d/a.go:function:A:1:17", "/src/test/pkg/d/d2/b.go:function:B:1:39"},
{Query: "is:exported"}: {"/src/test/pkg/d/a.go:function:A:1:17", "/src/test/pkg/d/d2/b.go:function:B:1:39"},
{Query: "dir:"}: {"/src/test/pkg/d/a.go:function:A:1:17"},
{Query: "dir:/"}: {"/src/test/pkg/d/a.go:function:A:1:17"},
{Query: "dir:."}: {"/src/test/pkg/d/a.go:function:A:1:17"},
{Query: "dir:./"}: {"/src/test/pkg/d/a.go:function:A:1:17"},
{Query: "dir:/d2"}: {"/src/test/pkg/d/d2/b.go:function:B:1:39"},
{Query: "dir:./d2"}: {"/src/test/pkg/d/d2/b.go:function:B:1:39"},
{Query: "dir:d2/"}: {"/src/test/pkg/d/d2/b.go:function:B:1:39"},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
// Non-matching name query.
{Query: lspext.SymbolDescriptor{"name": "nope"}}: {},
// Matching against invalid field name.
{Query: lspext.SymbolDescriptor{"nope": "A"}}: {},
// Matching against an invalid dirs hint.
{Query: lspext.SymbolDescriptor{"package": "test/pkg/d"}, Hints: map[string]interface{}{"dirs": []string{"file:///src/test/pkg/d/d3"}}}: {},
// Matching against a dirs hint with multiple dirs.
{Query: lspext.SymbolDescriptor{"package": "test/pkg/d"}, Hints: map[string]interface{}{"dirs": []string{"file:///src/test/pkg/d/d2", "file:///src/test/pkg/d/invalid"}}}: {
"/src/test/pkg/d/d2/b.go:1:20-1:32 -> id:test/pkg/d name: package:test/pkg/d packageName:d recv: vendor:false",
"/src/test/pkg/d/d2/b.go:1:47-1:48 -> id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
},
// Matching against a dirs hint.
{Query: lspext.SymbolDescriptor{"package": "test/pkg/d"}, Hints: map[string]interface{}{"dirs": []string{"file:///src/test/pkg/d/d2"}}}: {
"/src/test/pkg/d/d2/b.go:1:20-1:32 -> id:test/pkg/d name: package:test/pkg/d packageName:d recv: vendor:false",
"/src/test/pkg/d/d2/b.go:1:47-1:48 -> id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
},
// Matching against single field.
{Query: lspext.SymbolDescriptor{"package": "test/pkg/d"}}: {
"/src/test/pkg/d/d2/b.go:1:20-1:32 -> id:test/pkg/d name: package:test/pkg/d packageName:d recv: vendor:false",
"/src/test/pkg/d/d2/b.go:1:47-1:48 -> id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
},
// Matching against no fields.
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/d/d2/b.go:1:20-1:32 -> id:test/pkg/d name: package:test/pkg/d packageName:d recv: vendor:false",
"/src/test/pkg/d/d2/b.go:1:47-1:48 -> id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false",
},
{
Query: lspext.SymbolDescriptor{
"name": "",
"package": "test/pkg/d",
"packageName": "d",
"recv": "",
"vendor": false,
},
}: {"/src/test/pkg/d/d2/b.go:1:20-1:32 -> id:test/pkg/d name: package:test/pkg/d packageName:d recv: vendor:false"},
{
Query: lspext.SymbolDescriptor{
"name": "A",
"package": "test/pkg/d",
"packageName": "d",
"recv": "",
"vendor": false,
},
}: {"/src/test/pkg/d/d2/b.go:1:47-1:48 -> id:test/pkg/d/-/A name:A package:test/pkg/d packageName:d recv: vendor:false"},
},
},
},
"go multiple packages in dir": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": "package p; func A() { A() }",
"main.go": `// +build ignore
package main; import "test/pkg"; func B() { p.A(); B() }`,
},
cases: lspTestCases{
wantHover: map[string]string{
"a.go:1:17": "func A()",
"a.go:1:23": "func A()",
// Not parsing build-tag-ignored files:
//
// "main.go:3:39": "func B()", // func B()
// "main.go:3:47": "func A()", // p.A()
// "main.go:3:52": "func B()", // B()
},
wantDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/a.go:1:17-1:18",
"a.go:1:23": "/src/test/pkg/a.go:1:17-1:18",
// Not parsing build-tag-ignored files:
//
// "main.go:3:39": "/src/test/pkg/main.go:3:39", // B() -> func B()
// "main.go:3:47": "/src/test/pkg/a.go:1:17", // p.A() -> a.go func A()
// "main.go:3:52": "/src/test/pkg/main.go:3:39", // B() -> func B()
},
wantXDefinition: map[string]string{
"a.go:1:17": "/src/test/pkg/a.go:1:17 id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
"a.go:1:23": "/src/test/pkg/a.go:1:17 id:test/pkg/-/A name:A package:test/pkg packageName:p recv: vendor:false",
},
wantSymbols: map[string][]string{
"a.go": {"/src/test/pkg/a.go:function:A:1:17"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/a.go:function:A:1:17"},
{Query: "is:exported"}: {"/src/test/pkg/a.go:function:A:1:17"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "A", "packageName": "p", "recv": "", "vendor": false}}: {"/src/test/pkg/a.go:function:A:1:17"},
},
},
},
"goroot": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package p; import "fmt"; var _ = fmt.Println; var x int`,
},
mountFS: map[string]map[string]string{
"/goroot": {
"src/fmt/print.go": "package fmt; func Println(a ...interface{}) (n int, err error) { return }",
"src/builtin/builtin.go": "package builtin; type int int",
},
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
"a.go:1:40": "func Println(a ...interface{}) (n int, err error); Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. \n\n",
// "a.go:1:53": "type int int",
},
wantHover: map[string]string{
"a.go:1:40": "func Println(a ...interface{}) (n int, err error)",
// "a.go:1:53": "type int int",
},
overrideGodefDefinition: map[string]string{
"a.go:1:40": "/goroot/src/fmt/print.go", // hitting the real GOROOT
"a.go:1:53": "/goroot/src/builtin/builtin.go:1:1-1:1", // TODO: accurate builtin positions
},
wantDefinition: map[string]string{
"a.go:1:40": "/goroot/src/fmt/print.go:1:19-1:26",
// "a.go:1:53": "/goroot/src/builtin/builtin.go:TODO:TODO", // TODO(sqs): support builtins
},
wantXDefinition: map[string]string{
"a.go:1:40": "/goroot/src/fmt/print.go:1:19 id:fmt/-/Println name:Println package:fmt packageName:fmt recv: vendor:false",
},
wantCompletion: map[string]string{
// use default GOROOT, since gocode needs package binaries
// "a.go:1:21": "1:21-1:21 x variable int", TODO(anjmao): bug in gocode, it returns all builtins when adding . in pkg import path
// "a.go:1:44": "1:38-1:44 Println function func(a ...interface{}) (n int, err error)", // TODO(anjmao): check this test
},
wantSymbols: map[string][]string{
"a.go": {
"/src/test/pkg/a.go:variable:x:1:51",
},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {
"/src/test/pkg/a.go:variable:x:1:51",
},
{Query: "is:exported"}: {},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "x", "packageName": "p", "recv": "", "vendor": false}}: {"/src/test/pkg/a.go:variable:x:1:51"},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:24 -> id:fmt name: package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/a.go:1:38-1:45 -> id:fmt/-/Println name:Println package:fmt packageName:fmt recv: vendor:false",
},
},
},
},
"gopath": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a/a.go": `package a; func A() {}`,
"b/b.go": `package b; import "test/pkg/a"; var _ = a.A`,
},
cases: lspTestCases{
wantHover: map[string]string{
"a/a.go:1:17": "func A()",
// "b/b.go:1:20": "package", // TODO(sqs): make import paths hoverable
"b/b.go:1:43": "func A()",
},
wantDefinition: map[string]string{
"a/a.go:1:17": "/src/test/pkg/a/a.go:1:17-1:18",
// "b/b.go:1:20": "/src/test/pkg/a", // TODO(sqs): make import paths hoverable
"b/b.go:1:43": "/src/test/pkg/a/a.go:1:17-1:18",
},
wantXDefinition: map[string]string{
"a/a.go:1:17": "/src/test/pkg/a/a.go:1:17 id:test/pkg/a/-/A name:A package:test/pkg/a packageName:a recv: vendor:false",
"b/b.go:1:43": "/src/test/pkg/a/a.go:1:17 id:test/pkg/a/-/A name:A package:test/pkg/a packageName:a recv: vendor:false",
},
wantCompletion: map[string]string{
// "b/b.go:1:26": "1:20-1:26 test/pkg/a module , test/pkg/b module ", // TODO(anjmao): gocode doesn't support package autocomplete yet
"b/b.go:1:43": "1:43-1:43 A function func()",
},
wantReferences: map[string][]string{
"a/a.go:1:17": {
"/src/test/pkg/a/a.go:1:17",
"/src/test/pkg/b/b.go:1:43",
},
"b/b.go:1:43": { // calling "references" on call site should return same result as on decl
"/src/test/pkg/a/a.go:1:17",
"/src/test/pkg/b/b.go:1:43",
},
"b/b.go:1:41": { // calling "references" on package
"/src/test/pkg/b/b.go:1:19",
"/src/test/pkg/b/b.go:1:41",
},
},
wantSymbols: map[string][]string{
"a/a.go": {"/src/test/pkg/a/a.go:function:A:1:17"},
"b/b.go": {},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/a/a.go:function:A:1:17"},
{Query: "is:exported"}: {"/src/test/pkg/a/a.go:function:A:1:17"},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/b/b.go:1:19-1:31 -> id:test/pkg/a name: package:test/pkg/a packageName:a recv: vendor:false",
"/src/test/pkg/b/b.go:1:43-1:44 -> id:test/pkg/a/-/A name:A package:test/pkg/a packageName:a recv: vendor:false",
},
},
},
},
"go vendored dep": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package a; import "github.com/v/vendored"; var _ = vendored.V`,
"vendor/github.com/v/vendored/v.go": "package vendored; func V() {}",
},
cases: lspTestCases{
wantHover: map[string]string{
"a.go:1:61": "func V()",
},
wantDefinition: map[string]string{
"a.go:1:61": "/src/test/pkg/vendor/github.com/v/vendored/v.go:1:24-1:25",
//"a.go:1:40": "/src/test/pkg/vendor/github.com/v/vendored/v.go:1:24-1:25",
},
wantXDefinition: map[string]string{
"a.go:1:61": "/src/test/pkg/vendor/github.com/v/vendored/v.go:1:24 id:test/pkg/vendor/github.com/v/vendored/-/V name:V package:test/pkg/vendor/github.com/v/vendored packageName:vendored recv: vendor:true",
},
wantCompletion: map[string]string{
// "a.go:1:34": "1:20-1:34 github.com/v/vendored module ", // TODO(anjmao): gocode doesn't support package autocomplete yet
"a.go:1:61": "1:61-1:61 V function func()",
},
wantReferences: map[string][]string{
"vendor/github.com/v/vendored/v.go:1:24": {
"/src/test/pkg/vendor/github.com/v/vendored/v.go:1:24",
"/src/test/pkg/a.go:1:61",
},
},
wantSymbols: map[string][]string{
"a.go": {},
"vendor/github.com/v/vendored/v.go": {"/src/test/pkg/vendor/github.com/v/vendored/v.go:function:V:1:24"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/vendor/github.com/v/vendored/v.go:function:V:1:24"},
{Query: "is:exported"}: {},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg", "name": "_", "packageName": "a", "recv": "", "vendor": false}}: {},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg/vendor/github.com/v/vendored", "name": "V", "packageName": "vendored", "recv": "", "vendor": true}}: {"/src/test/pkg/vendor/github.com/v/vendored/v.go:function:V:1:24"},
{Symbol: lspext.SymbolDescriptor{"package": "test/pkg/vendor/github.com/v/vendored", "name": "V", "packageName": "vendored", "recv": "", "vendor": false}}: {},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:42 -> id:test/pkg/vendor/github.com/v/vendored name: package:test/pkg/vendor/github.com/v/vendored packageName:vendored recv: vendor:true",
"/src/test/pkg/a.go:1:61-1:62 -> id:test/pkg/vendor/github.com/v/vendored/-/V name:V package:test/pkg/vendor/github.com/v/vendored packageName:vendored recv: vendor:true",
},
},
},
},
"go vendor symbols with same name": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"z.go": `package pkg; func x() bool { return true }`,
"vendor/github.com/a/pkg2/x.go": `package pkg2; func x() bool { return true }`,
"vendor/github.com/x/pkg3/x.go": `package pkg3; func x() bool { return true }`,
},
cases: lspTestCases{
wantSymbols: map[string][]string{
"z.go": {"/src/test/pkg/z.go:function:x:1:19"},
"vendor/github.com/a/pkg2/x.go": {"/src/test/pkg/vendor/github.com/a/pkg2/x.go:function:x:1:20"},
"vendor/github.com/x/pkg3/x.go": {"/src/test/pkg/vendor/github.com/x/pkg3/x.go:function:x:1:20"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {
"/src/test/pkg/z.go:function:x:1:19",
"/src/test/pkg/vendor/github.com/a/pkg2/x.go:function:x:1:20",
"/src/test/pkg/vendor/github.com/x/pkg3/x.go:function:x:1:20",
},
{Query: "x"}: {
"/src/test/pkg/z.go:function:x:1:19",
"/src/test/pkg/vendor/github.com/a/pkg2/x.go:function:x:1:20",
"/src/test/pkg/vendor/github.com/x/pkg3/x.go:function:x:1:20",
},
{Query: "pkg2.x"}: {
"/src/test/pkg/z.go:function:x:1:19",
"/src/test/pkg/vendor/github.com/a/pkg2/x.go:function:x:1:20",
"/src/test/pkg/vendor/github.com/x/pkg3/x.go:function:x:1:20",
},
{Query: "pkg3.x"}: {
"/src/test/pkg/z.go:function:x:1:19",
"/src/test/pkg/vendor/github.com/x/pkg3/x.go:function:x:1:20",
"/src/test/pkg/vendor/github.com/a/pkg2/x.go:function:x:1:20",
},
{Query: "is:exported"}: {},
},
},
},
"go external dep": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package a; import "github.com/d/dep"; var _ = dep.D; var _ = dep.D`,
},
mountFS: map[string]map[string]string{
"/src/github.com/d/dep": {
"d.go": "package dep; func D() {}; var _ = D",
},
},
cases: lspTestCases{
wantHover: map[string]string{
"a.go:1:51": "func D()",
},
wantDefinition: map[string]string{
"a.go:1:51": "/src/github.com/d/dep/d.go:1:19-1:20",
},
wantXDefinition: map[string]string{
"a.go:1:51": "/src/github.com/d/dep/d.go:1:19 id:github.com/d/dep/-/D name:D package:github.com/d/dep packageName:dep recv: vendor:false",
},
wantCompletion: map[string]string{
// "a.go:1:34": "1:20-1:34 github.com/d/dep module ", // TODO(anjmao): gocode doesn't support package autocomplete yet
"a.go:1:51": "1:51-1:51 D function func()",
},
wantReferences: map[string][]string{
"a.go:1:51": {
"/src/test/pkg/a.go:1:51",
"/src/test/pkg/a.go:1:66",
// Do not include "refs" from the dependency
// package itself; only return results in the
// workspace.
},
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:37 -> id:github.com/d/dep name: package:github.com/d/dep packageName:dep recv: vendor:false",
"/src/test/pkg/a.go:1:51-1:52 -> id:github.com/d/dep/-/D name:D package:github.com/d/dep packageName:dep recv: vendor:false",
"/src/test/pkg/a.go:1:66-1:67 -> id:github.com/d/dep/-/D name:D package:github.com/d/dep packageName:dep recv: vendor:false",
},
},
},
},
"external dep with vendor": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package p; import "github.com/d/dep"; var _ = dep.D().F`,
},
mountFS: map[string]map[string]string{
"/src/github.com/d/dep": {
"d.go": `package dep; import "vendp"; func D() (v vendp.V) { return }`,
"vendor/vendp/vp.go": "package vendp; type V struct { F int }",
},
},
cases: lspTestCases{
wantDefinition: map[string]string{
"a.go:1:55": "/src/github.com/d/dep/vendor/vendp/vp.go:1:32-1:33",
},
wantXDefinition: map[string]string{
"a.go:1:55": "/src/github.com/d/dep/vendor/vendp/vp.go:1:32 id:github.com/d/dep/vendor/vendp/-/V/F name:F package:github.com/d/dep/vendor/vendp packageName:vendp recv:V vendor:true",
},
wantCompletion: map[string]string{
"a.go:1:55": "1:55-1:55 F variable int",
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:37 -> id:github.com/d/dep name: package:github.com/d/dep packageName:dep recv: vendor:false",
"/src/test/pkg/a.go:1:55-1:56 -> id:github.com/d/dep/vendor/vendp/-/V/F name:F package:github.com/d/dep/vendor/vendp packageName:vendp recv:V vendor:true",
"/src/test/pkg/a.go:1:51-1:52 -> id:github.com/d/dep/-/D name:D package:github.com/d/dep packageName:dep recv: vendor:false",
},
},
},
},
"go external dep at subtree": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package a; import "github.com/d/dep/subp"; var _ = subp.D`,
},
mountFS: map[string]map[string]string{
"/src/github.com/d/dep": {
"subp/d.go": "package subp; func D() {}",
},
},
cases: lspTestCases{
wantHover: map[string]string{
"a.go:1:57": "func D()",
},
wantDefinition: map[string]string{
"a.go:1:57": "/src/github.com/d/dep/subp/d.go:1:20-1:21",
},
wantXDefinition: map[string]string{
"a.go:1:57": "/src/github.com/d/dep/subp/d.go:1:20 id:github.com/d/dep/subp/-/D name:D package:github.com/d/dep/subp packageName:subp recv: vendor:false",
},
wantCompletion: map[string]string{
// "a.go:1:34": "1:20-1:34 github.com/d/dep/subp module ", // TODO(anjmao): gocode doesn't support package autocomplete yet
"a.go:1:57": "1:57-1:57 D function func()",
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:42 -> id:github.com/d/dep/subp name: package:github.com/d/dep/subp packageName:subp recv: vendor:false",
"/src/test/pkg/a.go:1:57-1:58 -> id:github.com/d/dep/subp/-/D name:D package:github.com/d/dep/subp packageName:subp recv: vendor:false",
},
},
},
},
"go nested external dep": { // a depends on dep1, dep1 depends on dep2
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package a; import "github.com/d/dep1"; var _ = dep1.D1().D2`,
},
mountFS: map[string]map[string]string{
"/src/github.com/d/dep1": {
"d1.go": `package dep1; import "github.com/d/dep2"; func D1() dep2.D2 { return dep2.D2{} }`,
},
"/src/github.com/d/dep2": {
"d2.go": "package dep2; type D2 struct { D2 int }",
},
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
"a.go:1:53": "func D1() dep2.D2",
"a.go:1:59": "struct field D2 int",
},
wantHover: map[string]string{
"a.go:1:53": "func D1() D2",
"a.go:1:59": "struct field D2 int",
},
wantDefinition: map[string]string{
"a.go:1:53": "/src/github.com/d/dep1/d1.go:1:48-1:50", // func D1
"a.go:1:58": "/src/github.com/d/dep2/d2.go:1:32-1:34", // field D2
},
wantXDefinition: map[string]string{
"a.go:1:53": "/src/github.com/d/dep1/d1.go:1:48 id:github.com/d/dep1/-/D1 name:D1 package:github.com/d/dep1 packageName:dep1 recv: vendor:false",
"a.go:1:58": "/src/github.com/d/dep2/d2.go:1:32 id:github.com/d/dep2/-/D2/D2 name:D2 package:github.com/d/dep2 packageName:dep2 recv:D2 vendor:false",
},
wantCompletion: map[string]string{
//"a.go:1:53": "1:53-1:53 D1 function func() D2", // gocode does not handle D2 correctly
"a.go:1:58": "1:58-1:58 D2 variable int",
},
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:38 -> id:github.com/d/dep1 name: package:github.com/d/dep1 packageName:dep1 recv: vendor:false",
"/src/test/pkg/a.go:1:58-1:60 -> id:github.com/d/dep2/-/D2/D2 name:D2 package:github.com/d/dep2 packageName:dep2 recv:D2 vendor:false",
"/src/test/pkg/a.go:1:53-1:55 -> id:github.com/d/dep1/-/D1 name:D1 package:github.com/d/dep1 packageName:dep1 recv: vendor:false",
},
},
},
},
"go symbols": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"abc.go": `package a
type XYZ struct {}
func (x XYZ) ABC() {}
var (
A = 1
)
const (
B = 2
)
type (
_ struct{}
C struct{}
)
type UVW interface {}
type T string
`,
"bcd.go": `package a
type YZA struct {}
func (y YZA) BCD() {}
`,
"cde.go": `package a
var(
a, b string
c int
)
`,
"xyz.go": `package a
func yza() {}
`,
},
cases: lspTestCases{
wantSymbols: map[string][]string{
"abc.go": {"/src/test/pkg/abc.go:class:XYZ:3:6", "/src/test/pkg/abc.go:method:XYZ.ABC:5:14", "/src/test/pkg/abc.go:variable:A:8:2", "/src/test/pkg/abc.go:constant:B:12:2", "/src/test/pkg/abc.go:class:C:17:2", "/src/test/pkg/abc.go:interface:UVW:20:6", "/src/test/pkg/abc.go:class:T:22:6"},
"bcd.go": {"/src/test/pkg/bcd.go:class:YZA:3:6", "/src/test/pkg/bcd.go:method:YZA.BCD:5:14"},
"cde.go": {"/src/test/pkg/cde.go:variable:a:4:2", "/src/test/pkg/cde.go:variable:b:4:5", "/src/test/pkg/cde.go:variable:c:5:2"},
"xyz.go": {"/src/test/pkg/xyz.go:function:yza:3:6"},
},
wantWorkspaceSymbols: map[*lspext.WorkspaceSymbolParams][]string{
{Query: ""}: {"/src/test/pkg/abc.go:variable:A:8:2", "/src/test/pkg/abc.go:constant:B:12:2", "/src/test/pkg/abc.go:class:C:17:2", "/src/test/pkg/abc.go:class:T:22:6", "/src/test/pkg/abc.go:interface:UVW:20:6", "/src/test/pkg/abc.go:class:XYZ:3:6", "/src/test/pkg/bcd.go:class:YZA:3:6", "/src/test/pkg/cde.go:variable:a:4:2", "/src/test/pkg/cde.go:variable:b:4:5", "/src/test/pkg/cde.go:variable:c:5:2", "/src/test/pkg/xyz.go:function:yza:3:6", "/src/test/pkg/abc.go:method:XYZ.ABC:5:14", "/src/test/pkg/bcd.go:method:YZA.BCD:5:14"},
{Query: "xyz"}: {"/src/test/pkg/abc.go:class:XYZ:3:6", "/src/test/pkg/abc.go:method:XYZ.ABC:5:14", "/src/test/pkg/xyz.go:function:yza:3:6"},
{Query: "yza"}: {"/src/test/pkg/bcd.go:class:YZA:3:6", "/src/test/pkg/xyz.go:function:yza:3:6", "/src/test/pkg/bcd.go:method:YZA.BCD:5:14"},
{Query: "abc"}: {"/src/test/pkg/abc.go:method:XYZ.ABC:5:14", "/src/test/pkg/abc.go:variable:A:8:2", "/src/test/pkg/abc.go:constant:B:12:2", "/src/test/pkg/abc.go:class:C:17:2", "/src/test/pkg/abc.go:class:T:22:6", "/src/test/pkg/abc.go:interface:UVW:20:6", "/src/test/pkg/abc.go:class:XYZ:3:6"},
{Query: "bcd"}: {"/src/test/pkg/bcd.go:method:YZA.BCD:5:14", "/src/test/pkg/bcd.go:class:YZA:3:6"},
{Query: "cde"}: {"/src/test/pkg/cde.go:variable:a:4:2", "/src/test/pkg/cde.go:variable:b:4:5", "/src/test/pkg/cde.go:variable:c:5:2"},
{Query: "is:exported"}: {"/src/test/pkg/abc.go:variable:A:8:2", "/src/test/pkg/abc.go:constant:B:12:2", "/src/test/pkg/abc.go:class:C:17:2", "/src/test/pkg/abc.go:class:T:22:6", "/src/test/pkg/abc.go:interface:UVW:20:6", "/src/test/pkg/abc.go:class:XYZ:3:6", "/src/test/pkg/bcd.go:class:YZA:3:6", "/src/test/pkg/abc.go:method:XYZ.ABC:5:14", "/src/test/pkg/bcd.go:method:YZA.BCD:5:14"},
},
},
},
"go hover docs": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `// Copyright 2015 someone.
// Copyrights often span multiple lines.
// Some additional non-package docs.
// Package p is a package with lots of great things.
package p
import "github.com/a/pkg2"
// logit is pkg2.X
var logit = pkg2.X
// T is a struct.
type T struct {
// F is a string field.
F string
// H is a header.
H pkg2.Header
}
// Foo is the best string.
var Foo string
var (
// I1 is an int
I1 = 1
// I2 is an int
I2 = 3
)
`,
"vendor/github.com/a/pkg2/x.go": `// Package pkg2 shows dependencies.
//
// How to
//
// Example Code!
//
package pkg2
// A comment that should be ignored
// X does the unknown.
func X() {
panic("zomg")
}
// Header is like an HTTP header, only better.
type Header struct {
// F is a string, too.
F string
}
`,
},
cases: lspTestCases{
overrideGodefHover: map[string]string{
//"a.go:7:9": "package p; Package p is a package with lots of great things. \n\n", // TODO(slimsag): sub-optimal "no declaration found for p"
//"a.go:9:9": "", TODO: handle hovering on import statements (ast.BasicLit)
"a.go:12:5": "var logit = pkg2.X; logit is pkg2.X \n\n",
"a.go:12:13": "package pkg2 (\"test/pkg/vendor/github.com/a/pkg2\"); Package pkg2 shows dependencies. \n\nHow to \n\n```\nExample Code!\n\n```\n",
"a.go:12:18": "func X(); X does the unknown. \n\n",
"a.go:15:6": "type T struct; T is a struct. \n\n; struct {\n\t// F is a string field.\n\tF string\n\n\t// H is a header.\n\tH pkg2.Header\n}",
"a.go:17:2": "struct field F string; F is a string field. \n\n",
"a.go:20:2": "struct field H pkg2.Header; H is a header. \n\n",
"a.go:20:4": "package pkg2 (\"test/pkg/vendor/github.com/a/pkg2\"); Package pkg2 shows dependencies. \n\nHow to \n\n```\nExample Code!\n\n```\n",
"a.go:24:5": "var Foo string; Foo is the best string. \n\n",
"a.go:31:2": "var I2 = 3; I2 is an int \n\n",
},
wantHover: map[string]string{
"a.go:7:9": "package p; Package p is a package with lots of great things. \n\n",
//"a.go:9:9": "", TODO: handle hovering on import statements (ast.BasicLit)
"a.go:12:5": "var logit func(); logit is pkg2.X \n\n",
"a.go:12:13": "package pkg2 (\"test/pkg/vendor/github.com/a/pkg2\"); Package pkg2 shows dependencies. \n\nHow to \n\n```\nExample Code!\n\n```\n",
"a.go:12:18": "func X(); X does the unknown. \n\n",
"a.go:15:6": "type T struct; T is a struct. \n\n; struct {\n F string\n H Header\n}",
"a.go:17:2": "struct field F string; F is a string field. \n\n",
"a.go:20:2": "struct field H test/pkg/vendor/github.com/a/pkg2.Header; H is a header. \n\n",
"a.go:20:4": "package pkg2 (\"test/pkg/vendor/github.com/a/pkg2\"); Package pkg2 shows dependencies. \n\nHow to \n\n```\nExample Code!\n\n```\n",
"a.go:24:5": "var Foo string; Foo is the best string. \n\n",
"a.go:31:2": "var I2 int; I2 is an int \n\n",
},
},
},
"go hover docs special cases": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"q.go": `package p
type T struct {
Q string // Q is a string field.
// X is documented.
X int // X has comments.
}`,
},
cases: lspTestCases{
wantHover: map[string]string{
"q.go:3:2": "struct field Q string; Q is a string field. \n\n",
"q.go:5:2": "struct field X int; X is documented. \n\nX has comments. \n\n",
},
},
},
"workspace references multiple files": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"a.go": `package p; import "fmt"; var _ = fmt.Println; var x int`,
"b.go": `package p; import "fmt"; var _ = fmt.Println; var y int`,
"c.go": `package p; import "fmt"; var _ = fmt.Println; var z int`,
},
mountFS: map[string]map[string]string{
"/goroot": {
"src/fmt/print.go": "package fmt; func Println(a ...interface{}) (n int, err error) { return }",
"src/builtin/builtin.go": "package builtin; type int int",
},
},
cases: lspTestCases{
wantWorkspaceReferences: map[*lspext.WorkspaceReferencesParams][]string{
{Query: lspext.SymbolDescriptor{}}: {
"/src/test/pkg/a.go:1:19-1:24 -> id:fmt name: package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/a.go:1:38-1:45 -> id:fmt/-/Println name:Println package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/b.go:1:19-1:24 -> id:fmt name: package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/b.go:1:38-1:45 -> id:fmt/-/Println name:Println package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/c.go:1:19-1:24 -> id:fmt name: package:fmt packageName:fmt recv: vendor:false",
"/src/test/pkg/c.go:1:38-1:45 -> id:fmt/-/Println name:Println package:fmt packageName:fmt recv: vendor:false",
},
},
},
},
"interfaces and implementations": {
rootURI: "file:///src/test/pkg",
fs: map[string]string{
"i0.go": "package p; type I0 interface { M0() }",
"i1.go": "package p; type I1 interface { M1() }",
"i2.go": "package p; type I2 interface { M1(); M2() }",
"t0.go": "package p; type T0 struct{}",
"t1.go": "package p; type T1 struct {}; func (T1) M1() {}; func (T1) M3()",
"t1e.go": "package p; type T1E struct { T1 }; var _ = (T1E{}).M1",
"t1p.go": "package p; type T1P struct {}; func (*T1P) M1() {}",
"p2/p2.go": "package p2; type T2 struct{}; func (t2) M1() {}",
},
cases: lspTestCases{
wantImplementation: map[string][]string{
"i0.go:1:17": {}, // I0
"i0.go:1:32": {}, // (I0).M0
"i1.go:1:17": /* I1 */ {
"/src/test/pkg/i2.go:1:17:to",
"/src/test/pkg/t1.go:1:17:to",
"/src/test/pkg/t1e.go:1:17:to",
"/src/test/pkg/t1p.go:1:17:to",
},
"i1.go:1:32": /* I1.(M1)*/ {
"/src/test/pkg/i2.go:1:32:to:method",
"/src/test/pkg/t1.go:1:41:to:method",
"/src/test/pkg/t1p.go:1:44:to:method",
},
"i2.go:1:32":/* I2.(M1)*/ {"/src/test/pkg/i1.go:1:32:from:method"},
"i2.go:1:38":/* I2.(M2)*/ {},
"t0.go:1:17":/* T0 */ {},
"t1.go:1:17":/* T1 */ {"/src/test/pkg/i1.go:1:17:from"},
"t1.go:1:41":/* (T1).M1 */ {"/src/test/pkg/i1.go:1:32:from:method"},
"t1.go:1:59":/* (T1).M3 */ {},
"t1e.go:1:17":/* (T1E) */ {"/src/test/pkg/i1.go:1:17:from"},
"t1e.go:1:52":/* (T1E).M1 */ {"/src/test/pkg/i1.go:1:32:from:method"},