function getCompletionList()

in src/completion/completeVariables.ts [19:52]


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

  const list: CompletionList = {
    isIncomplete: false,
    items: items.map((name) => {
      const item = CompletionItem.create(name)
      item.commitCharacters = [',']

      item.kind = CompletionItemKind.Variable
      const completeVal = (prefix ? `${VARIABLE_PREFIX}${prefix}.` : '') + name

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

      return item
    }),
  }

  return list
}