From 4e7f8921add1b202b579ed7bac6d3ac390c9d63d Mon Sep 17 00:00:00 2001 From: goodhumored Date: Wed, 7 Aug 2024 17:45:46 +0300 Subject: [PATCH] nvim config updated: - ts organize imports; - inlay hints - auto pairs - debugging --- .config/nvim/init.lua | 348 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 346 insertions(+), 2 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 34a9776..efe52cc 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -453,7 +453,19 @@ require("lazy").setup({ -- https://github.com/pmizio/typescript-tools.nvim -- -- But for many setups, the LSP (`tsserver`) will work just fine - -- tsserver = {}, + tsserver = { + commands = { + OrganizeImports = { + function() + vim.lsp.buf.execute_command({ + command = "_typescript.organizeImports", + arguments = { vim.api.nvim_buf_get_name(0) }, + }) + end, + description = "Organize imports", + }, + }, + }, -- lua_ls = { @@ -627,7 +639,7 @@ require("lazy").setup({ -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display -- completions whenever it has completion options available. - [""] = cmp.mapping.complete({}), + [""] = cmp.mapping.complete({}), -- Think of as moving to the right of your snippet expansion. -- So if you have a snippet that's like: @@ -1106,6 +1118,338 @@ require("lazy").setup({ }) end, }, + { + "MysticalDevil/inlay-hints.nvim", + event = "LspAttach", + dependencies = { "neovim/nvim-lspconfig" }, + config = function() + require("inlay-hints").setup() + -- require("typescript-tools").setup({ + -- settings = { + -- tsserver_file_preferences = { + -- includeInlayParameterNameHints = "all", + -- includeInlayParameterNameHintsWhenArgumentMatchesName = false, + -- includeInlayFunctionParameterTypeHints = true, + -- includeInlayVariableTypeHints = true, + -- includeInlayVariableTypeHintsWhenTypeMatchesName = false, + -- includeInlayPropertyDeclarationTypeHints = true, + -- includeInlayFunctionLikeReturnTypeHints = true, + -- includeInlayEnumMemberValueHints = true, + -- }, + -- }, + -- }) + require("lspconfig").tsserver.setup({ + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }) + end, + }, + { + "jiangmiao/auto-pairs", + }, + { + "rcarriga/nvim-dap-ui", + event = "VeryLazy", + dependencies = "mfussenegger/nvim-dap", + config = function() + local dap = require("dap") + local dapui = require("dapui") + require("dapui").setup() + 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 + end, + }, + -- vscode-js-debug adapter + { + "microsoft/vscode-js-debug", + build = "npm i && npm run compile vsDebugServerBundle && rm -rf out && mv -f dist out", + }, + { + "mxsdev/nvim-dap-vscode-js", + opts = { + debugger_path = vim.fn.resolve(vim.fn.stdpath("data") .. "/lazy/vscode-js-debug"), + adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" }, + }, + }, + { + "mfussenegger/nvim-dap", + recommended = true, + desc = "Debugging support. Requires language specific adapters to be configured. (see lang extras)", + + dependencies = { + "rcarriga/nvim-dap-ui", + -- virtual text for the debugger + "mxsdev/nvim-dap-vscode-js", + { + "theHamsta/nvim-dap-virtual-text", + opts = {}, + }, + }, + + keys = { + { "d", "", desc = "+debug", mode = { "n", "v" } }, + { + "dB", + function() + require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) + end, + desc = "Breakpoint Condition", + }, + { + "db", + function() + require("dap").toggle_breakpoint() + end, + desc = "Toggle Breakpoint", + }, + { + "dc", + function() + require("dap").continue() + end, + desc = "Continue", + }, + { + "da", + function() + require("dap").continue({ before = get_args }) + end, + desc = "Run with Args", + }, + { + "dC", + function() + require("dap").run_to_cursor() + end, + desc = "Run to Cursor", + }, + { + "dg", + function() + require("dap").goto_() + end, + desc = "Go to Line (No Execute)", + }, + { + "di", + function() + require("dap").step_into() + end, + desc = "Step Into", + }, + { + "dj", + function() + require("dap").down() + end, + desc = "Down", + }, + { + "dk", + function() + require("dap").up() + end, + desc = "Up", + }, + { + "dl", + function() + require("dap").run_last() + end, + desc = "Run Last", + }, + { + "do", + function() + require("dap").step_out() + end, + desc = "Step Out", + }, + { + "dO", + function() + require("dap").step_over() + end, + desc = "Step Over", + }, + { + "dp", + function() + require("dap").pause() + end, + desc = "Pause", + }, + { + "dr", + function() + require("dap").repl.toggle() + end, + desc = "Toggle REPL", + }, + { + "ds", + function() + require("dap").session() + end, + desc = "Session", + }, + { + "dt", + function() + require("dap").terminate() + end, + desc = "Terminate", + }, + { + "dw", + function() + require("dap.ui.widgets").hover() + end, + desc = "Widgets", + }, + { + "", + function() + require("dap").continue() + end, + desc = "Contine debug", + }, + { + "", + function() + require("dap").step_over() + end, + desc = "Step over", + }, + { + "", + function() + require("dap").step_into() + end, + desc = "Step into", + }, + { + "", + function() + require("dap").step_out() + end, + desc = "Step out", + }, + }, + + config = function() + local dap = require("dap") + dap.adapters["pwa-node"] = { + type = "server", + host = "localhost", + port = "${port}", -- Replace with your chosen port number + executable = { + command = "node", + -- 💀 Make sure to update this path to point to your installation + args = { "/usr/bin/dapDebugServer.js", "${port}" }, + }, + } + dap.adapters.node2 = { + type = "executable", + command = "node", + args = { "/usr/lib/vscode-node-debug2/out/src/nodeDebug.js" }, + } + + if not dap.adapters["node"] then + dap.adapters["node"] = function(cb, config) + if config.type == "node" then + config.type = "pwa-node" + end + local nativeAdapter = dap.adapters["pwa-node"] + if type(nativeAdapter) == "function" then + nativeAdapter(cb, config) + else + cb(nativeAdapter) + end + end + end + for _, lang in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact" }) do + dap.configurations[lang] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + runtimeExecutable = "node", + }, + -- Debug nodejs processes (make sure to add --inspect when you run the process) + { + name = "Attach", + type = "pwa-node", + request = "attach", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + sourceMaps = true, + }, + { + -- For this to work you need to make sure the node process is started with the `--inspect` flag. + name = "Attach to process", + type = "node2", + request = "attach", + processId = require("dap.utils").pick_process, + + -- From https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/plugins/dap.lua + -- To test how it behaves + rootPath = "${workspaceFolder}", + cwd = "${workspaceFolder}", + console = "integratedTerminal", + internalConsoleOptions = "neverOpen", + sourceMapPathOverrides = { + ["./*"] = "${workspaceFolder}/src/*", + }, + }, + } + end + -- setup dap config by VsCode launch.json file + local vscode = require("dap.ext.vscode") + local json = require("plenary.json") + vscode.json_decode = function(str) + return vim.json.decode(json.json_strip_comments(str)) + end + + -- Extends dap.configurations with entries read from .vscode/launch.json + if vim.fn.filereadable(".vscode/launch.json") then + vscode.load_launchjs() + end + end, + }, -- { -- "coffebar/neovim-project", -- opts = {