LunarVim/lua/nv-utils/init.lua

191 lines
3.6 KiB
Lua
Raw Normal View History

2021-03-17 17:47:52 +01:00
local nv_utils = {}
2021-03-17 05:17:41 +01:00
2021-03-17 17:47:52 +01:00
function nv_utils.define_augroups(definitions) -- {{{1
2021-03-14 21:55:38 +01:00
-- Create autocommand groups based on the passed definitions
--
-- The key will be the name of the group, and each definition
-- within the group should have:
-- 1. Trigger
-- 2. Pattern
-- 3. Text
-- just like how they would normally be defined from Vim itself
for group_name, definition in pairs(definitions) do
vim.cmd('augroup ' .. group_name)
vim.cmd('autocmd!')
for _, def in pairs(definition) do
local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
vim.cmd(command)
end
vim.cmd('augroup END')
end
end
2021-03-23 03:10:58 +01:00
2021-03-17 05:17:41 +01:00
-- lsp
2021-03-17 17:47:52 +01:00
function nv_utils.add_to_workspace_folder()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.add_workspace_folder()
end
2021-03-17 17:47:52 +01:00
function nv_utils.clear_references()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.clear_references()
end
2021-03-17 17:47:52 +01:00
function nv_utils.code_action()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.code_action()
end
2021-03-17 17:47:52 +01:00
function nv_utils.declaration()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.declaration()
vim.lsp.buf.clear_references()
end
2021-03-17 17:47:52 +01:00
function nv_utils.definition()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.definition()
vim.lsp.buf.clear_references()
end
2021-03-17 17:47:52 +01:00
function nv_utils.document_highlight()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.document_highlight()
end
2021-03-17 17:47:52 +01:00
function nv_utils.document_symbol()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.document_symbol()
end
2021-03-17 17:47:52 +01:00
function nv_utils.formatting()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.formatting()
end
2021-03-17 17:47:52 +01:00
function nv_utils.formatting_sync()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.formatting_sync()
end
2021-03-17 17:47:52 +01:00
function nv_utils.hover()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.hover()
end
2021-03-17 17:47:52 +01:00
function nv_utils.implementation()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.implementation()
end
2021-03-17 17:47:52 +01:00
function nv_utils.incoming_calls()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.incoming_calls()
end
2021-03-17 17:47:52 +01:00
function nv_utils.list_workspace_folders()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.list_workspace_folders()
end
2021-03-17 17:47:52 +01:00
function nv_utils.outgoing_calls()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.outgoing_calls()
end
2021-03-17 17:47:52 +01:00
function nv_utils.range_code_action()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.range_code_action()
end
2021-03-17 17:47:52 +01:00
function nv_utils.range_formatting()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.range_formatting()
end
2021-03-17 17:47:52 +01:00
function nv_utils.references()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.references()
vim.lsp.buf.clear_references()
end
2021-03-17 17:47:52 +01:00
function nv_utils.remove_workspace_folder()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.remove_workspace_folder()
end
2021-03-17 17:47:52 +01:00
function nv_utils.rename()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.rename()
end
2021-03-17 17:47:52 +01:00
function nv_utils.signature_help()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.signature_help()
end
2021-03-17 17:47:52 +01:00
function nv_utils.type_definition()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.type_definition()
end
2021-03-17 17:47:52 +01:00
function nv_utils.workspace_symbol()
2021-03-17 05:17:41 +01:00
vim.lsp.buf.workspace_symbol()
end
-- diagnostic
2021-03-17 17:47:52 +01:00
function nv_utils.get_all()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.get_all()
end
2021-03-17 17:47:52 +01:00
function nv_utils.get_next()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.get_next()
end
2021-03-17 17:47:52 +01:00
function nv_utils.get_prev()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.get_prev()
end
2021-03-17 17:47:52 +01:00
function nv_utils.goto_next()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.goto_next()
end
2021-03-17 17:47:52 +01:00
function nv_utils.goto_prev()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.goto_prev()
end
2021-03-17 17:47:52 +01:00
function nv_utils.show_line_diagnostics()
2021-03-17 05:17:41 +01:00
vim.lsp.diagnostic.show_line_diagnostics()
end
-- git signs
2021-03-17 17:47:52 +01:00
function nv_utils.next_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').next_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.prev_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').prev_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.stage_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').stage_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.undo_stage_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').undo_stage_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.reset_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').reset_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.reset_buffer()
2021-03-17 07:19:25 +01:00
require('gitsigns').reset_buffer()
end
2021-03-17 17:47:52 +01:00
function nv_utils.preview_hunk()
2021-03-17 07:19:25 +01:00
require('gitsigns').preview_hunk()
end
2021-03-17 17:47:52 +01:00
function nv_utils.blame_line()
2021-03-17 07:19:25 +01:00
require('gitsigns').blame_line()
end
2021-03-17 05:17:41 +01:00
-- misc
2021-03-19 18:19:58 +01:00
function nv_utils.file_exists(name)
2021-03-23 03:10:58 +01:00
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
2021-03-19 18:19:58 +01:00
end
2021-03-17 05:17:41 +01:00
2021-03-17 17:47:52 +01:00
return nv_utils
2021-03-17 07:19:25 +01:00