lua: Fix formatting with lua-format

This commit is contained in:
Marty Oehme 2020-11-06 15:03:33 +01:00
parent b57db544b7
commit 0e34af1992
Signed by: Marty
GPG key ID: B7538B8F50A1C800
13 changed files with 3867 additions and 3385 deletions

View file

@ -3,40 +3,42 @@ local api = vim.api
function M.blameVirtText()
-- get the current file extension
local ft = vim.fn.expand('%:h:t')
-- get the current file extension
local ft = vim.fn.expand('%:h:t')
if ft == '' or ft == 'bin' then -- if we are in a scratch buffer, unknown filetype, or nvim's terminal window
return
end
M.clearBlameVirtText()
local currFile = vim.fn.expand('%')
local line = api.nvim_win_get_cursor(0)
local blame = vim.fn.system(string.format('git blame -c -L %d,%d %s', line[1], line[1], currFile))
local hash = vim.split(blame, '%s')[1]
local cmd = string.format("git show %s ", hash).."--format='%an | %ar | %s'"
if hash == '00000000' then
text = 'Not Committed Yet'
else
text = vim.fn.system(cmd)
text = vim.split(text, '\n')[1]
if text:find("fatal") then -- if the call to git show fails
text = 'Not Committed Yet'
if ft == '' or ft == 'bin' then -- if we are in a scratch buffer, unknown filetype, or nvim's terminal window
return
end
end
-- set virtual text for namespace 2 with the content from git and assign it to the higlight group 'GitLens'
api.nvim_buf_set_virtual_text(0, 2, line[1] - 1, {{ text,'GitLens' }}, {})
M.clearBlameVirtText()
local currFile = vim.fn.expand('%')
local line = api.nvim_win_get_cursor(0)
local blame = vim.fn.system(string.format('git blame -c -L %d,%d %s',
line[1], line[1], currFile))
local hash = vim.split(blame, '%s')[1]
local cmd = string.format("git show %s ", hash) ..
"--format='%an | %ar | %s'"
if hash == '00000000' then
text = 'Not Committed Yet'
else
text = vim.fn.system(cmd)
text = vim.split(text, '\n')[1]
if text:find("fatal") then -- if the call to git show fails
text = 'Not Committed Yet'
end
end
-- set virtual text for namespace 2 with the content from git and assign it to the higlight group 'GitLens'
api.nvim_buf_set_virtual_text(0, 2, line[1] - 1, {{text, 'GitLens'}}, {})
end
-- important for clearing out the text when our cursor moves
function M.clearBlameVirtText()
-- clear out virtual text from namespace 2 (the namespace we will set later)
api.nvim_buf_clear_namespace(0, 2, 0, -1)
-- clear out virtual text from namespace 2 (the namespace we will set later)
api.nvim_buf_clear_namespace(0, 2, 0, -1)
end
return M

View file

@ -1,31 +1,43 @@
local on_attach = function(client, bufnr)
-- Keybindings for LSPs
-- Note these are in on_attach so that they don't override bindings in a non-LSP setting
vim.fn.nvim_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.implementation()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gK", "<cmd>lua vim.lsp.buf.signature_help()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "1gD", "<cmd>lua vim.lsp.buf.type_definition()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gW", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", {noremap = true, silent = true})
-- Keybindings for LSPs
-- Note these are in on_attach so that they don't override bindings in a non-LSP setting
vim.fn.nvim_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gD",
"<cmd>lua vim.lsp.buf.implementation()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gK",
"<cmd>lua vim.lsp.buf.signature_help()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "1gD",
"<cmd>lua vim.lsp.buf.type_definition()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "g0",
"<cmd>lua vim.lsp.buf.document_symbol()<CR>",
{noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gW",
"<cmd>lua vim.lsp.buf.workspace_symbol()<CR>",
{noremap = true, silent = true})
end
require'nvim_lsp'.pyls.setup{on_attach=on_attach}
require'nvim_lsp'.vimls.setup{on_attach=on_attach}
require'nvim_lsp'.bashls.setup{on_attach=on_attach}
require'nvim_lsp'.gopls.setup{on_attach=on_attach}
require'nvim_lsp'.texlab.setup{on_attach=on_attach}
require'nvim_lsp'.pyls.setup {on_attach = on_attach}
require'nvim_lsp'.vimls.setup {on_attach = on_attach}
require'nvim_lsp'.bashls.setup {on_attach = on_attach}
require'nvim_lsp'.gopls.setup {on_attach = on_attach}
require'nvim_lsp'.texlab.setup {on_attach = on_attach}
-- To get builtin LSP running, do something like:
-- NOTE: This replaces the calls where you would have before done `require('nvim_lsp').sumneko_lua.setup()`
require('nlua.lsp.nvim').setup(require('nvim_lsp'), {
on_attach = on_attach,
on_attach = on_attach,
-- Include globals you want to tell the LSP are real :)
globals = {
-- Colorbuddy
"Color", "c", "Group", "g", "s",
}
-- Include globals you want to tell the LSP are real :)
globals = {
-- Colorbuddy
"Color", "c", "Group", "g", "s"
}
})

View file

@ -1,13 +1,12 @@
local M = {}
function M.getCompletionItems(prefix)
-- define your total completion items
local items = vim.api.nvim_call_function('pandoc#completion#Complete',{0, prefix})
return items
-- define your total completion items
local items = vim.api.nvim_call_function('pandoc#completion#Complete',
{0, prefix})
return items
end
M.complete_item = {
item = M.getCompletionItems
}
M.complete_item = {item = M.getCompletionItems}
return M

View file

@ -9,32 +9,34 @@ window, otherwise opens a new split.
The buffer, by default is set to the pandoc filetype.
This can be changed by setting the `g:scratchpad_ft` variable or the `b:scratchpad_ft`
variable to the intended filetype.
]]--
]] --
local api = vim.api
local M= {}
local M = {}
local function isempty(s)
return s == nil or s == ''
end
local function isempty(s) return s == nil or s == '' end
function M.create(split, ft)
-- should we create a new split or switch out the current buffer?
if isempty(split) then split = false else split = true end
-- which filetype to set for the scratchpad, defaults to pandoc
if isempty(ft) then ft = vim.b["scratchpad_ft"] or vim.g["scratchpad_ft"] or "pandoc" end
-- should we create a new split or switch out the current buffer?
if isempty(split) then
split = false
else
split = true
end
-- which filetype to set for the scratchpad, defaults to pandoc
if isempty(ft) then
ft = vim.b["scratchpad_ft"] or vim.g["scratchpad_ft"] or "pandoc"
end
local buf = api.nvim_create_buf(false, true)
if buf == 0 then
print("Error opening scratch buffer.")
end
api.nvim_buf_set_option(buf, "bufhidden", "hide")
api.nvim_buf_set_option(buf, "buftype", "nofile")
api.nvim_buf_set_option(buf, "swapfile",false)
api.nvim_buf_set_option(buf, "filetype",ft)
local buf = api.nvim_create_buf(false, true)
if buf == 0 then print("Error opening scratch buffer.") end
api.nvim_buf_set_option(buf, "bufhidden", "hide")
api.nvim_buf_set_option(buf, "buftype", "nofile")
api.nvim_buf_set_option(buf, "swapfile", false)
api.nvim_buf_set_option(buf, "filetype", ft)
if split then api.nvim_command('vsplit new') end -- i think this is the only way to interact with the buffers creating a new split
-- switch to scratchpad
api.nvim_win_set_buf(0, buf)
if split then api.nvim_command('vsplit new') end -- i think this is the only way to interact with the buffers creating a new split
-- switch to scratchpad
api.nvim_win_set_buf(0, buf)
end
return M

View file

@ -1,17 +1,15 @@
local w = vim.loop.new_fs_event()
local function on_change(err, fname, status)
-- Do work...
vim.api.nvim_command('checktime')
-- Debounce: stop/start.
w:stop()
watch_file(fname)
-- Do work...
vim.api.nvim_command('checktime')
-- Debounce: stop/start.
w:stop()
watch_file(fname)
end
function watch_file(fname)
local fullpath = vim.api.nvim_call_function(
'fnamemodify', {fname, ':p'})
w:start(fullpath, {}, vim.schedule_wrap(function(...)
on_change(...) end))
local fullpath = vim.api.nvim_call_function('fnamemodify', {fname, ':p'})
w:start(fullpath, {}, vim.schedule_wrap(function(...) on_change(...) end))
end
vim.api.nvim_command(
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")