(params *protocol.CompletionParams, nodeProps any, lines []string, lspLine int, whitespacePrefixedArrayAttribute bool, wordPrefixLength protocol.UInteger, file *ast.File, manager *document.Manager, documentPath document.DocumentPath, path []*ast.MappingValueNode)
| 299 | } |
| 300 | |
| 301 | func createSchemaItems(params *protocol.CompletionParams, nodeProps any, lines []string, lspLine int, whitespacePrefixedArrayAttribute bool, wordPrefixLength protocol.UInteger, file *ast.File, manager *document.Manager, documentPath document.DocumentPath, path []*ast.MappingValueNode) []protocol.CompletionItem { |
| 302 | items := []protocol.CompletionItem{} |
| 303 | if schema, ok := nodeProps.(*jsonschema.Schema); ok { |
| 304 | if schema.Enum != nil { |
| 305 | return createEnumItems(schema, params, wordPrefixLength) |
| 306 | } |
| 307 | } else if properties, ok := nodeProps.(map[string]*jsonschema.Schema); ok { |
| 308 | spacing := createSpacing(lines[lspLine], int(params.Position.Character), whitespacePrefixedArrayAttribute) |
| 309 | for attributeName, schema := range properties { |
| 310 | item := protocol.CompletionItem{ |
| 311 | Detail: extractDetail(schema), |
| 312 | Label: attributeName, |
| 313 | TextEdit: protocol.TextEdit{ |
| 314 | NewText: insertText(spacing, attributeName, schema), |
| 315 | Range: protocol.Range{ |
| 316 | Start: protocol.Position{ |
| 317 | Line: params.Position.Line, |
| 318 | Character: params.Position.Character - protocol.UInteger(wordPrefixLength), |
| 319 | }, |
| 320 | End: params.Position, |
| 321 | }, |
| 322 | }, |
| 323 | InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs), |
| 324 | InsertTextFormat: types.CreateInsertTextFormatPointer(protocol.InsertTextFormatSnippet), |
| 325 | } |
| 326 | if schema.Description != "" { |
| 327 | item.Documentation = schema.Description |
| 328 | } else if schema.Ref != nil && schema.Ref.Description != "" { |
| 329 | item.Documentation = schema.Ref.Description |
| 330 | } |
| 331 | |
| 332 | if schema.Enum != nil { |
| 333 | options := []string{} |
| 334 | for i := range schema.Enum.Values { |
| 335 | options = append(options, schema.Enum.Values[i].(string)) |
| 336 | } |
| 337 | slices.Sort(options) |
| 338 | sb := strings.Builder{} |
| 339 | sb.WriteString(attributeName) |
| 340 | sb.WriteString(": ${1|") |
| 341 | for i := range options { |
| 342 | sb.WriteString(options[i]) |
| 343 | if i != len(schema.Enum.Values)-1 { |
| 344 | sb.WriteString(",") |
| 345 | } |
| 346 | } |
| 347 | sb.WriteString("|}") |
| 348 | item.TextEdit = protocol.TextEdit{ |
| 349 | NewText: sb.String(), |
| 350 | Range: protocol.Range{ |
| 351 | Start: protocol.Position{ |
| 352 | Line: params.Position.Line, |
| 353 | Character: params.Position.Character - protocol.UInteger(wordPrefixLength), |
| 354 | }, |
| 355 | End: params.Position, |
| 356 | }, |
| 357 | } |
| 358 | } |
no test coverage detected