function processLineWithoutColon()

in src/yaml/yamlUtils.ts [44:116]


function processLineWithoutColon(document: TextDocument, cursorPosition: Position, currentLine: string, currentLineEnd: number): ProcessYamlDocForCompletionOutput {
    let modifiedDocText: string
    let shouldPrependSpace: boolean = false

    const tempPositionForCompletions: Position = { ...cursorPosition }
    const startPositionForInsertion: Position = { ...cursorPosition }

    // Since there's no colon to separate the key and value, replace all text after the cursor.
    const endPositionForInsertion: Position = {
        line: cursorPosition.line,
        character: currentLine.length
    }

    const docText = document.getText()
    const docTextLength = docText.length
    const lineOffsets = getLineOffsets(docText)
    const trimmedLine = currentLine.trim()

    let preText: string
    let postText: string
    let insertedText: string

    // Current line has no non-space characters, insert a placeholder node at the end of the line
    if (trimmedLine.length === 0) {
        preText = docText.substring(0, currentLineEnd)
        insertedText = '"":\n'
        postText = docText.substr(lineOffsets[cursorPosition.line + 1] || docTextLength)

        tempPositionForCompletions.character += 1

    // Trimmed line starts with '-'
    } else if (trimmedLine.length >= 1 && trimmedLine[0] === '-') {
        // Set start of insertion range to be immediately after the hyphen.
        const hyphenIndex = currentLine.indexOf('-')
        startPositionForInsertion.character = hyphenIndex + 1
        shouldPrependSpace = true

        const postHyphenTextTrimmed = currentLine.substring(hyphenIndex + 1).trim()

        // No non-space characters after the hyphen, insert a placeholder node after the hyphen
        if (postHyphenTextTrimmed.length === 0) {
            tempPositionForCompletions.character = hyphenIndex + 3
            preText = docText.substring(0, lineOffsets[cursorPosition.line] + hyphenIndex)
            insertedText = "- '':\n"
            postText = docText.substr(lineOffsets[cursorPosition.line + 1] || docTextLength)

        // There are non-space character after the hyphen, but no colon. Just insert colon at end of line.
        } else {
            preText = docText.substring(0, currentLineEnd)
            insertedText = (!currentLine.endsWith(' ') ? ' ' : '') + ':\n'
            postText = docText.substr(lineOffsets[cursorPosition.line + 1] || docTextLength)
        }

    // Non-empty line but missing colon, add colon to end of current line
    } else {
        preText = docText.substring(0, currentLineEnd)
        insertedText = ':\n'
        postText = docText.substr(lineOffsets[cursorPosition.line + 1] || docTextLength)

        // Starting pos is first non-space character
        startPositionForInsertion.character = currentLine.indexOf(trimmedLine)
    }

    modifiedDocText = `${preText}${insertedText}${postText}`

    return {
        modifiedDocText,
        tempPositionForCompletions,
        startPositionForInsertion,
        endPositionForInsertion,
        shouldPrependSpace
    }
}