diff --git a/lua/lazyvim/config/autocmds.lua b/lua/lazyvim/config/autocmds.lua index 5b519797..2fc283ba 100644 --- a/lua/lazyvim/config/autocmds.lua +++ b/lua/lazyvim/config/autocmds.lua @@ -66,6 +66,7 @@ vim.api.nvim_create_autocmd("FileType", { "checkhealth", "neotest-summary", "neotest-output-panel", + "dbout", }, callback = function(event) vim.bo[event.buf].buflisted = false diff --git a/lua/lazyvim/plugins/extras/lang/sql.lua b/lua/lazyvim/plugins/extras/lang/sql.lua new file mode 100644 index 00000000..6e43c0ef --- /dev/null +++ b/lua/lazyvim/plugins/extras/lang/sql.lua @@ -0,0 +1,130 @@ +local sql_ft = { "sql", "mysql", "plsql" } + +return { + recommended = function() + return LazyVim.extras.wants({ + 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, + }, + + -- Treesitter + { + "nvim-treesitter/nvim-treesitter", + optional = true, + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "sql" }) + end + end, + }, + + -- Edgy integration + { + "folke/edgy.nvim", + optional = true, + opts = function(_, opts) + table.insert(opts.right, { + title = "Database", + ft = "dbui", + pinned = true, + width = 0.3, + open = function() + vim.cmd("DBUI") + end, + }) + + table.insert(opts.bottom, { + title = "DB Query Result", + ft = "dbout", + }) + end, + }, + + -- Linters & formatters + { + "williamboman/mason.nvim", + opts = function(_, opts) + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { "sqlfluff" }) + end, + }, + { + "mfussenegger/nvim-lint", + optional = true, + opts = function(_, opts) + for _, ft in ipairs(sql_ft) do + opts.linters_by_ft[ft] = opts.linters_by_ft[ft] or {} + table.insert(opts.linters_by_ft[ft], "sqlfluff") + end + end, + }, + { + "stevearc/conform.nvim", + optional = true, + opts = function(_, opts) + opts.formatters.sqlfluff = { + args = { "format", "--dialect=ansi", "-" }, + } + for _, ft in ipairs(sql_ft) do + opts.formatters_by_ft[ft] = opts.formatters_by_ft[ft] or {} + table.insert(opts.formatters_by_ft[ft], "sqlfluff") + end + end, + }, +}