Add trailing colon check for completion (#171)
This commit is contained in:
@@ -333,6 +333,24 @@ jobs:
|
|||||||
expect(result).toHaveLength(16);
|
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 () => {
|
it("well known mapping keys have descriptions", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
o|
|
o|
|
||||||
|
|||||||
@@ -108,8 +108,20 @@ export async function complete(
|
|||||||
|
|
||||||
// Get the length of the current word
|
// Get the length of the current word
|
||||||
const val = line.match(/[\w_-]*$/)?.[0].length || 0;
|
const val = line.match(/[\w_-]*$/)?.[0].length || 0;
|
||||||
|
// 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);
|
replaceRange = Range.create({line: position.line, character: position.character - val}, position);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return values.map(value => {
|
return values.map(value => {
|
||||||
const newText = value.insertText || value.label;
|
const newText = value.insertText || value.label;
|
||||||
|
|||||||
Reference in New Issue
Block a user