From ee1be1a29ac6e1d09d837cfb6b5ef7fbbe0058ba Mon Sep 17 00:00:00 2001 From: alice-vu-163 Date: Tue, 6 May 2025 16:29:55 +0700 Subject: [PATCH] quandoan --- init.lua | 71 +++++++++++++++++--- lua/custom/keymaps/init.lua | 43 ++++++++++++ lua/custom/plugins/init.lua | 130 +++++++++++++++++++++++++++++++++++- lua/custom/setups/init.lua | 3 + lua/custom/setups/lsp.lua | 12 ++++ lua/custom/setups/term.lua | 10 +++ 6 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 lua/custom/keymaps/init.lua create mode 100644 lua/custom/setups/init.lua create mode 100644 lua/custom/setups/lsp.lua create mode 100644 lua/custom/setups/term.lua diff --git a/init.lua b/init.lua index 776c6873..43c2b3e6 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -275,7 +275,39 @@ require('lazy').setup({ }, }, }, + { + 'rcarriga/nvim-dap-ui', + requires = { 'mfussenegger/nvim-dap' }, + config = function() + local dap, dapui = require 'dap', require 'dapui' + -- set up with all the default layouts: + dapui.setup() + + -- auto-open when session starts, auto-close when it ends: + dap.listeners.after.event_initialized['dapui_config'] = function() + dapui.open() + end + dap.listeners.before.event_terminated['dapui_config'] = function() + dapui.close() + end + dap.listeners.before.event_exited['dapui_config'] = function() + dapui.close() + end + + -- optional: a handy toggle keymap + vim.keymap.set('n', 'du', dapui.toggle, { desc = '๏‘ฏ Toggle DAP UI' }) + end, + }, + { + 'mfussenegger/nvim-dap-python', + dependencies = { 'mfussenegger/nvim-dap' }, + config = function() + -- point to the Python that can `import debugpy` + local debugpy_path = vim.fn.stdpath 'data' .. '/mason/packages/debugpy/venv/bin/python' + require('dap-python').setup(debugpy_path) + end, + }, -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- -- This is often very useful to both group configuration, as well as handle @@ -665,7 +697,22 @@ require('lazy').setup({ local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, + pyright = { + settings = { + python = { + analysis = { + typeCheckingMode = 'off', -- โœ… disable type errors + diagnosticMode = 'openFilesOnly', -- โœ… optional: only open buffers, not full project + autoSearchPaths = true, + useLibraryCodeForTypes = true, + }, + }, + }, + }, + lemminx = {}, + + -- โœ… JavaScript/TypeScript LSP (recommended) + ts_ls = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -708,6 +755,8 @@ require('lazy').setup({ local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code + 'prettierd', -- JS/TS formatter + 'xmlformatter', -- for formatting XML if needed }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } @@ -965,18 +1014,20 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.debug', + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.lint', + require 'kickstart.plugins.autopairs', + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, + { import = 'custom.keymaps' }, + { import = 'custom.setups' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-๐Ÿ”Œ-plugin-spec` -- Or use telescope! diff --git a/lua/custom/keymaps/init.lua b/lua/custom/keymaps/init.lua new file mode 100644 index 00000000..fdf3e770 --- /dev/null +++ b/lua/custom/keymaps/init.lua @@ -0,0 +1,43 @@ +-- must be after `require("dap-python").setup(debugpy_path)` +local dap = require 'dap' +local dap_python = require 'dap-python' + +-- โ”€โ”€โ”€ General DAP mappings โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +vim.keymap.set('n', '', dap.continue, { desc = 'โ–ถ Continue' }) +vim.keymap.set('n', '', dap.step_over, { desc = 'โคผ Step Over' }) +vim.keymap.set('n', '', dap.step_into, { desc = 'โคฝ Step Into' }) +vim.keymap.set('n', '', dap.step_out, { desc = 'โคพ Step Out' }) + +vim.keymap.set('n', 'db', dap.toggle_breakpoint, { desc = '๏†ˆ Toggle Breakpoint' }) +vim.keymap.set('n', 'dB', function() -- conditional + dap.set_breakpoint(nil, nil, vim.fn.input 'Breakpoint condition: ') +end, { desc = '๏™ Set Conditional Breakpoint' }) + +vim.keymap.set('n', 'dr', dap.repl.open, { desc = '๏„  Open DAP REPL' }) +vim.keymap.set('n', 'dl', dap.run_last, { desc = '๏‚ฉ Run Last Session' }) + +-- Move current line down with J +vim.keymap.set('n', 'J', ':m .+1==', { noremap = true, silent = true }) + +-- Move current line up with K +vim.keymap.set('n', 'K', ':m .-2==', { noremap = true, silent = true }) + +-- Map T to toggle terminal +vim.keymap.set('n', 'T', function() + local Terminal = require('toggleterm.terminal').Terminal + local float_term = Terminal:new { + direction = 'float', + hidden = true, -- ensures it doesn't persist visually + } + float_term:toggle() +end, { desc = 'Toggle Floating Terminal' }) + +vim.keymap.set('n', 'bd', function() + -- Close all open toggleterm terminals + require('toggleterm').toggle_all() + + -- Then close the current buffer + vim.cmd 'bdelete!' +end, { desc = 'Close buffer and toggleterm' }) + +return {} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..07c6febe 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,132 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + { + 'folke/tokyonight.nvim', + lazy = false, + priority = 1000, + config = function() + require('tokyonight').setup { + transparent = true, + } + vim.cmd 'colorscheme tokyonight' + end, + }, + { + 'akinsho/toggleterm.nvim', + tag = '*', + config = function() + require('toggleterm').setup() + end, + }, + { + 'mfussenegger/nvim-dap', + dependencies = { + 'rcarriga/nvim-dap-ui', + 'mfussenegger/nvim-dap-python', + }, + config = function() + local dap = require 'dap' + local dap_python = require 'dap-python' + local dapui = require 'dapui' + + local debugpy_path = vim.fn.stdpath 'data' .. '/mason/packages/debugpy/venv/bin/python' + dap_python.setup(debugpy_path) + + dap.configurations.python = dap.configurations.python or {} + -- Ta-yoong project debug config + table.insert(dap.configurations.python, { + name = 'Odoo Tayoong', + type = 'python', + request = 'launch', + program = '/Users/quandoan/Desktop/odoo-18.0/odoo-bin', + args = { + '-c', + '/Users/quandoan/Desktop/odoo-18.0/debian/odoo-tayoong.conf', + '-u', + 'a1_einvoice_to_gov', + '--xmlrpc-port', + '8066', + }, + pythonPath = function() + return '/usr/local/bin/python3.12' + end, + cwd = vim.fn.getcwd(), + env = { PYTHONUNBUFFERED = '1' }, + console = 'integratedTerminal', + }) + -- odoo 13 debug + table.insert(dap.configurations.python, { + name = 'Odoo 13', + type = 'python', + request = 'launch', + program = '/Users/quandoan/Desktop/odoo-13.0/odoo-bin', + args = { + '-c', + '/Users/quandoan/Desktop/odoo-13.0/debian/odoo.conf', + '-u', + 'a1_einvoice_to_gov', + '--xmlrpc-port', + '8066', + }, + pythonPath = function() + return '/usr/local/bin/python3.7' + end, + cwd = vim.fn.getcwd(), + env = { PYTHONUNBUFFERED = '1' }, + console = 'integratedTerminal', + }) + + -- UI signs + vim.fn.sign_define('DapBreakpoint', { text = 'B', texthl = 'DapBreakpoint' }) + vim.fn.sign_define('DapBreakpointCondition', { text = 'C', texthl = 'DapBreakpointCondition' }) + vim.fn.sign_define('DapStopped', { text = '>', texthl = 'DapStopped', linehl = 'CursorLine' }) + + vim.cmd [[ + highlight DapBreakpoint guifg=#FFA500 guibg=#1F1F28 + highlight DapBreakpointCondition guifg=#FFA500 guibg=#1F1F28 + highlight DapStopped guifg=#FFA500 guibg=#1F1F28 + ]] + + dapui.setup { + layouts = { + { + elements = { + { id = 'repl', size = 0.5 }, + { id = 'console', size = 0.5 }, + }, + size = 0.15, + position = 'left', + }, + { + elements = { + { id = 'scopes', size = 1.0 }, + }, + size = 0.85, + position = 'bottom', + }, + }, + } + end, + }, + { + -- Ensure toggleterm is loaded + 'akinsho/toggleterm.nvim', + keys = { + { + 'lg', + function() + local Terminal = require('toggleterm.terminal').Terminal + local lazygit = Terminal:new { + cmd = 'lazygit', + direction = 'float', + hidden = true, + } + lazygit:toggle() + end, + desc = 'Lazygit (float)', + }, + }, + }, +} diff --git a/lua/custom/setups/init.lua b/lua/custom/setups/init.lua new file mode 100644 index 00000000..b2739e64 --- /dev/null +++ b/lua/custom/setups/init.lua @@ -0,0 +1,3 @@ +-- Then load your custom setup scripts +require 'custom.setups.lsp' +require 'custom.setups.term' diff --git a/lua/custom/setups/lsp.lua b/lua/custom/setups/lsp.lua new file mode 100644 index 00000000..c08a2e9a --- /dev/null +++ b/lua/custom/setups/lsp.lua @@ -0,0 +1,12 @@ +require('lspconfig').pyright.setup { + settings = { + python = { + analysis = { + typeCheckingMode = 'off', -- disables type checking + diagnosticMode = 'openFilesOnly', -- optional: only analyze open files + autoSearchPaths = true, + useLibraryCodeForTypes = true, + }, + }, + }, +} diff --git a/lua/custom/setups/term.lua b/lua/custom/setups/term.lua new file mode 100644 index 00000000..e4580f53 --- /dev/null +++ b/lua/custom/setups/term.lua @@ -0,0 +1,10 @@ +require('toggleterm').setup { + direction = 'float', + float_opts = { + border = 'curved', + width = 100, + height = 30, + winblend = 0, -- optional: transparency + -- Omit row/col so it's automatically centered + }, +}