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

Function hoveredVariableName

internal/bake/hcl/hover.go:63–87  ·  view source on GitHub ↗
(input []byte, blocks hclsyntax.Blocks, position protocol.Position)

Source from the content-addressed store, hash-verified

61}
62
63func hoveredVariableName(input []byte, blocks hclsyntax.Blocks, position protocol.Position) string {
64 for _, block := range blocks {
65 if isInsideBodyRangeLines(block.Body, int(position.Line+1)) {
66 if block.Type == "variable" && len(block.LabelRanges) > 0 && isInsideRange(block.LabelRanges[0], position) {
67 label := string(input[block.LabelRanges[0].Start.Byte:block.LabelRanges[0].End.Byte])
68 if Quoted(label) {
69 if block.LabelRanges[0].Start.Column == int(position.Character+1) || block.LabelRanges[0].End.Column == int(position.Character+1) {
70 return ""
71 }
72 }
73 return block.Labels[0]
74 }
75
76 for _, attribute := range block.Body.Attributes {
77 if isInsideRange(attribute.Expr.Range(), position) {
78 name := extractVariableName(input, attribute.Expr)
79 if name != "" {
80 return name
81 }
82 }
83 }
84 }
85 }
86 return ""
87}
88
89func extractVariableName(input []byte, expression hclsyntax.Expression) string {
90 if tupleCons, ok := expression.(*hclsyntax.TupleConsExpr); ok {

Callers 1

HoverFunction · 0.85

Calls 4

isInsideBodyRangeLinesFunction · 0.85
isInsideRangeFunction · 0.85
QuotedFunction · 0.85
extractVariableNameFunction · 0.85

Tested by

no test coverage detected