function getCompletionList()

in src/completion/completeStateNames.ts [80:113]


function getCompletionList(
  items: string[],
  replaceRange: Range,
  languageId: string,
  options: CompleteStateNameOptions,
) {
  const { shouldAddLeftQuote, shouldAddRightQuote, shouldAddLeadingSpace, shoudlAddTrailingComma } = options

  const list: CompletionList = {
    isIncomplete: false,
    items: items.map((name) => {
      const shouldWrapStateNameInQuotes = languageId === LANGUAGE_IDS.YAML && isStateNameReservedYamlKeyword(name)
      const item = CompletionItem.create(name)
      item.commitCharacters = [',']

      item.kind = CompletionItemKind.Value

      const newText =
        (shouldAddLeadingSpace ? ' ' : '') +
        (shouldAddLeftQuote ? '"' : '') +
        (shouldWrapStateNameInQuotes ? "'" : '') +
        name +
        (shouldWrapStateNameInQuotes ? "'" : '') +
        (shouldAddRightQuote ? '"' : '') +
        (shoudlAddTrailingComma ? ',' : '')
      item.textEdit = TextEdit.replace(replaceRange, newText)
      item.filterText = name

      return item
    }),
  }

  return list
}