| 12 | ) |
| 13 | |
| 14 | func InlayHint(hubService hub.Service, doc document.DockerfileDocument, rng protocol.Range) ([]protocol.InlayHint, error) { |
| 15 | content := doc.Input() |
| 16 | lines := strings.Split(string(content), "\n") |
| 17 | nodes := doc.Nodes() |
| 18 | hints := []protocol.InlayHint{} |
| 19 | for _, node := range nodes { |
| 20 | line := protocol.UInteger(node.StartLine) - 1 |
| 21 | if rng.Start.Line <= line && line <= rng.End.Line { |
| 22 | if strings.EqualFold(node.Value, "FROM") && node.Next != nil { |
| 23 | repository, image, tag := types.HubRepositoryImage(node.Next.Value) |
| 24 | if repository != "" && image != "" && tag != "" { |
| 25 | tags, err := hubService.GetTags(repository, image) |
| 26 | if err == nil { |
| 27 | for _, t := range tags { |
| 28 | if t.Name == tag { |
| 29 | if t.TagLastPushed != "" { |
| 30 | c := carbon.Parse(t.TagLastPushed, carbon.Local) |
| 31 | if c != nil && c.IsValid() { |
| 32 | localFormat := c.Layout("2006-01-02 15:04:05 MST") |
| 33 | hints = append(hints, protocol.InlayHint{ |
| 34 | Label: fmt.Sprintf("(last pushed %v)", c.DiffForHumans()), |
| 35 | PaddingLeft: types.CreateBoolPointer(true), |
| 36 | Position: protocol.Position{Line: line, Character: protocol.UInteger(len(lines[node.StartLine-1]))}, |
| 37 | Tooltip: types.CreateAnyPointer(localFormat), |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | break |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | return hints, nil |
| 50 | } |