MCPcopy Create free account
hub / github.com/docker/docker-language-server / TestDocumentSymbol

Function TestDocumentSymbol

e2e-tests/documentSymbol_test.go:14–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestDocumentSymbol(t *testing.T) {
15 s := startServer()
16
17 client := bytes.NewBuffer(make([]byte, 0, 1024))
18 server := bytes.NewBuffer(make([]byte, 0, 1024))
19 serverStream := &TestStream{incoming: server, outgoing: client, closed: false}
20 defer serverStream.Close()
21 go s.ServeStream(serverStream)
22
23 clientStream := jsonrpc2.NewBufferedStream(&TestStream{incoming: client, outgoing: server, closed: false}, jsonrpc2.VSCodeObjectCodec{})
24 defer clientStream.Close()
25 conn := jsonrpc2.NewConn(context.Background(), clientStream, &ConfigurationHandler{t: t})
26 initialize(t, conn, protocol.InitializeParams{})
27
28 homedir, err := os.UserHomeDir()
29 require.NoError(t, err)
30
31 testCases := []struct {
32 name string
33 content string
34 symbols []*protocol.DocumentSymbol
35 }{
36 {
37 name: "target \"api\" {}",
38 content: "target \"api\" {}",
39 symbols: []*protocol.DocumentSymbol{
40 {
41 Name: "api",
42 Kind: protocol.SymbolKindFunction,
43 Range: protocol.Range{
44 Start: protocol.Position{Line: 0, Character: 0},
45 End: protocol.Position{Line: 0, Character: 0},
46 },
47 },
48 },
49 },
50 }
51
52 for _, tc := range testCases {
53 t.Run(tc.name, func(t *testing.T) {
54 didOpen := createDidOpenTextDocumentParams(homedir, t.Name()+".hcl", tc.content, "dockerbake")
55 err := conn.Notify(context.Background(), protocol.MethodTextDocumentDidOpen, didOpen)
56 require.NoError(t, err)
57
58 var symbols []*protocol.DocumentSymbol
59 err = conn.Call(context.Background(), protocol.MethodTextDocumentDocumentSymbol, protocol.DocumentSymbolParams{
60 TextDocument: protocol.TextDocumentIdentifier{URI: didOpen.TextDocument.URI},
61 }, &symbols)
62 require.NoError(t, err)
63 require.Equal(t, tc.symbols, symbols)
64 })
65 }
66}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
startServerFunction · 0.85
initializeFunction · 0.85
CloseMethod · 0.65
ServeStreamMethod · 0.45

Tested by

no test coverage detected