diff --git a/languageservice/src/complete.test.ts b/languageservice/src/complete.test.ts index 84abd19..02fab47 100644 --- a/languageservice/src/complete.test.ts +++ b/languageservice/src/complete.test.ts @@ -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| diff --git a/languageservice/src/complete.ts b/languageservice/src/complete.ts index 8050570..4d6341b 100644 --- a/languageservice/src/complete.ts +++ b/languageservice/src/complete.ts @@ -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 => {