(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func TestHover(t *testing.T) { |
| 45 | s := startServer() |
| 46 | |
| 47 | client := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 48 | server := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 49 | serverStream := &TestStream{incoming: server, outgoing: client, closed: false} |
| 50 | defer serverStream.Close() |
| 51 | go s.ServeStream(serverStream) |
| 52 | |
| 53 | clientStream := jsonrpc2.NewBufferedStream(&TestStream{incoming: client, outgoing: server, closed: false}, jsonrpc2.VSCodeObjectCodec{}) |
| 54 | defer clientStream.Close() |
| 55 | conn := jsonrpc2.NewConn(context.Background(), clientStream, &ConfigurationHandler{t: t}) |
| 56 | initialize(t, conn, protocol.InitializeParams{}) |
| 57 | |
| 58 | homedir, err := os.UserHomeDir() |
| 59 | require.NoError(t, err) |
| 60 | |
| 61 | testCases := []struct { |
| 62 | languageID protocol.LanguageIdentifier |
| 63 | fileExtensionSuffix string |
| 64 | name string |
| 65 | content string |
| 66 | position protocol.Position |
| 67 | result *protocol.Hover |
| 68 | }{ |
| 69 | { |
| 70 | languageID: protocol.DockerBakeLanguage, |
| 71 | fileExtensionSuffix: ".hcl", |
| 72 | name: "hover over target block type", |
| 73 | content: "target \"api\" {}", |
| 74 | position: protocol.Position{Line: 0, Character: 3}, |
| 75 | result: &protocol.Hover{ |
| 76 | Contents: protocol.MarkupContent{ |
| 77 | Kind: protocol.MarkupKindMarkdown, |
| 78 | Value: "**target** _Block_\n\nA target reflects a single `docker build` invocation.", |
| 79 | }, |
| 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | languageID: protocol.DockerfileLanguage, |
| 84 | fileExtensionSuffix: "", |
| 85 | name: "hover over alpine:3.16.1", |
| 86 | content: "FROM alpine:3.16.1", |
| 87 | position: protocol.Position{Line: 0, Character: 8}, |
| 88 | result: &protocol.Hover{ |
| 89 | Contents: protocol.MarkupContent{ |
| 90 | Kind: protocol.MarkupKindMarkdown, |
| 91 | Value: "Current image vulnerabilities: 1C 3H 9M 0L ", |
| 92 | }, |
| 93 | }, |
| 94 | }, |
| 95 | } |
| 96 | |
| 97 | for _, tc := range testCases { |
| 98 | t.Run(tc.name, func(t *testing.T) { |
| 99 | didOpen := createDidOpenTextDocumentParams(homedir, t.Name()+tc.fileExtensionSuffix, tc.content, tc.languageID) |
| 100 | err := conn.Notify(context.Background(), protocol.MethodTextDocumentDidOpen, didOpen) |
| 101 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected