From a0f33c9a372da3535ebd372db88a5bfe32d3c3ac Mon Sep 17 00:00:00 2001 From: anott03 Date: Thu, 17 Jun 2021 07:36:53 -0700 Subject: [PATCH] moving from vim.fn to vim.api where possible vim.fn functions are vimsciprt, while vim.api functions are lua, so api functions tend to perform better --- lua/harpoon/mark.lua | 29 +++++++++++++++-------------- lua/harpoon/term.lua | 6 +++--- lua/harpoon/ui.lua | 4 ++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index f590992..3a15b69 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -56,7 +56,7 @@ end local function get_buf_name(id) log.trace("_get_buf_name():", id) if id == nil then - return utils.normalize_path(vim.fn.bufname()) + return utils.normalize_path(vim.api.nvim_buf_get_name(0)) elseif type(id) == "string" then return utils.normalize_path(id) end @@ -72,17 +72,17 @@ local function get_buf_name(id) end local function create_mark(filename) - local cursor_pos = vim.fn.getcurpos() + local cursor_pos = vim.api.nvim_win_get_cursor(0) log.trace(string.format( "_create_mark(): Creating mark at row: %d, col: %d for %s", + cursor_pos[1], cursor_pos[2], - cursor_pos[4], filename )) return { filename = filename, - row = cursor_pos[2], - col = cursor_pos[3], + row = cursor_pos[1], + col = cursor_pos[2], } end @@ -144,9 +144,9 @@ M.status = function(bufnr) log.trace("status()") local buf_name if bufnr then - buf_name = vim.fn.bufname(bufnr) + buf_name = vim.api.nvim_buf_get_name(bufnr) else - buf_name = vim.fn.bufname() + buf_name = vim.api.nvim_buf_get_name(0) end local norm_name = utils.normalize_path(buf_name) @@ -218,14 +218,14 @@ M.store_offset = function() return end - local cursor_pos = vim.fn.getcurpos() + local cursor_pos = vim.api.nvim_win_get_cursor(0) log.debug(string.format( "store_offset(): Stored row: %d, col: %d", - cursor_pos[2], - cursor_pos[3] + cursor_pos[1], + cursor_pos[2] )) - harpoon.get_mark_config().marks[idx].row = cursor_pos[2] - harpoon.get_mark_config().marks[idx].col = cursor_pos[3] + harpoon.get_mark_config().marks[idx].row = cursor_pos[1] + harpoon.get_mark_config().marks[idx].col = cursor_pos[2] end) if not ok then @@ -313,7 +313,8 @@ M.to_quickfix_list = function() } end log.debug("to_quickfix_list(): qf_list:", qf_list) - vim.fn.setqflist(qf_list) + -- Does this only work when there is an LSP attached to the buffer? + vim.lsp.util.set_qflist(qf_list) end M.set_mark_list = function(new_list) @@ -355,7 +356,7 @@ end M.get_current_index = function() log.trace("get_current_index()") - return M.get_index_of(vim.fn.bufname()) + return M.get_index_of(vim.api.nvim_buf_get_name(0)) end M.on = function(event, cb) diff --git a/lua/harpoon/term.lua b/lua/harpoon/term.lua index 4ab640b..b824993 100644 --- a/lua/harpoon/term.lua +++ b/lua/harpoon/term.lua @@ -9,10 +9,10 @@ local function create_terminal(create_with) create_with = ":terminal" end log.trace("_create_terminal(): Init:", create_with) - local current_id = vim.fn.bufnr() + local current_id = vim.api.nvim_get_current_buf() vim.cmd(create_with) - local buf_id = vim.fn.bufnr() + local buf_id = vim.api.nvim_get_current_buf() local term_id = vim.b.terminal_job_id if term_id == nil then @@ -68,7 +68,7 @@ M.sendCommand = function(idx, cmd, ...) if cmd then log.debug("sendCommand:", cmd) - vim.fn.chansend(term_handle.term_id, string.format(cmd, ...)) + vim.api.nvim_chan_send(term_handle.term_id, string.format(cmd, ...)) end end diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index 494031b..7598e5a 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -161,8 +161,8 @@ function M.location_window(options) } options = vim.tbl_extend("keep", options, default_options) - local bufnr = options.bufnr or vim.fn.nvim_create_buf(false, true) - local win_id = vim.fn.nvim_open_win(bufnr, true, options) + local bufnr = options.bufnr or vim.api.nvim_create_buf(false, true) + local win_id = vim.api.nvim_open_win(bufnr, true, options) return { bufnr = bufnr,