Skip to content

Commit 3b3dd25

Browse files
committed
fix: some PR comments
1 parent b4ee7b4 commit 3b3dd25

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class YamlCompletion {
144144

145145
this.arrayPrefixIndentation = '';
146146
let overwriteRange: Range = null;
147-
const isOnlyHyphen = lineContent.match(/^\s*(-)\s*$/);
147+
const isOnlyHyphen = lineContent.match(/^\s*(-)\s*($|#)/);
148148
if (areOnlySpacesAfterPosition) {
149149
overwriteRange = Range.create(position, Position.create(position.line, lineContent.length));
150150
const isOnlyWhitespace = lineContent.trim().length === 0;

test/autoCompletionFix.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ objB:
883883
},
884884
};
885885
languageService.addSchema(SCHEMA_ID, schema);
886-
const content = 'array:\n - na ';
887-
const completion = await parseSetup(content, 1, 5);
886+
const content = 'array:\n - na| | ';
887+
const completion = await parseCaret(content);
888888

889889
expect(completion.items.length).equal(1);
890890
expect(completion.items[0].insertText).eql('obj1:\n ');
@@ -1208,16 +1208,25 @@ objB:
12081208
};
12091209
it('should get extra space compensation for the 1st prop in array object item', async () => {
12101210
languageService.addSchema(SCHEMA_ID, schema);
1211-
const content = 'array1:\n - \n propB: test';
1212-
const result = await parseSetup(content, 1, 4); // after `- `
1211+
const content = 'array1:\n - |\n| propB: test';
1212+
const result = await parseCaret(content);
12131213

12141214
expect(result.items.length).to.be.equal(1);
12151215
expect(result.items[0].insertText).to.be.equal('objA:\n ');
12161216
});
12171217
it('should get extra space compensation for the 1st prop in array object item - extra spaces', async () => {
12181218
languageService.addSchema(SCHEMA_ID, schema);
1219-
const content = 'array1:\n - \n propB: test';
1220-
const result = await parseSetup(content, 1, 4); // after `- `
1219+
const content = 'array1:\n - | | \n propB: test';
1220+
const result = await parseCaret(content);
1221+
1222+
expect(result.items.length).to.be.equal(1);
1223+
expect(result.items[0].insertText).to.be.equal('objA:\n ');
1224+
});
1225+
// previous PR doesn't fix this
1226+
it.skip('should get extra space compensation for the 1st prop in array object item - extra lines', async () => {
1227+
languageService.addSchema(SCHEMA_ID, schema);
1228+
const content = 'array1:\n - \n |\n| propB: test';
1229+
const result = await parseCaret(content);
12211230

12221231
expect(result.items.length).to.be.equal(1);
12231232
expect(result.items[0].insertText).to.be.equal('objA:\n ');

test/yaml-documents.test.ts

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,77 @@ objB:
211211
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('bar');
212212
});
213213

214-
it('Find closes node: array', () => {
215-
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
216-
const yamlDoc = documents.getYamlDocument(doc);
217-
const textBuffer = new TextBuffer(doc);
214+
describe('Array', () => {
215+
it('Find closes node: array', () => {
216+
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
217+
const yamlDoc = documents.getYamlDocument(doc);
218+
const textBuffer = new TextBuffer(doc);
219+
220+
const result = yamlDoc.documents[0].findClosestNode(20, textBuffer);
221+
222+
expect(result).is.not.undefined;
223+
expect(isSeq(result)).is.true;
224+
expect((((result as YAMLSeq).items[0] as YAMLMap).items[0].key as Scalar).value).eqls('bar');
225+
});
226+
it.skip('Find first array item node', () => {
227+
const doc = setupTextDocument(`foo:
228+
-
229+
item1: aaa
230+
`);
231+
const yamlDoc = documents.getYamlDocument(doc);
232+
const textBuffer = new TextBuffer(doc);
233+
234+
const result = yamlDoc.documents[0].findClosestNode(9, textBuffer);
235+
236+
expect(result).is.not.undefined;
237+
expect(isMap(result)).is.true;
238+
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item1');
239+
});
240+
it.skip('Find first array item node - extra indent', () => {
241+
const doc = setupTextDocument(`foo:
242+
-
243+
244+
item1: aaa
245+
`);
246+
const yamlDoc = documents.getYamlDocument(doc);
247+
const textBuffer = new TextBuffer(doc);
248+
249+
const result = yamlDoc.documents[0].findClosestNode(9, textBuffer);
250+
251+
expect(result).is.not.undefined;
252+
expect(isMap(result)).is.true;
253+
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item1');
254+
});
255+
256+
it.skip('Find second array item node', () => {
257+
const doc = setupTextDocument(`foo:
258+
- item1: aaa
259+
-
260+
item2: bbb`);
261+
const yamlDoc = documents.getYamlDocument(doc);
262+
const textBuffer = new TextBuffer(doc);
263+
264+
const result = yamlDoc.documents[0].findClosestNode(24, textBuffer);
265+
266+
expect(result).is.not.undefined;
267+
expect(isMap(result)).is.true;
268+
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item2');
269+
});
270+
it.skip('Find second array item node: - extra indent', () => {
271+
const doc = setupTextDocument(`foo:
272+
- item1: aaa
273+
-
274+
275+
item2: bbb`);
276+
const yamlDoc = documents.getYamlDocument(doc);
277+
const textBuffer = new TextBuffer(doc);
218278

219-
const result = yamlDoc.documents[0].findClosestNode(20, textBuffer);
279+
const result = yamlDoc.documents[0].findClosestNode(28, textBuffer);
220280

221-
expect(result).is.not.undefined;
222-
expect(isSeq(result)).is.true;
223-
expect((((result as YAMLSeq).items[0] as YAMLMap).items[0].key as Scalar).value).eqls('bar');
281+
expect(result).is.not.undefined;
282+
expect(isMap(result)).is.true;
283+
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item2');
284+
});
224285
});
225286

226287
it('Find closes node: root map', () => {

0 commit comments

Comments
 (0)