Passing findToken tests

This commit is contained in:
Christopher Schleiden
2022-11-22 17:01:59 -08:00
parent 3eabb5ad81
commit 9f5ced7bd3
2 changed files with 18 additions and 29 deletions
@@ -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"]
});
});
});
+14 -25
View File
@@ -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({