From 1ced81e035d5d4fc46dd77b50f4ffc2c92ece772 Mon Sep 17 00:00:00 2001 From: spike Date: Mon, 29 Aug 2022 16:46:20 +0200 Subject: [PATCH] LSP no lsp autostart, improved utils --- lua/core/mappings.lua | 24 ++++++-- lua/custom/plugins/configs/navigator.lua | 71 +++++++++++++++++++----- lua/custom/plugins/init.lua | 25 +++++++-- lua/custom/utils.lua | 22 ++++++++ lua/plugins/configs/lspconfig.lua | 1 + lua/plugins/init.lua | 8 +-- 6 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 lua/custom/utils.lua diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index df04562..c44fe26 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -45,7 +45,7 @@ M.general = { --{{{ -- quit dont save ["qq"] = { " quitall! ", "quit/close all windows, don't save" }, - ["Q"] = { " q!", "quit now" }, + -- ["Q"] = { " q!", "quit now" }, -- easier horizontal scrolling ["zl"] = { "zL", "horizontal scroll left" }, @@ -170,12 +170,17 @@ M.general = { --{{{ }, + -- TODO: move to lspconfig section + -- ["lsp"] = { " lua require('custom.plugins.configs.navigator').enable()", "lsp enable"}, + ["lsp"] = { " LspStart", "lsp enable"}, + ["lst"] = { " LspStop", "lsp disable"}, + --------------- -- Programming languages specifics --------------- -- luadev - ["ls"] = {"Luadev", "Luadev scratch window"}, + ["lsc"] = {"Luadev", "Luadev scratch window"}, ["ll"] = {"(Luadev-RunLine)", "Luadev Run Line"}, ["lr"] = {"(Luadev-Run)", "Luadev Run over movement or text object"}, ["lw"] = {"(Luadev-RunWord)", "Luadev Run word under cursor"}, @@ -264,7 +269,8 @@ M.comment = { --{{{ n = { ["/"] = { function() - require("Comment.api").toggle.linewise.current() + -- require("Comment.api").toggle.linewise.current() + vim.notify("use gcc !") end, "toggle comment", }, @@ -575,7 +581,8 @@ M.blankline = { --{{{ M.navigator = {--{{{ plugin = true, n = { - [""] = { " TSymbols h", "toggle TreeSitter symbols " }, + [""] = { " lua require'navigator.treesitter'.side_panel()h", "toggle TreeSitter symbols panel " }, + [""] = { " lua require'navigator.symbols'.side_panel()h", "toggle LSP symbols panel" }, } }--}}} @@ -598,4 +605,13 @@ M.asyncrun = { --{{{ }, } --}}} +-- M.neorepl = { +-- plugin = true, +-- +-- i = { +-- ["C-p"] = { "(neorepl-hist-prev)"}, +-- } +-- +-- } + return M diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua index 52c0627..a121fe3 100644 --- a/lua/custom/plugins/configs/navigator.lua +++ b/lua/custom/plugins/configs/navigator.lua @@ -5,28 +5,36 @@ if not present then end +M = {} + + local config = { -- debug = true, - transparency = nil, + transparency = 5, + lsp_signature_help = true, default_mapping = true, + icons = { icons = true, -- set to false to use system default ( if you using a terminal does not have nerd/icon) -- Code action - code_action_icon = ' ', -- "", + code_action_icon = ' ', -- "", + -- code lens - code_lens_action_icon = '👓', + code_lens_action_icon = '', + -- Diagnostics - diagnostic_head = '🐛', - diagnostic_err = '📛', - diagnostic_warn = '👎', - diagnostic_info = [[👩]], - diagnostic_hint = [[💁]], + diagnostic_head = '', -- default diagnostic head on dialogs + diagnostic_err = '', -- severity 1 + diagnostic_warn = '', -- 2 + diagnostic_info = '', -- 3 + diagnostic_hint = '', -- 4 - diagnostic_head_severity_1 = '🈲', - diagnostic_head_severity_2 = '☣️', - diagnostic_head_severity_3 = '👎', - diagnostic_head_description = '👹', - diagnostic_virtual_text = '🦊', + -- used in the diagnostics summary window + diagnostic_head_severity_1 = '', + diagnostic_head_severity_2 = '', + diagnostic_head_severity_3 = 'i', + diagnostic_head_description = ' ', + diagnostic_virtual_text = '', diagnostic_file = '🚑', -- Values value_changed = '📝', @@ -61,7 +69,42 @@ local config = { mason = true, format_on_save = false, -- applies to all formatting feature of neovim -- including auto-fold + diagnostic = { + underline = true, + virtual_text = { + spacing = 3, + source = true + }, -- show virtual for diagnostic message + update_in_insert = false, -- update diagnostic message in insert mode + severity_sort = { reverse = true }, + }, + + -- disable_lsp = {"sqls"}, + + -- disable auto start of lsp per language + -- set global default on lspconfig (see lspconfig doc) + -- ["lua-dev"] = { + -- autostart = false, + -- } } } -navigator.setup(config) +M.setup = function() + navigator.setup(config) +end + +M.enable = function() + local lspconfig = require("lspconfig") + lspconfig.util.default_config = vim.tbl_extend( + "force", + lspconfig.util.default_config, + { + autostart = true + } + ) + vim.cmd[[ + LspStart + ]] +end + +return M diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 2ce7573..da2ec5c 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -69,7 +69,7 @@ return { keys = {"s", "S"}, setup = function() vim.cmd[[ - let g:sneak#label=1 + let g:sneak#s_next=1 ]] end }, @@ -113,7 +113,16 @@ return { event = "InsertEnter", }, ["neovim/nvim-lspconfig"] = { - config = nil -- disable lspconfig, handled by navigator + config = function() + local lspconfig = require("lspconfig") + lspconfig.util.default_config = vim.tbl_extend( + "force", + lspconfig.util.default_config, + { + autostart = false + } + ) + end-- disable lspconfig, handled by navigator }, ["williamboman/mason-lspconfig.nvim"] = { requires = {"williamboman/mason.nvim", "nvim-lspconfig"}, @@ -126,13 +135,17 @@ return { -- -- ["https://git.sp4ke.xyz/sp4ke/navigator.lua"] = { ["ray-x/navigator.lua"] = { - after = "nvim-lspconfig", + after = { "nvim-lspconfig", "base46", "ui" }, requires = {"neovim/nvim-lspconfig", "ray-x/guihua.lua", "nvim-treesitter/nvim-treesitter"}, setup = function() require("core.utils").load_mappings "navigator" end, config = function() - require("custom.plugins.configs.navigator") + require("custom.plugins.configs.navigator").setup() + require("base46").load_highlight "lsp" + + -- TODO: use nvchadui_lsp features manually + -- require("nvchad_ui.lsp") end }, ["ray-x/guihua.lua"] = { @@ -172,6 +185,10 @@ return { pattern = "neorepl", callback = function () require('cmp').setup.buffer({enabled = false}) + + -- custom keymap example + -- activate corresponding section in mappings + -- mappings = require("custom.utils").set_plugin_mappings "neorepl" end }) end diff --git a/lua/custom/utils.lua b/lua/custom/utils.lua new file mode 100644 index 0000000..d4087e0 --- /dev/null +++ b/lua/custom/utils.lua @@ -0,0 +1,22 @@ +local M = {} + + M.set_plugin_mappings = function(plugin_name, mapping_opt) + mappings = require("core.utils").load_config().mappings[plugin_name] + mappings.plugin = nil + + for mode, mode_values in pairs(mappings) do + local default_opts = vim.tbl_deep_extend("force", { mode = mode }, mapping_opt or {}) + for keybind, mapping_info in pairs(mode_values) do + -- merge default + user opts + local opts = vim.tbl_deep_extend("force", default_opts, mapping_info.opts or {}) + + mapping_info.opts, opts.mode = nil, nil + opts.desc = mapping_info[2] + + vim.keymap.set(mode, keybind, mapping_info[1], opts) + end + end +end + + +return M diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 10c1dd8..5c2d9a6 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -13,6 +13,7 @@ local utils = require "core.utils" -- export on_attach & capabilities for custom lspconfigs M.on_attach = function(client, bufnr) + print("NVCHAD ON ATTACH") if vim.g.vim_version > 7 then -- nightly client.server_capabilities.documentFormattingProvider = false diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index f10a8c6..b9ad7e3 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -108,9 +108,9 @@ local plugins = { setup = function() require("core.lazy_load").on_file_open "nvim-lspconfig" end, - config = function() - require "plugins.configs.lspconfig" - end, + -- config = function() + -- require "plugins.configs.lspconfig" + -- end, }, -- load luasnips + cmp related in insert mode only @@ -208,7 +208,7 @@ local plugins = { ["folke/which-key.nvim"] = { disable = true, module = "which-key", - keys = "", + keys = {""}, config = function() require "plugins.configs.whichkey" end,