Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ All notable changes to the Docker Language Server will be documented in this fil

- Compose
- update schema to the latest version
- textDocument/completion
- support completing model object names ([#343](https://github.com/docker/docker-language-server/issues/343))
- textDocument/definition
- support jumping to referenced model objects ([#343](https://github.com/docker/docker-language-server/issues/343))
- textDocument/documentHighlight
- support highlighting referenced models objects ([#343](https://github.com/docker/docker-language-server/issues/343))
- textDocument/documentLink
- support recursing into anchors when searching for document links ([#329](https://github.com/docker/docker-language-server/issues/329))
- return document links for the `file` attribute of a service object's `credential_spec` ([#338](https://github.com/docker/docker-language-server/issues/338))
- textDocument/documentSymbol
- show model objects in the document symbol tree ([#343](https://github.com/docker/docker-language-server/issues/343))
- textDocument/prepareRename
- allow preparing rename on model objects ([#343](https://github.com/docker/docker-language-server/issues/343))
- textDocument/rename
- support renaming model objects ([#343](https://github.com/docker/docker-language-server/issues/343))

### Fixed

Expand Down
1 change: 1 addition & 0 deletions internal/compose/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ func createBuildStageItems(params *protocol.CompletionParams, manager *document.
func dependencyCompletionItems(file *ast.File, u *url.URL, path []*ast.MappingValueNode, params *protocol.CompletionParams, prefixLength protocol.UInteger) []protocol.CompletionItem {
dependency := map[string]string{
"depends_on": "services",
"models": "models",
"networks": "networks",
}
for serviceAttribute, dependencyType := range dependency {
Expand Down
22 changes: 22 additions & 0 deletions internal/compose/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,28 @@ secrets:
},
},
},
{
name: "model names suggested",
content: `
services:
app:
image: app
models:
-
models:
ai_model:
model: ai/model`,
line: 5,
character: 8,
list: &protocol.CompletionList{
Items: []protocol.CompletionItem{
{
Label: "ai_model",
TextEdit: textEdit("ai_model", 5, 8, 0),
},
},
},
},
}

composeFileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "compose.yaml")), "/"))
Expand Down
26 changes: 26 additions & 0 deletions internal/compose/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ func TestDefinition_Secrets(t *testing.T) {
}
}

func TestDefinition_Models(t *testing.T) {
composeFileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "compose.yaml")), "/"))
u := uri.URI(composeFileURI)
for _, tc := range modelReferenceTestCases {
doc := document.NewComposeDocument(document.NewDocumentManager(), u, 1, []byte(tc.content))
params := protocol.DefinitionParams{
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
TextDocument: protocol.TextDocumentIdentifier{URI: composeFileURI},
Position: protocol.Position{Line: tc.line, Character: tc.character},
},
}

t.Run(fmt.Sprintf("%v (Location)", tc.name), func(t *testing.T) {
locations, err := Definition(context.Background(), false, doc, &params)
require.NoError(t, err)
require.Equal(t, tc.locations(composeFileURI), locations)
})

t.Run(fmt.Sprintf("%v (LocationLink)", tc.name), func(t *testing.T) {
links, err := Definition(context.Background(), true, doc, &params)
require.NoError(t, err)
require.Equal(t, tc.links(composeFileURI), links)
})
}
}

func TestDefinition_Fragments(t *testing.T) {
composeFileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "compose.yaml")), "/"))
u := uri.URI(composeFileURI)
Expand Down
9 changes: 9 additions & 0 deletions internal/compose/documentHighlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,12 @@ func DocumentHighlights(doc document.ComposeDocument, position protocol.Position
var volumeRefs []*token.Token
var configRefs []*token.Token
var secretRefs []*token.Token
var modelRefs []*token.Token
var networkDeclarations []*token.Token
var volumeDeclarations []*token.Token
var configDeclarations []*token.Token
var secretDeclarations []*token.Token
var modelDeclarations []*token.Token
for _, node := range mappingNode.Values {
name, value := convertTopLevelNode(node)
if name == nil || value == nil {
Expand All @@ -299,6 +301,7 @@ func DocumentHighlights(doc document.ComposeDocument, position protocol.Position
networkRefs = serviceDependencyReferences(value, "networks", false)
configRefs = serviceDependencyReferences(value, "configs", true)
secretRefs = serviceDependencyReferences(value, "secrets", true)
modelRefs = serviceDependencyReferences(value, "models", false)
volumeRefs = volumeReferences(value)
case "networks":
networkDeclarations = declarations(value)
Expand All @@ -308,6 +311,8 @@ func DocumentHighlights(doc document.ComposeDocument, position protocol.Position
configDeclarations = declarations(value)
case "secrets":
secretDeclarations = declarations(value)
case "models":
modelDeclarations = declarations(value)
}
}
name, highlights := highlightReferences("networks", networkRefs, networkDeclarations, line, character)
Expand All @@ -326,6 +331,10 @@ func DocumentHighlights(doc document.ComposeDocument, position protocol.Position
if len(highlights.documentHighlights) > 0 {
return name, highlights
}
name, highlights = highlightReferences("models", modelRefs, modelDeclarations, line, character)
if len(highlights.documentHighlights) > 0 {
return name, highlights
}

fragments := []protocol.DocumentHighlight{}
anchor, aliases := fragmentReference(mappingNode, line, character)
Expand Down
Loading
Loading