From 5e18789e03503fa77fa25121c8e0db229499ee1b Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 6 Jun 2024 22:18:19 +0200 Subject: [PATCH] refactor: specs --- lua/lazyvim/plugins/extras/lang/sql.lua | 114 ++++++++++++------------ 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/sql.lua b/lua/lazyvim/plugins/extras/lang/sql.lua index fb25b761..0e7ea20d 100644 --- a/lua/lazyvim/plugins/extras/lang/sql.lua +++ b/lua/lazyvim/plugins/extras/lang/sql.lua @@ -3,9 +3,66 @@ local sql_ft = { "sql", "mysql", "plsql" } return { recommended = function() return LazyVim.extras.wants({ - ft = { "sql", "mysql", "plsql" }, + ft = sql_ft, }) end, + + { + "tpope/vim-dadbod", + cmd = "DB", + }, + + { + "kristijanhusak/vim-dadbod-completion", + dependencies = "vim-dadbod", + ft = sql_ft, + init = function() + vim.api.nvim_create_autocmd("FileType", { + pattern = sql_ft, + callback = function() + local cmp = require("cmp") + + -- global sources + ---@param source cmp.SourceConfig + local sources = vim.tbl_map(function(source) + return { name = source.name } + end, cmp.get_config().sources) + + -- add vim-dadbod-completion source + table.insert(sources, { name = "vim-dadbod-completion" }) + + -- update sources for the current buffer + cmp.setup.buffer({ sources = sources }) + end, + }) + end, + }, + + { + "kristijanhusak/vim-dadbod-ui", + cmd = { "DBUI", "DBUIToggle", "DBUIAddConnection", "DBUIFindBuffer" }, + dependencies = "vim-dadbod", + keys = { + { "D", "DBUIToggle", desc = "Toggle DBUI" }, + }, + init = function() + local data_path = vim.fn.stdpath("data") + + vim.g.db_ui_auto_execute_table_helpers = 1 + vim.g.db_ui_save_location = data_path .. "/dadbod_ui" + vim.g.db_ui_show_database_icon = true + vim.g.db_ui_tmp_query_location = data_path .. "/dadbod_ui/tmp" + vim.g.db_ui_use_nerd_fonts = true + vim.g.db_ui_use_nvim_notify = true + + -- NOTE: The default behavior of auto-execution of queries on save is disabled + -- this is useful when you have a big query that you don't want to run every time + -- you save the file running those queries can crash neovim to run use the + -- default keymap: S + vim.g.db_ui_execute_on_save = false + end, + }, + { "nvim-treesitter/nvim-treesitter", optional = true, @@ -23,6 +80,7 @@ return { title = "Database", ft = "dbui", pinned = true, + width = 0.3, open = function() vim.cmd("DBUI") end, @@ -34,63 +92,9 @@ return { }) end, }, - { - "tpope/vim-dadbod", - cmd = "DB", - dependencies = { - { - "kristijanhusak/vim-dadbod-completion", - ft = sql_ft, - init = function() - vim.api.nvim_create_autocmd("FileType", { - pattern = sql_ft, - callback = function() - ---@diagnostic disable-next-line: missing-fields - local cmp = require("cmp") - local global_sources = cmp.get_config().sources - local buffer_sources = {} - -- add globally defined sources (see separate nvim-cmp config) - -- this makes e.g. luasnip snippets available since luasnip is configured globally - if global_sources then - for _, source in ipairs(global_sources) do - table.insert(buffer_sources, { name = source.name }) - end - end - - -- add vim-dadbod-completion source - table.insert(buffer_sources, { name = "vim-dadbod-completion" }) - - -- update sources for the current buffer - cmp.setup.buffer({ sources = buffer_sources }) - end, - }) - end, - }, - { "jsborjesson/vim-uppercase-sql", ft = sql_ft }, - }, }, { - "kristijanhusak/vim-dadbod-ui", - cmd = { "DBUI", "DBUIToggle", "DBUIAddConnection", "DBUIFindBuffer" }, - dependencies = { - "tpope/vim-dadbod", - }, - init = function() - local data_path = vim.fn.stdpath("data") - - vim.g.db_ui_save_location = data_path .. "/dadbod_ui" - vim.g.db_ui_tmp_query_location = data_path .. "/dadbod_ui/tmp" - - vim.g.db_ui_use_nerd_fonts = true - vim.g.db_ui_show_database_icon = true - vim.g.db_ui_use_nvim_notify = true - - -- NOTE: The default behavior of auto-execution of queries on save is disabled - -- this is useful when you have a big query that you don't want to run every time - -- you save the file running those queries can crash neovim to run use the - -- default keymap: S - vim.g.db_ui_execute_on_save = false end, }, }