(t *testing.T, composeSupport bool)
| 119 | } |
| 120 | |
| 121 | func testHover_Compose(t *testing.T, composeSupport bool) { |
| 122 | s := startServer() |
| 123 | |
| 124 | client := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 125 | server := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 126 | serverStream := &TestStream{incoming: server, outgoing: client, closed: false} |
| 127 | defer serverStream.Close() |
| 128 | go s.ServeStream(serverStream) |
| 129 | |
| 130 | clientStream := jsonrpc2.NewBufferedStream(&TestStream{incoming: client, outgoing: server, closed: false}, jsonrpc2.VSCodeObjectCodec{}) |
| 131 | defer clientStream.Close() |
| 132 | conn := jsonrpc2.NewConn(context.Background(), clientStream, &ConfigurationHandler{t: t}) |
| 133 | initialize(t, conn, protocol.InitializeParams{ |
| 134 | InitializationOptions: map[string]any{ |
| 135 | "dockercomposeExperimental": map[string]bool{"composeSupport": composeSupport}, |
| 136 | }, |
| 137 | }) |
| 138 | |
| 139 | homedir, err := os.UserHomeDir() |
| 140 | require.NoError(t, err) |
| 141 | |
| 142 | testCases := []struct { |
| 143 | name string |
| 144 | content string |
| 145 | position protocol.Position |
| 146 | result *protocol.Hover |
| 147 | }{ |
| 148 | { |
| 149 | name: "version description", |
| 150 | content: "version: 1.2.3", |
| 151 | position: protocol.Position{Line: 0, Character: 4}, |
| 152 | result: &protocol.Hover{ |
| 153 | Contents: protocol.MarkupContent{ |
| 154 | Kind: protocol.MarkupKindMarkdown, |
| 155 | Value: "declared for backward compatibility, ignored. Please remove it.\n\nSchema: [compose-spec.json](https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json)\n\n[Online documentation](https://docs.docker.com/reference/compose-file/version-and-name/)", |
| 156 | }, |
| 157 | }, |
| 158 | }, |
| 159 | { |
| 160 | name: "hovering outside the file", |
| 161 | content: "version: 1.2.3", |
| 162 | position: protocol.Position{Line: 1, Character: 4}, |
| 163 | result: nil, |
| 164 | }, |
| 165 | } |
| 166 | |
| 167 | for _, tc := range testCases { |
| 168 | t.Run(fmt.Sprintf("%v (composeSupport=%v)", tc.name, composeSupport), func(t *testing.T) { |
| 169 | didOpen := createDidOpenTextDocumentParams(homedir, t.Name()+".yaml", tc.content, protocol.DockerComposeLanguage) |
| 170 | err := conn.Notify(context.Background(), protocol.MethodTextDocumentDidOpen, didOpen) |
| 171 | require.NoError(t, err) |
| 172 | |
| 173 | var hover *protocol.Hover |
| 174 | err = conn.Call(context.Background(), protocol.MethodTextDocumentHover, protocol.HoverParams{ |
| 175 | TextDocumentPositionParams: protocol.TextDocumentPositionParams{ |
| 176 | TextDocument: protocol.TextDocumentIdentifier{URI: didOpen.TextDocument.URI}, |
| 177 | Position: tc.position, |
| 178 | }, |
no test coverage detected