Add trailing colon check for completion (#171)
This commit is contained in:
@@ -333,6 +333,24 @@ jobs:
|
||||
expect(result).toHaveLength(16);
|
||||
});
|
||||
|
||||
it("complete from behind a colon will replace it", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
one:
|
||||
runs-on: ubuntu-latest
|
||||
|:
|
||||
- uses: actions/checkout@v2
|
||||
`;
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
expect(result).toHaveLength(16);
|
||||
let textEdit = result[0].textEdit as TextEdit;
|
||||
expect(textEdit.range).toEqual({
|
||||
start: {line: 5, character: 4},
|
||||
end: {line: 5, character: 5}
|
||||
});
|
||||
});
|
||||
|
||||
it("well known mapping keys have descriptions", async () => {
|
||||
const input = `
|
||||
o|
|
||||
|
||||
@@ -108,7 +108,19 @@ export async function complete(
|
||||
|
||||
// Get the length of the current word
|
||||
const val = line.match(/[\w_-]*$/)?.[0].length || 0;
|
||||
replaceRange = Range.create({line: position.line, character: position.character - val}, position);
|
||||
// Check if we need to remove a trailing colon
|
||||
const charAfterPos = textDocument.getText({
|
||||
start: {line: position.line, character: position.character},
|
||||
end: {line: position.line, character: position.character + 1}
|
||||
});
|
||||
if (charAfterPos === ":") {
|
||||
replaceRange = Range.create(
|
||||
{line: position.line, character: position.character - val},
|
||||
{line: position.line, character: position.character + 1}
|
||||
);
|
||||
} else {
|
||||
replaceRange = Range.create({line: position.line, character: position.character - val}, position);
|
||||
}
|
||||
}
|
||||
|
||||
return values.map(value => {
|
||||
|
||||
Reference in New Issue
Block a user