lua format

This commit is contained in:
2022-03-16 22:56:51 +01:00
parent 4c543d7f44
commit c3deaa45c6
17 changed files with 343 additions and 325 deletions

View File

@@ -1,4 +1,4 @@
local opt = vim.opt -- to set options
local opt = vim.opt -- to set options
local utils = require('utils')
-- require('telescope').load_extension('cmake')
require('cmake').setup({
@@ -8,7 +8,6 @@ require('cmake').setup({
utils.map('n', '<F5>', ':CMake build<CR>:copen<CR>')
-- msbuild errorformat
opt.errorformat:append("\\ %#%f(%l\\\\\\,%c):\\ %m")
opt.errorformat:append('\\ %#%f(%l\\\\\\,%c):\\ %m')
-- cl.exe errorformat
-- o.errorformat:append('\ %#%f(%l) : %#%t%[A-z]%# %m')

View File

@@ -1,101 +1,106 @@
local cmp = require('cmp')
local luasnip = require("luasnip")
local luasnip = require('luasnip')
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil
local col = vim.fn.col('.') - 1
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
end
cmp.setup {
cmp.setup({
formatting = {
format = function(entry, vim_item)
-- fancy icons and a name of kind
vim_item.kind = require("lspkind").presets.default[vim_item.kind] ..
" " .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
ultisnips = "[UltiSnips]",
nvim_lua = "[Lua]",
cmp_tabnine = "[TabNine]",
look = "[Look]",
path = "[Path]",
spell = "[Spell]",
calc = "[Calc]",
emoji = "[Emoji]"
})[entry.source.name]
return vim_item
end
},
mapping = {
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's'}),
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }),
['<C-e>'] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }),
['<CR>'] = cmp.mapping({
i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
c = cmp.mapping.confirm({ select = false }),
s = cmp.mapping.confirm({ select = false }),
}),
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
vim.api.nvim_feedkeys(t("<Plug>luasnip-expand-or-jump"), "", true)
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
vim.api.nvim_feedkeys(t("<Plug>luasnip-jump-prev"), "", true)
else
fallback()
end
end, {
"i",
"s",
}),
},
snippet = {
expand = function(args)
require'luasnip'.lsp_expand(args.body)
formatting = {
format = function(entry, vim_item)
-- fancy icons and a name of kind
vim_item.kind = require('lspkind').presets.default[vim_item.kind] .. ' ' .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
ultisnips = '[UltiSnips]',
nvim_lua = '[Lua]',
cmp_tabnine = '[TabNine]',
look = '[Look]',
path = '[Path]',
spell = '[Spell]',
calc = '[Calc]',
emoji = '[Emoji]',
})[entry.source.name]
return vim_item
end,
},
mapping = {
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }),
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }),
['<C-e>'] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }),
['<CR>'] = cmp.mapping({
i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
c = cmp.mapping.confirm({ select = false }),
s = cmp.mapping.confirm({ select = false }),
}),
['<Tab>'] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
vim.api.nvim_feedkeys(t('<Plug>luasnip-expand-or-jump'), '', true)
else
fallback()
end
},
sources = {
{name = "luasnip"}, {name = 'nvim_lsp'}, {name = 'buffer'},
{name = "nvim_lua"}, {name = "look"}, {name = "path"},
{name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"},
{name = "emoji"}
},
completion = {completeopt = 'menu,menuone,noinsert, noselect'},
-- experimental = { native_menu = true }
}
end, {
'i',
's',
}),
['<S-Tab>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
vim.api.nvim_feedkeys(t('<Plug>luasnip-jump-prev'), '', true)
else
fallback()
end
end, {
'i',
's',
}),
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
sources = {
{ name = 'luasnip' },
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'nvim_lua' },
{ name = 'look' },
{ name = 'path' },
{ name = 'cmp_tabnine' },
{ name = 'calc' },
{ name = 'spell' },
{ name = 'emoji' },
},
completion = { completeopt = 'menu,menuone,noinsert, noselect' },
-- experimental = { native_menu = true }
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
{ name = 'buffer' },
},
})
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
{ name = 'path' },
}, {
{ name = 'cmdline' }
{ name = 'cmdline' },
}, {
{ name = 'buffer' }
{ name = 'buffer' },
}),
})
@@ -106,13 +111,16 @@ cmp.setup.cmdline(':', {
-- auto_select = true
--})
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
-- TabNine
--local tabnine = require('cmp_tabnine.config')
--tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true})
-- Database completion
vim.api.nvim_exec([[
vim.api.nvim_exec(
[[
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
]], false)
]],
false
)

View File

@@ -1,12 +1,12 @@
local opt = vim.opt -- to set options
opt.listchars:append("eol:↴")
local opt = vim.opt -- to set options
opt.listchars:append('eol:↴')
-- opt.listchars:append("space: ")
opt.listchars:append("trail: ")
opt.listchars:append("tab:→ ")
opt.listchars:append('trail: ')
opt.listchars:append('tab:→ ')
require("indent_blankline").setup {
require('indent_blankline').setup({
show_end_of_line = true,
use_treesitter = true,
show_current_context = true,
context_patterns = {'class', 'function', 'method', 'block', '^if', '^for', '^while'},
}
context_patterns = { 'class', 'function', 'method', 'block', '^if', '^for', '^while' },
})

View File

@@ -9,7 +9,7 @@ capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
capabilities.offsetEncoding = { "utf-16" }
capabilities.offsetEncoding = { 'utf-16' }
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = {
'documentation',
@@ -19,14 +19,18 @@ capabilities.textDocument.completion.completionItem.resolveSupport = {
}
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
vim.api.nvim_buf_set_option(0, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
-- Mappings.
local opts = { noremap=true, silent=true }
local opts = { noremap = true, silent = true }
buf_set_keymap('n', '<space>,', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', '<space>;', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>a', '<cmd>Telescope lsp_code_actions<CR>', opts)
@@ -47,7 +51,7 @@ local on_attach = function(client, bufnr)
buf_set_keymap('n', '<space>v', '<cmd>Telescope diagnostics bufnr=0<cr>', opts)
buf_set_keymap('n', '<A-o>', ':ClangdSwitchSourceHeader<CR>', opts)
vim.cmd [[autocmd CursorHold <buffer> lua vim.diagnostic.open_float({focusable = false})]]
vim.cmd([[autocmd CursorHold <buffer> lua vim.diagnostic.open_float({focusable = false})]])
-- Set some keybinds conditional on server capabilities
if client.resolved_capabilities.document_formatting then
@@ -59,7 +63,8 @@ local on_attach = function(client, bufnr)
-- Set autocommands conditional on server_capabilities
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec([[
vim.api.nvim_exec(
[[
hi LspReferenceRead cterm=bold ctermbg=red guibg=DarkGreen
hi LspReferenceWrite cterm=bold ctermbg=red guibg=DarkRed
augroup lsp_document_highlight
@@ -68,34 +73,36 @@ local on_attach = function(client, bufnr)
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]], false)
]],
false
)
end
require "lsp_signature".on_attach({
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = "single"
},
hi_parameter = "IncSearch"
}, bufnr)
require('lsp_signature').on_attach({
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = 'single',
},
hi_parameter = 'IncSearch',
}, bufnr)
end
local lsp_installer = require("nvim-lsp-installer")
local lsp_installer = require('nvim-lsp-installer')
local servers = {
"pyright",
"cmake",
"clangd",
"jsonls",
"groovyls",
"sumneko_lua",
"dockerls",
'pyright',
'cmake',
'clangd',
'jsonls',
'groovyls',
'sumneko_lua',
'dockerls',
}
for _, name in pairs(servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
print('Installing ' .. name)
server:install()
end
end
@@ -107,18 +114,18 @@ lsp_installer.on_server_ready(function(server)
capabilities = capabilities,
}
-- (optional) Customize the options passed to the server
if server.name == "clangd" then
opts.cmd = { "clangd" , "--compile-commands-dir=build_nvim"}
end
-- (optional) Customize the options passed to the server
if server.name == 'clangd' then
opts.cmd = { 'clangd', '--compile-commands-dir=build_nvim' }
end
-- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart)
server:setup(opts)
vim.cmd [[ do User LspAttachBuffers ]]
-- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart)
server:setup(opts)
vim.cmd([[ do User LspAttachBuffers ]])
end)
local null_ls = require("null-ls")
null_ls.setup {
local null_ls = require('null-ls')
null_ls.setup({
sources = {
null_ls.builtins.code_actions.gitsigns,
null_ls.builtins.formatting.autopep8,
@@ -126,9 +133,9 @@ null_ls.setup {
null_ls.builtins.formatting.stylua,
null_ls.builtins.diagnostics.flake8,
null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.cmake_format
null_ls.builtins.formatting.cmake_format,
},
on_attach = on_attach,
capabilities = capabilities
}
vim.diagnostic.config({virtual_text = false})
capabilities = capabilities,
})
vim.diagnostic.config({ virtual_text = false })

View File

@@ -1,5 +1,5 @@
require('lualine').setup {
options = {theme = 'gruvbox-material'},
sections = {lualine_c = {'getcwd', {'filename', path = 1, file_status = true}}},
inactive_sections = {lualine_c = {'getcwd', {'filename', path = 1, file_status = true}}}
}
require('lualine').setup({
options = { theme = 'gruvbox-material' },
sections = { lualine_c = { 'getcwd', { 'filename', path = 1, file_status = true } } },
inactive_sections = { lualine_c = { 'getcwd', { 'filename', path = 1, file_status = true } } },
})

View File

@@ -1,5 +1,5 @@
local ls = require("luasnip")
require("luasnip.loaders.from_vscode").load()
local ls = require('luasnip')
require('luasnip.loaders.from_vscode').load()
-- some shorthands...
local s = ls.snippet
local sn = ls.snippet_node
@@ -10,25 +10,24 @@ local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local r = ls.restore_node
local l = require("luasnip.extras").lambda
local rep = require("luasnip.extras").rep
local p = require("luasnip.extras").partial
local m = require("luasnip.extras").match
local n = require("luasnip.extras").nonempty
local dl = require("luasnip.extras").dynamic_lambda
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local types = require("luasnip.util.types")
local conds = require("luasnip.extras.expand_conditions")
local l = require('luasnip.extras').lambda
local rep = require('luasnip.extras').rep
local p = require('luasnip.extras').partial
local m = require('luasnip.extras').match
local n = require('luasnip.extras').nonempty
local dl = require('luasnip.extras').dynamic_lambda
local fmt = require('luasnip.extras.fmt').fmt
local fmta = require('luasnip.extras.fmt').fmta
local types = require('luasnip.util.types')
local conds = require('luasnip.extras.expand_conditions')
local function getRegA(capitalize)
local clipboard = vim.fn.getreg('a')
clipboard = clipboard:gsub('^m_', '')
if capitalize then
clipboard = clipboard:gsub("^%l", string.upper);
clipboard = clipboard:gsub('^%l', string.upper)
end
return clipboard
return clipboard
end

View File

@@ -1,20 +1,20 @@
require('neogen').setup {
require('neogen').setup({
enabled = true,
languages = {
cpp = {
template = {
annotation_convention = "custom",
custom = {
{ nil, "/// file", { no_results = true, type = { "file" } } },
{ nil, "/// $1", { no_results = true, type = { "func", "file" } } },
{ nil, "", { no_results = true, type = { "file" } } },
annotation_convention = 'custom',
custom = {
{ nil, '/// file', { no_results = true, type = { 'file' } } },
{ nil, '/// $1', { no_results = true, type = { 'func', 'file' } } },
{ nil, '', { no_results = true, type = { 'file' } } },
{ nil, "/// $1", { type = { "func" } } },
{ "tparam", "/// \\tparam %s $1" },
{ "parameters", "/// \\param %s $1" },
{ "return_statement", "/// \\return $1" },
{ nil, '/// $1', { type = { 'func' } } },
{ 'tparam', '/// \\tparam %s $1' },
{ 'parameters', '/// \\param %s $1' },
{ 'return_statement', '/// \\return $1' },
},
}
},
},
}
}
},
})

View File

@@ -1 +1 @@
require('nvim-autopairs').setup{}
require('nvim-autopairs').setup({})

View File

@@ -1,26 +1,26 @@
local utils = require('utils')
require('nvim-tree').setup({
auto_close = true,
update_cwd = true,
update_to_buf_dir = {
update_cwd = true,
update_to_buf_dir = {
-- enable the feature
enable = true,
-- allow to open the tree if it was previously closed
auto_open = false,
},
update_focused_file = {
enable = true,
update_cwd = false,
ignore_list = {}
enable = true,
update_cwd = false,
ignore_list = {},
},
diagnostics = {
diagnostics = {
enable = true,
icons = {
hint = "",
info = "",
warning = "",
error = "",
}
hint = '',
info = '',
warning = '',
error = '',
},
},
})
utils.map('n', '<leader>tt', '<cmd>NvimTreeToggle<CR>')

View File

@@ -1,6 +1,6 @@
local utils = require('utils')
require("project_nvim").setup {
require('project_nvim').setup({
silent_chdir = true,
}
})
require('telescope').load_extension('projects')
utils.map('n', '<space>p', '<cmd>Telescope projects<cr>')

View File

@@ -4,19 +4,19 @@ local mappingTab = {
i = {
['<cr>'] = actions.select_tab,
['<C-b>'] = actions.select_default,
}
},
}
require('telescope').setup {
require('telescope').setup({
defaults = {
mappings = {
i = {
['<esc>'] = actions.close,
['<cr>'] = actions.select_default + actions.center,
['<C-l>'] = actions.send_selected_to_loclist,
['<C-q>'] = actions.smart_send_to_qflist
}
}
['<C-q>'] = actions.smart_send_to_qflist,
},
},
},
pickers = {
-- Your special builtin config goes in here
@@ -30,8 +30,8 @@ require('telescope').setup {
},
n = {
['<c-w>'] = actions.delete_buffer,
}
}
},
},
},
find_files = {
theme = 'ivy',
@@ -44,9 +44,8 @@ require('telescope').setup {
theme = 'ivy',
previewer = false,
},
lsp_dynamic_workspace_symbols = {
},
}
}
lsp_dynamic_workspace_symbols = {},
},
})
require('telescope').load_extension('fzf')