b31b6de
Branches > main > b31b6de > files
Completion changes
Commit: b31b6de92eebde9ffa53c8d08847dc3ee931b79e
Parent: 2dd1574
1 changed file:
nvim/lua/complete.lua view file
@@ -207,14 +207,36 @@ end end -local function set_candidates(s, items)- s.items, s.labels, s.by_label = items, {}, {}+local function index(items)+ local c = {items = items, labels = {}, by_label = {}} for _, item in ipairs(items) do- if not s.by_label[item.label] then- s.by_label[item.label] = item- s.labels[#s.labels + 1] = item.label+ if not c.by_label[item.label] then+ c.by_label[item.label] = item+ c.labels[#c.labels + 1] = item.label end end+ return c+end++local function set_candidates(s, items)+ s.candidates, s.instance_candidates = index(items), nil+end++--- clojure-lsp completes nothing for Class/.method, so derive it from the Class/ members,+--- skipping constructors and nested classes (they have no detail)+local function instance_candidates(s)+ if not s.instance_candidates then+ local items = {}+ for _, item in ipairs(s.candidates.items) do+ local class, member = item.label:match("^([^/]+/)([^/%.]+)$")+ if class and item.lsp and item.lsp.detail ~= "" then+ local label = class .. "." .. member+ items[#items + 1] = vim.tbl_extend("force", item, {label = label, word = label})+ end+ end+ s.instance_candidates = index(items)+ end+ return s.instance_candidates end local function group_of(item, word_is_capitalized)@@ -224,13 +246,19 @@ end local function matching(s, word)+ local c = s.candidates if word == "" then- return vim.tbl_filter(function(item) return item.is_local end, s.items)+ return vim.tbl_filter(function(item) return item.is_local end, c.items)+ end++ if word:match("^[^/]+/%.") then+ c = instance_candidates(s)+ if word:match("/%.$") then return c.items end end local fuzzy = {}- for _, label in ipairs(vim.fn.matchfuzzy(s.labels, word)) do- local item = s.by_label[label]+ for _, label in ipairs(vim.fn.matchfuzzy(c.labels, word)) do+ local item = c.by_label[label] if not item.auto_resolved or word:match("^::") then fuzzy[#fuzzy + 1] = item end end @@ -297,17 +325,17 @@ local still_typing_same_word = session and session.key == key and vim.startswith(word, session.word) local more_typing_narrows_results = session and session.truncated and word ~= session.word- and not word:match("^::")+ and not word:match("^::") and not word:match("^[^/]+/%.") if still_typing_same_word and not more_typing_narrows_results then- if session.items then show(session, word) end+ if session.candidates then show(session, word) end return end if cancel_fetch then cancel_fetch() end local s = {key = key, row = row, start = start, word = word}- if session and session.items and session.row == row and session.start == start then- s.items, s.labels, s.by_label = session.items, session.labels, session.by_label+ if session and session.candidates and session.row == row and session.start == start then+ s.candidates, s.instance_candidates = session.candidates, session.instance_candidates show(s, word) end session = s@@ -373,5 +401,11 @@ session, cancel_fetch, accepted_at = nil, nil, nil end}) +--- With noinsert, <CR> on an unselected menu just closes it instead of making a newline+vim.keymap.set("i", "<CR>", function()+ local unselected = vim.fn.pumvisible() == 1 and vim.fn.complete_info({"selected"}).selected == -1+ return unselected and "<C-e><CR>" or "<CR>"+end, {expr = true})+ vim.opt.completeopt = {"menu", "menuone", "noinsert", "noselect"} vim.opt.shortmess:append("c")