From 2ac5fc926a183dea0b7b6bc810c6b146c3bb7127 Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Sat, 15 Feb 2025 22:59:12 +0100 Subject: [PATCH] better --- lazy-lock.json | 15 ++- lua/config/autopairs.lua | 16 +-- lua/config/{dap.lua => dapconf.lua} | 0 lua/config/lspconfig.lua | 157 ++++++++++++++++++++++++++++ lua/config/lualine.lua | 25 +++-- lua/plugins/init.lua | 47 +++++---- 6 files changed, 213 insertions(+), 47 deletions(-) rename lua/config/{dap.lua => dapconf.lua} (100%) create mode 100644 lua/config/lspconfig.lua diff --git a/lazy-lock.json b/lazy-lock.json index c00d0bb..aea55b6 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,15 +1,26 @@ { "CopilotChat.nvim": { "branch": "main", "commit": "7e6583c75f1231ea1eac70e06995dd3f97a58478" }, + "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, "auto-session": { "branch": "main", "commit": "9c3f977aafb56bd73ba0d082c4dcbdba5666faf3" }, "base46-colors": { "branch": "main", "commit": "131ca742f6e8d1eb4c938a2519a94840ba129c2f" }, "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, - "coc.nvim": { "branch": "release", "commit": "408e2506338a137b607a00dffe3bad56518a6686" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "command-completion.nvim": { "branch": "main", "commit": "56c98f8d59a88ed96a80d43abca74a60ba31ea3a" }, "copilot.lua": { "branch": "master", "commit": "30321e33b03cb924fdcd6a806a0dc6fa0b0eafb9" }, + "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "lazy.nvim": { "branch": "main", "commit": "ac21a639c7ecfc8b822dcc9455deceea3778f839" }, "lightline-gruvbox.vim": { "branch": "master", "commit": "d233416d566e61f879bd19d9d498b01b1b7e336c" }, "lualine.nvim": { "branch": "master", "commit": "f4f791f67e70d378a754d02da068231d2352e5bc" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "a8e6efcf623b86bae6d2223eede7c43883329f80" }, + "mason.nvim": { "branch": "main", "commit": "1114b2336e917d883c30f89cd63ba94050001b2d" }, "nvim-autopairs": { "branch": "master", "commit": "68f0e5c3dab23261a945272032ee6700af86227a" }, + "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, "nvim-dap": { "branch": "master", "commit": "52302f02fea3a490e55475de52fa4deb8af2eb11" }, + "nvim-lspconfig": { "branch": "master", "commit": "7af2c37192deae28d1305ae9e68544f7fb5408e1" }, "nvim-notify": { "branch": "master", "commit": "22f29093eae7785773ee9d543f8750348b1a195c" }, "nvim-tree.lua": { "branch": "master", "commit": "80523101f0ae48b7f1990e907b685a3d79776c01" }, "nvim-treesitter": { "branch": "master", "commit": "00a513f87ee3c339c2024b08db3eb63ba7736ed6" }, @@ -17,7 +28,7 @@ "onedarkpro.nvim": { "branch": "main", "commit": "992780fb5b28abcef125271c8c2c41e302c2df26" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "rainbow-delimiters.nvim": { "branch": "master", "commit": "011d98eaa3a73b5a51d82ce5bc6b1397dde95562" }, - "snacks.nvim": { "branch": "main", "commit": "57445057395fd1f5b315defa367c57651ea2e5f2" }, + "snacks.nvim": { "branch": "main", "commit": "74ce61b727cd0b34468464ffbfbb380f192de592" }, "telescope.nvim": { "branch": "master", "commit": "78857db9e8d819d3cc1a9a7bdc1d39d127a36495" }, "undotree": { "branch": "main", "commit": "eab459ab87dd249617b5f7187bb69e614a083047" }, "vim-fugitive": { "branch": "master", "commit": "b068eaf1e6cbe35d1ac100d435cd7f7b74a5c87d" }, diff --git a/lua/config/autopairs.lua b/lua/config/autopairs.lua index c84fbfa..7d73a0a 100644 --- a/lua/config/autopairs.lua +++ b/lua/config/autopairs.lua @@ -1,17 +1,3 @@ -local remap = vim.api.nvim_set_keymap local npairs = require('nvim-autopairs') -npairs.setup({map_cr=false}) - --- skip it, if you use another global object -_G.MUtils= {} - -MUtils.completion_confirm=function() - if vim.fn["coc#pum#visible"]() ~= 0 then - return vim.fn["coc#pum#confirm"]() - else - return npairs.autopairs_cr() - end -end - -remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) +npairs.setup({}) diff --git a/lua/config/dap.lua b/lua/config/dapconf.lua similarity index 100% rename from lua/config/dap.lua rename to lua/config/dapconf.lua diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua new file mode 100644 index 0000000..c9db17c --- /dev/null +++ b/lua/config/lspconfig.lua @@ -0,0 +1,157 @@ +local cmp = require("cmp") +local cmp_lsp = require("cmp_nvim_lsp") +local capabilities = vim.tbl_deep_extend( + "force", + {}, + vim.lsp.protocol.make_client_capabilities(), + cmp_lsp.default_capabilities() +) + +require("fidget").setup({}) +require("mason").setup() +require("mason-lspconfig").setup({ + ensure_installed = { + "lua_ls", + "rust_analyzer", + "gopls", + }, + handlers = { + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup { + capabilities = capabilities + } + end, + + zls = function() + local lspconfig = require("lspconfig") + lspconfig.zls.setup({ + root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"), + settings = { + zls = { + enable_inlay_hints = true, + enable_snippets = true, + warn_style = true, + }, + }, + }) + vim.g.zig_fmt_parse_errors = 0 + vim.g.zig_fmt_autosave = 0 + + end, + ["lua_ls"] = function() + local lspconfig = require("lspconfig") + lspconfig.lua_ls.setup { + capabilities = capabilities, + settings = { + Lua = { + runtime = { version = "Lua 5.1" }, + diagnostics = { + globals = { "bit", "vim", "it", "describe", "before_each", "after_each" }, + } + } + } + } + end, + } +}) + +local cmp_select = { behaivior = cmp.SelectBehavior.Select } + +cmp.setup { + completion = { completeopt = "menu,menuone" }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "async_path" }, + }), +} + +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' }, + { name = 'cmdline' }, + }), + matching = { disallow_symbol_nonprefix_matching = false }, +}) + +vim.diagnostic.config({ + -- update_in_insert = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, +}) + +local lspconfig = require "lspconfig" + +-- EXAMPLE +local servers = { + "html", + "cssls", + "bashls", + "texlab", + "pyright", + "ts_ls", + "jdtls", + "sourcekit", + "zls", +} + +for _, server in ipairs(servers) do + lspconfig[server].setup { + } +end + +-- lspconfig.hyprls.setup { +-- root_dir = vim.fs.root( 0, 'hyprland.conf' ), +-- single_file_support = false, +-- filetypes = { "conf" }, +-- } diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index bc27c7c..0a9434d 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -1,16 +1,21 @@ local fn = vim.fn -local function get_coc_lsp_client() - local clients = vim.g.coc_service_initialized and vim.fn['CocAction']('services') or {} - for _, client in pairs(clients) do - if client['state'] == 'running' then - local client_name = client['id'] - -- Remove 'languageserver.' prefix if it exists - client_name = client_name:gsub('^languageserver%.', '') - return client_name +local get_active_lsp = function() + local msg = "🚫" + local buf_ft = vim.api.nvim_get_option_value("filetype", {}) + local clients = vim.lsp.get_clients { bufnr = 0 } + if next(clients) == nil then + return msg + end + + for _, client in ipairs(clients) do + ---@diagnostic disable-next-line: undefined-field + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name end end - return '' + return msg end local function spell() @@ -127,7 +132,7 @@ require("lualine").setup { color = { fg = "black", bg = "#f46868" }, }, { - get_coc_lsp_client, + get_active_lsp, icon = " LSP:", }, { diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index d791f4b..166be52 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -12,13 +12,6 @@ return { require("config.autosession") end, }, - { - "neoclide/coc.nvim", - branch = 'release', - }, - -- { - -- "sainnhe/gruvbox-material", - -- }, { "olimorris/onedarkpro.nvim", config = function() @@ -54,9 +47,6 @@ return { require("config.barbar") end, }, - -- { - -- "itchyny/lightline.vim", - -- }, { "nvim-lualine/lualine.nvim", event = "VeryLazy", @@ -73,15 +63,6 @@ return { require("config.undotree") end, }, - -- { - -- "lukas-reineke/indent-blankline.nvim", - -- main = "ibl", - -- ---@module "ibl" - -- ---@type ibl.config - -- config = function() - -- require("config.indent-blankline") - -- end, - -- }, { "hiphish/rainbow-delimiters.nvim", }, @@ -124,7 +105,7 @@ return { { "mfussenegger/nvim-dap", config = function() - require("config.dap") + require("config.dapconf") end, }, { @@ -172,4 +153,30 @@ return { { "notken12/base46-colors", }, + { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "j-hui/fidget.nvim", + }, + config = function() + require("config.lspconfig") + end, + }, + { + "smolck/command-completion.nvim", + opts = { + border = nil, + highlight_selection = true, + use_matchfuzzy = true, + }, + }, }