Skip to content

Commit

Permalink
fix: some PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
p-spacek committed Jun 6, 2023
1 parent 47366ca commit 856cb85
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class YamlCompletion {

this.arrayPrefixIndentation = '';
let overwriteRange: Range = null;
const isOnlyHyphen = lineContent.match(/^\s*(-)\s*$/);
const isOnlyHyphen = lineContent.match(/^\s*(-)\s*($|#)/);
if (areOnlySpacesAfterPosition) {
overwriteRange = Range.create(position, Position.create(position.line, lineContent.length));
const isOnlyWhitespace = lineContent.trim().length === 0;
Expand Down
21 changes: 15 additions & 6 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ objB:
},
};
languageService.addSchema(SCHEMA_ID, schema);
const content = 'array:\n - na ';
const completion = await parseSetup(content, 1, 5);
const content = 'array:\n - na| | ';
const completion = await parseCaret(content);

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

expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n ');
});
it('should get extra space compensation for the 1st prop in array object item - extra spaces', async () => {
languageService.addSchema(SCHEMA_ID, schema);
const content = 'array1:\n - \n propB: test';
const result = await parseSetup(content, 1, 4); // after `- `
const content = 'array1:\n - | | \n propB: test';
const result = await parseCaret(content);

expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n ');
});
// previous PR doesn't fix this
it.skip('should get extra space compensation for the 1st prop in array object item - extra lines', async () => {
languageService.addSchema(SCHEMA_ID, schema);
const content = 'array1:\n - \n |\n| propB: test';
const result = await parseCaret(content);

expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n ');
Expand Down
77 changes: 69 additions & 8 deletions test/yaml-documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,77 @@ objB:
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('bar');
});

it('Find closes node: array', () => {
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);
describe('Array', () => {
it('Find closes node: array', () => {
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);

const result = yamlDoc.documents[0].findClosestNode(20, textBuffer);

expect(result).is.not.undefined;
expect(isSeq(result)).is.true;
expect((((result as YAMLSeq).items[0] as YAMLMap).items[0].key as Scalar).value).eqls('bar');
});
it.skip('Find first array item node', () => {
const doc = setupTextDocument(`foo:
-
item1: aaa
`);
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);

const result = yamlDoc.documents[0].findClosestNode(9, textBuffer);

expect(result).is.not.undefined;
expect(isMap(result)).is.true;
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item1');
});
it.skip('Find first array item node - extra indent', () => {
const doc = setupTextDocument(`foo:
-
item1: aaa
`);
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);

const result = yamlDoc.documents[0].findClosestNode(9, textBuffer);

expect(result).is.not.undefined;
expect(isMap(result)).is.true;
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item1');
});

it.skip('Find second array item node', () => {
const doc = setupTextDocument(`foo:
- item1: aaa
-
item2: bbb`);
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);

const result = yamlDoc.documents[0].findClosestNode(24, textBuffer);

expect(result).is.not.undefined;
expect(isMap(result)).is.true;
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item2');
});
it.skip('Find second array item node: - extra indent', () => {
const doc = setupTextDocument(`foo:
- item1: aaa
-
item2: bbb`);
const yamlDoc = documents.getYamlDocument(doc);
const textBuffer = new TextBuffer(doc);

const result = yamlDoc.documents[0].findClosestNode(20, textBuffer);
const result = yamlDoc.documents[0].findClosestNode(28, textBuffer);

expect(result).is.not.undefined;
expect(isSeq(result)).is.true;
expect((((result as YAMLSeq).items[0] as YAMLMap).items[0].key as Scalar).value).eqls('bar');
expect(result).is.not.undefined;
expect(isMap(result)).is.true;
expect(((result as YAMLMap).items[0].key as Scalar).value).eqls('item2');
});
});

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

0 comments on commit 856cb85

Please sign in to comment.