{"repo_name": "colorful-menu.nvim", "file_name": "/colorful-menu.nvim/lua/colorful-menu/languages/cs.lua", "inference_info": {"prefix_code": "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\n", "suffix_code": "\n\nreturn M\n", "middle_code": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/colorful-menu.nvim/lua/colorful-menu/languages/typescript.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.ts_server(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n local kind = completion_item.kind\n -- Combine label + detail for final display\n local text = (detail and config.ls.ts_ls.extra_info_hl ~= false) and (label .. \" \" .. detail) or label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if detail and config.ls.ts_ls.extra_info_hl ~= false then\n local extra_info_hl = config.ls.ts_ls.extra_info_hl\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #label + 1 + #detail },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\n-- see https://github.com/zed-industries/zed/pull/13043\n-- Untested.\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.vtsls(completion_item, ls)\n local function one_line(s)\n s = s:gsub(\" \", \"\")\n s = s:gsub(\"\\n\", \" \")\n return s\n end\n\n local label = completion_item.label\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local detail = completion_item.detail\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if config.ls.vtsls.extra_info_hl ~= false then\n if description then\n text = label .. \" \" .. one_line(description)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n elseif detail then\n text = label .. \" \" .. one_line(detail)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/cpp.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \"\"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal function path_align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _clangd(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.detail\n local labelDetails = completion_item.labelDetails\n\n -- If no kind, just fallback to highlighting the cleaned-up label\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Constants or Variables with detail => \"detail label\", highlight entire text\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {int x;std::unique_ptr x;}\n -- | |\n -- @variable |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ int %s x;}\", text)\n return utils.highlight_range(source, ls, 16, 16 + #text)\n\n -- Functions or Methods with detail => \"detail label\", might find '('\n elseif kind == Kind.Field and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {f->x;std::unique_ptr x;}\n -- | |\n -- @field |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ f->%s x;}\", text)\n return utils.highlight_range(source, ls, 15, 15 + #text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = \"\"\n if labelDetails and labelDetails.detail then\n signature = labelDetails.detail\n end\n local text = string.format(\n \"void %s%s;%s%s x;\",\n label,\n signature,\n align_spaces(label .. signature .. \";\", detail),\n detail\n )\n return utils.highlight_range(text, ls, 5, #text - 3)\n --\n else\n local highlight_name = nil\n local lang = vim.bo.filetype == \"c\" and \"c\" or \"cpp\"\n if kind == Kind.Struct or kind == Kind.Interface then\n highlight_name = \"@type\"\n elseif kind == Kind.Class then\n highlight_name = utils.hl_exist_or(\"@lsp.type.class\", \"@variant\", lang)\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@variant\", lang)\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n -- If we found a special highlight name, highlight the portion before '('\n if highlight_name then\n local paren_index = string.find(label, \"%(\", 1, true)\n local end_index = paren_index and (paren_index - 1) or #label\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { vim.startswith(label, \"•\") and 3 or 0, end_index },\n },\n },\n }\n end\n end\n\n return {\n text = label,\n highlights = {},\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.clangd(completion_item, ls)\n local vim_item = _clangd(completion_item, ls)\n local max_width = require(\"colorful-menu.utils\").max_width()\n if vim_item.text ~= nil then\n if vim.startswith(vim_item.text, \"•\") then\n table.insert(vim_item.highlights, 1, {\n config.ls.clangd.import_dot_hl,\n range = { 0, 3 },\n })\n end\n vim_item.text = vim_item.text:gsub(\";\", \" \")\n -- If it is already overflow, just return.\n if max_width and max_width > 0 then\n local display_width = vim.fn.strdisplaywidth(vim_item.text)\n if display_width >= max_width then\n return vim_item\n end\n end\n\n -- Append path.\n local document = completion_item.documentation\n if document and document.value and vim.startswith(document.value, \"From \") then\n local len = #vim_item.text\n local include_path = vim.trim(vim.split(document.value:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1])\n :sub(6, #document.value)\n if include_path:sub(1, 1) == \"`\" and include_path:sub(#include_path, #include_path) == \"`\" then\n include_path = include_path:sub(2, #include_path - 1)\n end\n local spaces = path_align_spaces(vim_item.text, include_path)\n vim_item.text = string.gsub(vim_item.text .. spaces .. include_path, \"\\n\", \" \")\n table.insert(vim_item.highlights, {\n config.ls.clangd.extra_info_hl,\n range = { len + #spaces, #vim_item.text },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/lua.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.lua_ls(completion_item, ls)\n local vim_item = _lua_compute_completion_highlights(completion_item, ls)\n if vim_item.text ~= nil then\n local s, e = string.find(vim_item.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls.lua_ls.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/rust.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal insertTextFormat = require(\"colorful-menu\").insertTextFormat\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal cashed_self_hl = nil\n---@return CMHighlightRange[]\nlocal function iter_chain()\n if cashed_self_hl == nil then\n local source = \"fn iter(){}\"\n local hl = utils.highlight_range(source, \"rust-analyzer\", 3, #source - 2)\n cashed_self_hl = hl.highlights\n end\n return cashed_self_hl\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _rust_analyzer(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local function_signature = completion_item.labelDetails and completion_item.labelDetails.description\n or completion_item.detail\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(completion_item.label, ls, 0, #completion_item.label)\n end\n\n if kind == Kind.Field and detail then\n local name = completion_item.label\n local text = string.format(\"%s:%s%s\", name, align_spaces(name .. \" \", detail), detail)\n local source = string.format(\"struct S { %s }\", text)\n local hl = utils.highlight_range(source, ls, 11, 11 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif\n completion_item.insertTextFormat == insertTextFormat.Snippet\n and (label:find(\"::\", nil, true) ~= nil or label == \"Some(…)\" or label == \"None\" or label == \"Ok(…)\" or label == \"Err(…)\")\n and label:sub(1, 1) >= \"A\"\n and label:sub(1, 1) <= \"Z\"\n then\n local source = string.format(\"match s { %s }\", label)\n return utils.highlight_range(source, ls, 10, 10 + #label)\n elseif\n (kind == Kind.Constant or kind == Kind.Variable)\n and detail\n and completion_item.insertTextFormat ~= insertTextFormat.Snippet\n then\n local name = completion_item.label\n local text = string.format(\n \"%s:%s%s\",\n name,\n align_spaces(name .. \" \", completion_item.detail),\n completion_item.detail or detail\n )\n local source = string.format(\"let %s = ();\", text)\n local hl = utils.highlight_range(source, ls, 4, 4 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif (kind == Kind.EnumMember) and detail then\n local source = string.format(\"enum S { %s }\", detail)\n return utils.highlight_range(source, ls, 9, 9 + #detail)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local pattern = \"%((.-)%)\"\n\n local ignored = nil\n if label:match(\"^iter%(%)%..+\") ~= nil then\n ignored = \"iter().\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n if label:match(\"^self%..+\") ~= nil then\n ignored = \"self.\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n local function adjust(hl)\n if ignored == \"self.\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored)\n elseif ignored == \"iter().\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored, nil, iter_chain())\n end\n end\n\n local result = string.match(label, pattern)\n if not result then\n label = label .. \"()\"\n end\n local regex_pattern = \"%b()\"\n local prefix, suffix = string.match(function_signature or \"\", \"^(.*fn)(.*)$\")\n if prefix ~= nil and suffix ~= nil then\n local start_pos = string.find(suffix, \"(\", nil, true)\n if start_pos then\n suffix = suffix:sub(start_pos, #suffix)\n end\n\n if\n config.ls[\"rust-analyzer\"].preserve_type_when_truncate\n and config.ls[\"rust-analyzer\"].align_type_to_right\n then\n local params, type = string.match(suffix, \"(%b()) %-> (.*)\")\n if params == nil and type == nil then\n params = suffix\n type = \"\"\n end\n local call, num_subs = string.gsub(label, regex_pattern, params, 1)\n if num_subs == 0 then\n call = completion_item.label\n end\n local source = string.format(\n \"%s %s->%s%s{}\",\n prefix,\n call,\n align_spaces(call .. \" \", ignored ~= nil and type .. ignored or type),\n type or \"\"\n )\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 2)\n hl.text = hl.text:sub(1, #call) .. \" \" .. hl.text:sub(#call + 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n else\n local call, num_subs = string.gsub(label, regex_pattern, suffix, 1)\n if num_subs == 0 then\n call = label\n end\n local source = string.format(\"%s %s {}\", prefix, call)\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n end\n else\n -- Check if the detail starts with \"macro_rules! \"\n if completion_item.detail and vim.startswith(completion_item.detail, \"macro\") then\n local source = completion_item.label\n return utils.highlight_range(source, ls, 0, #source)\n else\n -- simd_swizzle!()\n return {\n text = completion_item.label,\n highlights = {\n {\n config.fallback_highlight,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Struct then\n highlight_name = \"@type\"\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", \"rust\")\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@constant\", \"rust\")\n elseif kind == Kind.Interface then\n highlight_name = utils.hl_exist_or(\"@lsp.type.interface\", \"@type\", \"rust\")\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n if detail then\n detail = vim.trim(detail)\n if vim.startswith(detail, \"(\") then\n local space = align_spaces(completion_item.label, detail)\n return {\n text = completion_item.label .. space .. detail,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { #completion_item.label + #space, #completion_item.label + #space + #detail },\n },\n },\n }\n end\n end\n\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.rust_analyzer(completion_item, ls)\n local vim_item = _rust_analyzer(completion_item, ls)\n if vim_item.text ~= nil then\n for _, match in ipairs({ \"%(use .-%)\", \"%(as .-%)\", \"%(alias .-%)\" }) do\n local s, e = string.find(vim_item.text, match)\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { s - 1, e },\n })\n end\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/zig.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.zls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.zls(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n or (completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail)\n if detail ~= nil then\n detail = vim.split(detail, \"\\n\")[1]\n end\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable or kind == Kind.Struct or kind == Kind.Enum) and detail then\n if detail == \"type\" then\n local source = string.format(\"fn(s: %s)\", label)\n return utils.highlight_range(source, ls, 6, 6 + #label)\n else\n local text = string.format(\"%s:%s%s\", label, align_spaces(label, detail .. \" \"), detail)\n local source = string.format(\"fn(%s)\", text)\n local hl = utils.highlight_range(source, ls, 3, 3 + #text)\n for _, highlight in ipairs(hl.highlights) do\n if vim.startswith(highlight[1], \"@variable.parameter\") then\n highlight[1] = highlight[1]:gsub(\"%.parameter\", \"\")\n end\n end\n if config.ls.zls.align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #label) .. \" \" .. hl.text:sub(#label + 2, #text)\n return hl\n end\n --\n elseif (kind == Kind.Field or kind == Kind.EnumMember) and detail then\n -- For some reason `const x = struct { name: *Foo }` can't get the type color for Foo.\n -- Here is the trick:\n -- xfn(foo: *Foo)\n -- x *Foo\n local source = string.format(\"%sfn(foo:%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(\n source:sub(#label + 1),\n ls,\n config.ls.zls.align_type_to_right and 7 or 6,\n #source:sub(#label + 1) - 1\n )\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n )\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n if detail:sub(1, 2) == \"fn\" then\n local ret_type = vim.split(\n (vim.tbl_get(completion_item, \"labelDetails\", \"description\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"),\n \"\\n\"\n )[1]\n local params =\n vim.split((vim.tbl_get(completion_item, \"labelDetails\", \"detail\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n local text, source\n if ret_type ~= \"\" and params ~= \"\" and config.ls.zls.align_type_to_right then\n text = string.format(\"%s%s%s%s\", label, params, align_spaces(label .. params, ret_type), ret_type)\n source = string.format(\"fn %s {}\", text)\n else\n local signature = detail:sub(4)\n text = string.format(\"%s%s\", label, signature)\n source = string.format(\"fn %s {}\", text)\n end\n return utils.highlight_range(source, ls, 3, 3 + #text)\n elseif detail:sub(1, 1) == \"@\" then\n return utils.highlight_range(detail, ls, 0, #detail)\n else\n return {\n text = completion_item.label,\n highlights = {\n {\n \"@function\",\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Field then\n highlight_name = utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/php.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.intelephense(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local kind = completion_item.kind\n\n if (kind == Kind.Function or kind == Kind.Method) and detail and #detail > 0 then\n local signature = detail:sub(#label + 1)\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s 0 then\n detail = string.gsub(detail, \".*\\\\(.)\", \"%1\")\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s \n -- assign.Analyzer \"golang.org/x/tools/go/analysis/passes/assign\"\n local path = detail:match(\".*%(from(.*)%)\")\n if path then\n local highlight_name = utils.hl_by_kind(kind)\n local spaces = align_spaces(label, path)\n local text = label .. align_spaces(label, path) .. path\n return {\n text = text,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n {\n \"@string\",\n range = { #label + #spaces, #text },\n },\n },\n }\n end\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Gopls returns nested fields and methods as completions.\n -- To syntax highlight these, combine their final component\n -- with their detail.\n local name_offset = label:reverse():find(\"%.\") or 0\n if name_offset > 0 then\n name_offset = #label - name_offset + 2\n else\n name_offset = 0\n end\n\n if kind == Kind.Module and detail then\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"import %s\", text)\n return utils.highlight_range(source, ls, 7, 7 + #text)\n --\n elseif (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local var_part = text:sub(name_offset)\n local source = string.format(\"var %s\", var_part)\n local item = utils.highlight_range(source, ls, 4, 4 + #var_part)\n if kind == Kind.Constant then\n if #item.highlights >= 1 then\n item.highlights[1][1] = utils.hl_exist_or(\"@constant\", \"@variable\", \"go\")\n end\n end\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Struct then\n detail = \"struct{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s struct {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Interface then\n detail = \"interface{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s interface {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Field and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local source = string.format(\"type T struct { %s }\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 16, 16 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = vim.trim(detail)\n if detail:sub(1, 4) == \"func\" then\n signature = detail:sub(5)\n end\n\n local text = string.format(\"%s%s\", label, signature)\n if signature ~= \"()\" then\n local params, returns = parse_signature(signature)\n text = label .. params .. align_spaces(label, params .. returns) .. returns\n end\n\n local source = string.format(\"func %s {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n else\n -- Handle other kinds\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/utils.lua", "local Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal query_cache = {}\n\n---@param str string\n---@param ls string\n---@return CMHighlights\nlocal function compute_highlights(str, ls)\n local highlights = {}\n\n local lang = vim.treesitter.language.get_lang(vim.bo.filetype)\n if not lang then\n return {}\n end\n\n local query, ok\n if query_cache[ls] == nil then\n ok, query = pcall(vim.treesitter.query.get, lang, \"highlights\")\n if not ok then\n return {}\n end\n query_cache[ls] = query\n else\n query = query_cache[ls]\n end\n\n ---@diagnostic disable-next-line: redefined-local\n local ok, parser = pcall(vim.treesitter.get_string_parser, str, lang)\n if not ok then\n return {}\n end\n\n if not parser then\n vim.notify(string.format(\"No Tree-sitter parser found for filetype: %s\", lang), vim.log.levels.WARN)\n return highlights\n end\n\n -- Parse the string\n local tree = parser:parse(true)[1]\n if not tree then\n vim.notify(\"Failed to parse the string with Tree-sitter.\", vim.log.levels.ERROR)\n return {}\n end\n\n local root = tree:root()\n\n if not query then\n return {}\n end\n\n -- Iterate over all captures in the query\n for id, node in query:iter_captures(root, str, 0, -1) do\n local name = \"@\" .. query.captures[id] .. \".\" .. lang\n local range = { node:range() }\n local _, nscol, _, necol = range[1], range[2], range[3], range[4]\n table.insert(highlights, {\n hl_group = name,\n range = { nscol, necol },\n })\n end\n\n return highlights\nend\n\n-- `left` is inclusive and `right` is exclusive (also zero indexed), to better fit\n-- `nvim_buf_set_extmark` semantic, so `M.highlight_range(text, ft, 0, #text)` is the entire range.\n--\n---@param text string\n---@param ls string\n---@param left integer\n---@param right integer\n---@return CMHighlights\nfunction M.highlight_range(text, ls, left, right)\n local highlights = {}\n local full_hl = compute_highlights(text, ls)\n\n for _, hl in ipairs(full_hl) do\n local s, e = hl.range[1], hl.range[2]\n if e < left then\n goto continue\n end\n if s > right or e > right + 1 then\n break\n end\n\n table.insert(highlights, {\n hl.hl_group,\n range = { hl.range[1] - left, hl.range[2] - left },\n text = text:sub(s + 1, e),\n })\n ::continue::\n end\n\n return {\n text = text:sub(left + 1, right),\n highlights = highlights,\n }\nend\n\n-- Shift a highlight range right by name_offset,\n-- insert a color with fallback_hl for label with range (0, name_offset).\n---@param item CMHighlights\n---@param name_offset integer\n---@param label string\n---@param fallback_hl string?\n---@param custom_hl CMHighlightRange[]?\n---@return CMHighlights\nfunction M.adjust_range(item, name_offset, label, fallback_hl, custom_hl)\n if name_offset == 0 then\n return item\n end\n name_offset = name_offset - 1\n for _, highlight in ipairs(item.highlights) do\n highlight.range[1] = highlight.range[1] + name_offset\n highlight.range[2] = highlight.range[2] + name_offset\n end\n item.text = label:sub(1, name_offset) .. item.text\n if custom_hl then\n for _, hl in ipairs(custom_hl) do\n table.insert(item.highlights, hl)\n end\n else\n table.insert(item.highlights, {\n fallback_hl or \"@variable\",\n range = { 0, name_offset },\n })\n end\n return item\nend\n\n---@param hl_group string\n---@param fallback string\n---@param lang? string\nfunction M.hl_exist_or(hl_group, fallback, lang)\n local f = function()\n local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = hl_group })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return hl_group\n end\n return fallback\n end\n\n local ok, hl\n if lang ~= nil then\n local lang_hl = hl_group .. \".\" .. lang\n ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = lang_hl })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return lang_hl\n else\n return f()\n end\n else\n return f()\n end\nend\n\n---@param kind? integer\n---@param lang? string\n---@return string\nfunction M.hl_by_kind(kind, lang)\n local highlight_name\n if kind == Kind.Method then\n highlight_name = M.hl_exist_or(\"@lsp.type.method\", \"@function\", lang)\n elseif kind == Kind.Function then\n highlight_name = M.hl_exist_or(\"@lsp.type.function\", \"@function\", lang)\n elseif kind == Kind.Constructor then\n highlight_name = \"@constructor\"\n elseif kind == Kind.Variable then\n highlight_name = M.hl_exist_or(\"@lsp.type.variable\", \"@variable\", lang)\n elseif kind == Kind.Field then\n highlight_name = M.hl_exist_or(\"@lsp.type.field\", \"@field\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Property then\n highlight_name = M.hl_exist_or(\"@lsp.type.property\", \"@property\", lang)\n elseif kind == Kind.Module then\n highlight_name = M.hl_exist_or(\"@lsp.type.namespace\", \"@namespace\", lang)\n elseif kind == Kind.Class then\n highlight_name = M.hl_exist_or(\"@lsp.type.class\", \"@type\", lang)\n elseif kind == Kind.Struct then\n highlight_name = M.hl_exist_or(\"@lsp.type.struct\", \"@type\", lang)\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return highlight_name\nend\n\n---@param item CMHighlights\n---@param rang {left:integer, right:integer}\nlocal function remove_color_in_range(item, rang)\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local r = hl.range\n if r[1] > rang.left and r[1] < rang.right then\n table.remove(item.highlights, i)\n elseif r[1] <= rang.left and r[2] > rang.left then\n r[2] = rang.left\n end\n end\nend\n\nlocal function left_brace_one_more_than_right_brace(s)\n local left = 0\n local right = 0\n for i = 1, #s do\n local char = s:sub(i, i)\n if char == \"(\" then\n left = left + 1\n elseif char == \")\" then\n right = right + 1\n end\n end\n return left == right + 1\nend\n\n---@param item CMHighlights\n---@param max_width integer\n---@param direct boolean -- without type info\nlocal function cut_label(item, max_width, direct)\n if vim.fn.strdisplaywidth(item.text) <= max_width then\n return\n end\n local text = item.text\n --- Given\n --- self.foo(asdasd)\n --- self.foo(asdasd…\n --- self.foo(asdas…)\n if direct and left_brace_one_more_than_right_brace(vim.fn.strcharpart(text, 0, max_width)) then\n local truncated = vim.fn.strcharpart(text, 0, max_width - 2) .. \"…)\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 4, truncated_width - 1 },\n })\n table.insert(item.highlights, {\n \"@punctuation.bracket\",\n range = { truncated_width - 1, truncated_width },\n })\n else\n local truncated = vim.fn.strcharpart(text, 0, max_width - 1) .. \"…\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 3, truncated_width },\n })\n end\nend\n\n---@param item CMHighlights\n---@param offset integer\n---@param start integer\nlocal function shift_color_by(item, offset, start)\n for _, highlight in ipairs(item.highlights) do\n if highlight.range[1] > start then\n highlight.range[1] = highlight.range[1] - offset\n highlight.range[2] = highlight.range[2] - offset\n end\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param item CMHighlights\nfunction M.validate_newline(completion_item, item)\n if string.find(item.text, \"\\n\") ~= nil or string.find(item.text, \"\\r\") ~= nil then\n vim.notify_once(\n '[colorful-menu.nvim]: Completion \"'\n .. completion_item.label\n .. '\" has new line character, please open an issue',\n vim.log.levels.WARN\n )\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n nil,\n nil,\n require(\"colorful-menu\").config.ls.fallback_extra_info_hl\n )\n end\n return item\nend\n\n---@param item CMHighlights\n---@param ls string\n---@return CMHighlights?\nfunction M.apply_post_processing(completion_item, item, ls)\n -- if the user override or fallback logic didn't produce a table, bail\n if type(item) ~= \"table\" or not item.text then\n return item\n end\n\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local range = hl.range\n if range[2] < 0 then\n table.remove(item.highlights, i)\n elseif range[1] < 0 then\n range[1] = 0\n end\n end\n\n local max_width = require(\"colorful-menu.utils\").max_width()\n if not (max_width and max_width > 0) then\n return\n end\n\n local label = completion_item.label\n local display_width = vim.fn.strdisplaywidth(item.text)\n if display_width > (item.text:find(\"\\7\") ~= nil and (max_width + 1) or max_width) then\n local long_label, type = item.text:match(\"(.*)\\7%s*(.*)\")\n local is_func = completion_item.kind == Kind.Function or completion_item.kind == Kind.Method\n if\n item.text == label\n or type == nil\n or #type == 0\n or not is_func\n or not config.ls[ls]\n or not config.ls[ls].preserve_type_when_truncate\n then\n item.text = item.text:gsub(\"\\7\", \" \")\n cut_label(item, max_width, is_func)\n return\n end\n\n local _, le = item.text:find(\"\\7\")\n local ts = item.text:find(type, le, true)\n local space_between = ts - le\n item.text = item.text:gsub(\"\\7\", \" \")\n\n -- Now we need to deal with color shifting stuff.\n -- Foo(a string b string) \"some random stuff\"\n -- | | | |\n -- long_label_width type_width\n --\n -- | short | | type_width |\n -- Foo(a st… \"some random stuff\"\n -- | max_width |\n local long_label_width, type_width = #long_label, #type\n local short_label_width = math.max(max_width - type_width - 2 - space_between, #label)\n local should_cut_all = short_label_width == #label\n if should_cut_all then\n remove_color_in_range(item, { left = short_label_width, right = long_label_width })\n local pretty_end = \"(…)\"\n if label:sub(short_label_width, short_label_width) == \")\" then\n pretty_end = \"…)\"\n end\n shift_color_by(item, long_label_width - short_label_width - string.len(pretty_end), long_label_width)\n item.text = item.text:sub(1, short_label_width) .. pretty_end .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = {\n short_label_width + (pretty_end == \"(…)\" and 1 or 0),\n short_label_width + (pretty_end == \"(…)\" and string.len(\"…)\") or string.len(\"…\")),\n },\n })\n cut_label(item, max_width, false)\n else\n -- Caculate display_width and real byte diff.\n local diff = short_label_width - vim.fn.strdisplaywidth(item.text:sub(1, short_label_width))\n -- We increase the cut threshold if display_width is lower than\n -- byte count, otherwise the hole is not enough.\n short_label_width = short_label_width + diff\n local ascii_pos = short_label_width\n for i = short_label_width, 1, -1 do\n if item.text:sub(i, i):match(\"[a-zA-Z(]\") ~= nil then\n ascii_pos = i\n break\n end\n end\n remove_color_in_range(item, { left = ascii_pos, right = long_label_width })\n shift_color_by(item, long_label_width - short_label_width - string.len(\"…)\"), long_label_width)\n item.text = item.text:sub(1, ascii_pos)\n .. \"…)\"\n .. string.rep(\" \", short_label_width - ascii_pos)\n .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = { ascii_pos, ascii_pos + string.len(\"…)\") - 1 },\n })\n end\n else\n item.text = item.text:gsub(\"\\7\", \" \")\n end\nend\n\nfunction M.align_spaces_bell(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \"\\7 \"\n end\n return \"\\7\" .. string.rep(\" \", blank - 1)\nend\n\nfunction M.align_spaces(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \" \"\n end\n return string.rep(\" \", blank)\nend\n\nfunction M.max_width()\n local max_width = config.max_width\n if max_width < 1 and max_width > 0 then\n max_width = math.floor(max_width * vim.api.nvim_win_get_width(0))\n end\n return max_width\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/dart.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.dartls(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail ~= nil and detail:find(\"Auto\") ~= nil then\n detail = detail:gsub(\"Auto import.*\\n\\n\", \"\")\n detail = vim.split(detail:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n -- x int\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n -- var x int x\n local source = string.format(\"var %s x\", text)\n return utils.highlight_range(source, ls, 4, 4 + #text)\n --\n elseif (kind == Kind.Field or kind == Kind.Property) and detail then\n -- Here is the trick same as zls:\n -- xvoid( *Foo)\n -- x *Foo\n local source = string.format(\"%svoid(%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(source:sub(#label + 1), ls, 5, #source:sub(#label + 1) - 1)\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"dart\")\n )\n --\n elseif (kind == Kind.Function or kind == Kind.Method or kind == Kind.Constructor) and detail then\n -- elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n -- label: fetchData(..)\n -- detail: (int a, int b) -> Future\n -- fetchData(int a, int b);(Future s)\n local params = string.match(detail or \"\", \"^(%b())\")\n local type = string.match(detail or \"\", \"→ (.*)\")\n if params ~= nil then\n label = label:gsub(\"%b()$\", \"\") .. params\n end\n if type ~= nil and kind ~= Kind.Constructor then\n local text = string.format(\"%s%s;(%s)\", label, align_spaces(label, type):sub(3), type)\n local comma_pos = #text - #type - 3\n local ranges = utils.highlight_range(text, ls, 0, #text - 1)\n ranges.text = ranges.text:sub(1, comma_pos) .. \" \" .. ranges.text:sub(comma_pos + 3, #ranges.text)\n return ranges\n end\n return utils.highlight_range(label, ls, 0, #label)\n --\n else\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n detail,\n \"dart\",\n config.ls[ls].extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/init.lua", "local M = {}\n\nM.insertTextFormat = { PlainText = 1, Snippet = 2 }\n-- stylua: ignore\nM.Kind = { Text = 1, Method = 2, Function = 3, Constructor = 4, Field = 5, Variable = 6, Class = 7, Interface = 8, Module = 9, Property = 10, Unit = 11, Value = 12, Enum = 13, Keyword = 14, Snippet = 15, Color = 16, File = 17, Reference = 18, Folder = 19, EnumMember = 20, Constant = 21, Struct = 22, Event = 23, Operator = 24, TypeParameter = 25 }\n\n---@alias CMHighlightRange {hl_group: string, range: integer[], text: string}\n---\n---@class CMHighlights\n---@field text string\n---@field highlights CMHighlightRange[]\n\n---@class ColorfulMenuConfig\nM.config = {\n ls = {\n lua_ls = {\n -- Maybe you want to dim arguments a bit.\n arguments_hl = \"@comment\",\n },\n gopls = {\n -- When true, label for field and variable will format like \"foo: Foo\"\n -- instead of go's original syntax \"foo Foo\".\n add_colon_before_type = false,\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n ts_ls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n vtsls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n zls = {\n align_type_to_right = true,\n },\n [\"rust-analyzer\"] = {\n -- Such as (as Iterator), (use std::io).\n extra_info_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n clangd = {\n -- Such as \"\".\n extra_info_hl = \"@comment\",\n -- the hl of leading dot of \"•std::filesystem::permissions(..)\"\n import_dot_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n roslyn = {\n extra_info_hl = \"@comment\",\n },\n -- The same applies to pyright/pylance\n basedpyright = {\n extra_info_hl = \"@comment\",\n },\n pylsp = {\n extra_info_hl = \"@comment\",\n -- Dim the function argument area, which is the main\n -- difference with pyright.\n arguments_hl = \"@comment\",\n },\n dartls = {\n extra_info_hl = \"@comment\",\n },\n fallback = true,\n fallback_extra_info_hl = \"@comment\",\n },\n fallback_highlight = \"@variable\",\n max_width = 60,\n}\n\nlocal hl_cache = {}\nlocal hl_cache_size = 0\n-- about 30M max memory usage.\nlocal MAX_HL_CACHE_SIZE = 10000\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return string\nlocal function cache_key(completion_item, ls)\n return string.format(\n \"%s!%s!%s!%s!%s%s\",\n completion_item.label or \"\",\n completion_item.detail or \"\",\n completion_item.labelDetails\n and (completion_item.labelDetails.detail or \"\") .. (completion_item.labelDetails.description or \"\")\n or \"\",\n completion_item.kind and tostring(completion_item.kind) or \"\",\n ls,\n require(\"colorful-menu.utils\").max_width()\n )\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nlocal function _highlights(completion_item, ls)\n if completion_item == nil or ls == nil or ls == \"\" or vim.b.ts_highlight == false then\n return nil\n end\n\n local item\n\n local key = cache_key(completion_item, ls)\n if hl_cache[key] ~= nil then\n return hl_cache[key]\n end\n\n if ls == \"gopls\" then\n item = require(\"colorful-menu.languages.go\").gopls(completion_item, ls)\n --\n elseif ls == \"rust-analyzer\" or ls == \"rust_analyzer\" then\n item = require(\"colorful-menu.languages.rust\").rust_analyzer(completion_item, ls)\n ls = \"rust-analyzer\"\n --\n elseif ls == \"lua_ls\" then\n item = require(\"colorful-menu.languages.lua\").lua_ls(completion_item, ls)\n --\n elseif ls == \"clangd\" then\n item = require(\"colorful-menu.languages.cpp\").clangd(completion_item, ls)\n --\n elseif ls == \"typescript-language-server\" or ls == \"ts_ls\" or ls == \"tsserver\" or ls == \"typescript-tools\" then\n item = require(\"colorful-menu.languages.typescript\").ts_server(completion_item, ls)\n --\n elseif ls == \"vtsls\" then\n item = require(\"colorful-menu.languages.typescript\").vtsls(completion_item, ls)\n --\n elseif ls == \"zls\" then\n item = require(\"colorful-menu.languages.zig\").zls(completion_item, ls)\n --\n elseif ls == \"intelephense\" then\n item = require(\"colorful-menu.languages.php\").intelephense(completion_item, ls)\n --\n elseif ls == \"roslyn\" then\n item = require(\"colorful-menu.languages.cs\").roslyn(completion_item, ls)\n --\n elseif ls == \"dartls\" then\n item = require(\"colorful-menu.languages.dart\").dartls(completion_item, ls)\n --\n elseif ls == \"basedpyright\" or ls == \"pyright\" or ls == \"pylance\" or ls == \"pylsp\" then\n item = require(\"colorful-menu.languages.python\").py(completion_item, ls)\n --\n else\n -- No languages detected so check if we should highlight with default or not\n if not M.config.ls.fallback then\n return nil\n end\n item = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail,\n nil,\n M.config.ls.fallback_extra_info_hl\n )\n end\n\n if item then\n item = require(\"colorful-menu.utils\").validate_newline(completion_item, item)\n require(\"colorful-menu.utils\").apply_post_processing(completion_item, item, ls)\n end\n\n hl_cache_size = hl_cache_size + 1\n if hl_cache_size > MAX_HL_CACHE_SIZE then\n hl_cache_size = 0\n hl_cache = {}\n end\n hl_cache[key] = item\n\n return item\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param entry cmp.Entry\nfunction M.cmp_highlights(entry)\n local client = vim.tbl_get(entry, \"source\", \"source\", \"client\") -- For example `lua_ls` etc\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n return _highlights(entry:get_completion_item(), client.name)\n end\n return nil\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_text(ctx)\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n return highlights_info.label\n else\n ---@diagnostic disable-next-line: undefined-field\n return ctx.label\n end\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_highlight(ctx)\n local highlights = {}\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n highlights = highlights_info.highlights\n end\n ---@diagnostic disable-next-line: undefined-field\n for _, idx in ipairs(ctx.label_matched_indices) do\n table.insert(highlights, { idx, idx + 1, group = \"BlinkCmpLabelMatch\" })\n end\n return highlights\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_highlights(ctx)\n ---@diagnostic disable-next-line: undefined-field\n local client = vim.lsp.get_client_by_id(ctx.item.client_id)\n local highlights = {}\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n local highlights_info = _highlights(ctx.item, client.name)\n if highlights_info ~= nil then\n for _, info in ipairs(highlights_info.highlights or {}) do\n table.insert(highlights, {\n info.range[1],\n info.range[2],\n ---@diagnostic disable-next-line: undefined-field\n group = ctx.deprecated and \"BlinkCmpLabelDeprecated\" or info[1],\n })\n end\n else\n return nil\n end\n return { label = highlights_info.text, highlights = highlights }\n end\n return nil\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nfunction M.highlights(completion_item, ls)\n if ls == vim.bo.filetype then\n vim.notify_once(\n \"colorful-menu.nvim: Integration with nvim-cmp or blink.cmp has been simplified, and legacy per-filetype options is also deprecated\"\n .. \" to prefer per-language-server options, please see README\",\n vim.log.levels.WARN\n )\n return nil\n end\n\n return _highlights(completion_item, ls)\nend\n\n---@param opts ColorfulMenuConfig\nfunction M.setup(opts)\n opts = opts or {}\n M.config = vim.tbl_deep_extend(\"force\", M.config, opts)\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/default.lua", "local utils = require(\"colorful-menu.utils\")\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param detail? string\n---@param lang? string\n---@param extra_info_hl? string\n---@return CMHighlights\nfunction M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n -- If there are any information, append it\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/python.lua", "local config = require(\"colorful-menu\").config\nlocal Kind = require(\"colorful-menu\").Kind\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@return CMHighlights\nlocal function pylsp(completion_item)\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n local hls = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.pylsp.extra_info_hl\n )\n if hls.text ~= nil and (completion_item.kind == Kind.Function or completion_item.kind == Kind.Method) then\n local s, e = string.find(hls.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(hls.highlights, {\n config.ls.pylsp.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return hls\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.py(completion_item, ls)\n if ls == \"pylsp\" then\n return pylsp(completion_item)\n else\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.basedpyright.extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/repro_cmp.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n {\n \"hrsh7th/nvim-cmp\",\n lazy = false,\n dependencies = {\n \"hrsh7th/cmp-nvim-lsp\",\n {\n \"xzbdmw/colorful-menu.nvim\",\n config = function()\n require(\"colorful-menu\").setup({})\n end,\n },\n },\n config = function(_, opts)\n local cmp = require(\"cmp\")\n require(\"cmp\").setup({\n mapping = cmp.mapping.preset.insert({\n [\"\"] = cmp.mapping(function(fallback)\n if cmp.visible() then\n cmp.confirm()\n end\n end, { \"i\" }),\n }),\n completion = {\n completeopt = \"menu,menuone,noinsert\",\n },\n formatting = {\n format = function(entry, vim_item)\n local highlights_info = require(\"colorful-menu\").cmp_highlights(entry)\n if highlights_info ~= nil then\n vim_item.abbr_hl_group = highlights_info.highlights\n vim_item.abbr = highlights_info.text\n end\n return vim_item\n end,\n },\n sources = require(\"cmp\").config.sources({\n { name = \"nvim_lsp\" },\n }, {}),\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n capabilities = require(\"cmp_nvim_lsp\").default_capabilities(),\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n workspace = {\n library = {\n \"/usr/local/share/nvim/runtime\",\n },\n },\n completion = {\n callSnippet = \"Replace\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"], ["/colorful-menu.nvim/repro_blink.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n \"xzbdmw/colorful-menu.nvim\",\n {\n \"saghen/blink.cmp\",\n version = \"v0.*\",\n config = function()\n require(\"blink.cmp\").setup({\n completion = {\n menu = {\n draw = {\n -- We don't need label_description now because label and label_description are already\n -- conbined together in label by colorful-menu.nvim.\n columns = { { \"kind_icon\" }, { \"label\", gap = 1 } },\n components = {\n label = {\n text = require(\"colorful-menu\").blink_components_text,\n highlight = require(\"colorful-menu\").blink_components_highlight,\n },\n },\n },\n },\n },\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"]], "task_instance_info": {"created_time": "2025-08-21 00:42:04", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Map completion item types to syntax highlighting tokens and construct annotated text with corresponding highlight regions based on metadata attributes."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nfunction M.get_completion_kind_hl(completion_item, ls)\n local kind_name = Kind.get_completion_kind(completion_item.kind)\n local hl_name = config.hl_completion_kind[kind_name] or \"CMCompletionItemKindDefault\"\n \n return {\n fg = utils.get_hl(hl_name, \"fg\") or utils.get_hl(\"CMCompletionItemKindDefault\", \"fg\"),\n bg = utils.get_hl(hl_name, \"bg\") or utils.get_hl(\"CMCompletionItemKindDefault\", \"bg\")\n }\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-42-22"}, "editdistance_info": {"edit_distance": 10.356, "calculate_time": "2025-08-21 00:42:22", "true_code_clean": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "predict_code_clean": "function M.get_completion_kind_hl(completion_item, ls)\n local kind_name = Kind.get_completion_kind(completion_item.kind)\n local hl_name = config.hl_completion_kind[kind_name] or \"CMCompletionItemKindDefault\"\n return {\n fg = utils.get_hl(hl_name, \"fg\") or utils.get_hl(\"CMCompletionItemKindDefault\", \"fg\"),\n bg = utils.get_hl(hl_name, \"bg\") or utils.get_hl(\"CMCompletionItemKindDefault\", \"bg\")\n }\nend"}} {"repo_name": "colorful-menu.nvim", "file_name": "/colorful-menu.nvim/lua/colorful-menu/languages/default.lua", "inference_info": {"prefix_code": "local utils = require(\"colorful-menu.utils\")\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param detail? string\n---@param lang? string\n---@param extra_info_hl? string\n---@return CMHighlights\n", "suffix_code": "\n\nreturn M\n", "middle_code": "function M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/colorful-menu.nvim/lua/colorful-menu/languages/cpp.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \"\"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal function path_align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _clangd(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.detail\n local labelDetails = completion_item.labelDetails\n\n -- If no kind, just fallback to highlighting the cleaned-up label\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Constants or Variables with detail => \"detail label\", highlight entire text\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {int x;std::unique_ptr x;}\n -- | |\n -- @variable |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ int %s x;}\", text)\n return utils.highlight_range(source, ls, 16, 16 + #text)\n\n -- Functions or Methods with detail => \"detail label\", might find '('\n elseif kind == Kind.Field and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {f->x;std::unique_ptr x;}\n -- | |\n -- @field |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ f->%s x;}\", text)\n return utils.highlight_range(source, ls, 15, 15 + #text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = \"\"\n if labelDetails and labelDetails.detail then\n signature = labelDetails.detail\n end\n local text = string.format(\n \"void %s%s;%s%s x;\",\n label,\n signature,\n align_spaces(label .. signature .. \";\", detail),\n detail\n )\n return utils.highlight_range(text, ls, 5, #text - 3)\n --\n else\n local highlight_name = nil\n local lang = vim.bo.filetype == \"c\" and \"c\" or \"cpp\"\n if kind == Kind.Struct or kind == Kind.Interface then\n highlight_name = \"@type\"\n elseif kind == Kind.Class then\n highlight_name = utils.hl_exist_or(\"@lsp.type.class\", \"@variant\", lang)\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@variant\", lang)\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n -- If we found a special highlight name, highlight the portion before '('\n if highlight_name then\n local paren_index = string.find(label, \"%(\", 1, true)\n local end_index = paren_index and (paren_index - 1) or #label\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { vim.startswith(label, \"•\") and 3 or 0, end_index },\n },\n },\n }\n end\n end\n\n return {\n text = label,\n highlights = {},\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.clangd(completion_item, ls)\n local vim_item = _clangd(completion_item, ls)\n local max_width = require(\"colorful-menu.utils\").max_width()\n if vim_item.text ~= nil then\n if vim.startswith(vim_item.text, \"•\") then\n table.insert(vim_item.highlights, 1, {\n config.ls.clangd.import_dot_hl,\n range = { 0, 3 },\n })\n end\n vim_item.text = vim_item.text:gsub(\";\", \" \")\n -- If it is already overflow, just return.\n if max_width and max_width > 0 then\n local display_width = vim.fn.strdisplaywidth(vim_item.text)\n if display_width >= max_width then\n return vim_item\n end\n end\n\n -- Append path.\n local document = completion_item.documentation\n if document and document.value and vim.startswith(document.value, \"From \") then\n local len = #vim_item.text\n local include_path = vim.trim(vim.split(document.value:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1])\n :sub(6, #document.value)\n if include_path:sub(1, 1) == \"`\" and include_path:sub(#include_path, #include_path) == \"`\" then\n include_path = include_path:sub(2, #include_path - 1)\n end\n local spaces = path_align_spaces(vim_item.text, include_path)\n vim_item.text = string.gsub(vim_item.text .. spaces .. include_path, \"\\n\", \" \")\n table.insert(vim_item.highlights, {\n config.ls.clangd.extra_info_hl,\n range = { len + #spaces, #vim_item.text },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/utils.lua", "local Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal query_cache = {}\n\n---@param str string\n---@param ls string\n---@return CMHighlights\nlocal function compute_highlights(str, ls)\n local highlights = {}\n\n local lang = vim.treesitter.language.get_lang(vim.bo.filetype)\n if not lang then\n return {}\n end\n\n local query, ok\n if query_cache[ls] == nil then\n ok, query = pcall(vim.treesitter.query.get, lang, \"highlights\")\n if not ok then\n return {}\n end\n query_cache[ls] = query\n else\n query = query_cache[ls]\n end\n\n ---@diagnostic disable-next-line: redefined-local\n local ok, parser = pcall(vim.treesitter.get_string_parser, str, lang)\n if not ok then\n return {}\n end\n\n if not parser then\n vim.notify(string.format(\"No Tree-sitter parser found for filetype: %s\", lang), vim.log.levels.WARN)\n return highlights\n end\n\n -- Parse the string\n local tree = parser:parse(true)[1]\n if not tree then\n vim.notify(\"Failed to parse the string with Tree-sitter.\", vim.log.levels.ERROR)\n return {}\n end\n\n local root = tree:root()\n\n if not query then\n return {}\n end\n\n -- Iterate over all captures in the query\n for id, node in query:iter_captures(root, str, 0, -1) do\n local name = \"@\" .. query.captures[id] .. \".\" .. lang\n local range = { node:range() }\n local _, nscol, _, necol = range[1], range[2], range[3], range[4]\n table.insert(highlights, {\n hl_group = name,\n range = { nscol, necol },\n })\n end\n\n return highlights\nend\n\n-- `left` is inclusive and `right` is exclusive (also zero indexed), to better fit\n-- `nvim_buf_set_extmark` semantic, so `M.highlight_range(text, ft, 0, #text)` is the entire range.\n--\n---@param text string\n---@param ls string\n---@param left integer\n---@param right integer\n---@return CMHighlights\nfunction M.highlight_range(text, ls, left, right)\n local highlights = {}\n local full_hl = compute_highlights(text, ls)\n\n for _, hl in ipairs(full_hl) do\n local s, e = hl.range[1], hl.range[2]\n if e < left then\n goto continue\n end\n if s > right or e > right + 1 then\n break\n end\n\n table.insert(highlights, {\n hl.hl_group,\n range = { hl.range[1] - left, hl.range[2] - left },\n text = text:sub(s + 1, e),\n })\n ::continue::\n end\n\n return {\n text = text:sub(left + 1, right),\n highlights = highlights,\n }\nend\n\n-- Shift a highlight range right by name_offset,\n-- insert a color with fallback_hl for label with range (0, name_offset).\n---@param item CMHighlights\n---@param name_offset integer\n---@param label string\n---@param fallback_hl string?\n---@param custom_hl CMHighlightRange[]?\n---@return CMHighlights\nfunction M.adjust_range(item, name_offset, label, fallback_hl, custom_hl)\n if name_offset == 0 then\n return item\n end\n name_offset = name_offset - 1\n for _, highlight in ipairs(item.highlights) do\n highlight.range[1] = highlight.range[1] + name_offset\n highlight.range[2] = highlight.range[2] + name_offset\n end\n item.text = label:sub(1, name_offset) .. item.text\n if custom_hl then\n for _, hl in ipairs(custom_hl) do\n table.insert(item.highlights, hl)\n end\n else\n table.insert(item.highlights, {\n fallback_hl or \"@variable\",\n range = { 0, name_offset },\n })\n end\n return item\nend\n\n---@param hl_group string\n---@param fallback string\n---@param lang? string\nfunction M.hl_exist_or(hl_group, fallback, lang)\n local f = function()\n local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = hl_group })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return hl_group\n end\n return fallback\n end\n\n local ok, hl\n if lang ~= nil then\n local lang_hl = hl_group .. \".\" .. lang\n ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = lang_hl })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return lang_hl\n else\n return f()\n end\n else\n return f()\n end\nend\n\n---@param kind? integer\n---@param lang? string\n---@return string\nfunction M.hl_by_kind(kind, lang)\n local highlight_name\n if kind == Kind.Method then\n highlight_name = M.hl_exist_or(\"@lsp.type.method\", \"@function\", lang)\n elseif kind == Kind.Function then\n highlight_name = M.hl_exist_or(\"@lsp.type.function\", \"@function\", lang)\n elseif kind == Kind.Constructor then\n highlight_name = \"@constructor\"\n elseif kind == Kind.Variable then\n highlight_name = M.hl_exist_or(\"@lsp.type.variable\", \"@variable\", lang)\n elseif kind == Kind.Field then\n highlight_name = M.hl_exist_or(\"@lsp.type.field\", \"@field\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Property then\n highlight_name = M.hl_exist_or(\"@lsp.type.property\", \"@property\", lang)\n elseif kind == Kind.Module then\n highlight_name = M.hl_exist_or(\"@lsp.type.namespace\", \"@namespace\", lang)\n elseif kind == Kind.Class then\n highlight_name = M.hl_exist_or(\"@lsp.type.class\", \"@type\", lang)\n elseif kind == Kind.Struct then\n highlight_name = M.hl_exist_or(\"@lsp.type.struct\", \"@type\", lang)\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return highlight_name\nend\n\n---@param item CMHighlights\n---@param rang {left:integer, right:integer}\nlocal function remove_color_in_range(item, rang)\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local r = hl.range\n if r[1] > rang.left and r[1] < rang.right then\n table.remove(item.highlights, i)\n elseif r[1] <= rang.left and r[2] > rang.left then\n r[2] = rang.left\n end\n end\nend\n\nlocal function left_brace_one_more_than_right_brace(s)\n local left = 0\n local right = 0\n for i = 1, #s do\n local char = s:sub(i, i)\n if char == \"(\" then\n left = left + 1\n elseif char == \")\" then\n right = right + 1\n end\n end\n return left == right + 1\nend\n\n---@param item CMHighlights\n---@param max_width integer\n---@param direct boolean -- without type info\nlocal function cut_label(item, max_width, direct)\n if vim.fn.strdisplaywidth(item.text) <= max_width then\n return\n end\n local text = item.text\n --- Given\n --- self.foo(asdasd)\n --- self.foo(asdasd…\n --- self.foo(asdas…)\n if direct and left_brace_one_more_than_right_brace(vim.fn.strcharpart(text, 0, max_width)) then\n local truncated = vim.fn.strcharpart(text, 0, max_width - 2) .. \"…)\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 4, truncated_width - 1 },\n })\n table.insert(item.highlights, {\n \"@punctuation.bracket\",\n range = { truncated_width - 1, truncated_width },\n })\n else\n local truncated = vim.fn.strcharpart(text, 0, max_width - 1) .. \"…\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 3, truncated_width },\n })\n end\nend\n\n---@param item CMHighlights\n---@param offset integer\n---@param start integer\nlocal function shift_color_by(item, offset, start)\n for _, highlight in ipairs(item.highlights) do\n if highlight.range[1] > start then\n highlight.range[1] = highlight.range[1] - offset\n highlight.range[2] = highlight.range[2] - offset\n end\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param item CMHighlights\nfunction M.validate_newline(completion_item, item)\n if string.find(item.text, \"\\n\") ~= nil or string.find(item.text, \"\\r\") ~= nil then\n vim.notify_once(\n '[colorful-menu.nvim]: Completion \"'\n .. completion_item.label\n .. '\" has new line character, please open an issue',\n vim.log.levels.WARN\n )\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n nil,\n nil,\n require(\"colorful-menu\").config.ls.fallback_extra_info_hl\n )\n end\n return item\nend\n\n---@param item CMHighlights\n---@param ls string\n---@return CMHighlights?\nfunction M.apply_post_processing(completion_item, item, ls)\n -- if the user override or fallback logic didn't produce a table, bail\n if type(item) ~= \"table\" or not item.text then\n return item\n end\n\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local range = hl.range\n if range[2] < 0 then\n table.remove(item.highlights, i)\n elseif range[1] < 0 then\n range[1] = 0\n end\n end\n\n local max_width = require(\"colorful-menu.utils\").max_width()\n if not (max_width and max_width > 0) then\n return\n end\n\n local label = completion_item.label\n local display_width = vim.fn.strdisplaywidth(item.text)\n if display_width > (item.text:find(\"\\7\") ~= nil and (max_width + 1) or max_width) then\n local long_label, type = item.text:match(\"(.*)\\7%s*(.*)\")\n local is_func = completion_item.kind == Kind.Function or completion_item.kind == Kind.Method\n if\n item.text == label\n or type == nil\n or #type == 0\n or not is_func\n or not config.ls[ls]\n or not config.ls[ls].preserve_type_when_truncate\n then\n item.text = item.text:gsub(\"\\7\", \" \")\n cut_label(item, max_width, is_func)\n return\n end\n\n local _, le = item.text:find(\"\\7\")\n local ts = item.text:find(type, le, true)\n local space_between = ts - le\n item.text = item.text:gsub(\"\\7\", \" \")\n\n -- Now we need to deal with color shifting stuff.\n -- Foo(a string b string) \"some random stuff\"\n -- | | | |\n -- long_label_width type_width\n --\n -- | short | | type_width |\n -- Foo(a st… \"some random stuff\"\n -- | max_width |\n local long_label_width, type_width = #long_label, #type\n local short_label_width = math.max(max_width - type_width - 2 - space_between, #label)\n local should_cut_all = short_label_width == #label\n if should_cut_all then\n remove_color_in_range(item, { left = short_label_width, right = long_label_width })\n local pretty_end = \"(…)\"\n if label:sub(short_label_width, short_label_width) == \")\" then\n pretty_end = \"…)\"\n end\n shift_color_by(item, long_label_width - short_label_width - string.len(pretty_end), long_label_width)\n item.text = item.text:sub(1, short_label_width) .. pretty_end .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = {\n short_label_width + (pretty_end == \"(…)\" and 1 or 0),\n short_label_width + (pretty_end == \"(…)\" and string.len(\"…)\") or string.len(\"…\")),\n },\n })\n cut_label(item, max_width, false)\n else\n -- Caculate display_width and real byte diff.\n local diff = short_label_width - vim.fn.strdisplaywidth(item.text:sub(1, short_label_width))\n -- We increase the cut threshold if display_width is lower than\n -- byte count, otherwise the hole is not enough.\n short_label_width = short_label_width + diff\n local ascii_pos = short_label_width\n for i = short_label_width, 1, -1 do\n if item.text:sub(i, i):match(\"[a-zA-Z(]\") ~= nil then\n ascii_pos = i\n break\n end\n end\n remove_color_in_range(item, { left = ascii_pos, right = long_label_width })\n shift_color_by(item, long_label_width - short_label_width - string.len(\"…)\"), long_label_width)\n item.text = item.text:sub(1, ascii_pos)\n .. \"…)\"\n .. string.rep(\" \", short_label_width - ascii_pos)\n .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = { ascii_pos, ascii_pos + string.len(\"…)\") - 1 },\n })\n end\n else\n item.text = item.text:gsub(\"\\7\", \" \")\n end\nend\n\nfunction M.align_spaces_bell(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \"\\7 \"\n end\n return \"\\7\" .. string.rep(\" \", blank - 1)\nend\n\nfunction M.align_spaces(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \" \"\n end\n return string.rep(\" \", blank)\nend\n\nfunction M.max_width()\n local max_width = config.max_width\n if max_width < 1 and max_width > 0 then\n max_width = math.floor(max_width * vim.api.nvim_win_get_width(0))\n end\n return max_width\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/typescript.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.ts_server(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n local kind = completion_item.kind\n -- Combine label + detail for final display\n local text = (detail and config.ls.ts_ls.extra_info_hl ~= false) and (label .. \" \" .. detail) or label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if detail and config.ls.ts_ls.extra_info_hl ~= false then\n local extra_info_hl = config.ls.ts_ls.extra_info_hl\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #label + 1 + #detail },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\n-- see https://github.com/zed-industries/zed/pull/13043\n-- Untested.\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.vtsls(completion_item, ls)\n local function one_line(s)\n s = s:gsub(\" \", \"\")\n s = s:gsub(\"\\n\", \" \")\n return s\n end\n\n local label = completion_item.label\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local detail = completion_item.detail\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if config.ls.vtsls.extra_info_hl ~= false then\n if description then\n text = label .. \" \" .. one_line(description)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n elseif detail then\n text = label .. \" \" .. one_line(detail)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/zig.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.zls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.zls(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n or (completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail)\n if detail ~= nil then\n detail = vim.split(detail, \"\\n\")[1]\n end\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable or kind == Kind.Struct or kind == Kind.Enum) and detail then\n if detail == \"type\" then\n local source = string.format(\"fn(s: %s)\", label)\n return utils.highlight_range(source, ls, 6, 6 + #label)\n else\n local text = string.format(\"%s:%s%s\", label, align_spaces(label, detail .. \" \"), detail)\n local source = string.format(\"fn(%s)\", text)\n local hl = utils.highlight_range(source, ls, 3, 3 + #text)\n for _, highlight in ipairs(hl.highlights) do\n if vim.startswith(highlight[1], \"@variable.parameter\") then\n highlight[1] = highlight[1]:gsub(\"%.parameter\", \"\")\n end\n end\n if config.ls.zls.align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #label) .. \" \" .. hl.text:sub(#label + 2, #text)\n return hl\n end\n --\n elseif (kind == Kind.Field or kind == Kind.EnumMember) and detail then\n -- For some reason `const x = struct { name: *Foo }` can't get the type color for Foo.\n -- Here is the trick:\n -- xfn(foo: *Foo)\n -- x *Foo\n local source = string.format(\"%sfn(foo:%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(\n source:sub(#label + 1),\n ls,\n config.ls.zls.align_type_to_right and 7 or 6,\n #source:sub(#label + 1) - 1\n )\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n )\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n if detail:sub(1, 2) == \"fn\" then\n local ret_type = vim.split(\n (vim.tbl_get(completion_item, \"labelDetails\", \"description\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"),\n \"\\n\"\n )[1]\n local params =\n vim.split((vim.tbl_get(completion_item, \"labelDetails\", \"detail\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n local text, source\n if ret_type ~= \"\" and params ~= \"\" and config.ls.zls.align_type_to_right then\n text = string.format(\"%s%s%s%s\", label, params, align_spaces(label .. params, ret_type), ret_type)\n source = string.format(\"fn %s {}\", text)\n else\n local signature = detail:sub(4)\n text = string.format(\"%s%s\", label, signature)\n source = string.format(\"fn %s {}\", text)\n end\n return utils.highlight_range(source, ls, 3, 3 + #text)\n elseif detail:sub(1, 1) == \"@\" then\n return utils.highlight_range(detail, ls, 0, #detail)\n else\n return {\n text = completion_item.label,\n highlights = {\n {\n \"@function\",\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Field then\n highlight_name = utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/init.lua", "local M = {}\n\nM.insertTextFormat = { PlainText = 1, Snippet = 2 }\n-- stylua: ignore\nM.Kind = { Text = 1, Method = 2, Function = 3, Constructor = 4, Field = 5, Variable = 6, Class = 7, Interface = 8, Module = 9, Property = 10, Unit = 11, Value = 12, Enum = 13, Keyword = 14, Snippet = 15, Color = 16, File = 17, Reference = 18, Folder = 19, EnumMember = 20, Constant = 21, Struct = 22, Event = 23, Operator = 24, TypeParameter = 25 }\n\n---@alias CMHighlightRange {hl_group: string, range: integer[], text: string}\n---\n---@class CMHighlights\n---@field text string\n---@field highlights CMHighlightRange[]\n\n---@class ColorfulMenuConfig\nM.config = {\n ls = {\n lua_ls = {\n -- Maybe you want to dim arguments a bit.\n arguments_hl = \"@comment\",\n },\n gopls = {\n -- When true, label for field and variable will format like \"foo: Foo\"\n -- instead of go's original syntax \"foo Foo\".\n add_colon_before_type = false,\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n ts_ls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n vtsls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n zls = {\n align_type_to_right = true,\n },\n [\"rust-analyzer\"] = {\n -- Such as (as Iterator), (use std::io).\n extra_info_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n clangd = {\n -- Such as \"\".\n extra_info_hl = \"@comment\",\n -- the hl of leading dot of \"•std::filesystem::permissions(..)\"\n import_dot_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n roslyn = {\n extra_info_hl = \"@comment\",\n },\n -- The same applies to pyright/pylance\n basedpyright = {\n extra_info_hl = \"@comment\",\n },\n pylsp = {\n extra_info_hl = \"@comment\",\n -- Dim the function argument area, which is the main\n -- difference with pyright.\n arguments_hl = \"@comment\",\n },\n dartls = {\n extra_info_hl = \"@comment\",\n },\n fallback = true,\n fallback_extra_info_hl = \"@comment\",\n },\n fallback_highlight = \"@variable\",\n max_width = 60,\n}\n\nlocal hl_cache = {}\nlocal hl_cache_size = 0\n-- about 30M max memory usage.\nlocal MAX_HL_CACHE_SIZE = 10000\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return string\nlocal function cache_key(completion_item, ls)\n return string.format(\n \"%s!%s!%s!%s!%s%s\",\n completion_item.label or \"\",\n completion_item.detail or \"\",\n completion_item.labelDetails\n and (completion_item.labelDetails.detail or \"\") .. (completion_item.labelDetails.description or \"\")\n or \"\",\n completion_item.kind and tostring(completion_item.kind) or \"\",\n ls,\n require(\"colorful-menu.utils\").max_width()\n )\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nlocal function _highlights(completion_item, ls)\n if completion_item == nil or ls == nil or ls == \"\" or vim.b.ts_highlight == false then\n return nil\n end\n\n local item\n\n local key = cache_key(completion_item, ls)\n if hl_cache[key] ~= nil then\n return hl_cache[key]\n end\n\n if ls == \"gopls\" then\n item = require(\"colorful-menu.languages.go\").gopls(completion_item, ls)\n --\n elseif ls == \"rust-analyzer\" or ls == \"rust_analyzer\" then\n item = require(\"colorful-menu.languages.rust\").rust_analyzer(completion_item, ls)\n ls = \"rust-analyzer\"\n --\n elseif ls == \"lua_ls\" then\n item = require(\"colorful-menu.languages.lua\").lua_ls(completion_item, ls)\n --\n elseif ls == \"clangd\" then\n item = require(\"colorful-menu.languages.cpp\").clangd(completion_item, ls)\n --\n elseif ls == \"typescript-language-server\" or ls == \"ts_ls\" or ls == \"tsserver\" or ls == \"typescript-tools\" then\n item = require(\"colorful-menu.languages.typescript\").ts_server(completion_item, ls)\n --\n elseif ls == \"vtsls\" then\n item = require(\"colorful-menu.languages.typescript\").vtsls(completion_item, ls)\n --\n elseif ls == \"zls\" then\n item = require(\"colorful-menu.languages.zig\").zls(completion_item, ls)\n --\n elseif ls == \"intelephense\" then\n item = require(\"colorful-menu.languages.php\").intelephense(completion_item, ls)\n --\n elseif ls == \"roslyn\" then\n item = require(\"colorful-menu.languages.cs\").roslyn(completion_item, ls)\n --\n elseif ls == \"dartls\" then\n item = require(\"colorful-menu.languages.dart\").dartls(completion_item, ls)\n --\n elseif ls == \"basedpyright\" or ls == \"pyright\" or ls == \"pylance\" or ls == \"pylsp\" then\n item = require(\"colorful-menu.languages.python\").py(completion_item, ls)\n --\n else\n -- No languages detected so check if we should highlight with default or not\n if not M.config.ls.fallback then\n return nil\n end\n item = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail,\n nil,\n M.config.ls.fallback_extra_info_hl\n )\n end\n\n if item then\n item = require(\"colorful-menu.utils\").validate_newline(completion_item, item)\n require(\"colorful-menu.utils\").apply_post_processing(completion_item, item, ls)\n end\n\n hl_cache_size = hl_cache_size + 1\n if hl_cache_size > MAX_HL_CACHE_SIZE then\n hl_cache_size = 0\n hl_cache = {}\n end\n hl_cache[key] = item\n\n return item\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param entry cmp.Entry\nfunction M.cmp_highlights(entry)\n local client = vim.tbl_get(entry, \"source\", \"source\", \"client\") -- For example `lua_ls` etc\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n return _highlights(entry:get_completion_item(), client.name)\n end\n return nil\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_text(ctx)\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n return highlights_info.label\n else\n ---@diagnostic disable-next-line: undefined-field\n return ctx.label\n end\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_highlight(ctx)\n local highlights = {}\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n highlights = highlights_info.highlights\n end\n ---@diagnostic disable-next-line: undefined-field\n for _, idx in ipairs(ctx.label_matched_indices) do\n table.insert(highlights, { idx, idx + 1, group = \"BlinkCmpLabelMatch\" })\n end\n return highlights\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_highlights(ctx)\n ---@diagnostic disable-next-line: undefined-field\n local client = vim.lsp.get_client_by_id(ctx.item.client_id)\n local highlights = {}\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n local highlights_info = _highlights(ctx.item, client.name)\n if highlights_info ~= nil then\n for _, info in ipairs(highlights_info.highlights or {}) do\n table.insert(highlights, {\n info.range[1],\n info.range[2],\n ---@diagnostic disable-next-line: undefined-field\n group = ctx.deprecated and \"BlinkCmpLabelDeprecated\" or info[1],\n })\n end\n else\n return nil\n end\n return { label = highlights_info.text, highlights = highlights }\n end\n return nil\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nfunction M.highlights(completion_item, ls)\n if ls == vim.bo.filetype then\n vim.notify_once(\n \"colorful-menu.nvim: Integration with nvim-cmp or blink.cmp has been simplified, and legacy per-filetype options is also deprecated\"\n .. \" to prefer per-language-server options, please see README\",\n vim.log.levels.WARN\n )\n return nil\n end\n\n return _highlights(completion_item, ls)\nend\n\n---@param opts ColorfulMenuConfig\nfunction M.setup(opts)\n opts = opts or {}\n M.config = vim.tbl_deep_extend(\"force\", M.config, opts)\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/rust.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal insertTextFormat = require(\"colorful-menu\").insertTextFormat\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal cashed_self_hl = nil\n---@return CMHighlightRange[]\nlocal function iter_chain()\n if cashed_self_hl == nil then\n local source = \"fn iter(){}\"\n local hl = utils.highlight_range(source, \"rust-analyzer\", 3, #source - 2)\n cashed_self_hl = hl.highlights\n end\n return cashed_self_hl\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _rust_analyzer(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local function_signature = completion_item.labelDetails and completion_item.labelDetails.description\n or completion_item.detail\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(completion_item.label, ls, 0, #completion_item.label)\n end\n\n if kind == Kind.Field and detail then\n local name = completion_item.label\n local text = string.format(\"%s:%s%s\", name, align_spaces(name .. \" \", detail), detail)\n local source = string.format(\"struct S { %s }\", text)\n local hl = utils.highlight_range(source, ls, 11, 11 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif\n completion_item.insertTextFormat == insertTextFormat.Snippet\n and (label:find(\"::\", nil, true) ~= nil or label == \"Some(…)\" or label == \"None\" or label == \"Ok(…)\" or label == \"Err(…)\")\n and label:sub(1, 1) >= \"A\"\n and label:sub(1, 1) <= \"Z\"\n then\n local source = string.format(\"match s { %s }\", label)\n return utils.highlight_range(source, ls, 10, 10 + #label)\n elseif\n (kind == Kind.Constant or kind == Kind.Variable)\n and detail\n and completion_item.insertTextFormat ~= insertTextFormat.Snippet\n then\n local name = completion_item.label\n local text = string.format(\n \"%s:%s%s\",\n name,\n align_spaces(name .. \" \", completion_item.detail),\n completion_item.detail or detail\n )\n local source = string.format(\"let %s = ();\", text)\n local hl = utils.highlight_range(source, ls, 4, 4 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif (kind == Kind.EnumMember) and detail then\n local source = string.format(\"enum S { %s }\", detail)\n return utils.highlight_range(source, ls, 9, 9 + #detail)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local pattern = \"%((.-)%)\"\n\n local ignored = nil\n if label:match(\"^iter%(%)%..+\") ~= nil then\n ignored = \"iter().\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n if label:match(\"^self%..+\") ~= nil then\n ignored = \"self.\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n local function adjust(hl)\n if ignored == \"self.\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored)\n elseif ignored == \"iter().\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored, nil, iter_chain())\n end\n end\n\n local result = string.match(label, pattern)\n if not result then\n label = label .. \"()\"\n end\n local regex_pattern = \"%b()\"\n local prefix, suffix = string.match(function_signature or \"\", \"^(.*fn)(.*)$\")\n if prefix ~= nil and suffix ~= nil then\n local start_pos = string.find(suffix, \"(\", nil, true)\n if start_pos then\n suffix = suffix:sub(start_pos, #suffix)\n end\n\n if\n config.ls[\"rust-analyzer\"].preserve_type_when_truncate\n and config.ls[\"rust-analyzer\"].align_type_to_right\n then\n local params, type = string.match(suffix, \"(%b()) %-> (.*)\")\n if params == nil and type == nil then\n params = suffix\n type = \"\"\n end\n local call, num_subs = string.gsub(label, regex_pattern, params, 1)\n if num_subs == 0 then\n call = completion_item.label\n end\n local source = string.format(\n \"%s %s->%s%s{}\",\n prefix,\n call,\n align_spaces(call .. \" \", ignored ~= nil and type .. ignored or type),\n type or \"\"\n )\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 2)\n hl.text = hl.text:sub(1, #call) .. \" \" .. hl.text:sub(#call + 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n else\n local call, num_subs = string.gsub(label, regex_pattern, suffix, 1)\n if num_subs == 0 then\n call = label\n end\n local source = string.format(\"%s %s {}\", prefix, call)\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n end\n else\n -- Check if the detail starts with \"macro_rules! \"\n if completion_item.detail and vim.startswith(completion_item.detail, \"macro\") then\n local source = completion_item.label\n return utils.highlight_range(source, ls, 0, #source)\n else\n -- simd_swizzle!()\n return {\n text = completion_item.label,\n highlights = {\n {\n config.fallback_highlight,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Struct then\n highlight_name = \"@type\"\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", \"rust\")\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@constant\", \"rust\")\n elseif kind == Kind.Interface then\n highlight_name = utils.hl_exist_or(\"@lsp.type.interface\", \"@type\", \"rust\")\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n if detail then\n detail = vim.trim(detail)\n if vim.startswith(detail, \"(\") then\n local space = align_spaces(completion_item.label, detail)\n return {\n text = completion_item.label .. space .. detail,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { #completion_item.label + #space, #completion_item.label + #space + #detail },\n },\n },\n }\n end\n end\n\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.rust_analyzer(completion_item, ls)\n local vim_item = _rust_analyzer(completion_item, ls)\n if vim_item.text ~= nil then\n for _, match in ipairs({ \"%(use .-%)\", \"%(as .-%)\", \"%(alias .-%)\" }) do\n local s, e = string.find(vim_item.text, match)\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { s - 1, e },\n })\n end\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/dart.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.dartls(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail ~= nil and detail:find(\"Auto\") ~= nil then\n detail = detail:gsub(\"Auto import.*\\n\\n\", \"\")\n detail = vim.split(detail:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n -- x int\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n -- var x int x\n local source = string.format(\"var %s x\", text)\n return utils.highlight_range(source, ls, 4, 4 + #text)\n --\n elseif (kind == Kind.Field or kind == Kind.Property) and detail then\n -- Here is the trick same as zls:\n -- xvoid( *Foo)\n -- x *Foo\n local source = string.format(\"%svoid(%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(source:sub(#label + 1), ls, 5, #source:sub(#label + 1) - 1)\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"dart\")\n )\n --\n elseif (kind == Kind.Function or kind == Kind.Method or kind == Kind.Constructor) and detail then\n -- elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n -- label: fetchData(..)\n -- detail: (int a, int b) -> Future\n -- fetchData(int a, int b);(Future s)\n local params = string.match(detail or \"\", \"^(%b())\")\n local type = string.match(detail or \"\", \"→ (.*)\")\n if params ~= nil then\n label = label:gsub(\"%b()$\", \"\") .. params\n end\n if type ~= nil and kind ~= Kind.Constructor then\n local text = string.format(\"%s%s;(%s)\", label, align_spaces(label, type):sub(3), type)\n local comma_pos = #text - #type - 3\n local ranges = utils.highlight_range(text, ls, 0, #text - 1)\n ranges.text = ranges.text:sub(1, comma_pos) .. \" \" .. ranges.text:sub(comma_pos + 3, #ranges.text)\n return ranges\n end\n return utils.highlight_range(label, ls, 0, #label)\n --\n else\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n detail,\n \"dart\",\n config.ls[ls].extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/go.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function parse_signature(signature)\n local params, returns = \"\", \"\"\n local pm, rm = signature:match(\"^(%b())%s*(%(?.*%)?)\")\n params = pm ~= nil and pm or \"\"\n returns = rm ~= nil and rm or \"\"\n return params, returns\nend\n\nlocal function align_spaces(abbr, detail)\n if config.ls.gopls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.gopls(completion_item, ls)\n if config.ls.gopls.align_type_to_right then\n -- This makes no sense then.\n config.ls.gopls.add_colon_before_type = false\n end\n\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail then\n -- In unimported one, we remove useless information\n -- assign.Analyzer var from(\"golang.org/x/tools/go/analysis/passes/assign\")\n -- =>\n -- assign.Analyzer \"golang.org/x/tools/go/analysis/passes/assign\"\n local path = detail:match(\".*%(from(.*)%)\")\n if path then\n local highlight_name = utils.hl_by_kind(kind)\n local spaces = align_spaces(label, path)\n local text = label .. align_spaces(label, path) .. path\n return {\n text = text,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n {\n \"@string\",\n range = { #label + #spaces, #text },\n },\n },\n }\n end\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Gopls returns nested fields and methods as completions.\n -- To syntax highlight these, combine their final component\n -- with their detail.\n local name_offset = label:reverse():find(\"%.\") or 0\n if name_offset > 0 then\n name_offset = #label - name_offset + 2\n else\n name_offset = 0\n end\n\n if kind == Kind.Module and detail then\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"import %s\", text)\n return utils.highlight_range(source, ls, 7, 7 + #text)\n --\n elseif (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local var_part = text:sub(name_offset)\n local source = string.format(\"var %s\", var_part)\n local item = utils.highlight_range(source, ls, 4, 4 + #var_part)\n if kind == Kind.Constant then\n if #item.highlights >= 1 then\n item.highlights[1][1] = utils.hl_exist_or(\"@constant\", \"@variable\", \"go\")\n end\n end\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Struct then\n detail = \"struct{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s struct {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Interface then\n detail = \"interface{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s interface {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Field and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local source = string.format(\"type T struct { %s }\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 16, 16 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = vim.trim(detail)\n if detail:sub(1, 4) == \"func\" then\n signature = detail:sub(5)\n end\n\n local text = string.format(\"%s%s\", label, signature)\n if signature ~= \"()\" then\n local params, returns = parse_signature(signature)\n text = label .. params .. align_spaces(label, params .. returns) .. returns\n end\n\n local source = string.format(\"func %s {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n else\n -- Handle other kinds\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/cs.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n\n local text = label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/lua.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.lua_ls(completion_item, ls)\n local vim_item = _lua_compute_completion_highlights(completion_item, ls)\n if vim_item.text ~= nil then\n local s, e = string.find(vim_item.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls.lua_ls.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/php.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.intelephense(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local kind = completion_item.kind\n\n if (kind == Kind.Function or kind == Kind.Method) and detail and #detail > 0 then\n local signature = detail:sub(#label + 1)\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s 0 then\n detail = string.gsub(detail, \".*\\\\(.)\", \"%1\")\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s \"] = cmp.mapping(function(fallback)\n if cmp.visible() then\n cmp.confirm()\n end\n end, { \"i\" }),\n }),\n completion = {\n completeopt = \"menu,menuone,noinsert\",\n },\n formatting = {\n format = function(entry, vim_item)\n local highlights_info = require(\"colorful-menu\").cmp_highlights(entry)\n if highlights_info ~= nil then\n vim_item.abbr_hl_group = highlights_info.highlights\n vim_item.abbr = highlights_info.text\n end\n return vim_item\n end,\n },\n sources = require(\"cmp\").config.sources({\n { name = \"nvim_lsp\" },\n }, {}),\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n capabilities = require(\"cmp_nvim_lsp\").default_capabilities(),\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n workspace = {\n library = {\n \"/usr/local/share/nvim/runtime\",\n },\n },\n completion = {\n callSnippet = \"Replace\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"], ["/colorful-menu.nvim/repro_blink.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n \"xzbdmw/colorful-menu.nvim\",\n {\n \"saghen/blink.cmp\",\n version = \"v0.*\",\n config = function()\n require(\"blink.cmp\").setup({\n completion = {\n menu = {\n draw = {\n -- We don't need label_description now because label and label_description are already\n -- conbined together in label by colorful-menu.nvim.\n columns = { { \"kind_icon\" }, { \"label\", gap = 1 } },\n components = {\n label = {\n text = require(\"colorful-menu\").blink_components_text,\n highlight = require(\"colorful-menu\").blink_components_highlight,\n },\n },\n },\n },\n },\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"]], "task_instance_info": {"created_time": "2025-08-21 00:42:04", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Format textual elements with contextual styling information and dynamically combine multiple data components while applying distinct visual properties to different sections of the resulting output."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nfunction M.get_highlights(completion_item, detail, lang, extra_info_hl)\n local kind = completion_item.kind or 1\n local highlights = {\n kind = {\n text = utils.get_icon(kind),\n hl_group = \"CmpItemKind\"..utils.camel_to_upper(vim.lsp.protocol.CompletionItemKind[kind] or \"\")\n }\n }\n\n if detail then\n highlights.detail = {\n text = detail,\n hl_group = highlights.kind.hl_group..\"Detail\"\n }\n end\n\n if lang then\n highlights.lang = {\n text = lang,\n hl_group = extra_info_hl or \"CmpItemMenu\"\n }\n end\n\n return highlights\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-42-22"}, "editdistance_info": {"edit_distance": 18.75, "calculate_time": "2025-08-21 00:42:22", "true_code_clean": "function M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "predict_code_clean": "function M.get_highlights(completion_item, detail, lang, extra_info_hl)\n local kind = completion_item.kind or 1\n local highlights = {\n kind = {\n text = utils.get_icon(kind),\n hl_group = \"CmpItemKind\"..utils.camel_to_upper(vim.lsp.protocol.CompletionItemKind[kind] or \"\")\n }\n }\n if detail then\n highlights.detail = {\n text = detail,\n hl_group = highlights.kind.hl_group..\"Detail\"\n }\n end\n if lang then\n highlights.lang = {\n text = lang,\n hl_group = extra_info_hl or \"CmpItemMenu\"\n }\n end\n return highlights\nend"}} {"repo_name": "colorful-menu.nvim", "file_name": "/colorful-menu.nvim/lua/colorful-menu/languages/lua.lua", "inference_info": {"prefix_code": "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\n", "suffix_code": "\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.lua_ls(completion_item, ls)\n local vim_item = _lua_compute_completion_highlights(completion_item, ls)\n if vim_item.text ~= nil then\n local s, e = string.find(vim_item.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls.lua_ls.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n", "middle_code": "local function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/colorful-menu.nvim/lua/colorful-menu/languages/rust.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal insertTextFormat = require(\"colorful-menu\").insertTextFormat\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal cashed_self_hl = nil\n---@return CMHighlightRange[]\nlocal function iter_chain()\n if cashed_self_hl == nil then\n local source = \"fn iter(){}\"\n local hl = utils.highlight_range(source, \"rust-analyzer\", 3, #source - 2)\n cashed_self_hl = hl.highlights\n end\n return cashed_self_hl\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _rust_analyzer(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local function_signature = completion_item.labelDetails and completion_item.labelDetails.description\n or completion_item.detail\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(completion_item.label, ls, 0, #completion_item.label)\n end\n\n if kind == Kind.Field and detail then\n local name = completion_item.label\n local text = string.format(\"%s:%s%s\", name, align_spaces(name .. \" \", detail), detail)\n local source = string.format(\"struct S { %s }\", text)\n local hl = utils.highlight_range(source, ls, 11, 11 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif\n completion_item.insertTextFormat == insertTextFormat.Snippet\n and (label:find(\"::\", nil, true) ~= nil or label == \"Some(…)\" or label == \"None\" or label == \"Ok(…)\" or label == \"Err(…)\")\n and label:sub(1, 1) >= \"A\"\n and label:sub(1, 1) <= \"Z\"\n then\n local source = string.format(\"match s { %s }\", label)\n return utils.highlight_range(source, ls, 10, 10 + #label)\n elseif\n (kind == Kind.Constant or kind == Kind.Variable)\n and detail\n and completion_item.insertTextFormat ~= insertTextFormat.Snippet\n then\n local name = completion_item.label\n local text = string.format(\n \"%s:%s%s\",\n name,\n align_spaces(name .. \" \", completion_item.detail),\n completion_item.detail or detail\n )\n local source = string.format(\"let %s = ();\", text)\n local hl = utils.highlight_range(source, ls, 4, 4 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif (kind == Kind.EnumMember) and detail then\n local source = string.format(\"enum S { %s }\", detail)\n return utils.highlight_range(source, ls, 9, 9 + #detail)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local pattern = \"%((.-)%)\"\n\n local ignored = nil\n if label:match(\"^iter%(%)%..+\") ~= nil then\n ignored = \"iter().\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n if label:match(\"^self%..+\") ~= nil then\n ignored = \"self.\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n local function adjust(hl)\n if ignored == \"self.\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored)\n elseif ignored == \"iter().\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored, nil, iter_chain())\n end\n end\n\n local result = string.match(label, pattern)\n if not result then\n label = label .. \"()\"\n end\n local regex_pattern = \"%b()\"\n local prefix, suffix = string.match(function_signature or \"\", \"^(.*fn)(.*)$\")\n if prefix ~= nil and suffix ~= nil then\n local start_pos = string.find(suffix, \"(\", nil, true)\n if start_pos then\n suffix = suffix:sub(start_pos, #suffix)\n end\n\n if\n config.ls[\"rust-analyzer\"].preserve_type_when_truncate\n and config.ls[\"rust-analyzer\"].align_type_to_right\n then\n local params, type = string.match(suffix, \"(%b()) %-> (.*)\")\n if params == nil and type == nil then\n params = suffix\n type = \"\"\n end\n local call, num_subs = string.gsub(label, regex_pattern, params, 1)\n if num_subs == 0 then\n call = completion_item.label\n end\n local source = string.format(\n \"%s %s->%s%s{}\",\n prefix,\n call,\n align_spaces(call .. \" \", ignored ~= nil and type .. ignored or type),\n type or \"\"\n )\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 2)\n hl.text = hl.text:sub(1, #call) .. \" \" .. hl.text:sub(#call + 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n else\n local call, num_subs = string.gsub(label, regex_pattern, suffix, 1)\n if num_subs == 0 then\n call = label\n end\n local source = string.format(\"%s %s {}\", prefix, call)\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n end\n else\n -- Check if the detail starts with \"macro_rules! \"\n if completion_item.detail and vim.startswith(completion_item.detail, \"macro\") then\n local source = completion_item.label\n return utils.highlight_range(source, ls, 0, #source)\n else\n -- simd_swizzle!()\n return {\n text = completion_item.label,\n highlights = {\n {\n config.fallback_highlight,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Struct then\n highlight_name = \"@type\"\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", \"rust\")\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@constant\", \"rust\")\n elseif kind == Kind.Interface then\n highlight_name = utils.hl_exist_or(\"@lsp.type.interface\", \"@type\", \"rust\")\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n if detail then\n detail = vim.trim(detail)\n if vim.startswith(detail, \"(\") then\n local space = align_spaces(completion_item.label, detail)\n return {\n text = completion_item.label .. space .. detail,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { #completion_item.label + #space, #completion_item.label + #space + #detail },\n },\n },\n }\n end\n end\n\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.rust_analyzer(completion_item, ls)\n local vim_item = _rust_analyzer(completion_item, ls)\n if vim_item.text ~= nil then\n for _, match in ipairs({ \"%(use .-%)\", \"%(as .-%)\", \"%(alias .-%)\" }) do\n local s, e = string.find(vim_item.text, match)\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { s - 1, e },\n })\n end\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/cpp.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \"\"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal function path_align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _clangd(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.detail\n local labelDetails = completion_item.labelDetails\n\n -- If no kind, just fallback to highlighting the cleaned-up label\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Constants or Variables with detail => \"detail label\", highlight entire text\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {int x;std::unique_ptr x;}\n -- | |\n -- @variable |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ int %s x;}\", text)\n return utils.highlight_range(source, ls, 16, 16 + #text)\n\n -- Functions or Methods with detail => \"detail label\", might find '('\n elseif kind == Kind.Field and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {f->x;std::unique_ptr x;}\n -- | |\n -- @field |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ f->%s x;}\", text)\n return utils.highlight_range(source, ls, 15, 15 + #text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = \"\"\n if labelDetails and labelDetails.detail then\n signature = labelDetails.detail\n end\n local text = string.format(\n \"void %s%s;%s%s x;\",\n label,\n signature,\n align_spaces(label .. signature .. \";\", detail),\n detail\n )\n return utils.highlight_range(text, ls, 5, #text - 3)\n --\n else\n local highlight_name = nil\n local lang = vim.bo.filetype == \"c\" and \"c\" or \"cpp\"\n if kind == Kind.Struct or kind == Kind.Interface then\n highlight_name = \"@type\"\n elseif kind == Kind.Class then\n highlight_name = utils.hl_exist_or(\"@lsp.type.class\", \"@variant\", lang)\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@variant\", lang)\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n -- If we found a special highlight name, highlight the portion before '('\n if highlight_name then\n local paren_index = string.find(label, \"%(\", 1, true)\n local end_index = paren_index and (paren_index - 1) or #label\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { vim.startswith(label, \"•\") and 3 or 0, end_index },\n },\n },\n }\n end\n end\n\n return {\n text = label,\n highlights = {},\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.clangd(completion_item, ls)\n local vim_item = _clangd(completion_item, ls)\n local max_width = require(\"colorful-menu.utils\").max_width()\n if vim_item.text ~= nil then\n if vim.startswith(vim_item.text, \"•\") then\n table.insert(vim_item.highlights, 1, {\n config.ls.clangd.import_dot_hl,\n range = { 0, 3 },\n })\n end\n vim_item.text = vim_item.text:gsub(\";\", \" \")\n -- If it is already overflow, just return.\n if max_width and max_width > 0 then\n local display_width = vim.fn.strdisplaywidth(vim_item.text)\n if display_width >= max_width then\n return vim_item\n end\n end\n\n -- Append path.\n local document = completion_item.documentation\n if document and document.value and vim.startswith(document.value, \"From \") then\n local len = #vim_item.text\n local include_path = vim.trim(vim.split(document.value:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1])\n :sub(6, #document.value)\n if include_path:sub(1, 1) == \"`\" and include_path:sub(#include_path, #include_path) == \"`\" then\n include_path = include_path:sub(2, #include_path - 1)\n end\n local spaces = path_align_spaces(vim_item.text, include_path)\n vim_item.text = string.gsub(vim_item.text .. spaces .. include_path, \"\\n\", \" \")\n table.insert(vim_item.highlights, {\n config.ls.clangd.extra_info_hl,\n range = { len + #spaces, #vim_item.text },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/typescript.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.ts_server(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n local kind = completion_item.kind\n -- Combine label + detail for final display\n local text = (detail and config.ls.ts_ls.extra_info_hl ~= false) and (label .. \" \" .. detail) or label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if detail and config.ls.ts_ls.extra_info_hl ~= false then\n local extra_info_hl = config.ls.ts_ls.extra_info_hl\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #label + 1 + #detail },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\n-- see https://github.com/zed-industries/zed/pull/13043\n-- Untested.\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.vtsls(completion_item, ls)\n local function one_line(s)\n s = s:gsub(\" \", \"\")\n s = s:gsub(\"\\n\", \" \")\n return s\n end\n\n local label = completion_item.label\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local detail = completion_item.detail\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if config.ls.vtsls.extra_info_hl ~= false then\n if description then\n text = label .. \" \" .. one_line(description)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n elseif detail then\n text = label .. \" \" .. one_line(detail)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/utils.lua", "local Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal query_cache = {}\n\n---@param str string\n---@param ls string\n---@return CMHighlights\nlocal function compute_highlights(str, ls)\n local highlights = {}\n\n local lang = vim.treesitter.language.get_lang(vim.bo.filetype)\n if not lang then\n return {}\n end\n\n local query, ok\n if query_cache[ls] == nil then\n ok, query = pcall(vim.treesitter.query.get, lang, \"highlights\")\n if not ok then\n return {}\n end\n query_cache[ls] = query\n else\n query = query_cache[ls]\n end\n\n ---@diagnostic disable-next-line: redefined-local\n local ok, parser = pcall(vim.treesitter.get_string_parser, str, lang)\n if not ok then\n return {}\n end\n\n if not parser then\n vim.notify(string.format(\"No Tree-sitter parser found for filetype: %s\", lang), vim.log.levels.WARN)\n return highlights\n end\n\n -- Parse the string\n local tree = parser:parse(true)[1]\n if not tree then\n vim.notify(\"Failed to parse the string with Tree-sitter.\", vim.log.levels.ERROR)\n return {}\n end\n\n local root = tree:root()\n\n if not query then\n return {}\n end\n\n -- Iterate over all captures in the query\n for id, node in query:iter_captures(root, str, 0, -1) do\n local name = \"@\" .. query.captures[id] .. \".\" .. lang\n local range = { node:range() }\n local _, nscol, _, necol = range[1], range[2], range[3], range[4]\n table.insert(highlights, {\n hl_group = name,\n range = { nscol, necol },\n })\n end\n\n return highlights\nend\n\n-- `left` is inclusive and `right` is exclusive (also zero indexed), to better fit\n-- `nvim_buf_set_extmark` semantic, so `M.highlight_range(text, ft, 0, #text)` is the entire range.\n--\n---@param text string\n---@param ls string\n---@param left integer\n---@param right integer\n---@return CMHighlights\nfunction M.highlight_range(text, ls, left, right)\n local highlights = {}\n local full_hl = compute_highlights(text, ls)\n\n for _, hl in ipairs(full_hl) do\n local s, e = hl.range[1], hl.range[2]\n if e < left then\n goto continue\n end\n if s > right or e > right + 1 then\n break\n end\n\n table.insert(highlights, {\n hl.hl_group,\n range = { hl.range[1] - left, hl.range[2] - left },\n text = text:sub(s + 1, e),\n })\n ::continue::\n end\n\n return {\n text = text:sub(left + 1, right),\n highlights = highlights,\n }\nend\n\n-- Shift a highlight range right by name_offset,\n-- insert a color with fallback_hl for label with range (0, name_offset).\n---@param item CMHighlights\n---@param name_offset integer\n---@param label string\n---@param fallback_hl string?\n---@param custom_hl CMHighlightRange[]?\n---@return CMHighlights\nfunction M.adjust_range(item, name_offset, label, fallback_hl, custom_hl)\n if name_offset == 0 then\n return item\n end\n name_offset = name_offset - 1\n for _, highlight in ipairs(item.highlights) do\n highlight.range[1] = highlight.range[1] + name_offset\n highlight.range[2] = highlight.range[2] + name_offset\n end\n item.text = label:sub(1, name_offset) .. item.text\n if custom_hl then\n for _, hl in ipairs(custom_hl) do\n table.insert(item.highlights, hl)\n end\n else\n table.insert(item.highlights, {\n fallback_hl or \"@variable\",\n range = { 0, name_offset },\n })\n end\n return item\nend\n\n---@param hl_group string\n---@param fallback string\n---@param lang? string\nfunction M.hl_exist_or(hl_group, fallback, lang)\n local f = function()\n local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = hl_group })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return hl_group\n end\n return fallback\n end\n\n local ok, hl\n if lang ~= nil then\n local lang_hl = hl_group .. \".\" .. lang\n ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = lang_hl })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return lang_hl\n else\n return f()\n end\n else\n return f()\n end\nend\n\n---@param kind? integer\n---@param lang? string\n---@return string\nfunction M.hl_by_kind(kind, lang)\n local highlight_name\n if kind == Kind.Method then\n highlight_name = M.hl_exist_or(\"@lsp.type.method\", \"@function\", lang)\n elseif kind == Kind.Function then\n highlight_name = M.hl_exist_or(\"@lsp.type.function\", \"@function\", lang)\n elseif kind == Kind.Constructor then\n highlight_name = \"@constructor\"\n elseif kind == Kind.Variable then\n highlight_name = M.hl_exist_or(\"@lsp.type.variable\", \"@variable\", lang)\n elseif kind == Kind.Field then\n highlight_name = M.hl_exist_or(\"@lsp.type.field\", \"@field\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Property then\n highlight_name = M.hl_exist_or(\"@lsp.type.property\", \"@property\", lang)\n elseif kind == Kind.Module then\n highlight_name = M.hl_exist_or(\"@lsp.type.namespace\", \"@namespace\", lang)\n elseif kind == Kind.Class then\n highlight_name = M.hl_exist_or(\"@lsp.type.class\", \"@type\", lang)\n elseif kind == Kind.Struct then\n highlight_name = M.hl_exist_or(\"@lsp.type.struct\", \"@type\", lang)\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return highlight_name\nend\n\n---@param item CMHighlights\n---@param rang {left:integer, right:integer}\nlocal function remove_color_in_range(item, rang)\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local r = hl.range\n if r[1] > rang.left and r[1] < rang.right then\n table.remove(item.highlights, i)\n elseif r[1] <= rang.left and r[2] > rang.left then\n r[2] = rang.left\n end\n end\nend\n\nlocal function left_brace_one_more_than_right_brace(s)\n local left = 0\n local right = 0\n for i = 1, #s do\n local char = s:sub(i, i)\n if char == \"(\" then\n left = left + 1\n elseif char == \")\" then\n right = right + 1\n end\n end\n return left == right + 1\nend\n\n---@param item CMHighlights\n---@param max_width integer\n---@param direct boolean -- without type info\nlocal function cut_label(item, max_width, direct)\n if vim.fn.strdisplaywidth(item.text) <= max_width then\n return\n end\n local text = item.text\n --- Given\n --- self.foo(asdasd)\n --- self.foo(asdasd…\n --- self.foo(asdas…)\n if direct and left_brace_one_more_than_right_brace(vim.fn.strcharpart(text, 0, max_width)) then\n local truncated = vim.fn.strcharpart(text, 0, max_width - 2) .. \"…)\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 4, truncated_width - 1 },\n })\n table.insert(item.highlights, {\n \"@punctuation.bracket\",\n range = { truncated_width - 1, truncated_width },\n })\n else\n local truncated = vim.fn.strcharpart(text, 0, max_width - 1) .. \"…\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 3, truncated_width },\n })\n end\nend\n\n---@param item CMHighlights\n---@param offset integer\n---@param start integer\nlocal function shift_color_by(item, offset, start)\n for _, highlight in ipairs(item.highlights) do\n if highlight.range[1] > start then\n highlight.range[1] = highlight.range[1] - offset\n highlight.range[2] = highlight.range[2] - offset\n end\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param item CMHighlights\nfunction M.validate_newline(completion_item, item)\n if string.find(item.text, \"\\n\") ~= nil or string.find(item.text, \"\\r\") ~= nil then\n vim.notify_once(\n '[colorful-menu.nvim]: Completion \"'\n .. completion_item.label\n .. '\" has new line character, please open an issue',\n vim.log.levels.WARN\n )\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n nil,\n nil,\n require(\"colorful-menu\").config.ls.fallback_extra_info_hl\n )\n end\n return item\nend\n\n---@param item CMHighlights\n---@param ls string\n---@return CMHighlights?\nfunction M.apply_post_processing(completion_item, item, ls)\n -- if the user override or fallback logic didn't produce a table, bail\n if type(item) ~= \"table\" or not item.text then\n return item\n end\n\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local range = hl.range\n if range[2] < 0 then\n table.remove(item.highlights, i)\n elseif range[1] < 0 then\n range[1] = 0\n end\n end\n\n local max_width = require(\"colorful-menu.utils\").max_width()\n if not (max_width and max_width > 0) then\n return\n end\n\n local label = completion_item.label\n local display_width = vim.fn.strdisplaywidth(item.text)\n if display_width > (item.text:find(\"\\7\") ~= nil and (max_width + 1) or max_width) then\n local long_label, type = item.text:match(\"(.*)\\7%s*(.*)\")\n local is_func = completion_item.kind == Kind.Function or completion_item.kind == Kind.Method\n if\n item.text == label\n or type == nil\n or #type == 0\n or not is_func\n or not config.ls[ls]\n or not config.ls[ls].preserve_type_when_truncate\n then\n item.text = item.text:gsub(\"\\7\", \" \")\n cut_label(item, max_width, is_func)\n return\n end\n\n local _, le = item.text:find(\"\\7\")\n local ts = item.text:find(type, le, true)\n local space_between = ts - le\n item.text = item.text:gsub(\"\\7\", \" \")\n\n -- Now we need to deal with color shifting stuff.\n -- Foo(a string b string) \"some random stuff\"\n -- | | | |\n -- long_label_width type_width\n --\n -- | short | | type_width |\n -- Foo(a st… \"some random stuff\"\n -- | max_width |\n local long_label_width, type_width = #long_label, #type\n local short_label_width = math.max(max_width - type_width - 2 - space_between, #label)\n local should_cut_all = short_label_width == #label\n if should_cut_all then\n remove_color_in_range(item, { left = short_label_width, right = long_label_width })\n local pretty_end = \"(…)\"\n if label:sub(short_label_width, short_label_width) == \")\" then\n pretty_end = \"…)\"\n end\n shift_color_by(item, long_label_width - short_label_width - string.len(pretty_end), long_label_width)\n item.text = item.text:sub(1, short_label_width) .. pretty_end .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = {\n short_label_width + (pretty_end == \"(…)\" and 1 or 0),\n short_label_width + (pretty_end == \"(…)\" and string.len(\"…)\") or string.len(\"…\")),\n },\n })\n cut_label(item, max_width, false)\n else\n -- Caculate display_width and real byte diff.\n local diff = short_label_width - vim.fn.strdisplaywidth(item.text:sub(1, short_label_width))\n -- We increase the cut threshold if display_width is lower than\n -- byte count, otherwise the hole is not enough.\n short_label_width = short_label_width + diff\n local ascii_pos = short_label_width\n for i = short_label_width, 1, -1 do\n if item.text:sub(i, i):match(\"[a-zA-Z(]\") ~= nil then\n ascii_pos = i\n break\n end\n end\n remove_color_in_range(item, { left = ascii_pos, right = long_label_width })\n shift_color_by(item, long_label_width - short_label_width - string.len(\"…)\"), long_label_width)\n item.text = item.text:sub(1, ascii_pos)\n .. \"…)\"\n .. string.rep(\" \", short_label_width - ascii_pos)\n .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = { ascii_pos, ascii_pos + string.len(\"…)\") - 1 },\n })\n end\n else\n item.text = item.text:gsub(\"\\7\", \" \")\n end\nend\n\nfunction M.align_spaces_bell(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \"\\7 \"\n end\n return \"\\7\" .. string.rep(\" \", blank - 1)\nend\n\nfunction M.align_spaces(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \" \"\n end\n return string.rep(\" \", blank)\nend\n\nfunction M.max_width()\n local max_width = config.max_width\n if max_width < 1 and max_width > 0 then\n max_width = math.floor(max_width * vim.api.nvim_win_get_width(0))\n end\n return max_width\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/zig.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.zls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.zls(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n or (completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail)\n if detail ~= nil then\n detail = vim.split(detail, \"\\n\")[1]\n end\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable or kind == Kind.Struct or kind == Kind.Enum) and detail then\n if detail == \"type\" then\n local source = string.format(\"fn(s: %s)\", label)\n return utils.highlight_range(source, ls, 6, 6 + #label)\n else\n local text = string.format(\"%s:%s%s\", label, align_spaces(label, detail .. \" \"), detail)\n local source = string.format(\"fn(%s)\", text)\n local hl = utils.highlight_range(source, ls, 3, 3 + #text)\n for _, highlight in ipairs(hl.highlights) do\n if vim.startswith(highlight[1], \"@variable.parameter\") then\n highlight[1] = highlight[1]:gsub(\"%.parameter\", \"\")\n end\n end\n if config.ls.zls.align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #label) .. \" \" .. hl.text:sub(#label + 2, #text)\n return hl\n end\n --\n elseif (kind == Kind.Field or kind == Kind.EnumMember) and detail then\n -- For some reason `const x = struct { name: *Foo }` can't get the type color for Foo.\n -- Here is the trick:\n -- xfn(foo: *Foo)\n -- x *Foo\n local source = string.format(\"%sfn(foo:%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(\n source:sub(#label + 1),\n ls,\n config.ls.zls.align_type_to_right and 7 or 6,\n #source:sub(#label + 1) - 1\n )\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n )\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n if detail:sub(1, 2) == \"fn\" then\n local ret_type = vim.split(\n (vim.tbl_get(completion_item, \"labelDetails\", \"description\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"),\n \"\\n\"\n )[1]\n local params =\n vim.split((vim.tbl_get(completion_item, \"labelDetails\", \"detail\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n local text, source\n if ret_type ~= \"\" and params ~= \"\" and config.ls.zls.align_type_to_right then\n text = string.format(\"%s%s%s%s\", label, params, align_spaces(label .. params, ret_type), ret_type)\n source = string.format(\"fn %s {}\", text)\n else\n local signature = detail:sub(4)\n text = string.format(\"%s%s\", label, signature)\n source = string.format(\"fn %s {}\", text)\n end\n return utils.highlight_range(source, ls, 3, 3 + #text)\n elseif detail:sub(1, 1) == \"@\" then\n return utils.highlight_range(detail, ls, 0, #detail)\n else\n return {\n text = completion_item.label,\n highlights = {\n {\n \"@function\",\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Field then\n highlight_name = utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/go.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function parse_signature(signature)\n local params, returns = \"\", \"\"\n local pm, rm = signature:match(\"^(%b())%s*(%(?.*%)?)\")\n params = pm ~= nil and pm or \"\"\n returns = rm ~= nil and rm or \"\"\n return params, returns\nend\n\nlocal function align_spaces(abbr, detail)\n if config.ls.gopls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.gopls(completion_item, ls)\n if config.ls.gopls.align_type_to_right then\n -- This makes no sense then.\n config.ls.gopls.add_colon_before_type = false\n end\n\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail then\n -- In unimported one, we remove useless information\n -- assign.Analyzer var from(\"golang.org/x/tools/go/analysis/passes/assign\")\n -- =>\n -- assign.Analyzer \"golang.org/x/tools/go/analysis/passes/assign\"\n local path = detail:match(\".*%(from(.*)%)\")\n if path then\n local highlight_name = utils.hl_by_kind(kind)\n local spaces = align_spaces(label, path)\n local text = label .. align_spaces(label, path) .. path\n return {\n text = text,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n {\n \"@string\",\n range = { #label + #spaces, #text },\n },\n },\n }\n end\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Gopls returns nested fields and methods as completions.\n -- To syntax highlight these, combine their final component\n -- with their detail.\n local name_offset = label:reverse():find(\"%.\") or 0\n if name_offset > 0 then\n name_offset = #label - name_offset + 2\n else\n name_offset = 0\n end\n\n if kind == Kind.Module and detail then\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"import %s\", text)\n return utils.highlight_range(source, ls, 7, 7 + #text)\n --\n elseif (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local var_part = text:sub(name_offset)\n local source = string.format(\"var %s\", var_part)\n local item = utils.highlight_range(source, ls, 4, 4 + #var_part)\n if kind == Kind.Constant then\n if #item.highlights >= 1 then\n item.highlights[1][1] = utils.hl_exist_or(\"@constant\", \"@variable\", \"go\")\n end\n end\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Struct then\n detail = \"struct{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s struct {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Interface then\n detail = \"interface{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s interface {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Field and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local source = string.format(\"type T struct { %s }\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 16, 16 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = vim.trim(detail)\n if detail:sub(1, 4) == \"func\" then\n signature = detail:sub(5)\n end\n\n local text = string.format(\"%s%s\", label, signature)\n if signature ~= \"()\" then\n local params, returns = parse_signature(signature)\n text = label .. params .. align_spaces(label, params .. returns) .. returns\n end\n\n local source = string.format(\"func %s {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n else\n -- Handle other kinds\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/php.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.intelephense(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local kind = completion_item.kind\n\n if (kind == Kind.Function or kind == Kind.Method) and detail and #detail > 0 then\n local signature = detail:sub(#label + 1)\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s 0 then\n detail = string.gsub(detail, \".*\\\\(.)\", \"%1\")\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s \".\n extra_info_hl = \"@comment\",\n -- the hl of leading dot of \"•std::filesystem::permissions(..)\"\n import_dot_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n roslyn = {\n extra_info_hl = \"@comment\",\n },\n -- The same applies to pyright/pylance\n basedpyright = {\n extra_info_hl = \"@comment\",\n },\n pylsp = {\n extra_info_hl = \"@comment\",\n -- Dim the function argument area, which is the main\n -- difference with pyright.\n arguments_hl = \"@comment\",\n },\n dartls = {\n extra_info_hl = \"@comment\",\n },\n fallback = true,\n fallback_extra_info_hl = \"@comment\",\n },\n fallback_highlight = \"@variable\",\n max_width = 60,\n}\n\nlocal hl_cache = {}\nlocal hl_cache_size = 0\n-- about 30M max memory usage.\nlocal MAX_HL_CACHE_SIZE = 10000\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return string\nlocal function cache_key(completion_item, ls)\n return string.format(\n \"%s!%s!%s!%s!%s%s\",\n completion_item.label or \"\",\n completion_item.detail or \"\",\n completion_item.labelDetails\n and (completion_item.labelDetails.detail or \"\") .. (completion_item.labelDetails.description or \"\")\n or \"\",\n completion_item.kind and tostring(completion_item.kind) or \"\",\n ls,\n require(\"colorful-menu.utils\").max_width()\n )\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nlocal function _highlights(completion_item, ls)\n if completion_item == nil or ls == nil or ls == \"\" or vim.b.ts_highlight == false then\n return nil\n end\n\n local item\n\n local key = cache_key(completion_item, ls)\n if hl_cache[key] ~= nil then\n return hl_cache[key]\n end\n\n if ls == \"gopls\" then\n item = require(\"colorful-menu.languages.go\").gopls(completion_item, ls)\n --\n elseif ls == \"rust-analyzer\" or ls == \"rust_analyzer\" then\n item = require(\"colorful-menu.languages.rust\").rust_analyzer(completion_item, ls)\n ls = \"rust-analyzer\"\n --\n elseif ls == \"lua_ls\" then\n item = require(\"colorful-menu.languages.lua\").lua_ls(completion_item, ls)\n --\n elseif ls == \"clangd\" then\n item = require(\"colorful-menu.languages.cpp\").clangd(completion_item, ls)\n --\n elseif ls == \"typescript-language-server\" or ls == \"ts_ls\" or ls == \"tsserver\" or ls == \"typescript-tools\" then\n item = require(\"colorful-menu.languages.typescript\").ts_server(completion_item, ls)\n --\n elseif ls == \"vtsls\" then\n item = require(\"colorful-menu.languages.typescript\").vtsls(completion_item, ls)\n --\n elseif ls == \"zls\" then\n item = require(\"colorful-menu.languages.zig\").zls(completion_item, ls)\n --\n elseif ls == \"intelephense\" then\n item = require(\"colorful-menu.languages.php\").intelephense(completion_item, ls)\n --\n elseif ls == \"roslyn\" then\n item = require(\"colorful-menu.languages.cs\").roslyn(completion_item, ls)\n --\n elseif ls == \"dartls\" then\n item = require(\"colorful-menu.languages.dart\").dartls(completion_item, ls)\n --\n elseif ls == \"basedpyright\" or ls == \"pyright\" or ls == \"pylance\" or ls == \"pylsp\" then\n item = require(\"colorful-menu.languages.python\").py(completion_item, ls)\n --\n else\n -- No languages detected so check if we should highlight with default or not\n if not M.config.ls.fallback then\n return nil\n end\n item = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail,\n nil,\n M.config.ls.fallback_extra_info_hl\n )\n end\n\n if item then\n item = require(\"colorful-menu.utils\").validate_newline(completion_item, item)\n require(\"colorful-menu.utils\").apply_post_processing(completion_item, item, ls)\n end\n\n hl_cache_size = hl_cache_size + 1\n if hl_cache_size > MAX_HL_CACHE_SIZE then\n hl_cache_size = 0\n hl_cache = {}\n end\n hl_cache[key] = item\n\n return item\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param entry cmp.Entry\nfunction M.cmp_highlights(entry)\n local client = vim.tbl_get(entry, \"source\", \"source\", \"client\") -- For example `lua_ls` etc\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n return _highlights(entry:get_completion_item(), client.name)\n end\n return nil\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_text(ctx)\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n return highlights_info.label\n else\n ---@diagnostic disable-next-line: undefined-field\n return ctx.label\n end\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_highlight(ctx)\n local highlights = {}\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n highlights = highlights_info.highlights\n end\n ---@diagnostic disable-next-line: undefined-field\n for _, idx in ipairs(ctx.label_matched_indices) do\n table.insert(highlights, { idx, idx + 1, group = \"BlinkCmpLabelMatch\" })\n end\n return highlights\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_highlights(ctx)\n ---@diagnostic disable-next-line: undefined-field\n local client = vim.lsp.get_client_by_id(ctx.item.client_id)\n local highlights = {}\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n local highlights_info = _highlights(ctx.item, client.name)\n if highlights_info ~= nil then\n for _, info in ipairs(highlights_info.highlights or {}) do\n table.insert(highlights, {\n info.range[1],\n info.range[2],\n ---@diagnostic disable-next-line: undefined-field\n group = ctx.deprecated and \"BlinkCmpLabelDeprecated\" or info[1],\n })\n end\n else\n return nil\n end\n return { label = highlights_info.text, highlights = highlights }\n end\n return nil\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nfunction M.highlights(completion_item, ls)\n if ls == vim.bo.filetype then\n vim.notify_once(\n \"colorful-menu.nvim: Integration with nvim-cmp or blink.cmp has been simplified, and legacy per-filetype options is also deprecated\"\n .. \" to prefer per-language-server options, please see README\",\n vim.log.levels.WARN\n )\n return nil\n end\n\n return _highlights(completion_item, ls)\nend\n\n---@param opts ColorfulMenuConfig\nfunction M.setup(opts)\n opts = opts or {}\n M.config = vim.tbl_deep_extend(\"force\", M.config, opts)\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/dart.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.dartls(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail ~= nil and detail:find(\"Auto\") ~= nil then\n detail = detail:gsub(\"Auto import.*\\n\\n\", \"\")\n detail = vim.split(detail:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n -- x int\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n -- var x int x\n local source = string.format(\"var %s x\", text)\n return utils.highlight_range(source, ls, 4, 4 + #text)\n --\n elseif (kind == Kind.Field or kind == Kind.Property) and detail then\n -- Here is the trick same as zls:\n -- xvoid( *Foo)\n -- x *Foo\n local source = string.format(\"%svoid(%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(source:sub(#label + 1), ls, 5, #source:sub(#label + 1) - 1)\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"dart\")\n )\n --\n elseif (kind == Kind.Function or kind == Kind.Method or kind == Kind.Constructor) and detail then\n -- elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n -- label: fetchData(..)\n -- detail: (int a, int b) -> Future\n -- fetchData(int a, int b);(Future s)\n local params = string.match(detail or \"\", \"^(%b())\")\n local type = string.match(detail or \"\", \"→ (.*)\")\n if params ~= nil then\n label = label:gsub(\"%b()$\", \"\") .. params\n end\n if type ~= nil and kind ~= Kind.Constructor then\n local text = string.format(\"%s%s;(%s)\", label, align_spaces(label, type):sub(3), type)\n local comma_pos = #text - #type - 3\n local ranges = utils.highlight_range(text, ls, 0, #text - 1)\n ranges.text = ranges.text:sub(1, comma_pos) .. \" \" .. ranges.text:sub(comma_pos + 3, #ranges.text)\n return ranges\n end\n return utils.highlight_range(label, ls, 0, #label)\n --\n else\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n detail,\n \"dart\",\n config.ls[ls].extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/python.lua", "local config = require(\"colorful-menu\").config\nlocal Kind = require(\"colorful-menu\").Kind\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@return CMHighlights\nlocal function pylsp(completion_item)\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n local hls = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.pylsp.extra_info_hl\n )\n if hls.text ~= nil and (completion_item.kind == Kind.Function or completion_item.kind == Kind.Method) then\n local s, e = string.find(hls.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(hls.highlights, {\n config.ls.pylsp.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return hls\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.py(completion_item, ls)\n if ls == \"pylsp\" then\n return pylsp(completion_item)\n else\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.basedpyright.extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/default.lua", "local utils = require(\"colorful-menu.utils\")\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param detail? string\n---@param lang? string\n---@param extra_info_hl? string\n---@return CMHighlights\nfunction M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n -- If there are any information, append it\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/repro_cmp.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n {\n \"hrsh7th/nvim-cmp\",\n lazy = false,\n dependencies = {\n \"hrsh7th/cmp-nvim-lsp\",\n {\n \"xzbdmw/colorful-menu.nvim\",\n config = function()\n require(\"colorful-menu\").setup({})\n end,\n },\n },\n config = function(_, opts)\n local cmp = require(\"cmp\")\n require(\"cmp\").setup({\n mapping = cmp.mapping.preset.insert({\n [\"\"] = cmp.mapping(function(fallback)\n if cmp.visible() then\n cmp.confirm()\n end\n end, { \"i\" }),\n }),\n completion = {\n completeopt = \"menu,menuone,noinsert\",\n },\n formatting = {\n format = function(entry, vim_item)\n local highlights_info = require(\"colorful-menu\").cmp_highlights(entry)\n if highlights_info ~= nil then\n vim_item.abbr_hl_group = highlights_info.highlights\n vim_item.abbr = highlights_info.text\n end\n return vim_item\n end,\n },\n sources = require(\"cmp\").config.sources({\n { name = \"nvim_lsp\" },\n }, {}),\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n capabilities = require(\"cmp_nvim_lsp\").default_capabilities(),\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n workspace = {\n library = {\n \"/usr/local/share/nvim/runtime\",\n },\n },\n completion = {\n callSnippet = \"Replace\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"], ["/colorful-menu.nvim/repro_blink.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n \"xzbdmw/colorful-menu.nvim\",\n {\n \"saghen/blink.cmp\",\n version = \"v0.*\",\n config = function()\n require(\"blink.cmp\").setup({\n completion = {\n menu = {\n draw = {\n -- We don't need label_description now because label and label_description are already\n -- conbined together in label by colorful-menu.nvim.\n columns = { { \"kind_icon\" }, { \"label\", gap = 1 } },\n components = {\n label = {\n text = require(\"colorful-menu\").blink_components_text,\n highlight = require(\"colorful-menu\").blink_components_highlight,\n },\n },\n },\n },\n },\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"]], "task_instance_info": {"created_time": "2025-08-21 00:42:04", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Dynamically assign syntax highlighting rules to code completion elements based on their semantic category and format specialized visual markers for specific data types."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nlocal function _lua_compute_completion_highlights(completion_item, ls)\n local vim_item = {\n highlights = {}\n }\n \n local label = completion_item.label or \"\"\n vim_item.text = label\n \n local kind = completion_item.kind or Kind.Unknown\n local hl = config.ls[ls][Kind[kind]]\n \n if hl then\n table.insert(vim_item.highlights, {\n hl,\n range = {0, #label}\n })\n end\n \n return vim_item\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-42-24"}, "editdistance_info": {"edit_distance": 18.2927, "calculate_time": "2025-08-21 00:42:24", "true_code_clean": "local function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend", "predict_code_clean": "local function _lua_compute_completion_highlights(completion_item, ls)\n local vim_item = {\n highlights = {}\n }\n local label = completion_item.label or \"\"\n vim_item.text = label\n local kind = completion_item.kind or Kind.Unknown\n local hl = config.ls[ls][Kind[kind]]\n if hl then\n table.insert(vim_item.highlights, {\n hl,\n range = {0, #label}\n })\n end\n return vim_item\nend"}} {"repo_name": "colorful-menu.nvim", "file_name": "/colorful-menu.nvim/lua/colorful-menu/languages/cs.lua", "inference_info": {"prefix_code": "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\n", "suffix_code": "\n\nreturn M\n", "middle_code": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/colorful-menu.nvim/lua/colorful-menu/languages/typescript.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.ts_server(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n local kind = completion_item.kind\n -- Combine label + detail for final display\n local text = (detail and config.ls.ts_ls.extra_info_hl ~= false) and (label .. \" \" .. detail) or label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if detail and config.ls.ts_ls.extra_info_hl ~= false then\n local extra_info_hl = config.ls.ts_ls.extra_info_hl\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #label + 1 + #detail },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\n-- see https://github.com/zed-industries/zed/pull/13043\n-- Untested.\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.vtsls(completion_item, ls)\n local function one_line(s)\n s = s:gsub(\" \", \"\")\n s = s:gsub(\"\\n\", \" \")\n return s\n end\n\n local label = completion_item.label\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local detail = completion_item.detail\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if config.ls.vtsls.extra_info_hl ~= false then\n if description then\n text = label .. \" \" .. one_line(description)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n elseif detail then\n text = label .. \" \" .. one_line(detail)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/cpp.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \"\"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal function path_align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _clangd(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.detail\n local labelDetails = completion_item.labelDetails\n\n -- If no kind, just fallback to highlighting the cleaned-up label\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Constants or Variables with detail => \"detail label\", highlight entire text\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {int x;std::unique_ptr x;}\n -- | |\n -- @variable |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ int %s x;}\", text)\n return utils.highlight_range(source, ls, 16, 16 + #text)\n\n -- Functions or Methods with detail => \"detail label\", might find '('\n elseif kind == Kind.Field and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {f->x;std::unique_ptr x;}\n -- | |\n -- @field |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ f->%s x;}\", text)\n return utils.highlight_range(source, ls, 15, 15 + #text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = \"\"\n if labelDetails and labelDetails.detail then\n signature = labelDetails.detail\n end\n local text = string.format(\n \"void %s%s;%s%s x;\",\n label,\n signature,\n align_spaces(label .. signature .. \";\", detail),\n detail\n )\n return utils.highlight_range(text, ls, 5, #text - 3)\n --\n else\n local highlight_name = nil\n local lang = vim.bo.filetype == \"c\" and \"c\" or \"cpp\"\n if kind == Kind.Struct or kind == Kind.Interface then\n highlight_name = \"@type\"\n elseif kind == Kind.Class then\n highlight_name = utils.hl_exist_or(\"@lsp.type.class\", \"@variant\", lang)\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@variant\", lang)\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n -- If we found a special highlight name, highlight the portion before '('\n if highlight_name then\n local paren_index = string.find(label, \"%(\", 1, true)\n local end_index = paren_index and (paren_index - 1) or #label\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { vim.startswith(label, \"•\") and 3 or 0, end_index },\n },\n },\n }\n end\n end\n\n return {\n text = label,\n highlights = {},\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.clangd(completion_item, ls)\n local vim_item = _clangd(completion_item, ls)\n local max_width = require(\"colorful-menu.utils\").max_width()\n if vim_item.text ~= nil then\n if vim.startswith(vim_item.text, \"•\") then\n table.insert(vim_item.highlights, 1, {\n config.ls.clangd.import_dot_hl,\n range = { 0, 3 },\n })\n end\n vim_item.text = vim_item.text:gsub(\";\", \" \")\n -- If it is already overflow, just return.\n if max_width and max_width > 0 then\n local display_width = vim.fn.strdisplaywidth(vim_item.text)\n if display_width >= max_width then\n return vim_item\n end\n end\n\n -- Append path.\n local document = completion_item.documentation\n if document and document.value and vim.startswith(document.value, \"From \") then\n local len = #vim_item.text\n local include_path = vim.trim(vim.split(document.value:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1])\n :sub(6, #document.value)\n if include_path:sub(1, 1) == \"`\" and include_path:sub(#include_path, #include_path) == \"`\" then\n include_path = include_path:sub(2, #include_path - 1)\n end\n local spaces = path_align_spaces(vim_item.text, include_path)\n vim_item.text = string.gsub(vim_item.text .. spaces .. include_path, \"\\n\", \" \")\n table.insert(vim_item.highlights, {\n config.ls.clangd.extra_info_hl,\n range = { len + #spaces, #vim_item.text },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/lua.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.lua_ls(completion_item, ls)\n local vim_item = _lua_compute_completion_highlights(completion_item, ls)\n if vim_item.text ~= nil then\n local s, e = string.find(vim_item.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls.lua_ls.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/rust.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal insertTextFormat = require(\"colorful-menu\").insertTextFormat\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal cashed_self_hl = nil\n---@return CMHighlightRange[]\nlocal function iter_chain()\n if cashed_self_hl == nil then\n local source = \"fn iter(){}\"\n local hl = utils.highlight_range(source, \"rust-analyzer\", 3, #source - 2)\n cashed_self_hl = hl.highlights\n end\n return cashed_self_hl\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _rust_analyzer(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local function_signature = completion_item.labelDetails and completion_item.labelDetails.description\n or completion_item.detail\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(completion_item.label, ls, 0, #completion_item.label)\n end\n\n if kind == Kind.Field and detail then\n local name = completion_item.label\n local text = string.format(\"%s:%s%s\", name, align_spaces(name .. \" \", detail), detail)\n local source = string.format(\"struct S { %s }\", text)\n local hl = utils.highlight_range(source, ls, 11, 11 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif\n completion_item.insertTextFormat == insertTextFormat.Snippet\n and (label:find(\"::\", nil, true) ~= nil or label == \"Some(…)\" or label == \"None\" or label == \"Ok(…)\" or label == \"Err(…)\")\n and label:sub(1, 1) >= \"A\"\n and label:sub(1, 1) <= \"Z\"\n then\n local source = string.format(\"match s { %s }\", label)\n return utils.highlight_range(source, ls, 10, 10 + #label)\n elseif\n (kind == Kind.Constant or kind == Kind.Variable)\n and detail\n and completion_item.insertTextFormat ~= insertTextFormat.Snippet\n then\n local name = completion_item.label\n local text = string.format(\n \"%s:%s%s\",\n name,\n align_spaces(name .. \" \", completion_item.detail),\n completion_item.detail or detail\n )\n local source = string.format(\"let %s = ();\", text)\n local hl = utils.highlight_range(source, ls, 4, 4 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif (kind == Kind.EnumMember) and detail then\n local source = string.format(\"enum S { %s }\", detail)\n return utils.highlight_range(source, ls, 9, 9 + #detail)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local pattern = \"%((.-)%)\"\n\n local ignored = nil\n if label:match(\"^iter%(%)%..+\") ~= nil then\n ignored = \"iter().\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n if label:match(\"^self%..+\") ~= nil then\n ignored = \"self.\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n local function adjust(hl)\n if ignored == \"self.\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored)\n elseif ignored == \"iter().\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored, nil, iter_chain())\n end\n end\n\n local result = string.match(label, pattern)\n if not result then\n label = label .. \"()\"\n end\n local regex_pattern = \"%b()\"\n local prefix, suffix = string.match(function_signature or \"\", \"^(.*fn)(.*)$\")\n if prefix ~= nil and suffix ~= nil then\n local start_pos = string.find(suffix, \"(\", nil, true)\n if start_pos then\n suffix = suffix:sub(start_pos, #suffix)\n end\n\n if\n config.ls[\"rust-analyzer\"].preserve_type_when_truncate\n and config.ls[\"rust-analyzer\"].align_type_to_right\n then\n local params, type = string.match(suffix, \"(%b()) %-> (.*)\")\n if params == nil and type == nil then\n params = suffix\n type = \"\"\n end\n local call, num_subs = string.gsub(label, regex_pattern, params, 1)\n if num_subs == 0 then\n call = completion_item.label\n end\n local source = string.format(\n \"%s %s->%s%s{}\",\n prefix,\n call,\n align_spaces(call .. \" \", ignored ~= nil and type .. ignored or type),\n type or \"\"\n )\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 2)\n hl.text = hl.text:sub(1, #call) .. \" \" .. hl.text:sub(#call + 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n else\n local call, num_subs = string.gsub(label, regex_pattern, suffix, 1)\n if num_subs == 0 then\n call = label\n end\n local source = string.format(\"%s %s {}\", prefix, call)\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n end\n else\n -- Check if the detail starts with \"macro_rules! \"\n if completion_item.detail and vim.startswith(completion_item.detail, \"macro\") then\n local source = completion_item.label\n return utils.highlight_range(source, ls, 0, #source)\n else\n -- simd_swizzle!()\n return {\n text = completion_item.label,\n highlights = {\n {\n config.fallback_highlight,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Struct then\n highlight_name = \"@type\"\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", \"rust\")\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@constant\", \"rust\")\n elseif kind == Kind.Interface then\n highlight_name = utils.hl_exist_or(\"@lsp.type.interface\", \"@type\", \"rust\")\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n if detail then\n detail = vim.trim(detail)\n if vim.startswith(detail, \"(\") then\n local space = align_spaces(completion_item.label, detail)\n return {\n text = completion_item.label .. space .. detail,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { #completion_item.label + #space, #completion_item.label + #space + #detail },\n },\n },\n }\n end\n end\n\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.rust_analyzer(completion_item, ls)\n local vim_item = _rust_analyzer(completion_item, ls)\n if vim_item.text ~= nil then\n for _, match in ipairs({ \"%(use .-%)\", \"%(as .-%)\", \"%(alias .-%)\" }) do\n local s, e = string.find(vim_item.text, match)\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { s - 1, e },\n })\n end\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/zig.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.zls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.zls(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n or (completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail)\n if detail ~= nil then\n detail = vim.split(detail, \"\\n\")[1]\n end\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable or kind == Kind.Struct or kind == Kind.Enum) and detail then\n if detail == \"type\" then\n local source = string.format(\"fn(s: %s)\", label)\n return utils.highlight_range(source, ls, 6, 6 + #label)\n else\n local text = string.format(\"%s:%s%s\", label, align_spaces(label, detail .. \" \"), detail)\n local source = string.format(\"fn(%s)\", text)\n local hl = utils.highlight_range(source, ls, 3, 3 + #text)\n for _, highlight in ipairs(hl.highlights) do\n if vim.startswith(highlight[1], \"@variable.parameter\") then\n highlight[1] = highlight[1]:gsub(\"%.parameter\", \"\")\n end\n end\n if config.ls.zls.align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #label) .. \" \" .. hl.text:sub(#label + 2, #text)\n return hl\n end\n --\n elseif (kind == Kind.Field or kind == Kind.EnumMember) and detail then\n -- For some reason `const x = struct { name: *Foo }` can't get the type color for Foo.\n -- Here is the trick:\n -- xfn(foo: *Foo)\n -- x *Foo\n local source = string.format(\"%sfn(foo:%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(\n source:sub(#label + 1),\n ls,\n config.ls.zls.align_type_to_right and 7 or 6,\n #source:sub(#label + 1) - 1\n )\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n )\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n if detail:sub(1, 2) == \"fn\" then\n local ret_type = vim.split(\n (vim.tbl_get(completion_item, \"labelDetails\", \"description\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"),\n \"\\n\"\n )[1]\n local params =\n vim.split((vim.tbl_get(completion_item, \"labelDetails\", \"detail\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n local text, source\n if ret_type ~= \"\" and params ~= \"\" and config.ls.zls.align_type_to_right then\n text = string.format(\"%s%s%s%s\", label, params, align_spaces(label .. params, ret_type), ret_type)\n source = string.format(\"fn %s {}\", text)\n else\n local signature = detail:sub(4)\n text = string.format(\"%s%s\", label, signature)\n source = string.format(\"fn %s {}\", text)\n end\n return utils.highlight_range(source, ls, 3, 3 + #text)\n elseif detail:sub(1, 1) == \"@\" then\n return utils.highlight_range(detail, ls, 0, #detail)\n else\n return {\n text = completion_item.label,\n highlights = {\n {\n \"@function\",\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Field then\n highlight_name = utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/php.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.intelephense(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local kind = completion_item.kind\n\n if (kind == Kind.Function or kind == Kind.Method) and detail and #detail > 0 then\n local signature = detail:sub(#label + 1)\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s 0 then\n detail = string.gsub(detail, \".*\\\\(.)\", \"%1\")\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s \n -- assign.Analyzer \"golang.org/x/tools/go/analysis/passes/assign\"\n local path = detail:match(\".*%(from(.*)%)\")\n if path then\n local highlight_name = utils.hl_by_kind(kind)\n local spaces = align_spaces(label, path)\n local text = label .. align_spaces(label, path) .. path\n return {\n text = text,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n {\n \"@string\",\n range = { #label + #spaces, #text },\n },\n },\n }\n end\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Gopls returns nested fields and methods as completions.\n -- To syntax highlight these, combine their final component\n -- with their detail.\n local name_offset = label:reverse():find(\"%.\") or 0\n if name_offset > 0 then\n name_offset = #label - name_offset + 2\n else\n name_offset = 0\n end\n\n if kind == Kind.Module and detail then\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"import %s\", text)\n return utils.highlight_range(source, ls, 7, 7 + #text)\n --\n elseif (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local var_part = text:sub(name_offset)\n local source = string.format(\"var %s\", var_part)\n local item = utils.highlight_range(source, ls, 4, 4 + #var_part)\n if kind == Kind.Constant then\n if #item.highlights >= 1 then\n item.highlights[1][1] = utils.hl_exist_or(\"@constant\", \"@variable\", \"go\")\n end\n end\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Struct then\n detail = \"struct{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s struct {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Interface then\n detail = \"interface{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s interface {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Field and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local source = string.format(\"type T struct { %s }\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 16, 16 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = vim.trim(detail)\n if detail:sub(1, 4) == \"func\" then\n signature = detail:sub(5)\n end\n\n local text = string.format(\"%s%s\", label, signature)\n if signature ~= \"()\" then\n local params, returns = parse_signature(signature)\n text = label .. params .. align_spaces(label, params .. returns) .. returns\n end\n\n local source = string.format(\"func %s {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n else\n -- Handle other kinds\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/utils.lua", "local Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal query_cache = {}\n\n---@param str string\n---@param ls string\n---@return CMHighlights\nlocal function compute_highlights(str, ls)\n local highlights = {}\n\n local lang = vim.treesitter.language.get_lang(vim.bo.filetype)\n if not lang then\n return {}\n end\n\n local query, ok\n if query_cache[ls] == nil then\n ok, query = pcall(vim.treesitter.query.get, lang, \"highlights\")\n if not ok then\n return {}\n end\n query_cache[ls] = query\n else\n query = query_cache[ls]\n end\n\n ---@diagnostic disable-next-line: redefined-local\n local ok, parser = pcall(vim.treesitter.get_string_parser, str, lang)\n if not ok then\n return {}\n end\n\n if not parser then\n vim.notify(string.format(\"No Tree-sitter parser found for filetype: %s\", lang), vim.log.levels.WARN)\n return highlights\n end\n\n -- Parse the string\n local tree = parser:parse(true)[1]\n if not tree then\n vim.notify(\"Failed to parse the string with Tree-sitter.\", vim.log.levels.ERROR)\n return {}\n end\n\n local root = tree:root()\n\n if not query then\n return {}\n end\n\n -- Iterate over all captures in the query\n for id, node in query:iter_captures(root, str, 0, -1) do\n local name = \"@\" .. query.captures[id] .. \".\" .. lang\n local range = { node:range() }\n local _, nscol, _, necol = range[1], range[2], range[3], range[4]\n table.insert(highlights, {\n hl_group = name,\n range = { nscol, necol },\n })\n end\n\n return highlights\nend\n\n-- `left` is inclusive and `right` is exclusive (also zero indexed), to better fit\n-- `nvim_buf_set_extmark` semantic, so `M.highlight_range(text, ft, 0, #text)` is the entire range.\n--\n---@param text string\n---@param ls string\n---@param left integer\n---@param right integer\n---@return CMHighlights\nfunction M.highlight_range(text, ls, left, right)\n local highlights = {}\n local full_hl = compute_highlights(text, ls)\n\n for _, hl in ipairs(full_hl) do\n local s, e = hl.range[1], hl.range[2]\n if e < left then\n goto continue\n end\n if s > right or e > right + 1 then\n break\n end\n\n table.insert(highlights, {\n hl.hl_group,\n range = { hl.range[1] - left, hl.range[2] - left },\n text = text:sub(s + 1, e),\n })\n ::continue::\n end\n\n return {\n text = text:sub(left + 1, right),\n highlights = highlights,\n }\nend\n\n-- Shift a highlight range right by name_offset,\n-- insert a color with fallback_hl for label with range (0, name_offset).\n---@param item CMHighlights\n---@param name_offset integer\n---@param label string\n---@param fallback_hl string?\n---@param custom_hl CMHighlightRange[]?\n---@return CMHighlights\nfunction M.adjust_range(item, name_offset, label, fallback_hl, custom_hl)\n if name_offset == 0 then\n return item\n end\n name_offset = name_offset - 1\n for _, highlight in ipairs(item.highlights) do\n highlight.range[1] = highlight.range[1] + name_offset\n highlight.range[2] = highlight.range[2] + name_offset\n end\n item.text = label:sub(1, name_offset) .. item.text\n if custom_hl then\n for _, hl in ipairs(custom_hl) do\n table.insert(item.highlights, hl)\n end\n else\n table.insert(item.highlights, {\n fallback_hl or \"@variable\",\n range = { 0, name_offset },\n })\n end\n return item\nend\n\n---@param hl_group string\n---@param fallback string\n---@param lang? string\nfunction M.hl_exist_or(hl_group, fallback, lang)\n local f = function()\n local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = hl_group })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return hl_group\n end\n return fallback\n end\n\n local ok, hl\n if lang ~= nil then\n local lang_hl = hl_group .. \".\" .. lang\n ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = lang_hl })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return lang_hl\n else\n return f()\n end\n else\n return f()\n end\nend\n\n---@param kind? integer\n---@param lang? string\n---@return string\nfunction M.hl_by_kind(kind, lang)\n local highlight_name\n if kind == Kind.Method then\n highlight_name = M.hl_exist_or(\"@lsp.type.method\", \"@function\", lang)\n elseif kind == Kind.Function then\n highlight_name = M.hl_exist_or(\"@lsp.type.function\", \"@function\", lang)\n elseif kind == Kind.Constructor then\n highlight_name = \"@constructor\"\n elseif kind == Kind.Variable then\n highlight_name = M.hl_exist_or(\"@lsp.type.variable\", \"@variable\", lang)\n elseif kind == Kind.Field then\n highlight_name = M.hl_exist_or(\"@lsp.type.field\", \"@field\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Property then\n highlight_name = M.hl_exist_or(\"@lsp.type.property\", \"@property\", lang)\n elseif kind == Kind.Module then\n highlight_name = M.hl_exist_or(\"@lsp.type.namespace\", \"@namespace\", lang)\n elseif kind == Kind.Class then\n highlight_name = M.hl_exist_or(\"@lsp.type.class\", \"@type\", lang)\n elseif kind == Kind.Struct then\n highlight_name = M.hl_exist_or(\"@lsp.type.struct\", \"@type\", lang)\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return highlight_name\nend\n\n---@param item CMHighlights\n---@param rang {left:integer, right:integer}\nlocal function remove_color_in_range(item, rang)\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local r = hl.range\n if r[1] > rang.left and r[1] < rang.right then\n table.remove(item.highlights, i)\n elseif r[1] <= rang.left and r[2] > rang.left then\n r[2] = rang.left\n end\n end\nend\n\nlocal function left_brace_one_more_than_right_brace(s)\n local left = 0\n local right = 0\n for i = 1, #s do\n local char = s:sub(i, i)\n if char == \"(\" then\n left = left + 1\n elseif char == \")\" then\n right = right + 1\n end\n end\n return left == right + 1\nend\n\n---@param item CMHighlights\n---@param max_width integer\n---@param direct boolean -- without type info\nlocal function cut_label(item, max_width, direct)\n if vim.fn.strdisplaywidth(item.text) <= max_width then\n return\n end\n local text = item.text\n --- Given\n --- self.foo(asdasd)\n --- self.foo(asdasd…\n --- self.foo(asdas…)\n if direct and left_brace_one_more_than_right_brace(vim.fn.strcharpart(text, 0, max_width)) then\n local truncated = vim.fn.strcharpart(text, 0, max_width - 2) .. \"…)\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 4, truncated_width - 1 },\n })\n table.insert(item.highlights, {\n \"@punctuation.bracket\",\n range = { truncated_width - 1, truncated_width },\n })\n else\n local truncated = vim.fn.strcharpart(text, 0, max_width - 1) .. \"…\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 3, truncated_width },\n })\n end\nend\n\n---@param item CMHighlights\n---@param offset integer\n---@param start integer\nlocal function shift_color_by(item, offset, start)\n for _, highlight in ipairs(item.highlights) do\n if highlight.range[1] > start then\n highlight.range[1] = highlight.range[1] - offset\n highlight.range[2] = highlight.range[2] - offset\n end\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param item CMHighlights\nfunction M.validate_newline(completion_item, item)\n if string.find(item.text, \"\\n\") ~= nil or string.find(item.text, \"\\r\") ~= nil then\n vim.notify_once(\n '[colorful-menu.nvim]: Completion \"'\n .. completion_item.label\n .. '\" has new line character, please open an issue',\n vim.log.levels.WARN\n )\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n nil,\n nil,\n require(\"colorful-menu\").config.ls.fallback_extra_info_hl\n )\n end\n return item\nend\n\n---@param item CMHighlights\n---@param ls string\n---@return CMHighlights?\nfunction M.apply_post_processing(completion_item, item, ls)\n -- if the user override or fallback logic didn't produce a table, bail\n if type(item) ~= \"table\" or not item.text then\n return item\n end\n\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local range = hl.range\n if range[2] < 0 then\n table.remove(item.highlights, i)\n elseif range[1] < 0 then\n range[1] = 0\n end\n end\n\n local max_width = require(\"colorful-menu.utils\").max_width()\n if not (max_width and max_width > 0) then\n return\n end\n\n local label = completion_item.label\n local display_width = vim.fn.strdisplaywidth(item.text)\n if display_width > (item.text:find(\"\\7\") ~= nil and (max_width + 1) or max_width) then\n local long_label, type = item.text:match(\"(.*)\\7%s*(.*)\")\n local is_func = completion_item.kind == Kind.Function or completion_item.kind == Kind.Method\n if\n item.text == label\n or type == nil\n or #type == 0\n or not is_func\n or not config.ls[ls]\n or not config.ls[ls].preserve_type_when_truncate\n then\n item.text = item.text:gsub(\"\\7\", \" \")\n cut_label(item, max_width, is_func)\n return\n end\n\n local _, le = item.text:find(\"\\7\")\n local ts = item.text:find(type, le, true)\n local space_between = ts - le\n item.text = item.text:gsub(\"\\7\", \" \")\n\n -- Now we need to deal with color shifting stuff.\n -- Foo(a string b string) \"some random stuff\"\n -- | | | |\n -- long_label_width type_width\n --\n -- | short | | type_width |\n -- Foo(a st… \"some random stuff\"\n -- | max_width |\n local long_label_width, type_width = #long_label, #type\n local short_label_width = math.max(max_width - type_width - 2 - space_between, #label)\n local should_cut_all = short_label_width == #label\n if should_cut_all then\n remove_color_in_range(item, { left = short_label_width, right = long_label_width })\n local pretty_end = \"(…)\"\n if label:sub(short_label_width, short_label_width) == \")\" then\n pretty_end = \"…)\"\n end\n shift_color_by(item, long_label_width - short_label_width - string.len(pretty_end), long_label_width)\n item.text = item.text:sub(1, short_label_width) .. pretty_end .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = {\n short_label_width + (pretty_end == \"(…)\" and 1 or 0),\n short_label_width + (pretty_end == \"(…)\" and string.len(\"…)\") or string.len(\"…\")),\n },\n })\n cut_label(item, max_width, false)\n else\n -- Caculate display_width and real byte diff.\n local diff = short_label_width - vim.fn.strdisplaywidth(item.text:sub(1, short_label_width))\n -- We increase the cut threshold if display_width is lower than\n -- byte count, otherwise the hole is not enough.\n short_label_width = short_label_width + diff\n local ascii_pos = short_label_width\n for i = short_label_width, 1, -1 do\n if item.text:sub(i, i):match(\"[a-zA-Z(]\") ~= nil then\n ascii_pos = i\n break\n end\n end\n remove_color_in_range(item, { left = ascii_pos, right = long_label_width })\n shift_color_by(item, long_label_width - short_label_width - string.len(\"…)\"), long_label_width)\n item.text = item.text:sub(1, ascii_pos)\n .. \"…)\"\n .. string.rep(\" \", short_label_width - ascii_pos)\n .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = { ascii_pos, ascii_pos + string.len(\"…)\") - 1 },\n })\n end\n else\n item.text = item.text:gsub(\"\\7\", \" \")\n end\nend\n\nfunction M.align_spaces_bell(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \"\\7 \"\n end\n return \"\\7\" .. string.rep(\" \", blank - 1)\nend\n\nfunction M.align_spaces(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \" \"\n end\n return string.rep(\" \", blank)\nend\n\nfunction M.max_width()\n local max_width = config.max_width\n if max_width < 1 and max_width > 0 then\n max_width = math.floor(max_width * vim.api.nvim_win_get_width(0))\n end\n return max_width\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/dart.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.dartls(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail ~= nil and detail:find(\"Auto\") ~= nil then\n detail = detail:gsub(\"Auto import.*\\n\\n\", \"\")\n detail = vim.split(detail:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n -- x int\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n -- var x int x\n local source = string.format(\"var %s x\", text)\n return utils.highlight_range(source, ls, 4, 4 + #text)\n --\n elseif (kind == Kind.Field or kind == Kind.Property) and detail then\n -- Here is the trick same as zls:\n -- xvoid( *Foo)\n -- x *Foo\n local source = string.format(\"%svoid(%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(source:sub(#label + 1), ls, 5, #source:sub(#label + 1) - 1)\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"dart\")\n )\n --\n elseif (kind == Kind.Function or kind == Kind.Method or kind == Kind.Constructor) and detail then\n -- elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n -- label: fetchData(..)\n -- detail: (int a, int b) -> Future\n -- fetchData(int a, int b);(Future s)\n local params = string.match(detail or \"\", \"^(%b())\")\n local type = string.match(detail or \"\", \"→ (.*)\")\n if params ~= nil then\n label = label:gsub(\"%b()$\", \"\") .. params\n end\n if type ~= nil and kind ~= Kind.Constructor then\n local text = string.format(\"%s%s;(%s)\", label, align_spaces(label, type):sub(3), type)\n local comma_pos = #text - #type - 3\n local ranges = utils.highlight_range(text, ls, 0, #text - 1)\n ranges.text = ranges.text:sub(1, comma_pos) .. \" \" .. ranges.text:sub(comma_pos + 3, #ranges.text)\n return ranges\n end\n return utils.highlight_range(label, ls, 0, #label)\n --\n else\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n detail,\n \"dart\",\n config.ls[ls].extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/init.lua", "local M = {}\n\nM.insertTextFormat = { PlainText = 1, Snippet = 2 }\n-- stylua: ignore\nM.Kind = { Text = 1, Method = 2, Function = 3, Constructor = 4, Field = 5, Variable = 6, Class = 7, Interface = 8, Module = 9, Property = 10, Unit = 11, Value = 12, Enum = 13, Keyword = 14, Snippet = 15, Color = 16, File = 17, Reference = 18, Folder = 19, EnumMember = 20, Constant = 21, Struct = 22, Event = 23, Operator = 24, TypeParameter = 25 }\n\n---@alias CMHighlightRange {hl_group: string, range: integer[], text: string}\n---\n---@class CMHighlights\n---@field text string\n---@field highlights CMHighlightRange[]\n\n---@class ColorfulMenuConfig\nM.config = {\n ls = {\n lua_ls = {\n -- Maybe you want to dim arguments a bit.\n arguments_hl = \"@comment\",\n },\n gopls = {\n -- When true, label for field and variable will format like \"foo: Foo\"\n -- instead of go's original syntax \"foo Foo\".\n add_colon_before_type = false,\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n ts_ls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n vtsls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n zls = {\n align_type_to_right = true,\n },\n [\"rust-analyzer\"] = {\n -- Such as (as Iterator), (use std::io).\n extra_info_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n clangd = {\n -- Such as \"\".\n extra_info_hl = \"@comment\",\n -- the hl of leading dot of \"•std::filesystem::permissions(..)\"\n import_dot_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n roslyn = {\n extra_info_hl = \"@comment\",\n },\n -- The same applies to pyright/pylance\n basedpyright = {\n extra_info_hl = \"@comment\",\n },\n pylsp = {\n extra_info_hl = \"@comment\",\n -- Dim the function argument area, which is the main\n -- difference with pyright.\n arguments_hl = \"@comment\",\n },\n dartls = {\n extra_info_hl = \"@comment\",\n },\n fallback = true,\n fallback_extra_info_hl = \"@comment\",\n },\n fallback_highlight = \"@variable\",\n max_width = 60,\n}\n\nlocal hl_cache = {}\nlocal hl_cache_size = 0\n-- about 30M max memory usage.\nlocal MAX_HL_CACHE_SIZE = 10000\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return string\nlocal function cache_key(completion_item, ls)\n return string.format(\n \"%s!%s!%s!%s!%s%s\",\n completion_item.label or \"\",\n completion_item.detail or \"\",\n completion_item.labelDetails\n and (completion_item.labelDetails.detail or \"\") .. (completion_item.labelDetails.description or \"\")\n or \"\",\n completion_item.kind and tostring(completion_item.kind) or \"\",\n ls,\n require(\"colorful-menu.utils\").max_width()\n )\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nlocal function _highlights(completion_item, ls)\n if completion_item == nil or ls == nil or ls == \"\" or vim.b.ts_highlight == false then\n return nil\n end\n\n local item\n\n local key = cache_key(completion_item, ls)\n if hl_cache[key] ~= nil then\n return hl_cache[key]\n end\n\n if ls == \"gopls\" then\n item = require(\"colorful-menu.languages.go\").gopls(completion_item, ls)\n --\n elseif ls == \"rust-analyzer\" or ls == \"rust_analyzer\" then\n item = require(\"colorful-menu.languages.rust\").rust_analyzer(completion_item, ls)\n ls = \"rust-analyzer\"\n --\n elseif ls == \"lua_ls\" then\n item = require(\"colorful-menu.languages.lua\").lua_ls(completion_item, ls)\n --\n elseif ls == \"clangd\" then\n item = require(\"colorful-menu.languages.cpp\").clangd(completion_item, ls)\n --\n elseif ls == \"typescript-language-server\" or ls == \"ts_ls\" or ls == \"tsserver\" or ls == \"typescript-tools\" then\n item = require(\"colorful-menu.languages.typescript\").ts_server(completion_item, ls)\n --\n elseif ls == \"vtsls\" then\n item = require(\"colorful-menu.languages.typescript\").vtsls(completion_item, ls)\n --\n elseif ls == \"zls\" then\n item = require(\"colorful-menu.languages.zig\").zls(completion_item, ls)\n --\n elseif ls == \"intelephense\" then\n item = require(\"colorful-menu.languages.php\").intelephense(completion_item, ls)\n --\n elseif ls == \"roslyn\" then\n item = require(\"colorful-menu.languages.cs\").roslyn(completion_item, ls)\n --\n elseif ls == \"dartls\" then\n item = require(\"colorful-menu.languages.dart\").dartls(completion_item, ls)\n --\n elseif ls == \"basedpyright\" or ls == \"pyright\" or ls == \"pylance\" or ls == \"pylsp\" then\n item = require(\"colorful-menu.languages.python\").py(completion_item, ls)\n --\n else\n -- No languages detected so check if we should highlight with default or not\n if not M.config.ls.fallback then\n return nil\n end\n item = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail,\n nil,\n M.config.ls.fallback_extra_info_hl\n )\n end\n\n if item then\n item = require(\"colorful-menu.utils\").validate_newline(completion_item, item)\n require(\"colorful-menu.utils\").apply_post_processing(completion_item, item, ls)\n end\n\n hl_cache_size = hl_cache_size + 1\n if hl_cache_size > MAX_HL_CACHE_SIZE then\n hl_cache_size = 0\n hl_cache = {}\n end\n hl_cache[key] = item\n\n return item\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param entry cmp.Entry\nfunction M.cmp_highlights(entry)\n local client = vim.tbl_get(entry, \"source\", \"source\", \"client\") -- For example `lua_ls` etc\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n return _highlights(entry:get_completion_item(), client.name)\n end\n return nil\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_text(ctx)\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n return highlights_info.label\n else\n ---@diagnostic disable-next-line: undefined-field\n return ctx.label\n end\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_highlight(ctx)\n local highlights = {}\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n highlights = highlights_info.highlights\n end\n ---@diagnostic disable-next-line: undefined-field\n for _, idx in ipairs(ctx.label_matched_indices) do\n table.insert(highlights, { idx, idx + 1, group = \"BlinkCmpLabelMatch\" })\n end\n return highlights\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_highlights(ctx)\n ---@diagnostic disable-next-line: undefined-field\n local client = vim.lsp.get_client_by_id(ctx.item.client_id)\n local highlights = {}\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n local highlights_info = _highlights(ctx.item, client.name)\n if highlights_info ~= nil then\n for _, info in ipairs(highlights_info.highlights or {}) do\n table.insert(highlights, {\n info.range[1],\n info.range[2],\n ---@diagnostic disable-next-line: undefined-field\n group = ctx.deprecated and \"BlinkCmpLabelDeprecated\" or info[1],\n })\n end\n else\n return nil\n end\n return { label = highlights_info.text, highlights = highlights }\n end\n return nil\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nfunction M.highlights(completion_item, ls)\n if ls == vim.bo.filetype then\n vim.notify_once(\n \"colorful-menu.nvim: Integration with nvim-cmp or blink.cmp has been simplified, and legacy per-filetype options is also deprecated\"\n .. \" to prefer per-language-server options, please see README\",\n vim.log.levels.WARN\n )\n return nil\n end\n\n return _highlights(completion_item, ls)\nend\n\n---@param opts ColorfulMenuConfig\nfunction M.setup(opts)\n opts = opts or {}\n M.config = vim.tbl_deep_extend(\"force\", M.config, opts)\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/default.lua", "local utils = require(\"colorful-menu.utils\")\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param detail? string\n---@param lang? string\n---@param extra_info_hl? string\n---@return CMHighlights\nfunction M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n -- If there are any information, append it\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/python.lua", "local config = require(\"colorful-menu\").config\nlocal Kind = require(\"colorful-menu\").Kind\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@return CMHighlights\nlocal function pylsp(completion_item)\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n local hls = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.pylsp.extra_info_hl\n )\n if hls.text ~= nil and (completion_item.kind == Kind.Function or completion_item.kind == Kind.Method) then\n local s, e = string.find(hls.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(hls.highlights, {\n config.ls.pylsp.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return hls\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.py(completion_item, ls)\n if ls == \"pylsp\" then\n return pylsp(completion_item)\n else\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.basedpyright.extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/repro_cmp.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n {\n \"hrsh7th/nvim-cmp\",\n lazy = false,\n dependencies = {\n \"hrsh7th/cmp-nvim-lsp\",\n {\n \"xzbdmw/colorful-menu.nvim\",\n config = function()\n require(\"colorful-menu\").setup({})\n end,\n },\n },\n config = function(_, opts)\n local cmp = require(\"cmp\")\n require(\"cmp\").setup({\n mapping = cmp.mapping.preset.insert({\n [\"\"] = cmp.mapping(function(fallback)\n if cmp.visible() then\n cmp.confirm()\n end\n end, { \"i\" }),\n }),\n completion = {\n completeopt = \"menu,menuone,noinsert\",\n },\n formatting = {\n format = function(entry, vim_item)\n local highlights_info = require(\"colorful-menu\").cmp_highlights(entry)\n if highlights_info ~= nil then\n vim_item.abbr_hl_group = highlights_info.highlights\n vim_item.abbr = highlights_info.text\n end\n return vim_item\n end,\n },\n sources = require(\"cmp\").config.sources({\n { name = \"nvim_lsp\" },\n }, {}),\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n capabilities = require(\"cmp_nvim_lsp\").default_capabilities(),\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n workspace = {\n library = {\n \"/usr/local/share/nvim/runtime\",\n },\n },\n completion = {\n callSnippet = \"Replace\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"], ["/colorful-menu.nvim/repro_blink.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n \"xzbdmw/colorful-menu.nvim\",\n {\n \"saghen/blink.cmp\",\n version = \"v0.*\",\n config = function()\n require(\"blink.cmp\").setup({\n completion = {\n menu = {\n draw = {\n -- We don't need label_description now because label and label_description are already\n -- conbined together in label by colorful-menu.nvim.\n columns = { { \"kind_icon\" }, { \"label\", gap = 1 } },\n components = {\n label = {\n text = require(\"colorful-menu\").blink_components_text,\n highlight = require(\"colorful-menu\").blink_components_highlight,\n },\n },\n },\n },\n },\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"]], "task_instance_info": {"created_time": "2025-08-21 00:42:04", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Categorize language elements by syntactic type and apply visual formatting rules to composite text components with contextual metadata."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nfunction M.get_kind_highlights(completion_item, ls)\n local kind = Kind.get(completion_item.kind or 1)\n local icon = config.icons[kind]\n return {\n parts = {\n { color = icon.color, text = icon.icon .. \" \" },\n { color = config.colors.default, text = ls },\n }\n }\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-42-30"}, "editdistance_info": {"edit_distance": 11.6505, "calculate_time": "2025-08-21 00:42:30", "true_code_clean": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "predict_code_clean": "function M.get_kind_highlights(completion_item, ls)\n local kind = Kind.get(completion_item.kind or 1)\n local icon = config.icons[kind]\n return {\n parts = {\n { color = icon.color, text = icon.icon .. \" \" },\n { color = config.colors.default, text = ls },\n }\n }\nend"}} {"repo_name": "colorful-menu.nvim", "file_name": "/colorful-menu.nvim/lua/colorful-menu/languages/cs.lua", "inference_info": {"prefix_code": "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\n", "suffix_code": "\n\nreturn M\n", "middle_code": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/colorful-menu.nvim/lua/colorful-menu/languages/typescript.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.ts_server(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n local kind = completion_item.kind\n -- Combine label + detail for final display\n local text = (detail and config.ls.ts_ls.extra_info_hl ~= false) and (label .. \" \" .. detail) or label\n\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n if detail and config.ls.ts_ls.extra_info_hl ~= false then\n local extra_info_hl = config.ls.ts_ls.extra_info_hl\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #label + 1 + #detail },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\n-- see https://github.com/zed-industries/zed/pull/13043\n-- Untested.\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.vtsls(completion_item, ls)\n local function one_line(s)\n s = s:gsub(\" \", \"\")\n s = s:gsub(\"\\n\", \" \")\n return s\n end\n\n local label = completion_item.label\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n else\n highlight_name = config.fallback_highlight\n end\n\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local detail = completion_item.detail\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n local text = label\n if config.ls.vtsls.extra_info_hl ~= false then\n if description then\n text = label .. \" \" .. one_line(description)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n elseif detail then\n text = label .. \" \" .. one_line(detail)\n table.insert(highlights, {\n config.ls.vtsls.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/cpp.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \"\"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal function path_align_spaces(abbr, detail)\n if config.ls.clangd.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _clangd(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.detail\n local labelDetails = completion_item.labelDetails\n\n -- If no kind, just fallback to highlighting the cleaned-up label\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Constants or Variables with detail => \"detail label\", highlight entire text\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {int x;std::unique_ptr x;}\n -- | |\n -- @variable |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ int %s x;}\", text)\n return utils.highlight_range(source, ls, 16, 16 + #text)\n\n -- Functions or Methods with detail => \"detail label\", might find '('\n elseif kind == Kind.Field and detail then\n local text = string.format(\"%s;%s%s\", label, align_spaces(label .. \" \", detail), detail)\n -- void foo() {f->x;std::unique_ptr x;}\n -- | |\n -- @field |-- @type\n -- later factor to `x std::unique_ptr`.\n local source = string.format(\"void foo(){ f->%s x;}\", text)\n return utils.highlight_range(source, ls, 15, 15 + #text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = \"\"\n if labelDetails and labelDetails.detail then\n signature = labelDetails.detail\n end\n local text = string.format(\n \"void %s%s;%s%s x;\",\n label,\n signature,\n align_spaces(label .. signature .. \";\", detail),\n detail\n )\n return utils.highlight_range(text, ls, 5, #text - 3)\n --\n else\n local highlight_name = nil\n local lang = vim.bo.filetype == \"c\" and \"c\" or \"cpp\"\n if kind == Kind.Struct or kind == Kind.Interface then\n highlight_name = \"@type\"\n elseif kind == Kind.Class then\n highlight_name = utils.hl_exist_or(\"@lsp.type.class\", \"@variant\", lang)\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@variant\", lang)\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n -- If we found a special highlight name, highlight the portion before '('\n if highlight_name then\n local paren_index = string.find(label, \"%(\", 1, true)\n local end_index = paren_index and (paren_index - 1) or #label\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { vim.startswith(label, \"•\") and 3 or 0, end_index },\n },\n },\n }\n end\n end\n\n return {\n text = label,\n highlights = {},\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.clangd(completion_item, ls)\n local vim_item = _clangd(completion_item, ls)\n local max_width = require(\"colorful-menu.utils\").max_width()\n if vim_item.text ~= nil then\n if vim.startswith(vim_item.text, \"•\") then\n table.insert(vim_item.highlights, 1, {\n config.ls.clangd.import_dot_hl,\n range = { 0, 3 },\n })\n end\n vim_item.text = vim_item.text:gsub(\";\", \" \")\n -- If it is already overflow, just return.\n if max_width and max_width > 0 then\n local display_width = vim.fn.strdisplaywidth(vim_item.text)\n if display_width >= max_width then\n return vim_item\n end\n end\n\n -- Append path.\n local document = completion_item.documentation\n if document and document.value and vim.startswith(document.value, \"From \") then\n local len = #vim_item.text\n local include_path = vim.trim(vim.split(document.value:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1])\n :sub(6, #document.value)\n if include_path:sub(1, 1) == \"`\" and include_path:sub(#include_path, #include_path) == \"`\" then\n include_path = include_path:sub(2, #include_path - 1)\n end\n local spaces = path_align_spaces(vim_item.text, include_path)\n vim_item.text = string.gsub(vim_item.text .. spaces .. include_path, \"\\n\", \" \")\n table.insert(vim_item.highlights, {\n config.ls.clangd.extra_info_hl,\n range = { len + #spaces, #vim_item.text },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/lua.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _lua_compute_completion_highlights(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if kind == Kind.Field then\n local text = string.format(\"%s\", label)\n local source = string.format(\"v.%s\", text)\n return utils.highlight_range(source, ls, 2, 2 + #text)\n end\n\n local highlight_name\n if kind == Kind.Constant then\n highlight_name = \"@constant.lua\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function.lua\"\n elseif kind == Kind.Property then\n highlight_name = \"@property.lua\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable.lua\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword.lua\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return {\n text = label,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n },\n }\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.lua_ls(completion_item, ls)\n local vim_item = _lua_compute_completion_highlights(completion_item, ls)\n if vim_item.text ~= nil then\n local s, e = string.find(vim_item.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls.lua_ls.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/rust.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal insertTextFormat = require(\"colorful-menu\").insertTextFormat\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces_bell(abbr, detail)\nend\n\nlocal cashed_self_hl = nil\n---@return CMHighlightRange[]\nlocal function iter_chain()\n if cashed_self_hl == nil then\n local source = \"fn iter(){}\"\n local hl = utils.highlight_range(source, \"rust-analyzer\", 3, #source - 2)\n cashed_self_hl = hl.highlights\n end\n return cashed_self_hl\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nlocal function _rust_analyzer(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local function_signature = completion_item.labelDetails and completion_item.labelDetails.description\n or completion_item.detail\n\n local kind = completion_item.kind\n if not kind then\n return utils.highlight_range(completion_item.label, ls, 0, #completion_item.label)\n end\n\n if kind == Kind.Field and detail then\n local name = completion_item.label\n local text = string.format(\"%s:%s%s\", name, align_spaces(name .. \" \", detail), detail)\n local source = string.format(\"struct S { %s }\", text)\n local hl = utils.highlight_range(source, ls, 11, 11 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif\n completion_item.insertTextFormat == insertTextFormat.Snippet\n and (label:find(\"::\", nil, true) ~= nil or label == \"Some(…)\" or label == \"None\" or label == \"Ok(…)\" or label == \"Err(…)\")\n and label:sub(1, 1) >= \"A\"\n and label:sub(1, 1) <= \"Z\"\n then\n local source = string.format(\"match s { %s }\", label)\n return utils.highlight_range(source, ls, 10, 10 + #label)\n elseif\n (kind == Kind.Constant or kind == Kind.Variable)\n and detail\n and completion_item.insertTextFormat ~= insertTextFormat.Snippet\n then\n local name = completion_item.label\n local text = string.format(\n \"%s:%s%s\",\n name,\n align_spaces(name .. \" \", completion_item.detail),\n completion_item.detail or detail\n )\n local source = string.format(\"let %s = ();\", text)\n local hl = utils.highlight_range(source, ls, 4, 4 + #text)\n if config.ls[\"rust-analyzer\"].align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #name) .. \" \" .. hl.text:sub(#name + 2, #text)\n return hl\n --\n elseif (kind == Kind.EnumMember) and detail then\n local source = string.format(\"enum S { %s }\", detail)\n return utils.highlight_range(source, ls, 9, 9 + #detail)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local pattern = \"%((.-)%)\"\n\n local ignored = nil\n if label:match(\"^iter%(%)%..+\") ~= nil then\n ignored = \"iter().\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n if label:match(\"^self%..+\") ~= nil then\n ignored = \"self.\"\n label = completion_item.label:sub(string.len(ignored) + 1)\n end\n local function adjust(hl)\n if ignored == \"self.\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored)\n elseif ignored == \"iter().\" then\n utils.adjust_range(hl, string.len(ignored) + 1, ignored, nil, iter_chain())\n end\n end\n\n local result = string.match(label, pattern)\n if not result then\n label = label .. \"()\"\n end\n local regex_pattern = \"%b()\"\n local prefix, suffix = string.match(function_signature or \"\", \"^(.*fn)(.*)$\")\n if prefix ~= nil and suffix ~= nil then\n local start_pos = string.find(suffix, \"(\", nil, true)\n if start_pos then\n suffix = suffix:sub(start_pos, #suffix)\n end\n\n if\n config.ls[\"rust-analyzer\"].preserve_type_when_truncate\n and config.ls[\"rust-analyzer\"].align_type_to_right\n then\n local params, type = string.match(suffix, \"(%b()) %-> (.*)\")\n if params == nil and type == nil then\n params = suffix\n type = \"\"\n end\n local call, num_subs = string.gsub(label, regex_pattern, params, 1)\n if num_subs == 0 then\n call = completion_item.label\n end\n local source = string.format(\n \"%s %s->%s%s{}\",\n prefix,\n call,\n align_spaces(call .. \" \", ignored ~= nil and type .. ignored or type),\n type or \"\"\n )\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 2)\n hl.text = hl.text:sub(1, #call) .. \" \" .. hl.text:sub(#call + 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n else\n local call, num_subs = string.gsub(label, regex_pattern, suffix, 1)\n if num_subs == 0 then\n call = label\n end\n local source = string.format(\"%s %s {}\", prefix, call)\n local hl = utils.highlight_range(source, ls, #prefix + 1, #source - 3)\n if ignored ~= nil then\n adjust(hl)\n end\n return hl\n end\n else\n -- Check if the detail starts with \"macro_rules! \"\n if completion_item.detail and vim.startswith(completion_item.detail, \"macro\") then\n local source = completion_item.label\n return utils.highlight_range(source, ls, 0, #source)\n else\n -- simd_swizzle!()\n return {\n text = completion_item.label,\n highlights = {\n {\n config.fallback_highlight,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Struct then\n highlight_name = \"@type\"\n elseif kind == Kind.Enum then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enum\", \"@type\", \"rust\")\n elseif kind == Kind.EnumMember then\n highlight_name = utils.hl_exist_or(\"@lsp.type.enumMember\", \"@constant\", \"rust\")\n elseif kind == Kind.Interface then\n highlight_name = utils.hl_exist_or(\"@lsp.type.interface\", \"@type\", \"rust\")\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Value or kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n if detail then\n detail = vim.trim(detail)\n if vim.startswith(detail, \"(\") then\n local space = align_spaces(completion_item.label, detail)\n return {\n text = completion_item.label .. space .. detail,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { #completion_item.label + #space, #completion_item.label + #space + #detail },\n },\n },\n }\n end\n end\n\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.rust_analyzer(completion_item, ls)\n local vim_item = _rust_analyzer(completion_item, ls)\n if vim_item.text ~= nil then\n for _, match in ipairs({ \"%(use .-%)\", \"%(as .-%)\", \"%(alias .-%)\" }) do\n local s, e = string.find(vim_item.text, match)\n if s ~= nil and e ~= nil then\n table.insert(vim_item.highlights, {\n config.ls[\"rust-analyzer\"].extra_info_hl,\n range = { s - 1, e },\n })\n end\n end\n end\n return vim_item\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/zig.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n if config.ls.zls.align_type_to_right == false then\n return \" \"\n end\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.zls(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.detail\n or (completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail)\n if detail ~= nil then\n detail = vim.split(detail, \"\\n\")[1]\n end\n local kind = completion_item.kind\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable or kind == Kind.Struct or kind == Kind.Enum) and detail then\n if detail == \"type\" then\n local source = string.format(\"fn(s: %s)\", label)\n return utils.highlight_range(source, ls, 6, 6 + #label)\n else\n local text = string.format(\"%s:%s%s\", label, align_spaces(label, detail .. \" \"), detail)\n local source = string.format(\"fn(%s)\", text)\n local hl = utils.highlight_range(source, ls, 3, 3 + #text)\n for _, highlight in ipairs(hl.highlights) do\n if vim.startswith(highlight[1], \"@variable.parameter\") then\n highlight[1] = highlight[1]:gsub(\"%.parameter\", \"\")\n end\n end\n if config.ls.zls.align_type_to_right == false then\n return hl\n end\n hl.text = hl.text:sub(1, #label) .. \" \" .. hl.text:sub(#label + 2, #text)\n return hl\n end\n --\n elseif (kind == Kind.Field or kind == Kind.EnumMember) and detail then\n -- For some reason `const x = struct { name: *Foo }` can't get the type color for Foo.\n -- Here is the trick:\n -- xfn(foo: *Foo)\n -- x *Foo\n local source = string.format(\"%sfn(foo:%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(\n source:sub(#label + 1),\n ls,\n config.ls.zls.align_type_to_right and 7 or 6,\n #source:sub(#label + 1) - 1\n )\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n )\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n if detail:sub(1, 2) == \"fn\" then\n local ret_type = vim.split(\n (vim.tbl_get(completion_item, \"labelDetails\", \"description\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"),\n \"\\n\"\n )[1]\n local params =\n vim.split((vim.tbl_get(completion_item, \"labelDetails\", \"detail\") or \"\"):gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n local text, source\n if ret_type ~= \"\" and params ~= \"\" and config.ls.zls.align_type_to_right then\n text = string.format(\"%s%s%s%s\", label, params, align_spaces(label .. params, ret_type), ret_type)\n source = string.format(\"fn %s {}\", text)\n else\n local signature = detail:sub(4)\n text = string.format(\"%s%s\", label, signature)\n source = string.format(\"fn %s {}\", text)\n end\n return utils.highlight_range(source, ls, 3, 3 + #text)\n elseif detail:sub(1, 1) == \"@\" then\n return utils.highlight_range(detail, ls, 0, #detail)\n else\n return {\n text = completion_item.label,\n highlights = {\n {\n \"@function\",\n range = { 0, #completion_item.label },\n },\n },\n }\n end\n --\n else\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Field then\n highlight_name = utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"zig\")\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/php.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.intelephense(completion_item, ls)\n local label = completion_item.label\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n local kind = completion_item.kind\n\n if (kind == Kind.Function or kind == Kind.Method) and detail and #detail > 0 then\n local signature = detail:sub(#label + 1)\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s 0 then\n detail = string.gsub(detail, \".*\\\\(.)\", \"%1\")\n local text = string.format(\"%s 0 then\n local text = string.format(\"%s \n -- assign.Analyzer \"golang.org/x/tools/go/analysis/passes/assign\"\n local path = detail:match(\".*%(from(.*)%)\")\n if path then\n local highlight_name = utils.hl_by_kind(kind)\n local spaces = align_spaces(label, path)\n local text = label .. align_spaces(label, path) .. path\n return {\n text = text,\n highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n {\n \"@string\",\n range = { #label + #spaces, #text },\n },\n },\n }\n end\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n -- Gopls returns nested fields and methods as completions.\n -- To syntax highlight these, combine their final component\n -- with their detail.\n local name_offset = label:reverse():find(\"%.\") or 0\n if name_offset > 0 then\n name_offset = #label - name_offset + 2\n else\n name_offset = 0\n end\n\n if kind == Kind.Module and detail then\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"import %s\", text)\n return utils.highlight_range(source, ls, 7, 7 + #text)\n --\n elseif (kind == Kind.Constant or kind == Kind.Variable) and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local var_part = text:sub(name_offset)\n local source = string.format(\"var %s\", var_part)\n local item = utils.highlight_range(source, ls, 4, 4 + #var_part)\n if kind == Kind.Constant then\n if #item.highlights >= 1 then\n item.highlights[1][1] = utils.hl_exist_or(\"@constant\", \"@variable\", \"go\")\n end\n end\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Struct then\n detail = \"struct{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s struct {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Interface then\n detail = \"interface{}\"\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n local source = string.format(\"type %s interface {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif kind == Kind.Field and detail then\n local text\n if config.ls.gopls.add_colon_before_type then\n text = string.format(\"%s:%s%s\", label, align_spaces(label, detail), detail)\n else\n text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n end\n local source = string.format(\"type T struct { %s }\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 16, 16 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n local signature = vim.trim(detail)\n if detail:sub(1, 4) == \"func\" then\n signature = detail:sub(5)\n end\n\n local text = string.format(\"%s%s\", label, signature)\n if signature ~= \"()\" then\n local params, returns = parse_signature(signature)\n text = label .. params .. align_spaces(label, params .. returns) .. returns\n end\n\n local source = string.format(\"func %s {}\", text:sub(name_offset))\n local item = utils.highlight_range(source, ls, 5, 5 + #text:sub(name_offset))\n return utils.adjust_range(item, name_offset, text)\n --\n else\n -- Handle other kinds\n local highlight_name = nil\n if kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n return {\n text = completion_item.label,\n highlights = {\n {\n highlight_name,\n range = { 0, #completion_item.label },\n },\n },\n }\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/utils.lua", "local Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal query_cache = {}\n\n---@param str string\n---@param ls string\n---@return CMHighlights\nlocal function compute_highlights(str, ls)\n local highlights = {}\n\n local lang = vim.treesitter.language.get_lang(vim.bo.filetype)\n if not lang then\n return {}\n end\n\n local query, ok\n if query_cache[ls] == nil then\n ok, query = pcall(vim.treesitter.query.get, lang, \"highlights\")\n if not ok then\n return {}\n end\n query_cache[ls] = query\n else\n query = query_cache[ls]\n end\n\n ---@diagnostic disable-next-line: redefined-local\n local ok, parser = pcall(vim.treesitter.get_string_parser, str, lang)\n if not ok then\n return {}\n end\n\n if not parser then\n vim.notify(string.format(\"No Tree-sitter parser found for filetype: %s\", lang), vim.log.levels.WARN)\n return highlights\n end\n\n -- Parse the string\n local tree = parser:parse(true)[1]\n if not tree then\n vim.notify(\"Failed to parse the string with Tree-sitter.\", vim.log.levels.ERROR)\n return {}\n end\n\n local root = tree:root()\n\n if not query then\n return {}\n end\n\n -- Iterate over all captures in the query\n for id, node in query:iter_captures(root, str, 0, -1) do\n local name = \"@\" .. query.captures[id] .. \".\" .. lang\n local range = { node:range() }\n local _, nscol, _, necol = range[1], range[2], range[3], range[4]\n table.insert(highlights, {\n hl_group = name,\n range = { nscol, necol },\n })\n end\n\n return highlights\nend\n\n-- `left` is inclusive and `right` is exclusive (also zero indexed), to better fit\n-- `nvim_buf_set_extmark` semantic, so `M.highlight_range(text, ft, 0, #text)` is the entire range.\n--\n---@param text string\n---@param ls string\n---@param left integer\n---@param right integer\n---@return CMHighlights\nfunction M.highlight_range(text, ls, left, right)\n local highlights = {}\n local full_hl = compute_highlights(text, ls)\n\n for _, hl in ipairs(full_hl) do\n local s, e = hl.range[1], hl.range[2]\n if e < left then\n goto continue\n end\n if s > right or e > right + 1 then\n break\n end\n\n table.insert(highlights, {\n hl.hl_group,\n range = { hl.range[1] - left, hl.range[2] - left },\n text = text:sub(s + 1, e),\n })\n ::continue::\n end\n\n return {\n text = text:sub(left + 1, right),\n highlights = highlights,\n }\nend\n\n-- Shift a highlight range right by name_offset,\n-- insert a color with fallback_hl for label with range (0, name_offset).\n---@param item CMHighlights\n---@param name_offset integer\n---@param label string\n---@param fallback_hl string?\n---@param custom_hl CMHighlightRange[]?\n---@return CMHighlights\nfunction M.adjust_range(item, name_offset, label, fallback_hl, custom_hl)\n if name_offset == 0 then\n return item\n end\n name_offset = name_offset - 1\n for _, highlight in ipairs(item.highlights) do\n highlight.range[1] = highlight.range[1] + name_offset\n highlight.range[2] = highlight.range[2] + name_offset\n end\n item.text = label:sub(1, name_offset) .. item.text\n if custom_hl then\n for _, hl in ipairs(custom_hl) do\n table.insert(item.highlights, hl)\n end\n else\n table.insert(item.highlights, {\n fallback_hl or \"@variable\",\n range = { 0, name_offset },\n })\n end\n return item\nend\n\n---@param hl_group string\n---@param fallback string\n---@param lang? string\nfunction M.hl_exist_or(hl_group, fallback, lang)\n local f = function()\n local ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = hl_group })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return hl_group\n end\n return fallback\n end\n\n local ok, hl\n if lang ~= nil then\n local lang_hl = hl_group .. \".\" .. lang\n ok, hl = pcall(vim.api.nvim_get_hl, 0, { name = lang_hl })\n if ok and hl ~= nil and not vim.tbl_isempty(hl) then\n return lang_hl\n else\n return f()\n end\n else\n return f()\n end\nend\n\n---@param kind? integer\n---@param lang? string\n---@return string\nfunction M.hl_by_kind(kind, lang)\n local highlight_name\n if kind == Kind.Method then\n highlight_name = M.hl_exist_or(\"@lsp.type.method\", \"@function\", lang)\n elseif kind == Kind.Function then\n highlight_name = M.hl_exist_or(\"@lsp.type.function\", \"@function\", lang)\n elseif kind == Kind.Constructor then\n highlight_name = \"@constructor\"\n elseif kind == Kind.Variable then\n highlight_name = M.hl_exist_or(\"@lsp.type.variable\", \"@variable\", lang)\n elseif kind == Kind.Field then\n highlight_name = M.hl_exist_or(\"@lsp.type.field\", \"@field\", lang)\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n elseif kind == Kind.Property then\n highlight_name = M.hl_exist_or(\"@lsp.type.property\", \"@property\", lang)\n elseif kind == Kind.Module then\n highlight_name = M.hl_exist_or(\"@lsp.type.namespace\", \"@namespace\", lang)\n elseif kind == Kind.Class then\n highlight_name = M.hl_exist_or(\"@lsp.type.class\", \"@type\", lang)\n elseif kind == Kind.Struct then\n highlight_name = M.hl_exist_or(\"@lsp.type.struct\", \"@type\", lang)\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n else\n highlight_name = config.fallback_highlight\n end\n\n return highlight_name\nend\n\n---@param item CMHighlights\n---@param rang {left:integer, right:integer}\nlocal function remove_color_in_range(item, rang)\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local r = hl.range\n if r[1] > rang.left and r[1] < rang.right then\n table.remove(item.highlights, i)\n elseif r[1] <= rang.left and r[2] > rang.left then\n r[2] = rang.left\n end\n end\nend\n\nlocal function left_brace_one_more_than_right_brace(s)\n local left = 0\n local right = 0\n for i = 1, #s do\n local char = s:sub(i, i)\n if char == \"(\" then\n left = left + 1\n elseif char == \")\" then\n right = right + 1\n end\n end\n return left == right + 1\nend\n\n---@param item CMHighlights\n---@param max_width integer\n---@param direct boolean -- without type info\nlocal function cut_label(item, max_width, direct)\n if vim.fn.strdisplaywidth(item.text) <= max_width then\n return\n end\n local text = item.text\n --- Given\n --- self.foo(asdasd)\n --- self.foo(asdasd…\n --- self.foo(asdas…)\n if direct and left_brace_one_more_than_right_brace(vim.fn.strcharpart(text, 0, max_width)) then\n local truncated = vim.fn.strcharpart(text, 0, max_width - 2) .. \"…)\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 4, truncated_width - 1 },\n })\n table.insert(item.highlights, {\n \"@punctuation.bracket\",\n range = { truncated_width - 1, truncated_width },\n })\n else\n local truncated = vim.fn.strcharpart(text, 0, max_width - 1) .. \"…\"\n item.text = truncated\n local truncated_width = #truncated\n remove_color_in_range(item, { left = truncated_width, right = math.huge })\n table.insert(item.highlights, {\n \"@comment\",\n range = { truncated_width - 3, truncated_width },\n })\n end\nend\n\n---@param item CMHighlights\n---@param offset integer\n---@param start integer\nlocal function shift_color_by(item, offset, start)\n for _, highlight in ipairs(item.highlights) do\n if highlight.range[1] > start then\n highlight.range[1] = highlight.range[1] - offset\n highlight.range[2] = highlight.range[2] - offset\n end\n end\nend\n\n---@param completion_item lsp.CompletionItem\n---@param item CMHighlights\nfunction M.validate_newline(completion_item, item)\n if string.find(item.text, \"\\n\") ~= nil or string.find(item.text, \"\\r\") ~= nil then\n vim.notify_once(\n '[colorful-menu.nvim]: Completion \"'\n .. completion_item.label\n .. '\" has new line character, please open an issue',\n vim.log.levels.WARN\n )\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n nil,\n nil,\n require(\"colorful-menu\").config.ls.fallback_extra_info_hl\n )\n end\n return item\nend\n\n---@param item CMHighlights\n---@param ls string\n---@return CMHighlights?\nfunction M.apply_post_processing(completion_item, item, ls)\n -- if the user override or fallback logic didn't produce a table, bail\n if type(item) ~= \"table\" or not item.text then\n return item\n end\n\n for i = #item.highlights, 1, -1 do\n local hl = item.highlights[i]\n local range = hl.range\n if range[2] < 0 then\n table.remove(item.highlights, i)\n elseif range[1] < 0 then\n range[1] = 0\n end\n end\n\n local max_width = require(\"colorful-menu.utils\").max_width()\n if not (max_width and max_width > 0) then\n return\n end\n\n local label = completion_item.label\n local display_width = vim.fn.strdisplaywidth(item.text)\n if display_width > (item.text:find(\"\\7\") ~= nil and (max_width + 1) or max_width) then\n local long_label, type = item.text:match(\"(.*)\\7%s*(.*)\")\n local is_func = completion_item.kind == Kind.Function or completion_item.kind == Kind.Method\n if\n item.text == label\n or type == nil\n or #type == 0\n or not is_func\n or not config.ls[ls]\n or not config.ls[ls].preserve_type_when_truncate\n then\n item.text = item.text:gsub(\"\\7\", \" \")\n cut_label(item, max_width, is_func)\n return\n end\n\n local _, le = item.text:find(\"\\7\")\n local ts = item.text:find(type, le, true)\n local space_between = ts - le\n item.text = item.text:gsub(\"\\7\", \" \")\n\n -- Now we need to deal with color shifting stuff.\n -- Foo(a string b string) \"some random stuff\"\n -- | | | |\n -- long_label_width type_width\n --\n -- | short | | type_width |\n -- Foo(a st… \"some random stuff\"\n -- | max_width |\n local long_label_width, type_width = #long_label, #type\n local short_label_width = math.max(max_width - type_width - 2 - space_between, #label)\n local should_cut_all = short_label_width == #label\n if should_cut_all then\n remove_color_in_range(item, { left = short_label_width, right = long_label_width })\n local pretty_end = \"(…)\"\n if label:sub(short_label_width, short_label_width) == \")\" then\n pretty_end = \"…)\"\n end\n shift_color_by(item, long_label_width - short_label_width - string.len(pretty_end), long_label_width)\n item.text = item.text:sub(1, short_label_width) .. pretty_end .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = {\n short_label_width + (pretty_end == \"(…)\" and 1 or 0),\n short_label_width + (pretty_end == \"(…)\" and string.len(\"…)\") or string.len(\"…\")),\n },\n })\n cut_label(item, max_width, false)\n else\n -- Caculate display_width and real byte diff.\n local diff = short_label_width - vim.fn.strdisplaywidth(item.text:sub(1, short_label_width))\n -- We increase the cut threshold if display_width is lower than\n -- byte count, otherwise the hole is not enough.\n short_label_width = short_label_width + diff\n local ascii_pos = short_label_width\n for i = short_label_width, 1, -1 do\n if item.text:sub(i, i):match(\"[a-zA-Z(]\") ~= nil then\n ascii_pos = i\n break\n end\n end\n remove_color_in_range(item, { left = ascii_pos, right = long_label_width })\n shift_color_by(item, long_label_width - short_label_width - string.len(\"…)\"), long_label_width)\n item.text = item.text:sub(1, ascii_pos)\n .. \"…)\"\n .. string.rep(\" \", short_label_width - ascii_pos)\n .. item.text:sub(long_label_width + 1)\n table.insert(item.highlights, {\n \"@comment\",\n range = { ascii_pos, ascii_pos + string.len(\"…)\") - 1 },\n })\n end\n else\n item.text = item.text:gsub(\"\\7\", \" \")\n end\nend\n\nfunction M.align_spaces_bell(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \"\\7 \"\n end\n return \"\\7\" .. string.rep(\" \", blank - 1)\nend\n\nfunction M.align_spaces(abbr, detail)\n local blank = M.max_width() - vim.fn.strdisplaywidth(abbr) - vim.fn.strdisplaywidth(detail)\n if blank <= 2 then\n return \" \"\n end\n return string.rep(\" \", blank)\nend\n\nfunction M.max_width()\n local max_width = config.max_width\n if max_width < 1 and max_width > 0 then\n max_width = math.floor(max_width * vim.api.nvim_win_get_width(0))\n end\n return max_width\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/dart.lua", "local utils = require(\"colorful-menu.utils\")\nlocal Kind = require(\"colorful-menu\").Kind\nlocal config = require(\"colorful-menu\").config\n\nlocal M = {}\n\nlocal function align_spaces(abbr, detail)\n return utils.align_spaces(abbr, detail)\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.dartls(completion_item, ls)\n local label = completion_item.label\n local kind = completion_item.kind\n local detail = completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail\n if detail ~= nil and detail:find(\"Auto\") ~= nil then\n detail = detail:gsub(\"Auto import.*\\n\\n\", \"\")\n detail = vim.split(detail:gsub(\"\\r\\n?\", \"\\n\"), \"\\n\")[1]\n end\n\n if not kind then\n return utils.highlight_range(label, ls, 0, #label)\n end\n\n if (kind == Kind.Constant or kind == Kind.Variable) and detail then\n -- x int\n local text = string.format(\"%s%s%s\", label, align_spaces(label, detail), detail)\n -- var x int x\n local source = string.format(\"var %s x\", text)\n return utils.highlight_range(source, ls, 4, 4 + #text)\n --\n elseif (kind == Kind.Field or kind == Kind.Property) and detail then\n -- Here is the trick same as zls:\n -- xvoid( *Foo)\n -- x *Foo\n local source = string.format(\"%svoid(%s%s)\", label, align_spaces(label, detail), detail)\n local items = utils.highlight_range(source:sub(#label + 1), ls, 5, #source:sub(#label + 1) - 1)\n return utils.adjust_range(\n items,\n #label + 1,\n source,\n utils.hl_exist_or(\"@lsp.type.property\", \"@variable.member\", \"dart\")\n )\n --\n elseif (kind == Kind.Function or kind == Kind.Method or kind == Kind.Constructor) and detail then\n -- elseif (kind == Kind.Function or kind == Kind.Method) and detail then\n -- label: fetchData(..)\n -- detail: (int a, int b) -> Future\n -- fetchData(int a, int b);(Future s)\n local params = string.match(detail or \"\", \"^(%b())\")\n local type = string.match(detail or \"\", \"→ (.*)\")\n if params ~= nil then\n label = label:gsub(\"%b()$\", \"\") .. params\n end\n if type ~= nil and kind ~= Kind.Constructor then\n local text = string.format(\"%s%s;(%s)\", label, align_spaces(label, type):sub(3), type)\n local comma_pos = #text - #type - 3\n local ranges = utils.highlight_range(text, ls, 0, #text - 1)\n ranges.text = ranges.text:sub(1, comma_pos) .. \" \" .. ranges.text:sub(comma_pos + 3, #ranges.text)\n return ranges\n end\n return utils.highlight_range(label, ls, 0, #label)\n --\n else\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n detail,\n \"dart\",\n config.ls[ls].extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/init.lua", "local M = {}\n\nM.insertTextFormat = { PlainText = 1, Snippet = 2 }\n-- stylua: ignore\nM.Kind = { Text = 1, Method = 2, Function = 3, Constructor = 4, Field = 5, Variable = 6, Class = 7, Interface = 8, Module = 9, Property = 10, Unit = 11, Value = 12, Enum = 13, Keyword = 14, Snippet = 15, Color = 16, File = 17, Reference = 18, Folder = 19, EnumMember = 20, Constant = 21, Struct = 22, Event = 23, Operator = 24, TypeParameter = 25 }\n\n---@alias CMHighlightRange {hl_group: string, range: integer[], text: string}\n---\n---@class CMHighlights\n---@field text string\n---@field highlights CMHighlightRange[]\n\n---@class ColorfulMenuConfig\nM.config = {\n ls = {\n lua_ls = {\n -- Maybe you want to dim arguments a bit.\n arguments_hl = \"@comment\",\n },\n gopls = {\n -- When true, label for field and variable will format like \"foo: Foo\"\n -- instead of go's original syntax \"foo Foo\".\n add_colon_before_type = false,\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n ts_ls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n vtsls = {\n -- false means do not include any extra info,\n -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42\n extra_info_hl = \"@comment\",\n },\n zls = {\n align_type_to_right = true,\n },\n [\"rust-analyzer\"] = {\n -- Such as (as Iterator), (use std::io).\n extra_info_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n clangd = {\n -- Such as \"\".\n extra_info_hl = \"@comment\",\n -- the hl of leading dot of \"•std::filesystem::permissions(..)\"\n import_dot_hl = \"@comment\",\n align_type_to_right = true,\n -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36\n preserve_type_when_truncate = true,\n },\n roslyn = {\n extra_info_hl = \"@comment\",\n },\n -- The same applies to pyright/pylance\n basedpyright = {\n extra_info_hl = \"@comment\",\n },\n pylsp = {\n extra_info_hl = \"@comment\",\n -- Dim the function argument area, which is the main\n -- difference with pyright.\n arguments_hl = \"@comment\",\n },\n dartls = {\n extra_info_hl = \"@comment\",\n },\n fallback = true,\n fallback_extra_info_hl = \"@comment\",\n },\n fallback_highlight = \"@variable\",\n max_width = 60,\n}\n\nlocal hl_cache = {}\nlocal hl_cache_size = 0\n-- about 30M max memory usage.\nlocal MAX_HL_CACHE_SIZE = 10000\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return string\nlocal function cache_key(completion_item, ls)\n return string.format(\n \"%s!%s!%s!%s!%s%s\",\n completion_item.label or \"\",\n completion_item.detail or \"\",\n completion_item.labelDetails\n and (completion_item.labelDetails.detail or \"\") .. (completion_item.labelDetails.description or \"\")\n or \"\",\n completion_item.kind and tostring(completion_item.kind) or \"\",\n ls,\n require(\"colorful-menu.utils\").max_width()\n )\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nlocal function _highlights(completion_item, ls)\n if completion_item == nil or ls == nil or ls == \"\" or vim.b.ts_highlight == false then\n return nil\n end\n\n local item\n\n local key = cache_key(completion_item, ls)\n if hl_cache[key] ~= nil then\n return hl_cache[key]\n end\n\n if ls == \"gopls\" then\n item = require(\"colorful-menu.languages.go\").gopls(completion_item, ls)\n --\n elseif ls == \"rust-analyzer\" or ls == \"rust_analyzer\" then\n item = require(\"colorful-menu.languages.rust\").rust_analyzer(completion_item, ls)\n ls = \"rust-analyzer\"\n --\n elseif ls == \"lua_ls\" then\n item = require(\"colorful-menu.languages.lua\").lua_ls(completion_item, ls)\n --\n elseif ls == \"clangd\" then\n item = require(\"colorful-menu.languages.cpp\").clangd(completion_item, ls)\n --\n elseif ls == \"typescript-language-server\" or ls == \"ts_ls\" or ls == \"tsserver\" or ls == \"typescript-tools\" then\n item = require(\"colorful-menu.languages.typescript\").ts_server(completion_item, ls)\n --\n elseif ls == \"vtsls\" then\n item = require(\"colorful-menu.languages.typescript\").vtsls(completion_item, ls)\n --\n elseif ls == \"zls\" then\n item = require(\"colorful-menu.languages.zig\").zls(completion_item, ls)\n --\n elseif ls == \"intelephense\" then\n item = require(\"colorful-menu.languages.php\").intelephense(completion_item, ls)\n --\n elseif ls == \"roslyn\" then\n item = require(\"colorful-menu.languages.cs\").roslyn(completion_item, ls)\n --\n elseif ls == \"dartls\" then\n item = require(\"colorful-menu.languages.dart\").dartls(completion_item, ls)\n --\n elseif ls == \"basedpyright\" or ls == \"pyright\" or ls == \"pylance\" or ls == \"pylsp\" then\n item = require(\"colorful-menu.languages.python\").py(completion_item, ls)\n --\n else\n -- No languages detected so check if we should highlight with default or not\n if not M.config.ls.fallback then\n return nil\n end\n item = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n completion_item.labelDetails and completion_item.labelDetails.detail or completion_item.detail,\n nil,\n M.config.ls.fallback_extra_info_hl\n )\n end\n\n if item then\n item = require(\"colorful-menu.utils\").validate_newline(completion_item, item)\n require(\"colorful-menu.utils\").apply_post_processing(completion_item, item, ls)\n end\n\n hl_cache_size = hl_cache_size + 1\n if hl_cache_size > MAX_HL_CACHE_SIZE then\n hl_cache_size = 0\n hl_cache = {}\n end\n hl_cache[key] = item\n\n return item\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param entry cmp.Entry\nfunction M.cmp_highlights(entry)\n local client = vim.tbl_get(entry, \"source\", \"source\", \"client\") -- For example `lua_ls` etc\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n return _highlights(entry:get_completion_item(), client.name)\n end\n return nil\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_text(ctx)\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n return highlights_info.label\n else\n ---@diagnostic disable-next-line: undefined-field\n return ctx.label\n end\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_components_highlight(ctx)\n local highlights = {}\n local highlights_info = M.blink_highlights(ctx)\n if highlights_info ~= nil then\n highlights = highlights_info.highlights\n end\n ---@diagnostic disable-next-line: undefined-field\n for _, idx in ipairs(ctx.label_matched_indices) do\n table.insert(highlights, { idx, idx + 1, group = \"BlinkCmpLabelMatch\" })\n end\n return highlights\nend\n\n---@diagnostic disable-next-line: undefined-doc-name\n---@param ctx blink.cmp.DrawItemContext\nfunction M.blink_highlights(ctx)\n ---@diagnostic disable-next-line: undefined-field\n local client = vim.lsp.get_client_by_id(ctx.item.client_id)\n local highlights = {}\n if client and not client:is_stopped() then\n ---@diagnostic disable-next-line: undefined-field\n local highlights_info = _highlights(ctx.item, client.name)\n if highlights_info ~= nil then\n for _, info in ipairs(highlights_info.highlights or {}) do\n table.insert(highlights, {\n info.range[1],\n info.range[2],\n ---@diagnostic disable-next-line: undefined-field\n group = ctx.deprecated and \"BlinkCmpLabelDeprecated\" or info[1],\n })\n end\n else\n return nil\n end\n return { label = highlights_info.text, highlights = highlights }\n end\n return nil\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string?\n---@return CMHighlights?\nfunction M.highlights(completion_item, ls)\n if ls == vim.bo.filetype then\n vim.notify_once(\n \"colorful-menu.nvim: Integration with nvim-cmp or blink.cmp has been simplified, and legacy per-filetype options is also deprecated\"\n .. \" to prefer per-language-server options, please see README\",\n vim.log.levels.WARN\n )\n return nil\n end\n\n return _highlights(completion_item, ls)\nend\n\n---@param opts ColorfulMenuConfig\nfunction M.setup(opts)\n opts = opts or {}\n M.config = vim.tbl_deep_extend(\"force\", M.config, opts)\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/default.lua", "local utils = require(\"colorful-menu.utils\")\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@param detail? string\n---@param lang? string\n---@param extra_info_hl? string\n---@return CMHighlights\nfunction M.default_highlight(completion_item, detail, lang, extra_info_hl)\n extra_info_hl = extra_info_hl or \"@comment\"\n local label = completion_item.label\n local highlight_name = utils.hl_by_kind(completion_item.kind, lang)\n\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n\n local text = label\n if detail and string.find(detail, \"\\n\") == nil and string.find(detail, \"\\r\") == nil then\n local spaces = utils.align_spaces(label, detail)\n -- If there are any information, append it\n text = label .. spaces .. detail\n table.insert(highlights, {\n extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n\n return {\n text = text,\n highlights = highlights,\n }\nend\n\nreturn M\n"], ["/colorful-menu.nvim/lua/colorful-menu/languages/python.lua", "local config = require(\"colorful-menu\").config\nlocal Kind = require(\"colorful-menu\").Kind\n\nlocal M = {}\n\n---@param completion_item lsp.CompletionItem\n---@return CMHighlights\nlocal function pylsp(completion_item)\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n local hls = require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.pylsp.extra_info_hl\n )\n if hls.text ~= nil and (completion_item.kind == Kind.Function or completion_item.kind == Kind.Method) then\n local s, e = string.find(hls.text, \"%b()\")\n if s ~= nil and e ~= nil then\n table.insert(hls.highlights, {\n config.ls.pylsp.arguments_hl,\n range = { s - 1, e },\n })\n end\n end\n return hls\nend\n\n---@param completion_item lsp.CompletionItem\n---@param ls string\n---@return CMHighlights\nfunction M.py(completion_item, ls)\n if ls == \"pylsp\" then\n return pylsp(completion_item)\n else\n local path = vim.tbl_get(completion_item, \"labelDetails\", \"description\")\n return require(\"colorful-menu.languages.default\").default_highlight(\n completion_item,\n path,\n \"python\",\n config.ls.basedpyright.extra_info_hl\n )\n end\nend\n\nreturn M\n"], ["/colorful-menu.nvim/repro_cmp.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n {\n \"hrsh7th/nvim-cmp\",\n lazy = false,\n dependencies = {\n \"hrsh7th/cmp-nvim-lsp\",\n {\n \"xzbdmw/colorful-menu.nvim\",\n config = function()\n require(\"colorful-menu\").setup({})\n end,\n },\n },\n config = function(_, opts)\n local cmp = require(\"cmp\")\n require(\"cmp\").setup({\n mapping = cmp.mapping.preset.insert({\n [\"\"] = cmp.mapping(function(fallback)\n if cmp.visible() then\n cmp.confirm()\n end\n end, { \"i\" }),\n }),\n completion = {\n completeopt = \"menu,menuone,noinsert\",\n },\n formatting = {\n format = function(entry, vim_item)\n local highlights_info = require(\"colorful-menu\").cmp_highlights(entry)\n if highlights_info ~= nil then\n vim_item.abbr_hl_group = highlights_info.highlights\n vim_item.abbr = highlights_info.text\n end\n return vim_item\n end,\n },\n sources = require(\"cmp\").config.sources({\n { name = \"nvim_lsp\" },\n }, {}),\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n capabilities = require(\"cmp_nvim_lsp\").default_capabilities(),\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n workspace = {\n library = {\n \"/usr/local/share/nvim/runtime\",\n },\n },\n completion = {\n callSnippet = \"Replace\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"], ["/colorful-menu.nvim/repro_blink.lua", "local root = vim.fn.fnamemodify(\"./.repro\", \":p\")\n-- set stdpaths to use .repro\nfor _, name in ipairs({ \"config\", \"data\", \"state\", \"cache\" }) do\n vim.env[(\"XDG_%s_HOME\"):format(name:upper())] = root .. \"/\" .. name\nend\n-- bootstrap lazy\nlocal lazypath = root .. \"/plugins/lazy.nvim\"\nif not vim.loop.fs_stat(lazypath) then\n vim.fn.system({\n \"git\",\n \"clone\",\n \"--filter=blob:none\",\n \"--single-branch\",\n \"https://github.com/folke/lazy.nvim.git\",\n lazypath,\n })\nend\nvim.opt.runtimepath:prepend(lazypath)\n-- install plugins\nlocal plugins = {\n -- do not remove the colorscheme!\n \"folke/tokyonight.nvim\",\n \"neovim/nvim-lspconfig\",\n \"xzbdmw/colorful-menu.nvim\",\n {\n \"saghen/blink.cmp\",\n version = \"v0.*\",\n config = function()\n require(\"blink.cmp\").setup({\n completion = {\n menu = {\n draw = {\n -- We don't need label_description now because label and label_description are already\n -- conbined together in label by colorful-menu.nvim.\n columns = { { \"kind_icon\" }, { \"label\", gap = 1 } },\n components = {\n label = {\n text = require(\"colorful-menu\").blink_components_text,\n highlight = require(\"colorful-menu\").blink_components_highlight,\n },\n },\n },\n },\n },\n })\n end,\n },\n}\nrequire(\"lazy\").setup(plugins, {\n root = root .. \"/plugins\",\n})\nrequire(\"lspconfig\").lua_ls.setup({\n settings = {\n Lua = {\n runtime = {\n version = \"LuaJIT\",\n },\n },\n },\n})\nvim.cmd([[colorscheme tokyonight]])\n"]], "task_instance_info": {"created_time": "2025-08-21 00:42:04", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Map semantic item categories to syntax highlighting groups and construct annotated text with associated visual styles based on input metadata characteristics."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nfunction M.completion_highlight(completion_item, ls)\n local kind_number = completion_item.kind or 1\n local kind = Kind.completion_kind[kind_number]\n local hl_group = utils.get_highlight(config.completion_highlights[kind] or config.completion_highlights.Text)\n \n return {\n label = hl_group,\n kind = hl_group,\n details = completion_item.detail and hl_group or nil,\n }\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-42-33"}, "editdistance_info": {"edit_distance": 11.6505, "calculate_time": "2025-08-21 00:42:33", "true_code_clean": "function M.roslyn(completion_item, ls)\n local label = completion_item.label\n local description = completion_item.labelDetails and completion_item.labelDetails.description\n local kind = completion_item.kind\n local text = label\n if not kind then\n return utils.highlight_range(text, ls, 0, #text)\n end\n local highlight_name\n if kind == Kind.Class or kind == Kind.Interface or kind == Kind.Enum then\n highlight_name = \"@type\"\n elseif kind == Kind.Constructor then\n highlight_name = \"@type\"\n elseif kind == Kind.Constant then\n highlight_name = \"@constant\"\n elseif kind == Kind.Function or kind == Kind.Method then\n highlight_name = \"@function\"\n elseif kind == Kind.Property or kind == Kind.Field then\n highlight_name = \"@property\"\n elseif kind == Kind.Variable then\n highlight_name = \"@variable\"\n elseif kind == Kind.Keyword then\n highlight_name = \"@keyword\"\n else\n highlight_name = config.fallback_highlight\n end\n local highlights = {\n {\n highlight_name,\n range = { 0, #label },\n },\n }\n if description then\n text = label .. \" \" .. description\n table.insert(highlights, {\n config.ls.roslyn.extra_info_hl,\n range = { #label + 1, #text },\n })\n end\n return {\n text = text,\n highlights = highlights,\n }\nend", "predict_code_clean": "function M.completion_highlight(completion_item, ls)\n local kind_number = completion_item.kind or 1\n local kind = Kind.completion_kind[kind_number]\n local hl_group = utils.get_highlight(config.completion_highlights[kind] or config.completion_highlights.Text)\n return {\n label = hl_group,\n kind = hl_group,\n details = completion_item.detail and hl_group or nil,\n }\nend"}}