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

Function CodeLens

internal/bake/hcl/codeLens.go:14–50  ·  view source on GitHub ↗
(ctx context.Context, documentURI string, doc document.BakeHCLDocument)

Source from the content-addressed store, hash-verified

12)
13
14func CodeLens(ctx context.Context, documentURI string, doc document.BakeHCLDocument) ([]protocol.CodeLens, error) {
15 body, ok := doc.File().Body.(*hclsyntax.Body)
16 if !ok {
17 return nil, errors.New("unrecognized body in HCL document")
18 }
19
20 dp, err := doc.DocumentPath()
21 if err != nil {
22 return nil, fmt.Errorf("could not parse URI (%v): %w", documentURI, err)
23 }
24
25 _, cwd := types.Concatenate(dp.Folder, ".", dp.WSLDollarSignHost)
26 result := []protocol.CodeLens{}
27 for _, block := range body.Blocks {
28 if len(block.Labels) > 0 {
29 switch block.Type {
30 case "group":
31 rng := protocol.Range{
32 Start: protocol.Position{Line: uint32(block.Range().Start.Line - 1)},
33 End: protocol.Position{Line: uint32(block.Range().Start.Line - 1)},
34 }
35 result = append(result, createCodeLens("Build", cwd, "build", block.Labels[0], rng))
36 result = append(result, createCodeLens("Check", cwd, "check", block.Labels[0], rng))
37 result = append(result, createCodeLens("Print", cwd, "print", block.Labels[0], rng))
38 case "target":
39 rng := protocol.Range{
40 Start: protocol.Position{Line: uint32(block.Range().Start.Line - 1)},
41 End: protocol.Position{Line: uint32(block.Range().Start.Line - 1)},
42 }
43 result = append(result, createCodeLens("Build", cwd, "build", block.Labels[0], rng))
44 result = append(result, createCodeLens("Check", cwd, "check", block.Labels[0], rng))
45 result = append(result, createCodeLens("Print", cwd, "print", block.Labels[0], rng))
46 }
47 }
48 }
49 return result, nil
50}
51
52func createCodeLens(title, cwd, call, target string, rng protocol.Range) protocol.CodeLens {
53 return protocol.CodeLens{

Callers 2

TextDocumentCodeLensMethod · 0.92
testCodeLensFunction · 0.70

Calls 4

ConcatenateFunction · 0.92
createCodeLensFunction · 0.85
FileMethod · 0.65
DocumentPathMethod · 0.65

Tested by 1

testCodeLensFunction · 0.56