MCPcopy Create free account
hub / github.com/docker/docker-language-server / InlayHint

Function InlayHint

internal/dockerfile/inlayHint.go:14–50  ·  view source on GitHub ↗
(hubService hub.Service, doc document.DockerfileDocument, rng protocol.Range)

Source from the content-addressed store, hash-verified

12)
13
14func 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}

Callers 2

TextDocumentInlayHintMethod · 0.92
TestInlayHintFunction · 0.70

Calls 6

HubRepositoryImageFunction · 0.92
CreateBoolPointerFunction · 0.92
CreateAnyPointerFunction · 0.92
InputMethod · 0.65
NodesMethod · 0.65
GetTagsMethod · 0.65

Tested by 1

TestInlayHintFunction · 0.56