Add dadbod as a database client for neovim

This commit is contained in:
Alexander Navarro 2023-10-29 22:24:50 -03:00
parent f9b0ddf8d9
commit 58f515d9d0
6 changed files with 91 additions and 5 deletions

View file

@ -3,6 +3,8 @@
"alpha-nvim": { "branch": "main", "commit": "234822140b265ec4ba3203e3e0be0e0bb826dff5" }, "alpha-nvim": { "branch": "main", "commit": "234822140b265ec4ba3203e3e0be0e0bb826dff5" },
"bufferline.nvim": { "branch": "main", "commit": "357cc8f8eeb64702e6fcf2995e3b9becee99a5d3" }, "bufferline.nvim": { "branch": "main", "commit": "357cc8f8eeb64702e6fcf2995e3b9becee99a5d3" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
"cmp-git": { "branch": "main", "commit": "f900a4cf117300fdc3ba31d26f8b6223ccd9c574" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
@ -54,6 +56,9 @@
"treesj": { "branch": "main", "commit": "070e6761d0b11a55446d988a69908f7a0928dbab" }, "treesj": { "branch": "main", "commit": "070e6761d0b11a55446d988a69908f7a0928dbab" },
"trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" }, "trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" },
"ts-node-action": { "branch": "master", "commit": "f266409809555d7604b1ba894ffad8958670d04f" }, "ts-node-action": { "branch": "master", "commit": "f266409809555d7604b1ba894ffad8958670d04f" },
"vim-dadbod": { "branch": "master", "commit": "fecf5a3ecfb1869f34252c7c27351de99f01ab0e" },
"vim-dadbod-completion": { "branch": "master", "commit": "bcdf3ff768cc7e544a0f78b0383d8719c2116569" },
"vim-dadbod-ui": { "branch": "master", "commit": "95fd22469507e86b78aa55d868c14108adee2881" },
"vim-fugitive": { "branch": "master", "commit": "cbe9dfa162c178946afa689dd3f42d4ea8bf89c1" }, "vim-fugitive": { "branch": "master", "commit": "cbe9dfa162c178946afa689dd3f42d4ea8bf89c1" },
"vim-illuminate": { "branch": "master", "commit": "3bd2ab64b5d63b29e05691e624927e5ebbf0fb86" }, "vim-illuminate": { "branch": "master", "commit": "3bd2ab64b5d63b29e05691e624927e5ebbf0fb86" },
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" } "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }

View file

@ -24,6 +24,8 @@ end
-- See `:help vim.keymap.set()` -- See `:help vim.keymap.set()`
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true }) vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
vim.keymap.set("n", "<C-s>", "<CMD>w<CR>", default("Keep cursor centered while junping"))
-- Remap for dealing with word wrap -- Remap for dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })

View file

@ -7,6 +7,12 @@ return { -- Change colors.none if not using a transparent background
transparent_background = false, transparent_background = false,
integrations = { integrations = {
cmp = true, cmp = true,
notify = true,
harpoon = true,
mason = true,
neogit = true,
noice = true,
lsp_trouble = true,
indent_blankline = { indent_blankline = {
enabled = true, enabled = true,
}, },
@ -17,6 +23,10 @@ return { -- Change colors.none if not using a transparent background
Pmenu = { bg = colors.none, blend = 0 }, Pmenu = { bg = colors.none, blend = 0 },
FloatBorder = { bg = colors.none }, FloatBorder = { bg = colors.none },
CmpItemMenu = { fg = colors.text, bg = colors.none }, CmpItemMenu = { fg = colors.text, bg = colors.none },
-- dadbod-ui
NotificationInfo = { bg = colors.none, fg = colors.text },
NotificationWarning = { bg = colors.none, fg = colors.yellow },
NotificationError = { bg = colors.none, fg = colors.red },
} }
end, end,
}, },

View file

@ -1,3 +1,4 @@
---@diagnostic disable: missing-fields
return { return {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
version = false, -- last release is way too old version = false, -- last release is way too old
@ -6,9 +7,11 @@ return {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
"petertriho/cmp-git",
"hrsh7th/cmp-cmdline",
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
}, },
opts = function() config = function()
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
local cmp = require("cmp") local cmp = require("cmp")
local defaults = require("cmp.config.default")() local defaults = require("cmp.config.default")()
@ -18,7 +21,7 @@ return {
-- fix colors for catppuccin colorscheme -- fix colors for catppuccin colorscheme
winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None", winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None",
} }
return { local opts = {
completion = { completion = {
completeopt = "menu,menuone,noinsert", completeopt = "menu,menuone,noinsert",
}, },
@ -37,11 +40,12 @@ return {
["<C-Space>"] = cmp.mapping.complete(), ["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(), ["<C-e>"] = cmp.mapping.abort(),
["<BR>"] = cmp.mapping.abort(), ["<BR>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ["<C-CR>"] = cmp.mapping.confirm({ select = false }), -- Confirm only if selected an item
["<S-CR>"] = cmp.mapping.confirm({ ["<CR>"] = cmp.mapping.confirm({
-- Auto confirms first item
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
}), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }),
}), }),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
@ -70,5 +74,25 @@ return {
}, },
sorting = defaults.sorting, sorting = defaults.sorting,
} }
cmp.setup(opts)
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
end, end,
} }

View file

@ -0,0 +1,44 @@
return {
"kristijanhusak/vim-dadbod-ui",
dependencies = {
{ "tpope/vim-dadbod", lazy = true },
{ "kristijanhusak/vim-dadbod-completion", ft = { "sql", "mysql", "plsql" }, lazy = true },
},
cmd = {
"DBUI",
"DBUIToggle",
"DBUIAddConnection",
"DBUIFindBuffer",
},
keys = {
{ "<Leader>ud", "<CMD>DBUIToggle<CR>", desc = "Toggle DB UI" },
},
init = function()
-- Your DBUI configuration
vim.g.db_ui_use_nerd_fonts = 1
vim.g.db_ui_force_echo_notifications = 1
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"sql",
"mysql",
"plsql",
},
command = [[setlocal omnifunc=vim_dadbod_completion#omni]],
})
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"sql",
"mysql",
"plsql",
},
callback = function()
---@diagnostic disable-next-line: missing-fields
require("cmp").setup.buffer({
sources = { { name = "vim-dadbod-completion" } },
})
end,
})
end,
}

View file

@ -22,6 +22,7 @@ return {
"python", "python",
"regex", "regex",
"rust", "rust",
"sql",
"tsx", "tsx",
"typescript", "typescript",
"vim", "vim",