From a1d61a1144bb129377b08873be8369c3da3a35e7 Mon Sep 17 00:00:00 2001 From: gameloader Date: Sun, 30 Oct 2022 18:22:57 +0800 Subject: [PATCH] change nvimtree cr and simplify lsp config --- lua/keybindings.lua | 13 ++++++++++++ lua/lsp/config/basic_config.lua | 35 ++++++++++++++++++++++++++++++++ lua/lsp/config/clangd.lua | 36 +-------------------------------- lua/lsp/config/eslint.lua | 36 +-------------------------------- lua/lsp/config/gopls.lua | 36 +-------------------------------- lua/lsp/config/lua.lua | 8 ++++---- lua/lsp/config/pyright.lua | 36 +-------------------------------- lua/lsp/config/ts.lua | 36 +-------------------------------- lua/lsp/config/vue.lua | 36 +-------------------------------- lua/plugin-config/nvim-tree.lua | 20 +++++++++++------- 10 files changed, 71 insertions(+), 221 deletions(-) create mode 100644 lua/lsp/config/basic_config.lua diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 2a68bc2..7b1808f 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -14,6 +14,19 @@ wk.register({ ["S"] = { ":wa", "Save All" }, }) +-- lsp 回调快捷键设置 +pluginKeys.maplsp = function(mapbuf) + -- go xx + mapbuf("n", "]d", "lua vim.lsp.buf.definition()", opt) + -- mapbuf("n", "gh", "lua vim.lsp.buf.hover()", opt) + mapbuf("n", "]D", "lua vim.lsp.buf.declaration()", opt) + mapbuf("n", "]i", "lua vim.lsp.buf.implementation()", opt) + mapbuf("n", "]r", "lua vim.lsp.buf.references()", opt) + -- diagnostic + mapbuf("n", "]p", "lua vim.diagnostic.goto_prev()", opt) + mapbuf("n", "]n", "lua vim.diagnostic.goto_next()", opt) +end + -- code related -- 代码相关 map("n", ",", ":RunCode", opt) diff --git a/lua/lsp/config/basic_config.lua b/lua/lsp/config/basic_config.lua new file mode 100644 index 0000000..5c5068d --- /dev/null +++ b/lua/lsp/config/basic_config.lua @@ -0,0 +1,35 @@ +return { + on_setup = function(server) + server.setup({ + flags = { + debounce_text_changes = 150, + }, + on_attach = function(client, bufnr) + -- 禁用格式化功能,交给专门插件插件处理 + client.server_capabilities.document_formatting = false + client.server_capabilities.document_range_formatting = false + + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = "rounded", + source = "always", + prefix = " ", + scope = "cursor", + } + vim.diagnostic.open_float(nil, opts) + end, + }) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- 绑定快捷键 + require("keybindings").maplsp(buf_set_keymap) + end, + }) + end, +} diff --git a/lua/lsp/config/clangd.lua b/lua/lsp/config/clangd.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/clangd.lua +++ b/lua/lsp/config/clangd.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/lsp/config/eslint.lua b/lua/lsp/config/eslint.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/eslint.lua +++ b/lua/lsp/config/eslint.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/lsp/config/gopls.lua b/lua/lsp/config/gopls.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/gopls.lua +++ b/lua/lsp/config/gopls.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/lsp/config/lua.lua b/lua/lsp/config/lua.lua index bbf4e01..6d220b2 100644 --- a/lua/lsp/config/lua.lua +++ b/lua/lsp/config/lua.lua @@ -49,13 +49,13 @@ local opts = { vim.diagnostic.open_float(nil, opts) end, }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + require("keybindings").maplsp(buf_set_keymap) end, -- -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end -- -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - -- end, } local capabilities = vim.lsp.protocol.make_client_capabilities() diff --git a/lua/lsp/config/pyright.lua b/lua/lsp/config/pyright.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/pyright.lua +++ b/lua/lsp/config/pyright.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/lsp/config/ts.lua b/lua/lsp/config/ts.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/ts.lua +++ b/lua/lsp/config/ts.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/lsp/config/vue.lua b/lua/lsp/config/vue.lua index a926d7b..723c978 100644 --- a/lua/lsp/config/vue.lua +++ b/lua/lsp/config/vue.lua @@ -1,35 +1 @@ -return { - on_setup = function(server) - server.setup({ - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", - prefix = " ", - scope = "cursor", - } - vim.diagnostic.open_float(nil, opts) - end, - }) - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - -- end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - end, - }) - end, -} +return require("lsp.config.basic_config") diff --git a/lua/plugin-config/nvim-tree.lua b/lua/plugin-config/nvim-tree.lua index 58a199a..7552686 100644 --- a/lua/plugin-config/nvim-tree.lua +++ b/lua/plugin-config/nvim-tree.lua @@ -1,8 +1,14 @@ -require 'nvim-tree'.setup({ - sync_root_with_cwd = true, - respect_buf_cwd = true, - update_focused_file = { - enable = true, - update_root = true - }, +require("nvim-tree").setup({ + sync_root_with_cwd = true, + respect_buf_cwd = true, + -- 更改回车为进入目录 + on_attach = function(bufnr) + local cd = require("nvim-tree.config").nvim_tree_callback("cd") + vim.keymap.set("n", "", cd, { buffer = bufnr, noremap = true }) + end, + + update_focused_file = { + enable = true, + update_root = true, + }, })