From 1941ccef40c7a0ef5e70f3ca4feb38cbef7c76b5 Mon Sep 17 00:00:00 2001 From: gameloader Date: Thu, 20 Oct 2022 10:30:00 +0800 Subject: [PATCH] make lsp some changes and a easy new file --- init.lua | 1 + lua/keybindings.lua | 2 +- lua/lsp/config/clangd.lua | 50 ++++++++++++++++++++++++-------------- lua/lsp/config/gopls.lua | 14 +++++++++++ lua/lsp/config/lua.lua | 14 +++++++++++ lua/lsp/config/pyright.lua | 50 ++++++++++++++++++++++++-------------- lua/lsp/ui.lua | 13 ++++++++++ lua/plugins.lua | 4 +++ 8 files changed, 111 insertions(+), 37 deletions(-) create mode 100644 lua/lsp/ui.lua diff --git a/init.lua b/init.lua index c49dce6..95e2ecb 100644 --- a/init.lua +++ b/init.lua @@ -31,5 +31,6 @@ require("plugin-config/lazygit") require("lsp") require("lsp.cmp") require("lsp.null-ls") +require("lsp.ui") require("nvim-dap") diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 22fb10b..2bfd76d 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -49,7 +49,7 @@ wk.register({ p = { ":Telescope projects", "Open project" }, r = { ":Telescope oldfiles", "Recent files" }, f = { ":Telescope file_browser", "File browser" }, - n = { ":enew", "New file" }, + n = { ":AdvancedNewFile", "New file" }, s = { ":Telescope live_grep", "Search in project" }, }, }) diff --git a/lua/lsp/config/clangd.lua b/lua/lsp/config/clangd.lua index 1ea090c..a926d7b 100644 --- a/lua/lsp/config/clangd.lua +++ b/lua/lsp/config/clangd.lua @@ -1,21 +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 + 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 - -- 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, + 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/gopls.lua b/lua/lsp/config/gopls.lua index 15bdd57..a926d7b 100644 --- a/lua/lsp/config/gopls.lua +++ b/lua/lsp/config/gopls.lua @@ -9,6 +9,20 @@ return { 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 diff --git a/lua/lsp/config/lua.lua b/lua/lsp/config/lua.lua index e80ed7c..bbf4e01 100644 --- a/lua/lsp/config/lua.lua +++ b/lua/lsp/config/lua.lua @@ -35,6 +35,20 @@ local opts = { 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, diff --git a/lua/lsp/config/pyright.lua b/lua/lsp/config/pyright.lua index 1ea090c..a926d7b 100644 --- a/lua/lsp/config/pyright.lua +++ b/lua/lsp/config/pyright.lua @@ -1,21 +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 + 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 - -- 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, + 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/ui.lua b/lua/lsp/ui.lua new file mode 100644 index 0000000..714965a --- /dev/null +++ b/lua/lsp/ui.lua @@ -0,0 +1,13 @@ +vim.diagnostic.config({ + virtual_text = false, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = false, +}) + +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end diff --git a/lua/plugins.lua b/lua/plugins.lua index c18da7f..5dc4415 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -98,6 +98,10 @@ return require("packer").startup(function() -- telescope-file-browser use({ "nvim-telescope/telescope-file-browser.nvim" }) + -- create new file + -- 快捷创建新文件 + use("Mohammed-Taher/AdvancedNewFile.nvim") + -- project -- 项目管理 use({