feat: Playing around with lazy-nvim and reworking my nvim config

This commit is contained in:
2024-12-19 22:40:55 -05:00
parent ef961fcfa8
commit ee7854eafc
28 changed files with 812 additions and 571 deletions

View File

@@ -1,197 +0,0 @@
-- since this is just an example spec, don't actually load anything here and return an empty spec
-- stylua: ignore
if true then return {} end
-- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim
--
-- In your plugin files, you can:
-- * add extra plugins
-- * disable/enabled LazyVim plugins
-- * override the configuration of LazyVim plugins
return {
-- add gruvbox
{ "ellisonleao/gruvbox.nvim" },
-- Configure LazyVim to load gruvbox
{
"LazyVim/LazyVim",
opts = {
colorscheme = "gruvbox",
},
},
-- change trouble config
{
"folke/trouble.nvim",
-- opts will be merged with the parent spec
opts = { use_diagnostic_signs = true },
},
-- disable trouble
{ "folke/trouble.nvim", enabled = false },
-- override nvim-cmp and add cmp-emoji
{
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-emoji" },
---@param opts cmp.ConfigSchema
opts = function(_, opts)
table.insert(opts.sources, { name = "emoji" })
end,
},
-- change some telescope options and a keymap to browse plugin files
{
"nvim-telescope/telescope.nvim",
keys = {
-- add a keymap to browse plugin files
-- stylua: ignore
{
"<leader>fp",
function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
desc = "Find Plugin File",
},
},
-- change some options
opts = {
defaults = {
layout_strategy = "horizontal",
layout_config = { prompt_position = "top" },
sorting_strategy = "ascending",
winblend = 0,
},
},
},
-- add pyright to lspconfig
{
"neovim/nvim-lspconfig",
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- pyright will be automatically installed with mason and loaded with lspconfig
pyright = {},
},
},
},
-- add tsserver and setup with typescript.nvim instead of lspconfig
{
"neovim/nvim-lspconfig",
dependencies = {
"jose-elias-alvarez/typescript.nvim",
init = function()
require("lazyvim.util").lsp.on_attach(function(_, buffer)
-- stylua: ignore
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
end)
end,
},
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- tsserver will be automatically installed with mason and loaded with lspconfig
tsserver = {},
},
-- you can do any additional lsp server setup here
-- return true if you don't want this server to be setup with lspconfig
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
setup = {
-- example to setup with typescript.nvim
tsserver = function(_, opts)
require("typescript").setup({ server = opts })
return true
end,
-- Specify * to use this function as a fallback for any server
-- ["*"] = function(server, opts) end,
},
},
},
-- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
-- treesitter, mason and typescript.nvim. So instead of the above, you can use:
{ import = "lazyvim.plugins.extras.lang.typescript" },
-- add more treesitter parsers
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"bash",
"html",
"javascript",
"json",
"lua",
"markdown",
"markdown_inline",
"python",
"query",
"regex",
"tsx",
"typescript",
"vim",
"yaml",
},
},
},
-- since `vim.tbl_deep_extend`, can only merge tables and not lists, the code above
-- would overwrite `ensure_installed` with the new value.
-- If you'd rather extend the default config, use the code below instead:
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
-- add tsx and treesitter
vim.list_extend(opts.ensure_installed, {
"tsx",
"typescript",
})
end,
},
-- the opts function can also be used to change the default opts:
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, {
function()
return "😄"
end,
})
end,
},
-- or you can return new options to override all the defaults
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function()
return {
--[[add your custom lualine config here]]
}
end,
},
-- use mini.starter instead of alpha
{ import = "lazyvim.plugins.extras.ui.mini-starter" },
-- add jsonls and schemastore packages, and setup treesitter for json, json5 and jsonc
{ import = "lazyvim.plugins.extras.lang.json" },
-- add any tools you want to have installed below
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"stylua",
"shellcheck",
"shfmt",
"flake8",
},
},
},
}

View File

@@ -0,0 +1,23 @@
return {
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
lua = { "stulua" },
markdown = {
"prettier",
prepend_args = {
"--print-width",
"100",
"--prose-wrap",
"always",
"--parser",
"markdown",
},
},
swift = { "swiftformat" },
-- ["*"] = {
-- require("formatter.filetypes.any").remove_trailing_whitespace,
-- },
},
},
}

View File

@@ -7,6 +7,7 @@ return {
{ import = "lazyvim.plugins.extras.lang.json" },
{ import = "lazyvim.plugins.extras.lang.markdown" },
{ import = "lazyvim.plugins.extras.lang.yaml" },
{ import = "lazyvim.plugins.extras.coding.luasnip" },
{
import = "lazyvim.plugins.extras.editor.mini-files",
opts = {

View File

@@ -1,100 +1,147 @@
-- The language servers to setup.
local lsp_servers = {
"bashls",
"clangd",
"dockerls",
"gopls",
"jsonls",
"lua_ls",
"marksman",
"sourcekit",
"yamlls",
}
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"hrsh7th/cmp-nvim-lsp",
{ "antosha417/nvim-lsp-file-operations", config = true },
{
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
{
"folke/lazydev.nvim",
ft = "lua",
opts = {
library = {
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
dependencies = {
"neovim/nvim-lspconfig",
},
opts = {
ensure_installed = {
"clangd",
"marksman",
"shfmt",
},
},
},
config = function()
require("mason").setup()
require("mason-lspconfig").setup({
opts = {
ensure_installed = lsp_servers,
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"bash",
"cmake",
"dockerfile",
"editorconfig",
"ini",
"json",
"jq",
"latex",
"make",
"swift",
},
})
local lspconfig = require("lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_nvim_lsp.default_capabilities()
local opts = { noremap = true, silent = true }
local on_attach = function(_, bufnr)
opts.buffer = bufnr
opts.desc = "Show line diagnostics"
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
opts.desc = "Show diagnostics in Telescope"
vim.keymap.set("n", "<leader><leader>d", "<CMD>Telescope diagnostics bufnr=0<CR>", opts)
opts.desc = "Show documentation for what is under cursor"
vim.keymap.set("n", "<C-k>", vim.lsp.buf.hover, opts)
opts.desc = "[G]oto [D]efinition"
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions trim_text=true<cr>", opts)
opts.desc = "[G]oto [D]eclaration"
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
opts.desc = "LSP [C]ode [A]ction"
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
--opts.desc = "[R]e-[N]ame"
--vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
opts.desc = "[R]eload or start LSP"
vim.keymap.set("n", "<leader>rl", ":LspRestart | :LspStart<CR>", opts)
opts.desc = "Goto previous diagnostic"
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
opts.desc = "Goto next diagnostic"
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
end
for _, lsp in ipairs(lsp_servers) do
lspconfig[lsp].setup({
capabilities = capabilities,
on_attach = on_attach,
on_init = function(client)
-- HACK: to fix some issues with LSP
-- more details: https://github.com/neovim/neovim/issues/19237#issuecomment-2237037154
client.offset_encoding = "utf-8"
},
},
{
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
opts = {
servers = {
bashls = {},
clangd = {},
dockerls = {},
gopls = {},
jsonls = {},
lua_ls = {},
marksman = {},
sourcekit = {},
yamlls = {},
},
setup = {
clangd = function(_, opts)
opts.capabilities.offsetEncoding = { "utf-16" }
end,
cmd = lsp == "sourcekit" and { vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")) } or nil,
})
end
-- nice icons
local signs = { Error = "", Warn = "", Hint = "󰠠 ", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
-- For some reason I was having trouble getting this to work inside the on-attach, so it's here.
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "[R]e-[N]ame" })
end,
sourcekit = function(_, opts)
opts.cmd = {
vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")) or nil
}
end
},
},
},
}
-- return {
-- "neovim/nvim-lspconfig",
-- event = { "BufReadPre", "BufNewFile" },
-- dependencies = {
-- "hrsh7th/cmp-nvim-lsp",
-- { "antosha417/nvim-lsp-file-operations", config = true },
-- "williamboman/mason.nvim",
-- "williamboman/mason-lspconfig.nvim",
-- {
-- "folke/lazydev.nvim",
-- ft = "lua",
-- opts = {
-- library = {
-- { path = "${3rd}/luv/library", words = { "vim%.uv" } },
-- },
-- },
-- },
-- },
-- config = function()
-- require("mason").setup()
-- require("mason-lspconfig").setup({
-- opts = {
-- ensure_installed = lsp_servers,
-- },
-- })
-- local lspconfig = require("lspconfig")
-- local cmp_nvim_lsp = require("cmp_nvim_lsp")
-- local capabilities = cmp_nvim_lsp.default_capabilities()
-- local opts = { noremap = true, silent = true }
-- local on_attach = function(_, bufnr)
-- opts.buffer = bufnr
--
-- opts.desc = "Show line diagnostics"
-- vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
--
-- opts.desc = "Show diagnostics in Telescope"
-- vim.keymap.set("n", "<leader><leader>d", "<CMD>Telescope diagnostics bufnr=0<CR>", opts)
--
-- opts.desc = "Show documentation for what is under cursor"
-- vim.keymap.set("n", "<C-k>", vim.lsp.buf.hover, opts)
--
-- opts.desc = "[G]oto [D]efinition"
-- vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions trim_text=true<cr>", opts)
--
-- opts.desc = "[G]oto [D]eclaration"
-- vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
--
-- opts.desc = "LSP [C]ode [A]ction"
-- vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
--
-- --opts.desc = "[R]e-[N]ame"
-- --vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
--
-- opts.desc = "[R]eload or start LSP"
-- vim.keymap.set("n", "<leader>rl", ":LspRestart | :LspStart<CR>", opts)
--
-- opts.desc = "Goto previous diagnostic"
-- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
--
-- opts.desc = "Goto next diagnostic"
-- vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
-- end
--
-- for _, lsp in ipairs(lsp_servers) do
-- lspconfig[lsp].setup({
-- capabilities = capabilities,
-- on_attach = on_attach,
-- on_init = function(client)
-- -- HACK: to fix some issues with LSP
-- -- more details: https://github.com/neovim/neovim/issues/19237#issuecomment-2237037154
-- client.offset_encoding = "utf-8"
-- end,
-- cmd = lsp == "sourcekit" and { vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")) } or nil,
-- })
-- end
--
-- -- nice icons
-- local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " }
-- for type, icon in pairs(signs) do
-- local hl = "DiagnosticSign" .. type
-- vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
-- end
--
-- -- For some reason I was having trouble getting this to work inside the on-attach, so it's here.
-- vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "[R]e-[N]ame" })
-- end,
-- }

View File

@@ -0,0 +1,39 @@
return {
{
"L3MON4D3/LuaSnip",
opts = function()
LazyVim.cmp.actions.snippet_forward = function()
if require("luasnip").jumpable(1) then
require("luasnip").jump(1)
return true
end
end
LazyVim.cmp.actions.snippet_stop = function()
if require("luasnip").expand_or_jumpable() then -- or just jumpable(1) is fine?
require("luasnip").unlink_current()
return true
end
end
end,
keys = {
{
"<C-k>",
mode = { "i", "s" },
function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end
},
{
"<C-j>",
mode = { "i", "s" },
function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end
},
},
},
}

View File

@@ -0,0 +1,36 @@
return {
"stevearc/oil.nvim",
event = "VeryLazy",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
opts = {
columns = { "icon" },
keymaps = {
["<C-h>"] = false,
["<M-h>"] = "actions.select_split",
["<C-v>"] = {
"actions.select",
opts = { vertical = true },
desc = "Open the entry in a vertical split",
},
view_options = {
is_hidden_file = function(name, _) -- second arg is bufnr, but not currently used.
-- Don't show .DS_Store in output.
local is_ds_store = name ~= ".DS_Store"
return not is_ds_store
end,
},
}
},
keys = {
-- Show the parent directory in current window.
{ "-", "<CMD>Oil<CR>", desc = "Open parent directory." },
-- Open parent directory in floating window.
{
"<space>-",
function() require("oil").toggle_float() end,
desc = "Open parent directory in floating window."
},
},
}

View File

@@ -2,6 +2,7 @@ local progress_handle
return {
"wojciech-kulik/xcodebuild.nvim",
event = "VeryLazy",
dependencies = {
"nvim-telescope/telescope.nvim",
"MunifTanjim/nui.nvim",
@@ -50,23 +51,23 @@ return {
},
},
keys = {
{ "<leader>X", "<cmd>XcodebuildPicker<cr>", desc = "Show Xcodebuild Actions" },
{ "<leader>xf", "<cmd>XcodebuildProjectManager<cr>", desc = "Show Project Manager Actions" },
{ "<leader>xb", "<cmd>XcodebuildBuild<cr>", desc = "Build Project" },
{ "<leader>xB", "<cmd>XcodebuildBuildForTesting<cr>", desc = "Build For Testing" },
{ "<leader>xr", "<cmd>XcodebuildBuildRun<cr>", desc = "Build & Run Project" },
{ "<leader>xt", "<cmd>XcodebuildTest<cr>", desc = "Run Tests" },
{ "<leader>xt", "<cmd>XcodebuildTestSelected<cr>", desc = "Run Selected Tests" },
{ "<leader>xT", "<cmd>XcodebuildTestClass<cr>", desc = "Run This Test Class" },
{ "<leader>xl", "<cmd>XcodebuildToggleLogs<cr>", desc = "Toggle Xcodebuild Logs" },
{ "<leader>xc", "<cmd>XcodebuildToggleCodeCoverage<cr>", desc = "Toggle Code Coverage" },
{ "<leader>X", "<cmd>XcodebuildPicker<cr>", desc = "Show Xcodebuild Actions" },
{ "<leader>xf", "<cmd>XcodebuildProjectManager<cr>", desc = "Show Project Manager Actions" },
{ "<leader>xb", "<cmd>XcodebuildBuild<cr>", desc = "Build Project" },
{ "<leader>xB", "<cmd>XcodebuildBuildForTesting<cr>", desc = "Build For Testing" },
{ "<leader>xr", "<cmd>XcodebuildBuildRun<cr>", desc = "Build & Run Project" },
{ "<leader>xt", "<cmd>XcodebuildTest<cr>", desc = "Run Tests" },
{ "<leader>xt", "<cmd>XcodebuildTestSelected<cr>", desc = "Run Selected Tests" },
{ "<leader>xT", "<cmd>XcodebuildTestClass<cr>", desc = "Run This Test Class" },
{ "<leader>xl", "<cmd>XcodebuildToggleLogs<cr>", desc = "Toggle Xcodebuild Logs" },
{ "<leader>xc", "<cmd>XcodebuildToggleCodeCoverage<cr>", desc = "Toggle Code Coverage" },
{ "<leader>xC", "<cmd>XcodebuildShowCodeCoverageReport<cr>", desc = "Show Code Coverage Report" },
{ "<leader>xe", "<cmd>XcodebuildTestExplorerToggle<cr>", desc = "Toggle Test Explorer" },
{ "<leader>xs", "<cmd>XcodebuildFailingSnapshots<cr>", desc = "Show Failing Snapshots" },
{ "<leader>xd", "<cmd>XcodebuildSelectDevice<cr>", desc = "Select Device" },
{ "<leader>xp", "<cmd>XcodebuildSelectTestPlan<cr>", desc = "Select Test Plan" },
{ "<leader>xq", "<cmd>Telescope quickfix<cr", desc = "Show QuickFix List" },
{ "<leader>xx", "<cmd>XcodebuildQuickfixLine<cr>", desc = "Quickfix Line" },
{ "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", desc = "Show Code Actions" },
{ "<leader>xe", "<cmd>XcodebuildTestExplorerToggle<cr>", desc = "Toggle Test Explorer" },
{ "<leader>xs", "<cmd>XcodebuildFailingSnapshots<cr>", desc = "Show Failing Snapshots" },
{ "<leader>xd", "<cmd>XcodebuildSelectDevice<cr>", desc = "Select Device" },
{ "<leader>xp", "<cmd>XcodebuildSelectTestPlan<cr>", desc = "Select Test Plan" },
{ "<leader>xq", "<cmd>Telescope quickfix<cr", desc = "Show QuickFix List" },
{ "<leader>xx", "<cmd>XcodebuildQuickfixLine<cr>", desc = "Quickfix Line" },
{ "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", desc = "Show Code Actions" },
},
}