From 190192438764dd56f9236bb1f703fcce9dd6fca9 Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Wed, 23 Nov 2022 07:43:29 -0800 Subject: [PATCH] Add failing test for empty node scenario --- .../src/utils/find-token.test.ts | 14 ++++++++++++++ actions-languageservice/src/utils/find-token.ts | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/actions-languageservice/src/utils/find-token.test.ts b/actions-languageservice/src/utils/find-token.test.ts index 1325fb4..29e8812 100644 --- a/actions-languageservice/src/utils/find-token.test.ts +++ b/actions-languageservice/src/utils/find-token.test.ts @@ -174,4 +174,18 @@ jobs: token: ["job", TokenType.String, "runs-"] }); }); + + it("empty node", () => { + expect( + testFindToken(`on: push +jobs: + build: + concurrency: + runs-on: ubu|`) + ).toEqual({ + parent: ["job-factory", TokenType.Mapping], + key: [null, TokenType.String, "runs-on"], + token: ["runs-on", TokenType.String, "ubu"] + }); + }); }); diff --git a/actions-languageservice/src/utils/find-token.ts b/actions-languageservice/src/utils/find-token.ts index 2bdf54b..d522172 100644 --- a/actions-languageservice/src/utils/find-token.ts +++ b/actions-languageservice/src/utils/find-token.ts @@ -67,6 +67,7 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult { for (let i = 0; i < mappingToken.count; i++) { const {key, value} = mappingToken.get(i); + // If the position is within the key, immediately return it as the token. if (posInToken(pos, key)) { return { parent: mappingToken, @@ -75,7 +76,7 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult { }; } - // Empty nodes positions won't always match the cursor, so check if we're on the same line + // If the value is an empty node (null, empty string) if (emptyNode(value)) { return { parent: mappingToken,