@@ -175,6 +175,14 @@ var update = flag.Bool("update", false, "if set, update test data during marker
175
175
// location information. There is no point to using more than one
176
176
// @symbol marker in a given file.
177
177
//
178
+ // - workspacesymbol(query, golden): makes a workspace/symbol request for the
179
+ // given query, formats the response with one symbol per line, and compares
180
+ // against the named golden file. As workspace symbols are by definition a
181
+ // workspace-wide request, the location of the workspace symbol marker does
182
+ // not matter. Each line is of the form:
183
+ //
184
+ // location name kind
185
+ //
178
186
// # Argument conversion
179
187
//
180
188
// Marker arguments are first parsed by the go/expect package, which accepts
@@ -492,18 +500,19 @@ arity:
492
500
// Marker funcs should not mutate the test environment (e.g. via opening files
493
501
// or applying edits in the editor).
494
502
var markerFuncs = map [string ]markerFunc {
495
- "complete" : makeMarkerFunc (completeMarker ),
496
- "def" : makeMarkerFunc (defMarker ),
497
- "diag" : makeMarkerFunc (diagMarker ),
498
- "hover" : makeMarkerFunc (hoverMarker ),
499
- "format" : makeMarkerFunc (formatMarker ),
500
- "implementation" : makeMarkerFunc (implementationMarker ),
501
- "loc" : makeMarkerFunc (locMarker ),
502
- "rename" : makeMarkerFunc (renameMarker ),
503
- "renameerr" : makeMarkerFunc (renameErrMarker ),
504
- "suggestedfix" : makeMarkerFunc (suggestedfixMarker ),
505
- "symbol" : makeMarkerFunc (symbolMarker ),
506
- "refs" : makeMarkerFunc (refsMarker ),
503
+ "complete" : makeMarkerFunc (completeMarker ),
504
+ "def" : makeMarkerFunc (defMarker ),
505
+ "diag" : makeMarkerFunc (diagMarker ),
506
+ "hover" : makeMarkerFunc (hoverMarker ),
507
+ "format" : makeMarkerFunc (formatMarker ),
508
+ "implementation" : makeMarkerFunc (implementationMarker ),
509
+ "loc" : makeMarkerFunc (locMarker ),
510
+ "rename" : makeMarkerFunc (renameMarker ),
511
+ "renameerr" : makeMarkerFunc (renameErrMarker ),
512
+ "suggestedfix" : makeMarkerFunc (suggestedfixMarker ),
513
+ "symbol" : makeMarkerFunc (symbolMarker ),
514
+ "refs" : makeMarkerFunc (refsMarker ),
515
+ "workspacesymbol" : makeMarkerFunc (workspaceSymbolMarker ),
507
516
}
508
517
509
518
// markerTest holds all the test data extracted from a test txtar archive.
@@ -863,6 +872,12 @@ func (run *markerTestRun) fmtPos(pos token.Pos) string {
863
872
// archive-relative paths for files and including the line number in the full
864
873
// archive file.
865
874
func (run * markerTestRun ) fmtLoc (loc protocol.Location ) string {
875
+ return run .fmtLocDetails (loc , true )
876
+ }
877
+
878
+ // See fmtLoc. If includeTxtPos is not set, the position in the full archive
879
+ // file is omitted.
880
+ func (run * markerTestRun ) fmtLocDetails (loc protocol.Location , includeTxtPos bool ) string {
866
881
if loc == (protocol.Location {}) {
867
882
return "<missing location>"
868
883
}
@@ -904,7 +919,11 @@ func (run *markerTestRun) fmtLoc(loc protocol.Location) string {
904
919
}
905
920
}
906
921
907
- return fmt .Sprintf ("%s:%s (%s:%s)" , name , innerSpan , run .test .name , outerSpan )
922
+ if includeTxtPos {
923
+ return fmt .Sprintf ("%s:%s (%s:%s)" , name , innerSpan , run .test .name , outerSpan )
924
+ } else {
925
+ return fmt .Sprintf ("%s:%s" , name , innerSpan )
926
+ }
908
927
}
909
928
910
929
// makeMarkerFunc uses reflection to create a markerFunc for the given func value.
@@ -1571,3 +1590,32 @@ func compareLocations(mark marker, got, want []protocol.Location) error {
1571
1590
}
1572
1591
return nil
1573
1592
}
1593
+
1594
+ func workspaceSymbolMarker (mark marker , query string , golden * Golden ) {
1595
+ params := & protocol.WorkspaceSymbolParams {
1596
+ Query : query ,
1597
+ }
1598
+
1599
+ gotSymbols , err := mark .server ().Symbol (mark .run .env .Ctx , params )
1600
+ if err != nil {
1601
+ mark .errorf ("Symbol(%q) failed: %v" , query , err )
1602
+ return
1603
+ }
1604
+ var got bytes.Buffer
1605
+ for _ , s := range gotSymbols {
1606
+ // Omit the txtar position of the symbol location; otherwise edits to the
1607
+ // txtar archive lead to unexpected failures.
1608
+ loc := mark .run .fmtLocDetails (s .Location , false )
1609
+ fmt .Fprintf (& got , "%s %s %s\n " , loc , s .Name , s .Kind )
1610
+ }
1611
+
1612
+ want , ok := golden .Get (mark .run .env .T , "" , got .Bytes ())
1613
+ if ! ok {
1614
+ mark .errorf ("missing golden file @%s" , golden .id )
1615
+ return
1616
+ }
1617
+
1618
+ if diff := compare .Bytes (want , got .Bytes ()); diff != "" {
1619
+ mark .errorf ("Symbol(%q) mismatch:\n %s" , query , diff )
1620
+ }
1621
+ }
0 commit comments