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

Function DocumentLink

internal/bake/hcl/documentLink.go:15–52  ·  view source on GitHub ↗
(ctx context.Context, documentURI protocol.URI, document document.BakeHCLDocument)

Source from the content-addressed store, hash-verified

13)
14
15func DocumentLink(ctx context.Context, documentURI protocol.URI, document document.BakeHCLDocument) ([]protocol.DocumentLink, error) {
16 body, ok := document.File().Body.(*hclsyntax.Body)
17 if !ok {
18 return nil, errors.New("unrecognized body in HCL document")
19 }
20
21 d, err := document.DocumentPath()
22 if err != nil {
23 return nil, fmt.Errorf("LSP client sent invalid URI: %v", string(documentURI))
24 }
25
26 bytes := document.Input()
27 links := []protocol.DocumentLink{}
28 for _, b := range body.Blocks {
29 attributes := b.Body.Attributes
30 for _, v := range attributes {
31 if v.Name == "dockerfile" {
32 dockerfilePath := string(bytes[v.Expr.Range().Start.Byte:v.Expr.Range().End.Byte])
33 if !Quoted(dockerfilePath) {
34 continue
35 }
36
37 dockerfilePath = strings.TrimPrefix(dockerfilePath, "\"")
38 dockerfilePath = strings.TrimSuffix(dockerfilePath, "\"")
39 target, tooltip := types.Concatenate(d.Folder, dockerfilePath, d.WSLDollarSignHost)
40 links = append(links, protocol.DocumentLink{
41 Range: protocol.Range{
42 Start: protocol.Position{Line: uint32(v.SrcRange.Start.Line) - 1, Character: uint32(v.Expr.Range().Start.Column)},
43 End: protocol.Position{Line: uint32(v.SrcRange.Start.Line) - 1, Character: uint32(v.Expr.Range().End.Column - 2)},
44 },
45 Target: types.CreateStringPointer(target),
46 Tooltip: types.CreateStringPointer(tooltip),
47 })
48 }
49 }
50 }
51 return links, nil
52}

Callers 3

TestDocumentLinkFunction · 0.70
TestDocumentLink_WSLFunction · 0.70

Calls 6

DocumentPathStruct · 0.92
ConcatenateFunction · 0.92
CreateStringPointerFunction · 0.92
QuotedFunction · 0.85
FileMethod · 0.65
InputMethod · 0.65

Tested by 2

TestDocumentLinkFunction · 0.56
TestDocumentLink_WSLFunction · 0.56