Skip to content

Commit bda342c

Browse files
authored
fix: correct indent when cursor is just after hyphen with trailing spaces (#26)
1 parent a1be171 commit bda342c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ export class YamlCompletion {
326326
Position.create(position.line, lineContent.length)
327327
);
328328
}
329+
} else if (node && isScalar(node) && node.value === null && currentWord === '-') {
330+
this.arrayPrefixIndentation = ' ';
329331
}
330332
} else if (node && isScalar(node) && node.value === 'null') {
331333
const nodeStartPos = document.positionAt(node.range[0]);

test/autoCompletionFix.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,42 @@ test:
11811181
expect(result.items[0].insertText).to.be.equal('objA:\n itemA: ');
11821182
});
11831183

1184+
it('array completion - should suggest correct indent when cursor is just after hyphen with trailing spaces', async () => {
1185+
schemaProvider.addSchema(SCHEMA_ID, {
1186+
type: 'object',
1187+
properties: {
1188+
test: {
1189+
type: 'array',
1190+
items: {
1191+
type: 'object',
1192+
properties: {
1193+
objA: {
1194+
type: 'object',
1195+
required: ['itemA'],
1196+
properties: {
1197+
itemA: {
1198+
type: 'string',
1199+
},
1200+
},
1201+
},
1202+
},
1203+
},
1204+
},
1205+
},
1206+
});
1207+
const content = `
1208+
test:
1209+
-| |
1210+
`;
1211+
const result = await parseCaret(content);
1212+
1213+
expect(result.items.length).to.be.equal(1);
1214+
expect(result.items[0].textEdit).to.deep.equal({
1215+
newText: ' objA:\n itemA: ',
1216+
// range should contains all the trailing spaces
1217+
range: Range.create(2, 3, 2, 9),
1218+
});
1219+
});
11841220
it('array of arrays completion - should suggest correct indent when extra spaces after cursor', async () => {
11851221
schemaProvider.addSchema(SCHEMA_ID, {
11861222
type: 'object',

0 commit comments

Comments
 (0)