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

Function buildTargetCompletionItems

internal/compose/completion.go:553–582  ·  view source on GitHub ↗
(params *protocol.CompletionParams, manager *document.Manager, path []*ast.MappingValueNode, documentPath document.DocumentPath, prefixLength protocol.UInteger)

Source from the content-addressed store, hash-verified

551}
552
553func buildTargetCompletionItems(params *protocol.CompletionParams, manager *document.Manager, path []*ast.MappingValueNode, documentPath document.DocumentPath, prefixLength protocol.UInteger) ([]protocol.CompletionItem, bool) {
554 if len(path) == 4 && path[2].Key.GetToken().Value == "build" && path[3].Key.GetToken().Value == "target" {
555 if mappingNode, ok := path[2].Value.(*ast.MappingNode); ok {
556 dockerfileAttributePath := "Dockerfile"
557 for _, buildAttribute := range mappingNode.Values {
558 switch buildAttribute.Key.GetToken().Value {
559 case "dockerfile_inline":
560 return nil, true
561 case "dockerfile":
562 dockerfileAttributePath = buildAttribute.Value.GetToken().Value
563 }
564 }
565
566 dockerfileURI, dockerfilePath := types.Concatenate(documentPath.Folder, dockerfileAttributePath, documentPath.WSLDollarSignHost)
567 if _, ok := path[3].Value.(*ast.NullNode); ok {
568 return createBuildStageItems(params, manager, dockerfileURI, dockerfilePath, "", prefixLength), true
569 } else if prefix, ok := path[3].Value.(*ast.StringNode); ok {
570 if int(params.Position.Line) == path[3].Value.GetToken().Position.Line-1 {
571 offset := int(params.Position.Character) - path[3].Value.GetToken().Position.Column + 1
572 // offset can be greater than the length if there's just empty whitespace after the string value,
573 // must be non-negative, if negative it suggests the cursor is in the whitespace before the attribute's value
574 if offset >= 0 && offset <= len(prefix.Value) {
575 return createBuildStageItems(params, manager, dockerfileURI, dockerfilePath, prefix.Value[0:offset], prefixLength), true
576 }
577 }
578 }
579 }
580 }
581 return nil, false
582}
583
584func serviceImageCompletionItems(hub hub.Service, path []*ast.MappingValueNode, prefix string) ([]protocol.CompletionItem, bool) {
585 if len(path) == 3 && path[0].Key.GetToken().Value == "services" && path[2].Key.GetToken().Value == "image" {

Callers 1

CompletionFunction · 0.85

Calls 2

ConcatenateFunction · 0.92
createBuildStageItemsFunction · 0.85

Tested by

no test coverage detected