From 8cd3dd5b8e9271253254885dba59498b469fc6f2 Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Tue, 28 Nov 2023 12:55:20 +0100 Subject: [PATCH] add LSP config --- lazy-lock.json | 11 ++-- lua/weeheavy/lazy.lua | 3 +- lua/weeheavy/plugins/lsp/conform.lua | 30 +++++++++ lua/weeheavy/plugins/lsp/lsp-zero.lua | 93 +++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 lua/weeheavy/plugins/lsp/conform.lua create mode 100644 lua/weeheavy/plugins/lsp/lsp-zero.lua diff --git a/lazy-lock.json b/lazy-lock.json index 5f1a879..eb4fd3b 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,22 +1,23 @@ { - "LuaSnip": { "branch": "master", "commit": "cab667e2674881001a86a7478fff7dc7791c63f5" }, + "LuaSnip": { "branch": "master", "commit": "df58ee1664cfda71479cd2bbd56114f56599eba6" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "conform.nvim": { "branch": "master", "commit": "eddd6431370814caacec1d1e3c7d6d95d41b133d" }, "gitsigns.nvim": { "branch": "main", "commit": "5fc573f2d2a49aec74dd6dc977e8b137429d1897" }, "indent-blankline.nvim": { "branch": "master", "commit": "29be0919b91fb59eca9e90690d76014233392bef" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, "lsp-zero.nvim": { "branch": "v3.x", "commit": "8a9ee4e11a3e23101d1d1d11aaac3159ad925cc9" }, "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "a5476087db0a20c05bd1163e1cd4a29b795e73a7" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "f522b5439bedac0225daf8d2fedb5039b59e83ee" }, "mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" }, "nightfox.nvim": { "branch": "main", "commit": "eb82712f86319272f4b7b9dbb4ec6df650e6987f" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-lspconfig": { "branch": "master", "commit": "553c4e0e667167640c5398573f6f3a488ff8047a" }, - "nvim-treesitter": { "branch": "master", "commit": "649d137371e9214d30b20565e0574824fa3a3670" }, + "nvim-treesitter": { "branch": "master", "commit": "b056e4227b1c5d3ecfe96941352364c0c10668df" }, "nvim-treesitter-context": { "branch": "master", "commit": "bf4d15ee4e96ff5201f16a4ed14443670662eb90" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "dbcd9388e3b119a87c785e10a00d62876077d23d" }, "nvim-web-devicons": { "branch": "master", "commit": "cdbcca210cf3655aa9b31ebf2422763ecd85ee5c" }, - "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, - "telescope-file-browser.nvim": { "branch": "master", "commit": "f41675fddb1ea9003187d07ecc627a8bf8292633" }, + "plenary.nvim": { "branch": "master", "commit": "366b0837486f60ae0e7550c15de8ff66d057c4cd" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "d7c453396a043c265bef1227920628e7b811ff30" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope.nvim": { "branch": "master", "commit": "7011eaae0ac1afe036e30c95cf80200b8dc3f21a" }, "tokyonight.nvim": { "branch": "main", "commit": "f247ee700b569ed43f39320413a13ba9b0aef0db" }, diff --git a/lua/weeheavy/lazy.lua b/lua/weeheavy/lazy.lua index 4f1d266..6f88a1c 100644 --- a/lua/weeheavy/lazy.lua +++ b/lua/weeheavy/lazy.lua @@ -12,5 +12,4 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) ---require("lazy").setup({ { import = "weeheavy.plugins" }, { import = "weeheavy.plugins.lsp" } }) -require("lazy").setup({ { import = "weeheavy.plugins" } }) +require("lazy").setup({ { import = "weeheavy.plugins" }, { import = "weeheavy.plugins.lsp" } }) diff --git a/lua/weeheavy/plugins/lsp/conform.lua b/lua/weeheavy/plugins/lsp/conform.lua new file mode 100644 index 0000000..9f2093d --- /dev/null +++ b/lua/weeheavy/plugins/lsp/conform.lua @@ -0,0 +1,30 @@ +-- Some things are from https://www.josean.com/posts/neovim-linting-and-formatting +return { + "stevearc/conform.nvim", + opts = {}, + config = function() + local conform = require("conform") + conform.setup({ + formatters_by_ft = { + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + svelte = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + graphql = { "prettier" }, + lua = { "stylua" }, + python = { "isort", "black" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 1000, -- default: 1000 + }, + }) + end, +} diff --git a/lua/weeheavy/plugins/lsp/lsp-zero.lua b/lua/weeheavy/plugins/lsp/lsp-zero.lua new file mode 100644 index 0000000..16b7bdf --- /dev/null +++ b/lua/weeheavy/plugins/lsp/lsp-zero.lua @@ -0,0 +1,93 @@ +return { + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + lazy = true, + config = false, + init = function() + -- Disable automatic setup, we are doing it manually + vim.g.lsp_zero_extend_cmp = 0 + vim.g.lsp_zero_extend_lspconfig = 0 + end, + }, + { + 'williamboman/mason.nvim', + lazy = false, + config = true, + }, + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + {'L3MON4D3/LuaSnip'}, + }, + config = function() + -- Here is where you configure the autocompletion settings. + local lsp_zero = require('lsp-zero') + lsp_zero.extend_cmp() + + local cmp = require('cmp') + local cmp_action = lsp_zero.cmp_action() + local cmp_select = { behavior = cmp.SelectBehavior.Select } + + cmp.setup({ + formatting = lsp_zero.cmp_format(), + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.confirm({select = true}), -- accept LSP autocompletion + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp_action.luasnip_jump_forward(), + [''] = cmp_action.luasnip_jump_backward(), + }) + }) + end + }, + + -- LSP + { + 'neovim/nvim-lspconfig', + cmd = {'LspInfo', 'LspInstall', 'LspStart'}, + event = {'BufReadPre', 'BufNewFile'}, + dependencies = { + {'hrsh7th/cmp-nvim-lsp'}, + {'williamboman/mason-lspconfig.nvim'}, + }, + config = function() + -- This is where all the LSP shenanigans will live + local lsp_zero = require('lsp-zero') + lsp_zero.extend_lspconfig() + + -- Keybindings only active when a LS is active for the curr. file + lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp-zero-keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) + end) + + require('mason').setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗", + }, + }, + }) + + require('mason-lspconfig').setup({ + ensure_installed = {}, + handlers = { + lsp_zero.default_setup, + lua_ls = function() + -- (Optional) Configure lua language server for neovim + local lua_opts = lsp_zero.nvim_lua_ls() + require('lspconfig').lua_ls.setup(lua_opts) + end, + } + }) + end + } +}