72087d4
Branches > main > 72087d4 > files
Add epic completion code from the LLM
Commit: 72087d4205db567269f122e912d395a806877cfb
Parent: 70744c0
3 changed files:
nvim/init.lua view file
@@ -16,6 +16,7 @@ require("lsp") require("format") require("lazy_ui")+ require("complete") end) --- TODO there's a bug tha parens and virtual text likes to stick around for longer than it should...nvim/lua/complete.lua view file
@@ -0,0 +1,377 @@+local api = vim.api+local autocmd = api.nvim_create_autocmd+local protocol = vim.lsp.protocol++local max_shown = 200+local clojure_lsp_max_items = 600+local symbol_chars = "[^%s%(%)%[%]{}\"',`;@^~\\]"++local prose_filetypes = {[""] = true, markdown = true, text = true, gitcommit = true}++local function syntax_names_at(buf, row, col)+ local names = {}+ if vim.treesitter.highlighter.active[buf] then+ for _, capture in ipairs(vim.treesitter.get_captures_at_pos(buf, row - 1, col - 1)) do+ names[#names + 1] = capture.capture+ end+ else+ for _, id in ipairs(vim.fn.synstack(row, col)) do+ names[#names + 1] = vim.fn.synIDattr(id, "name")+ end+ end+ return names+end++local function in_string_or_comment(buf, row, col)+ if col == 0 then return false end+ for _, name in ipairs(syntax_names_at(buf, row, col)) do+ name = name:lower()+ if name:match("string") or name:match("comment") then return true end+ end+ return false+end++local function namespace_of(detail)+ if not detail then return end+ return detail:match("^([%w%.%-_]+)/") or detail:match("^([%w%._]+)%.[%w_$]+$")+end++local function from_lsp(item)+ local is_snippet = item.insertTextFormat == protocol.InsertTextFormat.Snippet+ local insert = item.textEdit and item.textEdit.newText or item.insertText or item.label+ return {label = item.label,+ word = is_snippet and item.label or insert,+ snippet = is_snippet and insert or nil,+ ns = namespace_of(item.detail),+ is_local = item.kind == protocol.CompletionItemKind.Variable and item.detail == "",+ lsp = item}+end++local function ns_and_aliases(buf)+ local ns_lines = {}+ for _, line in ipairs(api.nvim_buf_get_lines(buf, 0, 200, false)) do+ if #ns_lines > 0 and line:match("^%(") then break end+ if #ns_lines > 0 or line:match("^%(ns%s") then ns_lines[#ns_lines + 1] = line end+ end+ local ns_form = table.concat(ns_lines, "\n")++ local aliases = {}+ for lib, alias in ns_form:gmatch("%[([^%s%]]+)[^%]]-:as%s+([^%s%]]+)") do+ aliases[lib] = alias+ end+ return ns_form:match("^%(ns%s+([^%s%)]+)"), aliases+end++local function auto_resolved_keyword(keyword)+ return {label = keyword, word = keyword, auto_resolved = true}+end++local function add_auto_resolved_keywords(buf, items)+ local ns, aliases = ns_and_aliases(buf)+ local keywords = {}+ for _, item in ipairs(items) do+ local kw_ns, name = item.label:match("^:([^/]+)/(.+)$")+ if kw_ns == ns then+ keywords[#keywords + 1] = auto_resolved_keyword("::" .. name)+ elseif aliases[kw_ns] then+ keywords[#keywords + 1] = auto_resolved_keyword("::" .. aliases[kw_ns] .. "/" .. name)+ end+ end++ for _, line in ipairs(api.nvim_buf_get_lines(buf, 0, -1, false)) do+ for keyword in line:gmatch("::" .. symbol_chars .. "+") do+ keywords[#keywords + 1] = auto_resolved_keyword(keyword)+ end+ end+ return vim.list_extend(items, keywords)+end++local function is_unfiltered_fallback(items, word)+ if word == "" or #items < clojure_lsp_max_items then return false end+ for _, item in ipairs(items) do+ if not vim.startswith(item.label:lower(), word:lower()) then return true end+ end+ return false+end++local clojure = {}++function clojure.word(before)nvim/lua/opts.lua view file
@@ -38,8 +38,4 @@ o.swapfile = false o.backup = false o.undofile = true-- --- Completion- o.completeopt = {"menu", "menuone", "fuzzy"}- end)