Skip to content

Commit

Permalink
Merge branch 'main' into fix/extra-space-after-position
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Spacek committed Jun 30, 2022
2 parents 91c2485 + 4956427 commit b9555f4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Contributing

### Certificate of Origin

By contributing to this project you agree to the Developer Certificate of
Origin (DCO). This document was created by the Linux Kernel community and is a
simple statement that you, as a contributor, have the legal right to make the
contribution. See the [DCO](DCO) file for details.
37 changes: 37 additions & 0 deletions DCO
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
2 changes: 1 addition & 1 deletion src/languageservice/parser/yaml-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class SingleYAMLDocument extends JSONDocument {
if (!range) {
return;
}
const diff = range[2] - offset;
const diff = range[1] - offset;
if (maxOffset <= range[0] && diff <= 0 && Math.abs(diff) <= offsetDiff) {
offsetDiff = Math.abs(diff);
maxOffset = range[0];
Expand Down
59 changes: 58 additions & 1 deletion test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CompletionList, Position, Range } from 'vscode-languageserver-types';
import { CompletionItemKind, CompletionList, InsertTextFormat, Position, Range } from 'vscode-languageserver-types';
import { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers';
import { LanguageService } from '../src/languageservice/yamlLanguageService';
import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings';
Expand Down Expand Up @@ -658,6 +658,63 @@ objB:
expect(completion.items.length).equal(1);
expect(completion.items[0].insertText).to.be.equal('test1');
});
describe('should suggest property before indented comment', () => {
const schema: JSONSchema = {
type: 'object',
properties: {
example: {
type: 'object',
properties: {
prop1: {
type: 'string',
},
prop2: {
type: 'string',
},
prop3: {
type: 'string',
},
},
},
},
};

it('completion should handle indented comment on new line', async () => {
languageService.addSchema(SCHEMA_ID, schema);
const content = 'example:\n prop1: "test"\n \n #comment';
const completion = await parseSetup(content, 2, 2);
expect(completion.items.length).equal(2);
expect(completion.items[0]).to.be.deep.equal(
createExpectedCompletion('prop2', 'prop2: ', 2, 2, 2, 2, CompletionItemKind.Property, InsertTextFormat.Snippet, {
documentation: '',
})
);
});

it('completion should handle comment at same indent level on new line', async () => {
languageService.addSchema(SCHEMA_ID, schema);
const content = 'example:\n prop1: "test"\n \n #comment';
const completion = await parseSetup(content, 2, 2);
expect(completion.items.length).equal(2);
expect(completion.items[0]).to.be.deep.equal(
createExpectedCompletion('prop2', 'prop2: ', 2, 2, 2, 2, CompletionItemKind.Property, InsertTextFormat.Snippet, {
documentation: '',
})
);
});

it('completion should handle suggestion without comment on next line', async () => {
languageService.addSchema(SCHEMA_ID, schema);
const content = 'example:\n prop1: "test"\n \n prop3: "test"';
const completion = await parseSetup(content, 2, 2);
expect(completion.items.length).equal(1);
expect(completion.items[0]).to.be.deep.equal(
createExpectedCompletion('prop2', 'prop2: ', 2, 2, 2, 2, CompletionItemKind.Property, InsertTextFormat.Snippet, {
documentation: '',
})
);
});
});
it('should suggest property of unknown object', async () => {
const schema: JSONSchema = {
type: 'object',
Expand Down

0 comments on commit b9555f4

Please sign in to comment.