diff --git a/actions-languageservice/src/utils/find-token.test.ts b/actions-languageservice/src/utils/find-token.test.ts index 46fecb0..20f0dec 100644 --- a/actions-languageservice/src/utils/find-token.test.ts +++ b/actions-languageservice/src/utils/find-token.test.ts @@ -67,9 +67,9 @@ describe("find-token", () => { testFindToken(`on: pu|sh:`) ).toEqual({ - parent: ["on-strict", TokenType.Mapping], - key: ["push-event-mapping", TokenType.String, "push"], - token: ["on-strict", TokenType.Mapping] + parent: ["on-mapping-strict", TokenType.Mapping], + key: null, + token: [null, TokenType.String, "push"] }); }); @@ -92,7 +92,7 @@ jo|bs: ).toEqual({ parent: ["workflow-root-strict", TokenType.Mapping], key: null, - token: ["jobs", TokenType.Mapping] + token: [null, TokenType.String, "jobs"] }); }); }); diff --git a/actions-languageservice/src/utils/find-token.ts b/actions-languageservice/src/utils/find-token.ts index 4e840f2..5e95694 100644 --- a/actions-languageservice/src/utils/find-token.ts +++ b/actions-languageservice/src/utils/find-token.ts @@ -67,32 +67,21 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult { for (let i = 0; i < mappingToken.count; i++) { const {key, value} = mappingToken.get(i); - if (onSameLine(pos, key, value)) { - if (posInToken(pos, key)) { - if (key.range!.end[1] + 1 === value.range!.start[1]) { - // There's no space between the key and value, this is not valid - return { - token: null, - keyToken: null, - parent: null - }; - } + if (posInToken(pos, key)) { + return { + token: key, + keyToken: null, + parent: mappingToken + }; + } - return { - token: key, - keyToken: null, - parent: mappingToken - }; - } - - // Empty nodes positions won't always match the cursor, so check if we're on the same line - if (emptyNode(value)) { - return { - token: value, - keyToken: null, - parent: key - }; - } + // Empty nodes positions won't always match the cursor, so check if we're on the same line + if (emptyNode(value)) { + return { + token: value, + keyToken: null, + parent: key + }; } s.push({