export function getOffsetData()

in src/yaml/yamlUtils.ts [459:490]


export function getOffsetData(document: TextDocument, offset: number) {
  const text = document.getText()
  const indexOfLastNewLine = text.lastIndexOf('\n', offset - 1)
  const indexOfNextNewLine = text.indexOf('\n', offset)
  const cursorLine = text.substring(indexOfLastNewLine + 1, indexOfNextNewLine)
  const hasCursorLineNonSpace = /\S/.test(cursorLine)
  const numberOfSpacesCursorLine = getNumberOfLeftSpaces(text.substring(indexOfLastNewLine + 1, offset))
  const initialNumberOfSpaces = numberOfSpacesCursorLine
  let isDirectChildOfStates = false
  let isWithinCatchRetryState = false
  let hasCatchPropSibling = false
  let hasRetryPropSibling = false

  if (!hasCursorLineNonSpace && numberOfSpacesCursorLine > 0) {
    const backwardOffsetData = getBackwardOffsetData(text, offset, initialNumberOfSpaces)
    const forwardOffsetData = getForwardOffsetData(text, offset, initialNumberOfSpaces)

    isDirectChildOfStates = backwardOffsetData.isDirectChildOfStates
    isWithinCatchRetryState =
      (backwardOffsetData.isWithinCatchRetryState || forwardOffsetData.isWithinCatchRetryState) &&
      backwardOffsetData.isGrandChildOfStates
    hasCatchPropSibling = backwardOffsetData.hasCatchPropSibling || forwardOffsetData.hasCatchPropSibling
    hasRetryPropSibling = backwardOffsetData.hasRetryPropSibling || forwardOffsetData.hasRetryPropSibling
  }

  return {
    isDirectChildOfStates,
    isWithinCatchRetryState,
    hasCatchPropSibling,
    hasRetryPropSibling,
  }
}