Add dadbod plugin for SQL manipulations

This commit is contained in:
pro100ton 2024-12-06 22:21:39 +03:00
parent 810f8f04d2
commit 969288d942
2 changed files with 88 additions and 76 deletions

View file

@ -0,0 +1,5 @@
return {
"tpope/vim-dadbod",
"kristijanhusak/vim-dadbod-completion",
"kristijanhusak/vim-dadbod-ui",
}

View file

@ -1,83 +1,90 @@
return { return {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
event = "InsertEnter", -- Only load plugin when in INSERT mode event = "InsertEnter", -- Only load plugin when in INSERT mode
dependencies = { dependencies = {
"hrsh7th/cmp-buffer", -- source for text in buffer "hrsh7th/cmp-buffer", -- source for text in buffer
"hrsh7th/cmp-path", -- source for file system paths "hrsh7th/cmp-path", -- source for file system paths
{ {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
-- follow latest release. -- follow latest release.
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release) version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
}, },
"saadparwaiz1/cmp_luasnip", -- for autocompletion "saadparwaiz1/cmp_luasnip", -- for autocompletion
"rafamadriz/friendly-snippets", -- useful snippets "rafamadriz/friendly-snippets", -- useful snippets
"onsails/lspkind.nvim", -- vs-code like pictograms "onsails/lspkind.nvim", -- vs-code like pictograms
}, },
config = function() config = function()
-- Load custom snippets from path -- Load custom snippets from path
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_vscode").lazy_load({ paths = vim.fn.stdpath("config") .. "/snippets/" }) require("luasnip.loaders.from_vscode").lazy_load({ paths = vim.fn.stdpath("config") .. "/snippets/" })
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
local lspkind = require("lspkind") local lspkind = require("lspkind")
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets) -- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({ cmp.setup({
completion = { completion = {
completeopt = "menu,menuone,preview,noselect", completeopt = "menu,menuone,preview,noselect",
}, },
snippet = { -- configure how nvim-cmp interacts with snippet engine snippet = { -- configure how nvim-cmp interacts with snippet engine
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(), ["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(), ["<C-j>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(), ["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(), ["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({ select = true }), ["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then elseif luasnip.locally_jumpable(1) then
luasnip.jump(1) luasnip.jump(1)
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
}), }),
-- sources for autocompletion -- sources for autocompletion
-- !! Priority is important - autocompletion will be ordered from top to bottom -- !! Priority is important - autocompletion will be ordered from top to bottom
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- nvim LSP servers { name = "nvim_lsp" }, -- nvim LSP servers
{ name = "luasnip" }, -- snippets { name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within current buffer { name = "buffer" }, -- text within current buffer
{ name = "path" }, -- file system paths { name = "path" }, -- file system paths
}), }),
-- configure lspkind for vs-code like pictograms in completion menu -- configure lspkind for vs-code like pictograms in completion menu
formatting = { formatting = {
format = lspkind.cmp_format({ format = lspkind.cmp_format({
maxwidth = 50, maxwidth = 50,
ellipsis_char = "...", ellipsis_char = "...",
}), }),
}, },
}) })
end,
cmp.setup.filetype({ "sql" }, {
sources = {
{ name = "vim-dadbod-completion" },
{ name = "buffer" }
}
})
end,
} }