Simplify same line logic in find token

This commit is contained in:
Josh Gross
2022-11-17 11:24:34 -08:00
committed by Christopher Schleiden
parent 634cac8eb4
commit b4f6e674b7
+10 -17
View File
@@ -54,9 +54,8 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
for (let i = 0; i < mappingToken.count; i++) {
const {key, value} = mappingToken.get(i);
const sameLine = onSameLine(pos, key, value);
if (posInToken(pos, key)) {
if (sameLine && key.range!.end[1] + 1 === value.range!.start[1]) {
if (onSameLine(pos, key, value)) {
if (posInToken(pos, key) && key.range!.end[1] + 1 === value.range!.start[1]) {
// There's no space between the key and value, there's nothing valid to complete here
return {
token: null,
@@ -65,20 +64,14 @@ export function findToken(pos: Position, root?: TemplateToken): TokenResult {
};
}
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 (sameLine && 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({