in src/completion/completeJSONata.ts [208:283]
export default async function completeJSONata(
node: ASTNode | undefined,
offset: number,
document: TextDocument,
asl: Asl,
): Promise<CompletionList | undefined> {
if (!node || document.languageId === LANGUAGE_IDS.YAML) {
return
}
if (!node || !node.parent || !isPropertyNode(node.parent)) {
return
}
const isValueNode = node.parent.valueNode?.offset === node.offset
if (!isStringNode(node) || !isValueNode) {
return
}
const stateInfo = getStateInfo(node)
// don't generate JSONata autocomplete strings if not inside a state
if (!stateInfo) {
return
}
const jsonataNodeData = await getJSONataNodeData(document, offset, node)
if (!jsonataNodeData) {
return
}
const { jsonataNode, nodePosition, jsonataNodePosition, jsonataFunctions } = jsonataNodeData
const jsonataNodeLength = jsonataNode.node.value ? String(jsonataNode?.node.value).length : 0
const endPosition = Position.create(
nodePosition.line,
jsonataNodePosition + JSONATA_TEMPLATE_WRAPPER.start.length + nodePosition.character,
)
const partialPathCompletion = getPartialPathCompletion({
jsonataNode,
nodePosition,
endPosition,
node,
asl,
})
if (partialPathCompletion) {
return partialPathCompletion
}
const incompletePathCompletion = getIncompletePathCompletion({
jsonataNode,
nodePosition,
endPosition,
node,
asl,
})
if (incompletePathCompletion) {
return incompletePathCompletion
}
const variableAndFunctionCompletions = getFunctionCompletions({
jsonataNodeLength,
jsonataFunctions,
properties: {
jsonataNode,
nodePosition,
endPosition,
node,
asl,
},
})
return variableAndFunctionCompletions
}