Set up LSP, completion, etc; adjust a few other small settings
This commit is contained in:
		@@ -1,22 +1,24 @@
 | 
			
		||||
function SetColorSchemeWrapper(scheme)
 | 
			
		||||
  scheme = scheme or "sorbet"
 | 
			
		||||
  scheme = scheme or "tokyonight-night"
 | 
			
		||||
  vim.cmd.colorscheme(scheme)
 | 
			
		||||
 | 
			
		||||
  -- Allow for transparency
 | 
			
		||||
  -- Allow for transparency -- TODO: do i actually want transparency?
 | 
			
		||||
  vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
 | 
			
		||||
  vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
 | 
			
		||||
end
 | 
			
		||||
SetColorSchemeWrapper()
 | 
			
		||||
 | 
			
		||||
-- TODO: get this working as desired
 | 
			
		||||
-- autocmd('BufEnter', {
 | 
			
		||||
--     group = ThePrimeagenGroup, -- TODO: group needed?
 | 
			
		||||
-- TODO: get this working as desired for different file types
 | 
			
		||||
-- local dsGroup = vim.api.nvim_create_augroup("DavidStandardGroup", { clear = false })
 | 
			
		||||
-- vim.api.nvim_create_autocmd('BufEnter', {
 | 
			
		||||
--     group = dsGroup,
 | 
			
		||||
--     callback = function()
 | 
			
		||||
--         if vim.bo.filetype == "zig" then
 | 
			
		||||
--             pcall(SetColorSchemeWrapper, "tokyonight-night")
 | 
			
		||||
--         else
 | 
			
		||||
--             pcall(SetColorSchemeWrapper, "rose-pine-main")
 | 
			
		||||
--             pcall(SetColorSchemeWrapper, "slate")
 | 
			
		||||
--             pcall(SetColorSchemeWrapper, "sorbet")
 | 
			
		||||
--         end
 | 
			
		||||
--     end
 | 
			
		||||
-- })
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,33 @@
 | 
			
		||||
vim.api.nvim_create_augroup("DavidStandardGroup", { clear = true })
 | 
			
		||||
local dsGroup = vim.api.nvim_create_augroup("DavidStandardGroup", { clear = true })
 | 
			
		||||
local dsgAutocmd = vim.api.nvim_create_autocmd
 | 
			
		||||
 | 
			
		||||
require("david_standard.settings")
 | 
			
		||||
require("david_standard.remaps")
 | 
			
		||||
require("david_standard.lazy_nvim")
 | 
			
		||||
 | 
			
		||||
require("david_standard.key_mappings")
 | 
			
		||||
require("david_standard.plugin_config")
 | 
			
		||||
require("david_standard.plugin_key_mappings")
 | 
			
		||||
require("david_standard.colorscheme_settings")
 | 
			
		||||
require("david_standard.lsp_enables")
 | 
			
		||||
 | 
			
		||||
dsgAutocmd({"BufWritePre"}, {
 | 
			
		||||
    group = DavidStandardGroup,
 | 
			
		||||
    group = dsGroup,
 | 
			
		||||
    pattern = "*",
 | 
			
		||||
    command = [[%s/\s\+$//e]],
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- TODO: put this into separate file(s) for lsp stuff? if so, pass in or make new autocmd
 | 
			
		||||
dsgAutocmd('LspAttach', {
 | 
			
		||||
    group = dsGroup,
 | 
			
		||||
    callback = function(e)
 | 
			
		||||
        local opts = { buffer = e.buf }
 | 
			
		||||
        vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
 | 
			
		||||
        vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vdv", function() vim.diagnostic.open_float() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vdn", function() vim.diagnostic.goto_next() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vdp", function() vim.diagnostic.goto_prev() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vrl", function() vim.lsp.buf.references() end, opts)
 | 
			
		||||
        vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
 | 
			
		||||
    end
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								src_files/.config/nvim/lua/david_standard/lsp/ruby.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src_files/.config/nvim/lua/david_standard/lsp/ruby.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
return {
 | 
			
		||||
    cmd = { "ruby-lsp" },
 | 
			
		||||
    filetypes = { "ruby", "eruby" },
 | 
			
		||||
    root_markers = { "Gemfile", ".git" },
 | 
			
		||||
    init_options = { formatter = "auto" },
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								src_files/.config/nvim/lua/david_standard/lsp_enables.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src_files/.config/nvim/lua/david_standard/lsp_enables.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
-- c
 | 
			
		||||
 | 
			
		||||
-- c++
 | 
			
		||||
 | 
			
		||||
-- ruby
 | 
			
		||||
vim.lsp.enable('ruby_lsp')
 | 
			
		||||
-- vim.lsp.enable('typeprof') -- ruby builtin/official (but still labled experimental)
 | 
			
		||||
-- vim.lsp.enable('standardrb')
 | 
			
		||||
-- vim.lsp.enable('solargraph')
 | 
			
		||||
-- vim.lsp.enable('herb_ls') -- targets html + ruby (erb files)
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
-- TODO: maybe switch this over from git-clone approach to neovim's builtin vim.pack.add
 | 
			
		||||
local path_lazy_nvim = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
 | 
			
		||||
if not vim.loop.fs_stat(path_lazy_nvim) then
 | 
			
		||||
  local git_output = vim.fn.system({
 | 
			
		||||
@@ -3,42 +3,52 @@ local builtin = require('telescope.builtin')
 | 
			
		||||
local custom_tscope_grep = function()
 | 
			
		||||
    builtin.grep_string({ search = vim.fn.input("grep > ")})
 | 
			
		||||
end
 | 
			
		||||
vim.keymap.set('n', '<leader>ft', builtin.live_grep, {
 | 
			
		||||
    desc = 'Telescope find text (live_grep)'
 | 
			
		||||
})
 | 
			
		||||
vim.keymap.set('n', '<leader>fT', custom_tscope_grep, {
 | 
			
		||||
    desc = 'Telescope find text (grep_string)'
 | 
			
		||||
})
 | 
			
		||||
vim.keymap.set('n', '<leader>fg', builtin.git_files, {
 | 
			
		||||
    desc = 'Telescope find git-tracked files'
 | 
			
		||||
})
 | 
			
		||||
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
 | 
			
		||||
vim.keymap.set('n', '<leader>ft', builtin.live_grep, { desc = 'Telescope find text (live_grep)' })
 | 
			
		||||
vim.keymap.set('n', '<leader>fT', custom_tscope_grep, { desc = 'Telescope find text (grep_string)' })
 | 
			
		||||
vim.keymap.set('n', '<leader>fg', builtin.git_files, { desc = 'Telescope find git-tracked files' })
 | 
			
		||||
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
 | 
			
		||||
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })
 | 
			
		||||
 | 
			
		||||
-- harpoon
 | 
			
		||||
local harpoon = require("harpoon")
 | 
			
		||||
vim.keymap.set("n", "<leader>hl", function()
 | 
			
		||||
    harpoon.ui:toggle_quick_menu(harpoon:list())
 | 
			
		||||
end)
 | 
			
		||||
vim.keymap.set("n", "<leader>ha", function() harpoon:list():add() end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hA", function() harpoon:list():prepend() end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hl", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hn", function() harpoon:list():next() end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hp", function() harpoon:list():prev() end)
 | 
			
		||||
vim.keymap.set("n", "<leader>z", function() harpoon:list():select(1) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>x", function() harpoon:list():select(2) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>c", function() harpoon:list():select(3) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>v", function() harpoon:list():select(4) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>Z", function() harpoon:list():replace_at(1) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>X", function() harpoon:list():replace_at(2) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>C", function() harpoon:list():replace_at(3) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>V", function() harpoon:list():replace_at(4) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hz", function() harpoon:list():select(1) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hx", function() harpoon:list():select(2) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hc", function() harpoon:list():select(3) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hv", function() harpoon:list():select(4) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hZ", function() harpoon:list():replace_at(1) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hX", function() harpoon:list():replace_at(2) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hC", function() harpoon:list():replace_at(3) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>hV", function() harpoon:list():replace_at(4) end)
 | 
			
		||||
 | 
			
		||||
-- undotree
 | 
			
		||||
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
 | 
			
		||||
 | 
			
		||||
-- treesitter and treesitter-context
 | 
			
		||||
vim.keymap.set("n", "<leader>tc", function() vim.cmd.TSContext({ "toggle" }) end)
 | 
			
		||||
 | 
			
		||||
-- fugitive (git integration)
 | 
			
		||||
vim.keymap.set("n", "<leader>gG", vim.cmd.Git)
 | 
			
		||||
vim.keymap.set("n", "<leader>gg", ":Git ") -- shortcut, arbitrary git commands
 | 
			
		||||
vim.keymap.set("n", "<leader>ga", function() vim.cmd.Git({ "add %"}) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>gs", function() vim.cmd.Git({ "--paginate status" }) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>gs", function() vim.cmd.Git({ "-p status" }) end)
 | 
			
		||||
vim.keymap.set("n", "<leader>gc", function() vim.cmd.Git({ "commit -a" }) end)
 | 
			
		||||
 | 
			
		||||
-- conform (formatter)
 | 
			
		||||
-- TODO: uncomment this once i set up the plugin
 | 
			
		||||
-- vim.keymap.set("n", "<leader>fmt", function()
 | 
			
		||||
--     require("conform").format({ bufnr = 0 })
 | 
			
		||||
-- end)
 | 
			
		||||
vim.keymap.set("n", "<leader>fmt", function()
 | 
			
		||||
    require("conform").format({ bufnr = 0 })
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,18 @@
 | 
			
		||||
-- TODO: set this up
 | 
			
		||||
return {
 | 
			
		||||
--     'stevearc/conform.nvim',
 | 
			
		||||
--     opts = {},
 | 
			
		||||
--     config = function()
 | 
			
		||||
--         require("conform").setup({
 | 
			
		||||
--             formatters_by_ft = {
 | 
			
		||||
--                 lua = { "stylua" },
 | 
			
		||||
--                 go = { "gofmt" },
 | 
			
		||||
--                 javascript = { "prettier" },
 | 
			
		||||
--                 typescript = { "prettier" },
 | 
			
		||||
--                 elixir = { "mix" }
 | 
			
		||||
--             }
 | 
			
		||||
--         })
 | 
			
		||||
--     end
 | 
			
		||||
    'stevearc/conform.nvim',
 | 
			
		||||
    opts = {},
 | 
			
		||||
    config = function()
 | 
			
		||||
        require("conform").setup({
 | 
			
		||||
            formatters_by_ft = {
 | 
			
		||||
                -- c = { "fill-in" },
 | 
			
		||||
                -- cpp = { "fill-in" },
 | 
			
		||||
                go = { "gofmt" },
 | 
			
		||||
                lua = { "stylua" },
 | 
			
		||||
                ruby = { "standardrb" },
 | 
			
		||||
                python = { "black" },
 | 
			
		||||
                javascript = { "prettier" },
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    end
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										138
									
								
								src_files/.config/nvim/lua/david_standard/plugins_lazy/lsp.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								src_files/.config/nvim/lua/david_standard/plugins_lazy/lsp.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,138 @@
 | 
			
		||||
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",
 | 
			
		||||
        -- snippets, using luasnip for now
 | 
			
		||||
        "L3MON4D3/LuaSnip",
 | 
			
		||||
        "saadparwaiz1/cmp_luasnip",
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    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 = {
 | 
			
		||||
                "lua_ls",
 | 
			
		||||
                -- "gopls",
 | 
			
		||||
                "ruby_lsp",
 | 
			
		||||
                -- "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-f>'] = 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(),
 | 
			
		||||
            },
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        -- `/` cmdline setup.
 | 
			
		||||
        cmp.setup.cmdline('/', {
 | 
			
		||||
            mapping = cmp.mapping.preset.cmdline(),
 | 
			
		||||
            sources = {
 | 
			
		||||
                { name = 'buffer' }
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        -- `:` 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 = "",
 | 
			
		||||
            },
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
}
 | 
			
		||||
@@ -57,7 +57,7 @@ return {
 | 
			
		||||
        "nvim-treesitter/nvim-treesitter-context",
 | 
			
		||||
        after = "nvim-treesitter",
 | 
			
		||||
        opts = {
 | 
			
		||||
            enable = true, -- can enable/disable via manual command
 | 
			
		||||
            enable = false, -- can enable/disable via manual command
 | 
			
		||||
            multiwindow = false,
 | 
			
		||||
            max_lines = 0, -- lines the window should span; x <= 0 means no limit
 | 
			
		||||
            min_window_height = 10, -- min window height to enable; x <= 0 means no limit
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ vim.opt.incsearch = true
 | 
			
		||||
vim.opt.termguicolors = true
 | 
			
		||||
vim.opt.scrolloff = 2
 | 
			
		||||
vim.opt.colorcolumn = "90"
 | 
			
		||||
vim.opt.signcolumn = "number" -- "auto", "yes", "no", "number"
 | 
			
		||||
vim.opt.signcolumn = "yes" -- "auto", "yes", "no", "number"
 | 
			
		||||
vim.opt.laststatus = 2
 | 
			
		||||
vim.opt.splitright = true
 | 
			
		||||
vim.opt.splitbelow = true
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user