From 60064aa16d8a1b56a86a71386d0b2641e6b1d51b Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Mon, 6 May 2024 23:18:42 +0200 Subject: [PATCH] Move some lsp configuration into functions --- lua/valeth/plugins/lsp.lua | 66 +++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/lua/valeth/plugins/lsp.lua b/lua/valeth/plugins/lsp.lua index a59c6be..64fd33d 100644 --- a/lua/valeth/plugins/lsp.lua +++ b/lua/valeth/plugins/lsp.lua @@ -10,6 +10,41 @@ spec.dependencies = { { "folke/neoconf.nvim", tag = "v1.2.2" }, } +local function rust_analyzer_setup(lsp_config) + local rust_analyzer_settings = { + cargo = { + features = "all" + }, + } + + -- Don't have rustup available if using nix shell + if vim.fn.executable("rustup") == 1 then + rust_analyzer_settings = vim.tbl_extend("keep", rust_analyzer_settings, { + rustfmt = { extraArgs = { "+nightly" } } + }) + end + + lsp_config.rust_analyzer.setup({ + settings = { + ["rust-analyzer"] = rust_analyzer_settings + } + }) +end + +local function lua_ls_setup(lsp_config) + lsp_config.lua_ls.setup({ + capabilities = { + textDocument = { + completion = { + completionItem = { + snippetSupport = false + } + } + } + } + }) +end + spec.config = function() local neoconf = require("neoconf") @@ -65,36 +100,9 @@ spec.config = function() require("neodev").setup() - lsp_config.lua_ls.setup({ - capabilities = { - textDocument = { - completion = { - completionItem = { - snippetSupport = false - } - } - } - } - }) + lua_ls_setup(lsp_config) - local rust_analyzer_settings = { - cargo = { - features = "all" - }, - } - - -- Don't have rustup available if using nix shell - if vim.fn.executable("rustup") == 1 then - rust_analyzer_settings = vim.tbl_extend("keep", rust_analyzer_settings, { - rustfmt = { extraArgs = { "+nightly" } } - }) - end - - lsp_config.rust_analyzer.setup({ - settings = { - ["rust-analyzer"] = rust_analyzer_settings - } - }) + rust_analyzer_setup(lsp_config) lsp_config.sqlls.setup({})