How to make an auto text suggestion system?
snippet in lua

How to make an auto text suggestion system?

user7885

function suggest(input, source, radius)
   local result = {}
   local min_distance = radius or math.huge

   for _, command in ipairs(source) do
      local current_distance = distance(input, command)

      if current_distance < min_distance then
         min_distance = current_distance
         result = {command}
      elseif current_distance == min_distance then
         table.insert(result, command)
      end
   end

   return result
end