Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion autoload/fireplace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function! s:candidate(val) abort
\ }
endfunction

function! s:get_complete_context() abort
function! s:internal_get_complete_context() abort
" Find toplevel form
" If cursor is on start parenthesis we don't want to find the form
" If cursor is on end parenthesis we want to find the form
Expand Down Expand Up @@ -223,6 +223,14 @@ function! s:get_complete_context() abort
return strpart(expr, 0, p) . ' __prefix__ ' . strpart(expr, p)
endfunction

if has('nvim-0.5')
let s:lua_impl = luaeval("require'_fireplace'")
else
let s:lua_impl = {}
endif

let s:get_complete_context = get(s:lua_impl, 'get_completion_context', function('s:internal_get_complete_context'))

function! s:complete_extract(msg) abort
let trans = '{"word": (v:val =~# ''[./]'' ? "" : matchstr(a:base, ''^.\+/'')) . v:val}'
let value = get(a:msg, 'value', get(a:msg, 'completions'))
Expand Down
43 changes: 43 additions & 0 deletions lua/_fireplace.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local fireplace_impl = {[vim.type_idx] = vim.types.dictionary}

if vim.treesitter then
local has_ts, ts = pcall(require, 'nvim-treesitter.ts_utils')

if has_ts and vim.treesitter.language.add('clojure') then
fireplace_impl['get_completion_context'] = function()
vim.treesitter.get_parser(0, 'clojure'):parse()
local node = ts.get_node_at_cursor()
local one_ago = nil
local two_ago = nil

while(node ~= nil) do
two_ago = one_ago
one_ago = node
node = node:parent()
end

local root_node = two_ago or one_ago or node

if root_node ~= nil then
local strs = ts.get_node_text(root_node)
local nrow1, ncol1, nline2, ncol2 = root_node:range()
local crow, ccol = unpack(vim.api.nvim_win_get_cursor(0))

local idx = crow - nrow1
local line = strs[idx]
local coloffset = 0
if crow == nrow1 then
coloffset = ncol1
end

strs[idx] = string.sub(line, 1 + coloffset, ccol + coloffset) .. ' __prefix__ ' .. string.sub(line, ccol+coloffset+1, -1)

return table.concat(strs, "\n")
else
return ""
end
end
end
end

return fireplace_impl