-- SPDX-FileCopyrightText: © 2026 Vladimir Zorin -- SPDX-License-Identifier: LicenseRef-OWL-1.0-or-later -- Licensed under OWL v1.0+. See LICENSE. local std = require("std") local cu = require("shell.completion.utils") local MAX_KEYS = 5000 local update = function(self, ft_keyspace) local keys = {} if ft_keyspace then local count = 0 for doc_id in ft_keyspace:scan() do keys[#keys + 1] = doc_id count = count + 1 if count >= MAX_KEYS then break end end table.sort(keys) end self.__state.keys = keys end local search = function(self, prefix) return cu.match_prefix(self.__state.keys, prefix or "", { suffix = " ", sort = false }) end local new = function(config) local source = { cfg = {}, __state = { keys = {}, }, update = update, search = search, } if config then std.tbl.merge(source.cfg, config) end return source end return { new = new }