nvim config updated:

- ts organize imports;
- inlay hints
- auto pairs
- debugging
This commit is contained in:
parent c1aececfa5
commit b85684570e

View File

@ -453,7 +453,19 @@ require("lazy").setup({
-- https://github.com/pmizio/typescript-tools.nvim -- https://github.com/pmizio/typescript-tools.nvim
-- --
-- But for many setups, the LSP (`tsserver`) will work just fine -- 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 = { lua_ls = {
@ -627,7 +639,7 @@ require("lazy").setup({
-- Manually trigger a completion from nvim-cmp. -- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display -- Generally you don't need this, because nvim-cmp will display
-- completions whenever it has completion options available. -- completions whenever it has completion options available.
["<C-Space>"] = cmp.mapping.complete({}), ["<C-k>"] = cmp.mapping.complete({}),
-- Think of <c-l> as moving to the right of your snippet expansion. -- Think of <c-l> as moving to the right of your snippet expansion.
-- So if you have a snippet that's like: -- So if you have a snippet that's like:
@ -1106,6 +1118,338 @@ require("lazy").setup({
}) })
end, 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 = {
{ "<leader>d", "", desc = "+debug", mode = { "n", "v" } },
{
"<leader>dB",
function()
require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))
end,
desc = "Breakpoint Condition",
},
{
"<leader>db",
function()
require("dap").toggle_breakpoint()
end,
desc = "Toggle Breakpoint",
},
{
"<leader>dc",
function()
require("dap").continue()
end,
desc = "Continue",
},
{
"<leader>da",
function()
require("dap").continue({ before = get_args })
end,
desc = "Run with Args",
},
{
"<leader>dC",
function()
require("dap").run_to_cursor()
end,
desc = "Run to Cursor",
},
{
"<leader>dg",
function()
require("dap").goto_()
end,
desc = "Go to Line (No Execute)",
},
{
"<leader>di",
function()
require("dap").step_into()
end,
desc = "Step Into",
},
{
"<leader>dj",
function()
require("dap").down()
end,
desc = "Down",
},
{
"<leader>dk",
function()
require("dap").up()
end,
desc = "Up",
},
{
"<leader>dl",
function()
require("dap").run_last()
end,
desc = "Run Last",
},
{
"<leader>do",
function()
require("dap").step_out()
end,
desc = "Step Out",
},
{
"<leader>dO",
function()
require("dap").step_over()
end,
desc = "Step Over",
},
{
"<leader>dp",
function()
require("dap").pause()
end,
desc = "Pause",
},
{
"<leader>dr",
function()
require("dap").repl.toggle()
end,
desc = "Toggle REPL",
},
{
"<leader>ds",
function()
require("dap").session()
end,
desc = "Session",
},
{
"<leader>dt",
function()
require("dap").terminate()
end,
desc = "Terminate",
},
{
"<leader>dw",
function()
require("dap.ui.widgets").hover()
end,
desc = "Widgets",
},
{
"<F5>",
function()
require("dap").continue()
end,
desc = "Contine debug",
},
{
"<F10>",
function()
require("dap").step_over()
end,
desc = "Step over",
},
{
"<F11>",
function()
require("dap").step_into()
end,
desc = "Step into",
},
{
"<F12>",
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", -- "coffebar/neovim-project",
-- opts = { -- opts = {