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

Function constructNodePath

internal/compose/hover.go:395–430  ·  view source on GitHub ↗
(matches []ast.Node, node ast.Node, line, col int)

Source from the content-addressed store, hash-verified

393}
394
395func constructNodePath(matches []ast.Node, node ast.Node, line, col int) []ast.Node {
396 node = resolveAnchor(node)
397 switch n := node.(type) {
398 case *ast.MappingValueNode:
399 nodeKey := resolveAnchor(n.Key)
400 if m := constructNodePath(matches, nodeKey, line, col); m != nil {
401 matches = append(matches, m...)
402 return matches
403 }
404 if m := constructNodePath(matches, n.Value, line, col); m != nil {
405 matches = append(matches, nodeKey)
406 matches = append(matches, m...)
407 return matches
408 }
409 case *ast.MappingNode:
410 for _, kv := range n.Values {
411 if m := constructNodePath(matches, kv, line, col); m != nil {
412 matches = append(matches, m...)
413 return matches
414 }
415 }
416 case *ast.SequenceNode:
417 for _, item := range n.Values {
418 if m := constructNodePath(matches, item, line, col); m != nil {
419 matches = append(matches, m...)
420 return matches
421 }
422 }
423 }
424
425 token := node.GetToken()
426 if token.Position.Line == line && token.Position.Column <= col && col <= token.Position.Column+len(token.Value) {
427 return []ast.Node{node}
428 }
429 return nil
430}
431
432func resolveAnchor(node ast.Node) ast.Node {
433 if anchor, ok := node.(*ast.AnchorNode); ok {

Callers 1

HoverFunction · 0.85

Calls 1

resolveAnchorFunction · 0.85

Tested by

no test coverage detected