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

Function Definition

internal/compose/definition.go:16–62  ·  view source on GitHub ↗
(ctx context.Context, definitionLinkSupport bool, doc document.ComposeDocument, params *protocol.DefinitionParams)

Source from the content-addressed store, hash-verified

14}
15
16func Definition(ctx context.Context, definitionLinkSupport bool, doc document.ComposeDocument, params *protocol.DefinitionParams) (any, error) {
17 name, dependency := DocumentHighlights(doc, params.Position)
18 if len(dependency.documentHighlights) == 0 {
19 return nil, nil
20 }
21
22 targetURI := params.TextDocument.URI
23 var sourceRange *protocol.Range
24 var definitionRange *protocol.Range
25 for _, highlight := range dependency.documentHighlights {
26 if *highlight.Kind == protocol.DocumentHighlightKindWrite {
27 definitionRange = &highlight.Range
28 if insideRange(highlight.Range, params.Position.Line, params.Position.Character) {
29 sourceRange = &highlight.Range
30 break
31 }
32 }
33 }
34
35 if definitionRange == nil {
36 node, u := dependencyLookup(doc, dependency.dependencyType, name)
37 if node != nil {
38 r := createRange(node.Key.GetToken(), len(node.Key.GetToken().Value))
39 definitionRange = &r
40 targetURI = u
41 }
42 }
43
44 for _, highlight := range dependency.documentHighlights {
45 if *highlight.Kind == protocol.DocumentHighlightKindRead {
46 if insideRange(highlight.Range, params.Position.Line, params.Position.Character) {
47 sourceRange = &highlight.Range
48 break
49 }
50 }
51 }
52
53 if definitionRange != nil {
54 return types.CreateDefinitionResult(
55 definitionLinkSupport,
56 *definitionRange,
57 sourceRange,
58 targetURI,
59 ), nil
60 }
61 return nil, nil
62}
63
64func dependencyLookup(doc document.ComposeDocument, dependencyType, name string) (*ast.MappingValueNode, string) {
65 files, _ := doc.IncludedFiles()

Callers 9

TestDefinition_ServicesFunction · 0.70
TestDefinition_NetworksFunction · 0.70
TestDefinition_VolumesFunction · 0.70
TestDefinition_ConfigsFunction · 0.70
TestDefinition_SecretsFunction · 0.70
TestDefinition_ModelsFunction · 0.70
TestDefinition_FragmentsFunction · 0.70

Calls 5

CreateDefinitionResultFunction · 0.92
DocumentHighlightsFunction · 0.85
insideRangeFunction · 0.85
dependencyLookupFunction · 0.85
createRangeFunction · 0.70

Tested by 8

TestDefinition_ServicesFunction · 0.56
TestDefinition_NetworksFunction · 0.56
TestDefinition_VolumesFunction · 0.56
TestDefinition_ConfigsFunction · 0.56
TestDefinition_SecretsFunction · 0.56
TestDefinition_ModelsFunction · 0.56
TestDefinition_FragmentsFunction · 0.56