Skip to content

Commit a4f2ecc

Browse files
authored
Merge pull request #116 from docker/compose-spacing-bug-fix
Fix spacing issue in Compose completions
2 parents 254f478 + 2a342b5 commit a4f2ecc

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ All notable changes to the Docker Language Server will be documented in this fil
77
### Fixed
88

99
- Compose
10+
- textDocument/completion
11+
- resolved a spacing offset issue with object or array completions ([#115](https://github.com/docker/docker-language-server/issues/115))
1012
- textDocument/hover
1113
- return the hover results for Compose files
1214

internal/compose/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func Completion(ctx context.Context, params *protocol.CompletionParams, doc docu
7777
} else if properties, ok := nodeProps.(map[string]*jsonschema.Schema); ok {
7878
sb := strings.Builder{}
7979
for i := range lines[lspLine] {
80-
if unicode.IsSpace(rune(lines[lspLine][i])) {
81-
sb.WriteString(string(lines[lspLine][i]))
80+
if unicode.IsSpace(rune(lines[lspLine][i])) || lines[lspLine][i] == '-' {
81+
sb.WriteString(" ")
8282
}
8383
}
8484
sb.WriteString(" ")

internal/compose/completion_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,76 @@ services:
13991399
Items: serviceProperties,
14001400
},
14011401
},
1402+
{
1403+
name: "properties of a volumes array item with no content",
1404+
content: `
1405+
services:
1406+
test:
1407+
image: alpine
1408+
volumes:
1409+
- `,
1410+
line: 5,
1411+
character: 8,
1412+
list: &protocol.CompletionList{
1413+
Items: []protocol.CompletionItem{
1414+
{
1415+
Label: "bind",
1416+
Detail: types.CreateStringPointer("object"),
1417+
InsertText: types.CreateStringPointer("bind:\n "),
1418+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1419+
},
1420+
{
1421+
Label: "consistency",
1422+
Detail: types.CreateStringPointer("string"),
1423+
InsertText: types.CreateStringPointer("consistency: "),
1424+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1425+
},
1426+
{
1427+
Label: "image",
1428+
Detail: types.CreateStringPointer("object"),
1429+
InsertText: types.CreateStringPointer("image:\n "),
1430+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1431+
},
1432+
{
1433+
Label: "read_only",
1434+
Detail: types.CreateStringPointer("boolean or string"),
1435+
InsertText: types.CreateStringPointer("read_only: "),
1436+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1437+
},
1438+
{
1439+
Label: "source",
1440+
Detail: types.CreateStringPointer("string"),
1441+
InsertText: types.CreateStringPointer("source: "),
1442+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1443+
},
1444+
{
1445+
Label: "target",
1446+
Detail: types.CreateStringPointer("string"),
1447+
InsertText: types.CreateStringPointer("target: "),
1448+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1449+
},
1450+
{
1451+
Label: "tmpfs",
1452+
Detail: types.CreateStringPointer("object"),
1453+
InsertText: types.CreateStringPointer("tmpfs:\n "),
1454+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1455+
},
1456+
{
1457+
Label: "type",
1458+
Detail: types.CreateStringPointer("string"),
1459+
InsertText: types.CreateStringPointer("type: ${1|bind,cluster,image,npipe,tmpfs,volume|}"),
1460+
InsertTextFormat: types.CreateInsertTextFormatPointer(protocol.InsertTextFormatSnippet),
1461+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1462+
},
1463+
{
1464+
Label: "volume",
1465+
Detail: types.CreateStringPointer("object"),
1466+
InsertText: types.CreateStringPointer("volume:\n "),
1467+
InsertTextMode: types.CreateInsertTextModePointer(protocol.InsertTextModeAsIs),
1468+
},
1469+
},
1470+
},
1471+
},
14021472
{
14031473
name: "properties of a volume array item's sibling attributes under a service object",
14041474
content: `

0 commit comments

Comments
 (0)