124 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			124 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
return {
 | 
						|
    "neovim/nvim-lspconfig",
 | 
						|
    dependencies = {
 | 
						|
        "stevearc/conform.nvim",
 | 
						|
        "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", -- snippets, using luasnip for now
 | 
						|
        "saadparwaiz1/cmp_luasnip", -- snippets, using luasnip for now
 | 
						|
    },
 | 
						|
 | 
						|
    config = function()
 | 
						|
        require("conform").setup({ formatters_by_ft = {} })
 | 
						|
        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("mason").setup()
 | 
						|
        require("mason-lspconfig").setup({
 | 
						|
            ensure_installed = {
 | 
						|
                "clangd",
 | 
						|
                "lua_ls",
 | 
						|
                "ruby_lsp",
 | 
						|
                -- "gopls",
 | 
						|
                -- "tailwindcss",
 | 
						|
            },
 | 
						|
            handlers = {
 | 
						|
                function(server_name) -- default
 | 
						|
                    require("lspconfig")[server_name].setup {
 | 
						|
                        capabilities = capabilities
 | 
						|
                    }
 | 
						|
                end,
 | 
						|
 | 
						|
                ["lua_ls"] = function()
 | 
						|
                    local lspconfig = require("lspconfig")
 | 
						|
                    lspconfig.lua_ls.setup {
 | 
						|
                        capabilities = capabilities,
 | 
						|
                        settings = {
 | 
						|
                            Lua = {
 | 
						|
                                format = {
 | 
						|
                                    enable = true,
 | 
						|
                                    defaultConfig = { -- NOTE: string values only
 | 
						|
                                        indent_style = "space",
 | 
						|
                                        indent_size = "2",
 | 
						|
                                    },
 | 
						|
                                },
 | 
						|
                            },
 | 
						|
                        },
 | 
						|
                    }
 | 
						|
                end,
 | 
						|
            }
 | 
						|
        })
 | 
						|
 | 
						|
        local cmp_select = { behavior = cmp.SelectBehavior.Select }
 | 
						|
        cmp.setup({
 | 
						|
            mapping = cmp.mapping.preset.insert({
 | 
						|
                ["<C-Space>"] = cmp.mapping.complete(),
 | 
						|
                ['<C-y>'] = cmp.mapping.confirm({ select = true }),
 | 
						|
                ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
 | 
						|
                ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
 | 
						|
                ['<C-d>'] = cmp.mapping.scroll_docs(-4),
 | 
						|
                ['<C-u>'] = cmp.mapping.scroll_docs(4),
 | 
						|
            }),
 | 
						|
            snippet = {
 | 
						|
                expand = function(args)
 | 
						|
                    -- vim.snippet.expand(args.body) -- TODO: native option, maybe try
 | 
						|
                    require('luasnip').lsp_expand(args.body)
 | 
						|
                end,
 | 
						|
            },
 | 
						|
            sources = cmp.config.sources({
 | 
						|
                { name = 'nvim_lsp' },
 | 
						|
                { name = 'luasnip' },
 | 
						|
            }, {
 | 
						|
                { name = 'buffer' },
 | 
						|
            }),
 | 
						|
            window = {
 | 
						|
                completion = cmp.config.window.bordered(),
 | 
						|
                documentation = cmp.config.window.bordered(),
 | 
						|
            },
 | 
						|
            performance = {
 | 
						|
                max_view_entries = 14,
 | 
						|
            },
 | 
						|
        })
 | 
						|
 | 
						|
        -- `/` cmdline setup.
 | 
						|
        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 = "",
 | 
						|
            },
 | 
						|
        })
 | 
						|
 | 
						|
        -- TODO: needed? seems like neovim/nvim-lspconfig covers by default
 | 
						|
        -- vim.lsp.enable('clangd')
 | 
						|
        -- vim.lsp.enable('ruby_lsp')
 | 
						|
        -- vim.lsp.enable('standardrb')
 | 
						|
        -- vim.lsp.enable('herb_ls') -- targets html + ruby (erb files)
 | 
						|
    end,
 | 
						|
}
 |