import type { TextDocument, Range, Position } from 'vscode-languageserver' export function isValidLocationForEmmetAbbreviation( document: TextDocument, abbreviationRange: Range ): boolean { const startAngle = '<' const endAngle = '>' const escape = '\\' const question = '?' let start: Position = { line: 0, character: 0 } let textToBackTrack = document.getText({ start: { line: start.line, character: start.character, }, end: { line: abbreviationRange.start.line, character: abbreviationRange.start.character, }, }) // Worse case scenario is when cursor is inside a big chunk of text which needs to backtracked // Backtrack only 500 offsets to ensure we dont waste time doing this if (textToBackTrack.length > 500) { textToBackTrack = textToBackTrack.substr(textToBackTrack.length - 500) } if (!textToBackTrack.trim()) { return true } let valid = true let foundSpace = false // If < is found before finding whitespace, then its valid abbreviation. E.g.: