From 843582f1c83ae266bdb014397414e86841fe1cb4 Mon Sep 17 00:00:00 2001 From: ant Date: Fri, 8 Dec 2023 00:40:10 +0700 Subject: [PATCH] Update --- lua/configs/cmp.lua | 3 ++ lua/configs/lspconfig.lua | 93 ++++++++++++++++++--------------------- lua/mappings.lua | 14 ++++++ lua/plugins.lua | 68 ++++++++++++++++++++++------ 4 files changed, 114 insertions(+), 64 deletions(-) diff --git a/lua/configs/cmp.lua b/lua/configs/cmp.lua index 39e2fe7..d616344 100644 --- a/lua/configs/cmp.lua +++ b/lua/configs/cmp.lua @@ -31,7 +31,10 @@ local options = { end, }, sources = { + { name = "luasnip" }, { name = "nvim_lsp" }, + -- { name = 'nvim_lsp_signature_help' }, + { name = "nvim_lsp_document_symbol" }, { name = "nvim_lua" }, { name = "path" }, }, diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua index f1940cd..e38a12b 100644 --- a/lua/configs/lspconfig.lua +++ b/lua/configs/lspconfig.lua @@ -1,58 +1,51 @@ -require("mason-lspconfig").setup_handlers { - -- The first entry (without a key) will be the default handler - -- and will be called for each installed server that doesn't have - -- a dedicated handler. - function(server_name) -- default handler (optional) - require("lspconfig")[server_name].setup {} - end, - -- Next, you can provide a dedicated handler for specific servers. - -- For example, a handler override for the `rust_analyzer`: - -- ["rust_analyzer"] = function () - -- require("rust-tools").setup {} - -- end - ["lua_ls"] = function() - require("lspconfig").lua_ls.setup { - settings = { - Lua = { - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = { - [vim.fn.expand "$VIMRUNTIME/lua"] = true, - [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, - [vim.fn.stdpath "data" .. "/lazy/extensions/nvchad_types"] = true, - [vim.fn.stdpath "data" .. "/lazy/lazy.nvim/lua/lazy"] = true, - }, - maxPreload = 100000, - preloadFileSize = 10000, - }, - }, +local default = { + on_attach = function(client, bufnr) + require "lsp_signature".on_attach( + { + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "none" }, + hint_enable = false, + doc_lines = 0, + floating_window_off_x = 999, + floating_window_off_y = 1, + -- floating_window = false, } + , bufnr) -- Note: add in lsp client on-attach end, - - ["ltex"] = function() - require("lspconfig").ltex.setup { - settings = { - ltex = { - language = "fr", - checkFrequency = "save" - }, - -- set formatter - formatters = { - ["latexindent"] = { - exe = "latexindent", - args = { "-sl", "-g /dev/stderr" }, - stdin = true, - }, - }, - }, - - } - end + capabilities = require('cmp_nvim_lsp').default_capabilities() } +local servers = { + java_language_server = { cmd = {"java-language-server"} }, + ocamllsp = {}, + -- "pyright", + lua_ls = {}, + clangd = {}, + jedi_language_server = {}, + nil_ls = {}, + ltex = { + settings = { + ltex = { + language = "fr", + }, + }, + } +} + +for server, config in pairs(servers) do + local lsp = require("lspconfig")[server] + + -- print(server) + local config = vim.tbl_deep_extend("keep", config, default, lsp.document_config.default_config) + if config.cmd ~= nil then + if vim.fn.executable(config.cmd[1]) == 1 then + lsp.setup(config) + end + end +end + vim.diagnostic.config({ virtual_text = false, -- signs = true, diff --git a/lua/mappings.lua b/lua/mappings.lua index 4b330dc..ece34fb 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -15,6 +15,11 @@ vim.keymap.set( 'ff', " Telescope find_files follow=true " ) +vim.keymap.set( + 'n', + 'fg', + " Telescope live_grep " +) vim.keymap.set( 'n', 'fF', @@ -31,6 +36,15 @@ vim.keymap.set('n', 'N', " Neogit ", { desc = "Open Neogit" }) vim.keymap.set('n', '', " Copilot ", { desc = "Start Copilot" }) vim.keymap.set('x', 'p', 'p:let @+=@0:let @"=@0', { desc = "Start Copilot" }) +-- Luasnip +local ls = require("luasnip") +vim.keymap.set({"i", "s"}, "", function() ls.jump( 1) end, {silent = true}) +vim.keymap.set({"i", "s"}, "", function() ls.jump(-1) end, {silent = true}) + +-- Hop +vim.keymap.set({'n', 'v'}, 'f', " HopWord ", { desc = "HopWord" }) + + -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions -- Use LspAttach autocommand to only map the following keys diff --git a/lua/plugins.lua b/lua/plugins.lua index 7a4b2e3..823fb07 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -13,16 +13,17 @@ local plugins = { require('configs.treesitter') end, }, - { - "williamboman/mason-lspconfig.nvim", - dependencies = { - "williamboman/mason.nvim", - }, - config = function() - require("mason").setup() - require("mason-lspconfig").setup() - end - }, + -- { + -- "williamboman/mason-lspconfig.nvim", + -- dependencies = { + -- "williamboman/mason.nvim", + -- }, + -- config = function() + -- require("mason").setup() + -- require("mason-lspconfig").setup() + -- -- + -- end + -- }, { "neovim/nvim-lspconfig", config = function() @@ -60,7 +61,13 @@ local plugins = { crust = "#000000", }, }, - custom_highlights = {}, + custom_highlights = function(C) + return { + HopNextKey = { bg = C.text, fg = C.base, style = { "bold", "underline" } }, + HopNextKey1 = { bg = C.text, fg = C.base, style = { "bold" } }, + HopNextKey2 = { bg = C.text, fg = C.base, style = { "bold", "italic" } }, + } + end, integrations = { cmp = true, gitsigns = true, @@ -72,6 +79,7 @@ local plugins = { illuminate = false, -- noice = true, notify = true, + flash = true, telescope = { enabled = true, style = "nvchad" @@ -80,6 +88,9 @@ local plugins = { enabled = true, enable_ui = true, -- enable nvim-dap-ui }, + indent_blankline = { + enabled = true, + }, native_lsp = { enabled = true, virtual_text = { @@ -136,7 +147,16 @@ local plugins = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-path", - "L3MON4D3/LuaSnip", + { + "L3MON4D3/LuaSnip", + dependencies = { + "rafamadriz/friendly-snippets", + }, + init = function() + require("luasnip.loaders.from_vscode").lazy_load() + end + + }, 'saadparwaiz1/cmp_luasnip' }, }, @@ -306,7 +326,16 @@ local plugins = { ) end, }, - { "lukas-reineke/indent-blankline.nvim" }, + { + "lukas-reineke/indent-blankline.nvim", + main = "ibl", + opts = { + scope = { + show_start = false, + show_end = false, + }, + }, + }, { 'michaelb/sniprun', -- run = 'sh ./install.sh', @@ -390,7 +419,18 @@ local plugins = { render = "minimal", stages = "static", } - } + }, + { + "ray-x/lsp_signature.nvim", + event = "VeryLazy", + }, + { + 'smoka7/hop.nvim', + version = "*", + opts = { + uppercase_labels = true, + }, + }, } return plugins