From fe2729a100f8a939dd45d3ae5e1c3eb034363dd3 Mon Sep 17 00:00:00 2001 From: Gustavo Silva Date: Wed, 25 Oct 2023 21:56:32 +0200 Subject: [PATCH] add dadbod --- init.lua | 9 +++ lua/custom/configs/maps.lua | 3 + lua/custom/configs/settings.lua | 2 +- lua/custom/plugins/README.md | 5 ++ lua/custom/plugins/dadbod.lua | 3 + lua/custom/plugins/dadbod_autocompletion.lua | 3 + lua/custom/plugins/dadbod_ui.lua | 48 +++++++++++++ lua/custom/plugins/debug.lua | 73 ++++++++++++++------ lua/custom/plugins/go.lua | 5 +- lua/custom/plugins/null_ls.lua | 4 +- 10 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 lua/custom/plugins/dadbod.lua create mode 100644 lua/custom/plugins/dadbod_autocompletion.lua create mode 100644 lua/custom/plugins/dadbod_ui.lua diff --git a/init.lua b/init.lua index a6ef5176..1fdb5312 100644 --- a/init.lua +++ b/init.lua @@ -198,6 +198,15 @@ require('lazy').setup({ map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) end, }, + config = function() + require('gitsigns').setup { + current_line_blame = true, + current_line_blame_opts = { + delay = 1000, + virt_text_pos = 'eol', + }, + } + end, }, { diff --git a/lua/custom/configs/maps.lua b/lua/custom/configs/maps.lua index c44ddca1..d80d43f0 100644 --- a/lua/custom/configs/maps.lua +++ b/lua/custom/configs/maps.lua @@ -2,6 +2,9 @@ local function map(mode, lhs, rhs) vim.keymap.set(mode, lhs, rhs, { silent = true }) end +-- (conflict with pw) keep copied stuffs in the buffer when pasting it +-- map("n", "p", "\"_dP") + -- Save map("n", "w", "update") diff --git a/lua/custom/configs/settings.lua b/lua/custom/configs/settings.lua index 8eb77107..fd0d34e9 100644 --- a/lua/custom/configs/settings.lua +++ b/lua/custom/configs/settings.lua @@ -36,7 +36,7 @@ o.swapfile = false -- Scrolling settings o.scrolloff = 8 -o.colorcolumn = '80' +o.colorcolumn = '120' o.timeoutlen = 500 diff --git a/lua/custom/plugins/README.md b/lua/custom/plugins/README.md index eea2655a..d30d21ec 100644 --- a/lua/custom/plugins/README.md +++ b/lua/custom/plugins/README.md @@ -45,3 +45,8 @@ install requests ``` sudo apt install python3-requests ``` + +format json (require jq installed) +``` +:%!jq . +``` diff --git a/lua/custom/plugins/dadbod.lua b/lua/custom/plugins/dadbod.lua new file mode 100644 index 00000000..6816b106 --- /dev/null +++ b/lua/custom/plugins/dadbod.lua @@ -0,0 +1,3 @@ +return { + "tpope/vim-dadbod", +} diff --git a/lua/custom/plugins/dadbod_autocompletion.lua b/lua/custom/plugins/dadbod_autocompletion.lua new file mode 100644 index 00000000..73653c38 --- /dev/null +++ b/lua/custom/plugins/dadbod_autocompletion.lua @@ -0,0 +1,3 @@ +return { + "kristijanhusak/vim-dadbod-completion", +} diff --git a/lua/custom/plugins/dadbod_ui.lua b/lua/custom/plugins/dadbod_ui.lua new file mode 100644 index 00000000..f1fd5c51 --- /dev/null +++ b/lua/custom/plugins/dadbod_ui.lua @@ -0,0 +1,48 @@ +return { + "kristijanhusak/vim-dadbod-ui", + dependencies = { + { 'tpope/vim-dadbod', lazy = true }, + { 'kristijanhusak/vim-dadbod-completion', ft = { 'javascript' }, lazy = true }, + }, + ft = { 'javascript' }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer', + }, + init = function() + -- Your DBUI configuration + vim.g.db_ui_use_nerd_fonts = 1 + vim.o.filetype = 'javascript' + end, + config = function() + vim.keymap.set("n", 'du', 'DBUIToggle') + vim.keymap.set("n", 'dl', 'DBUILastQueryInfo') + + vim.o.filetype = 'javascript' + vim.api.nvim_create_autocmd("FileType", { + pattern = { + "javascript", + }, + command = [[setlocal omnifunc=vim_dadbod_completion#omni]], + }) + + vim.api.nvim_create_autocmd("FileType", { + pattern = { + "sql", + "javascript", + }, + callback = function() + vim.schedule(function() + require("cmp").setup.buffer { sources = { { name = "vim-dadbod-completion" } } } + end + ) + end, + }) +-- nnoremap du :DBUIToggle +-- nnoremap df :DBUIFindBuffer +-- nnoremap dr :DBUIRenameBuffer +-- nnoremap dl :DBUILastQueryInfo + end, +} diff --git a/lua/custom/plugins/debug.lua b/lua/custom/plugins/debug.lua index c9b9a6b1..1abd8f53 100644 --- a/lua/custom/plugins/debug.lua +++ b/lua/custom/plugins/debug.lua @@ -58,7 +58,7 @@ return { -- a string that defines the port to start delve debugger. -- default to string "${port}" which instructs nvim-dap -- to start the process in a random available port - port = "${port}", + port = "2345", -- additional args to pass to dlv args = {} }, @@ -66,26 +66,54 @@ return { -- Dap UI setup -- For more information, see |:help nvim-dap-ui| - dapui.setup() - -- dapui.setup { - -- -- Set icons to characters that are more likely to work in every terminal. - -- -- Feel free to remove or use ones that you like more! :) - -- -- Don't feel like these are good choices. - -- icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - -- controls = { - -- icons = { - -- pause = '⏸', - -- play = '▶', - -- step_into = '⏎', - -- step_over = '⏭', - -- step_out = '⏮', - -- step_back = 'b', - -- run_last = '▶▶', - -- terminate = '⏹', - -- disconnect = "⏏", - -- }, - -- }, - -- } + -- dapui.setup() + dapui.setup { + -- Set icons to characters that are more likely to work in every terminal. + -- Feel free to remove or use ones that you like more! :) + -- Don't feel like these are good choices. + icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, + controls = { + icons = { + pause = '⏸', + play = '▶', + step_into = '⏎', + step_over = '⏭', + step_out = '⏮', + step_back = 'b', + run_last = '▶▶', + terminate = '⏹', + disconnect = "⏏", + }, + }, + -- Layouts define sections of the screen to place windows. + -- The position can be "left", "right", "top" or "bottom". + -- The size specifies the height/width depending on position. It can be an Int + -- or a Float. Integer specifies height/width directly (i.e. 20 lines/columns) while + -- Float value specifies percentage (i.e. 0.3 - 30% of available lines/columns) + -- Elements are the elements shown in the layout (in order). + -- Layouts are opened in order so that earlier layouts take priority in window sizing. + layouts = { + { + elements = { + -- Elements can be strings or table with id and size keys. + { id = "scopes", size = 0.25 }, + "breakpoints", + "stacks", + "watches", + }, + size = 40, -- 40 columns + position = "left", + }, + { + elements = { + "repl", + -- "console", + }, + size = 0.25, -- 25% of total lines + position = "bottom", + }, + }, + } -- require('nvim-dap-virtual-text').setup() require('mason-nvim-dap').setup { @@ -121,6 +149,9 @@ return { -- toggle to see last session result. Without this ,you can't see session output in case of unhandled exception. vim.keymap.set("n", "tt", dapui.toggle) + vim.keymap.set('n', 'tr', function() + dapui.open({ reset = true }) + end, { desc = 'dap reset ui' }) dap.listeners.after.event_initialized['dapui_config'] = dapui.open -- dap.listeners.before.event_terminated['dapui_config'] = dapui.close -- dap.listeners.before.event_exited['dapui_config'] = dapui.close diff --git a/lua/custom/plugins/go.lua b/lua/custom/plugins/go.lua index 5f453a54..fd7dffe7 100644 --- a/lua/custom/plugins/go.lua +++ b/lua/custom/plugins/go.lua @@ -9,10 +9,11 @@ return { "nvim-treesitter/nvim-treesitter", }, config = function() - -- local gofmt = require("go.format") require("go").setup() - -- vim.keymap.set('n', 'gF', gofmt.goimport, { desc = 'Go Import' }) + local gofmt = require("go.format") + + vim.keymap.set('n', 'gF', gofmt.goimport, { desc = 'Go Import' }) end, event = { "CmdlineEnter" }, ft = { "go", 'gomod' }, diff --git a/lua/custom/plugins/null_ls.lua b/lua/custom/plugins/null_ls.lua index 356bd399..815251e6 100644 --- a/lua/custom/plugins/null_ls.lua +++ b/lua/custom/plugins/null_ls.lua @@ -7,8 +7,8 @@ return { null_ls.setup { sources = { - null_ls.builtins.formatting.goimports_reviser, - -- null_ls.builtins.formatting.gofumpt, + -- null_ls.builtins.formatting.goimports_reviser, + null_ls.builtins.formatting.gofumpt, -- null_ls.builtins.formatting.golines, }, on_attach = function(client, bufnr)