(local M {}) (fn M.new [] (setmetatable {} {:__index M})) (fn M.get_completions [self ctx callback] (let [(ok preview) (pcall require :supermaven-nvim.completion_preview)] (if (not ok) (callback {:is_incomplete_backward false :is_incomplete_forward false :items []}) (let [inst (preview:get_inlay_instance)] (if (or (= inst nil) (= inst.is_active false)) (callback {:is_incomplete_backward false :is_incomplete_forward false :items []}) (let [text inst.completion_text lines (vim.split text "\n" {:plain true}) raw-label (: (. lines 1) :gsub "^%s*" "") label (if (> (length raw-label) 40) (.. (raw-label:sub 1 20) " ... " (raw-label:sub -15)) raw-label) row (- (. ctx.cursor 1) 1) col-start (math.max (- (. ctx.cursor 2) (or inst.prior_delete 0)) 0) col-end (vim.fn.col "$") range {:start {:line row :character col-start} :end {:line row :character col-end}}] (callback {:is_incomplete_backward false :is_incomplete_forward false :items [{:label label :kind (. vim.lsp.protocol.CompletionItemKind :Text) :insertTextFormat (if (> (length lines) 1) 2 1) :textEdit {:newText text :insert range :replace range} :documentation {:kind :markdown :value (.. "```" vim.bo.filetype "\n" text "\n```")}}]}))))))) (fn M.execute [self ctx item resolve default-impl] (pcall (fn [] (: (require :supermaven-nvim.completion_preview) :dispose_inlay))) (default-impl) (resolve)) M