| 15 | ) |
| 16 | |
| 17 | func Hover(ctx context.Context, params *protocol.HoverParams, doc document.ComposeDocument) (*protocol.Hover, error) { |
| 18 | file := doc.File() |
| 19 | if file == nil || len(file.Docs) == 0 { |
| 20 | return nil, nil |
| 21 | } |
| 22 | |
| 23 | line := int(params.Position.Line) + 1 |
| 24 | character := int(params.Position.Character) + 1 |
| 25 | lines := strings.Split(string(doc.Input()), "\n") |
| 26 | if line > len(lines) { |
| 27 | return nil, nil |
| 28 | } |
| 29 | |
| 30 | for _, documentNode := range file.Docs { |
| 31 | if mappingNode, ok := documentNode.Body.(*ast.MappingNode); ok { |
| 32 | nodePath := constructNodePath([]ast.Node{}, mappingNode, int(params.Position.Line+1), int(params.Position.Character+1)) |
| 33 | result := serviceHover(doc, mappingNode, nodePath) |
| 34 | if result != nil { |
| 35 | return result, nil |
| 36 | } |
| 37 | result = networkHover(doc, mappingNode, nodePath) |
| 38 | if result != nil { |
| 39 | return result, nil |
| 40 | } |
| 41 | result = configHover(doc, mappingNode, nodePath) |
| 42 | if result != nil { |
| 43 | return result, nil |
| 44 | } |
| 45 | result = secretHover(doc, mappingNode, nodePath) |
| 46 | if result != nil { |
| 47 | return result, nil |
| 48 | } |
| 49 | result = volumeHover(doc, params, mappingNode, nodePath) |
| 50 | if result != nil { |
| 51 | return result, nil |
| 52 | } |
| 53 | result = modelHover(doc, mappingNode, nodePath) |
| 54 | if result != nil { |
| 55 | return result, nil |
| 56 | } |
| 57 | result = hover(composeSchema, nodePath, line, character, len(lines[params.Position.Line])+1) |
| 58 | if result != nil { |
| 59 | return result, nil |
| 60 | } |
| 61 | |
| 62 | anchor, aliases := fragmentReference(mappingNode, line, character) |
| 63 | if anchor != nil { |
| 64 | t := anchor.Name.GetToken() |
| 65 | if t.Position.Line == line && t.Position.Column <= character && character <= t.Position.Column+len(t.Value) { |
| 66 | return createYamlHover(anchor.Value, t), nil |
| 67 | } |
| 68 | for i := range aliases { |
| 69 | t := aliases[i].Value.GetToken() |
| 70 | if t.Position.Line == line && t.Position.Column <= character && character <= t.Position.Column+len(t.Value) { |
| 71 | return createYamlHover(anchor.Value, t), nil |
| 72 | } |
| 73 | } |
| 74 | } |