From fb2bc3a713a5c7f8e6c1fee86d266d39a463a454 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Wed, 14 Jan 2026 20:11:08 -0500 Subject: [PATCH] fixing the issues on the tags --- lua/cargdev/core/keymaps/database.lua | 52 +++++++++ lua/cargdev/plugins/codetyper.lua | 12 +- lua/cargdev/plugins/dadbod.lua | 154 ++++++++++++++++++++++++++ lua/cargdev/plugins/snacks.lua | 3 +- 4 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 lua/cargdev/core/keymaps/database.lua create mode 100644 lua/cargdev/plugins/dadbod.lua diff --git a/lua/cargdev/core/keymaps/database.lua b/lua/cargdev/core/keymaps/database.lua new file mode 100644 index 0000000..91f5629 --- /dev/null +++ b/lua/cargdev/core/keymaps/database.lua @@ -0,0 +1,52 @@ +-- Database keymaps +local keymap = vim.keymap + +-- ============================================================================= +-- DATABASE KEYMAPS (vim-dadbod) +-- ============================================================================= + +-- Toggle database UI +keymap.set("n", "du", "DBUIToggle", { desc = "Toggle Database UI" }) + +-- Add a new database connection +keymap.set("n", "da", "DBUIAddConnection", { desc = "Add DB Connection" }) + +-- Find buffer (useful when you have multiple query buffers) +keymap.set("n", "df", "DBUIFindBuffer", { desc = "Find DB Buffer" }) + +-- Execute query (works in sql buffers) +keymap.set("n", "de", "(DBUI_ExecuteQuery)", { desc = "Execute Query" }) +keymap.set("v", "de", "(DBUI_ExecuteQuery)", { desc = "Execute Selected Query" }) + +-- Save query +keymap.set("n", "dw", "(DBUI_SaveQuery)", { desc = "Save Query" }) + +-- Rename buffer +keymap.set("n", "dr", "(DBUI_RenameBuf)", { desc = "Rename DB Buffer" }) + +-- ============================================================================= +-- QUICK CONNECTIONS +-- ============================================================================= + +-- PostgreSQL Docker (default: 5432 postgres postgres postgres) +keymap.set("n", "dp", "DBPostgresDocker", { desc = "Connect PostgreSQL Docker" }) + +-- ============================================================================= +-- MONGODB +-- ============================================================================= + +-- Open MongoDB shell (local) +keymap.set("n", "dm", "MongoDB", { desc = "Open MongoDB Shell" }) + +-- Open MongoDB in Docker container +keymap.set("n", "dM", "MongoDBDocker", { desc = "MongoDB Docker Shell" }) + +-- ============================================================================= +-- REDIS +-- ============================================================================= + +-- Open Redis CLI (local) +keymap.set("n", "di", "Redis", { desc = "Open Redis CLI" }) + +-- Open Redis in Docker container +keymap.set("n", "dI", "RedisDocker", { desc = "Redis Docker CLI" }) diff --git a/lua/cargdev/plugins/codetyper.lua b/lua/cargdev/plugins/codetyper.lua index 5cd3052..b28a088 100644 --- a/lua/cargdev/plugins/codetyper.lua +++ b/lua/cargdev/plugins/codetyper.lua @@ -50,7 +50,7 @@ return { require("codetyper").setup({ llm = { -- Available providers: "ollama", "claude", "openai", "gemini", "copilot" - provider = "ollama", + provider = "copilot", -- Using GitHub Copilot -- Ollama (local LLM) ollama = { @@ -84,10 +84,10 @@ return { -- -- model = "gemini-2.0-flash-exp", -- }, - -- GitHub Copilot (requires copilot.vim or copilot.lua plugin) - -- copilot = { - -- enabled = true, - -- }, + -- GitHub Copilot (uses OAuth from copilot.vim/copilot.lua) + copilot = { + model = "gpt-4o", -- or "gpt-4", "gpt-3.5-turbo" + }, }, window = { width = 0.25, -- 1/4 of window @@ -104,7 +104,7 @@ return { agent_mode = false, scheduler = { enabled = true, - ollama_scout = true, -- Use ollama first, escalate if low confidence + ollama_scout = false, -- Disabled since using Copilot directly escalation_threshold = 0.7, max_concurrent = 2, completion_delay_ms = 100, -- Delay before checking completion visibility diff --git a/lua/cargdev/plugins/dadbod.lua b/lua/cargdev/plugins/dadbod.lua new file mode 100644 index 0000000..bf8f8df --- /dev/null +++ b/lua/cargdev/plugins/dadbod.lua @@ -0,0 +1,154 @@ +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", + }, + init = function() + -- Database UI configuration + vim.g.db_ui_use_nerd_fonts = 1 + vim.g.db_ui_show_database_icon = 1 + vim.g.db_ui_force_echo_notifications = 1 + + -- Save query results to a file + vim.g.db_ui_save_location = vim.fn.stdpath("data") .. "/db_ui" + + -- Use better split + vim.g.db_ui_win_position = "left" + vim.g.db_ui_winwidth = 40 + + -- Table helpers + vim.g.db_ui_table_helpers = { + postgresql = { + Count = "SELECT COUNT(*) FROM {table}", + List = "SELECT * FROM {table} LIMIT 100", + Schema = "\\d+ {table}", + Indexes = "SELECT * FROM pg_indexes WHERE tablename = '{table}'", + Size = "SELECT pg_size_pretty(pg_total_relation_size('{table}'))", + }, + mysql = { + Count = "SELECT COUNT(*) FROM {table}", + List = "SELECT * FROM {table} LIMIT 100", + Schema = "DESCRIBE {table}", + Indexes = "SHOW INDEX FROM {table}", + }, + sqlite = { + Count = "SELECT COUNT(*) FROM {table}", + List = "SELECT * FROM {table} LIMIT 100", + Schema = ".schema {table}", + }, + } + + -- Icons + vim.g.db_ui_icons = { + expanded = "▾", + collapsed = "▸", + saved_query = "*", + new_query = "+", + tables = "~", + buffers = "»", + connection_ok = "✓", + connection_error = "✕", + } + + -- Quick connect to Docker PostgreSQL + -- Use 127.0.0.1 instead of localhost (localhost may resolve to IPv6) + vim.api.nvim_create_user_command("DBPostgresDocker", function(opts) + local args = opts.args + local port = "5432" + local user = "postgres" + local password = "postgres" + local database = "postgres" + + -- Parse arguments: port user password database + local parts = vim.split(args, " ") + if parts[1] and parts[1] ~= "" then port = parts[1] end + if parts[2] and parts[2] ~= "" then user = parts[2] end + if parts[3] and parts[3] ~= "" then password = parts[3] end + if parts[4] and parts[4] ~= "" then database = parts[4] end + + local url = string.format("postgresql://%s:%s@127.0.0.1:%s/%s", user, password, port, database) + -- Set the connection and open DBUI + local dbs = vim.g.dbs or {} + dbs[database] = url + vim.g.dbs = dbs + vim.cmd("DBUIToggle") + vim.notify("Added PostgreSQL connection: " .. database, vim.log.levels.INFO) + end, { + nargs = "*", + desc = "Connect to Docker PostgreSQL (args: port user password database)", + }) + + -- MongoDB terminal command + vim.api.nvim_create_user_command("MongoDB", function(opts) + local args = opts.args + local cmd = "mongosh" + if args and args ~= "" then + cmd = cmd .. " " .. args + else + cmd = cmd .. " mongodb://127.0.0.1:27017" + end + vim.cmd("terminal " .. cmd) + vim.cmd("startinsert") + end, { + nargs = "*", + desc = "Open MongoDB shell (args: connection string or options)", + }) + + -- Redis terminal command + vim.api.nvim_create_user_command("Redis", function(opts) + local args = opts.args + local cmd = "redis-cli" + if args and args ~= "" then + cmd = cmd .. " " .. args + else + cmd = cmd .. " -h 127.0.0.1 -p 6379" + end + vim.cmd("terminal " .. cmd) + vim.cmd("startinsert") + end, { + nargs = "*", + desc = "Open Redis CLI (args: host/port options)", + }) + + -- MongoDB with Docker + vim.api.nvim_create_user_command("MongoDBDocker", function(opts) + local container = opts.args ~= "" and opts.args or "mongodb" + vim.cmd("terminal docker exec -it " .. container .. " mongosh") + vim.cmd("startinsert") + end, { + nargs = "?", + desc = "Open MongoDB shell in Docker container (arg: container name)", + }) + + -- Redis with Docker + vim.api.nvim_create_user_command("RedisDocker", function(opts) + local container = opts.args ~= "" and opts.args or "redis" + vim.cmd("terminal docker exec -it " .. container .. " redis-cli") + vim.cmd("startinsert") + end, { + nargs = "?", + desc = "Open Redis CLI in Docker container (arg: container name)", + }) + end, + config = function() + -- Setup completion for sql files + vim.api.nvim_create_autocmd("FileType", { + pattern = { "sql", "mysql", "plsql" }, + callback = function() + require("cmp").setup.buffer({ + sources = { + { name = "vim-dadbod-completion" }, + { name = "buffer" }, + }, + }) + end, + }) + end, +} diff --git a/lua/cargdev/plugins/snacks.lua b/lua/cargdev/plugins/snacks.lua index 4b6f453..25eb46a 100644 --- a/lua/cargdev/plugins/snacks.lua +++ b/lua/cargdev/plugins/snacks.lua @@ -24,7 +24,7 @@ return { { section = "startup" }, }, }, - explorer = { enabled = true }, + explorer = { enabled = false }, image = { enabled = true, terminal = nil, @@ -51,5 +51,6 @@ return { vim.ui.input = require("snacks.input").input vim.ui.select = require("snacks.picker").select end) + end, }