autoformat on save configured
This commit is contained in:
parent
5bd1837e7d
commit
cf673381c5
21 changed files with 220 additions and 967 deletions
|
|
@ -1,6 +1,6 @@
|
|||
return {
|
||||
{'folke/tokyonight.nvim'},
|
||||
{ "nvim-lua/popup.nvim" }, -- An implementation of the Popup API from vim in Neovim
|
||||
{ 'folke/tokyonight.nvim' },
|
||||
{ "nvim-lua/popup.nvim" }, -- An implementation of the Popup API from vim in Neovim
|
||||
{ "nvim-lua/plenary.nvim" }, -- Useful lua functions used ny lots of plugins
|
||||
{ "windwp/nvim-autopairs" }, -- Autopairs
|
||||
-- "numToStr/Comment.nvim" -- Easily comment stuff
|
||||
|
|
@ -9,25 +9,12 @@ return {
|
|||
-- "lunarvim/colorschemes" -- A bunch of colorschemes you can try out
|
||||
{ "lunarvim/darkplus.nvim" },
|
||||
{ "moll/vim-bbye" },
|
||||
-- cmp plugins
|
||||
-- { "hrsh7th/nvim-cmp" }, -- The completion plugin
|
||||
-- { "hrsh7th/cmp-buffer" }, -- buffer completions
|
||||
-- { "hrsh7th/cmp-path" }, -- path completions
|
||||
-- { "hrsh7th/cmp-nvim-lua" },
|
||||
-- { "hrsh7th/cmp-cmdline" }, -- cmdline completions
|
||||
-- { "saadparwaiz1/cmp_luasnip" }, -- snippet completions
|
||||
-- { "hrsh7th/cmp-nvim-lsp" },
|
||||
|
||||
-- snippets
|
||||
{ "L3MON4D3/LuaSnip" }, --snippet engine
|
||||
-- snippets
|
||||
{ "L3MON4D3/LuaSnip" }, --snippet engine
|
||||
{ "rafamadriz/friendly-snippets" }, -- a bunch of snippets to use
|
||||
|
||||
-- LSP
|
||||
-- { "neovim/nvim-lspconfig" }, -- enable LSP
|
||||
-- { "williamboman/mason.nvim" }, -- simple to use language server installer
|
||||
-- { "williamboman/mason-lspconfig.nvim" }, -- simple to use language server installer
|
||||
|
||||
-- Telescope
|
||||
-- Telescope
|
||||
{ "nvim-telescope/telescope-media-files.nvim" },
|
||||
|
||||
-- Treesitter
|
||||
|
|
@ -37,4 +24,24 @@ return {
|
|||
},
|
||||
-- "p00f/nvim-ts-rainbow"
|
||||
-- "nvim-treesitter/playground"
|
||||
{ "neovim/nvim-lspconfig" },
|
||||
{ "williamboman/mason.nvim" },
|
||||
{ "williamboman/mason-lspconfig.nvim" },
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
dependencies = {
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'hrsh7th/cmp-buffer',
|
||||
'hrsh7th/cmp-path',
|
||||
'hrsh7th/cmp-cmdline',
|
||||
'L3MON4D3/LuaSnip',
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
'hrsh7th/cmp-vsnip',
|
||||
'hrsh7th/vim-vsnip',
|
||||
'rafamadriz/friendly-snippets',
|
||||
}
|
||||
},
|
||||
{ 'mfussenegger/nvim-lint', },
|
||||
{ 'mfussenegger/nvim-dap' },
|
||||
{ 'mhartington/formatter.nvim' }
|
||||
}
|
||||
|
|
|
|||
75
lua/plugins/cmp-settings.lua
Normal file
75
lua/plugins/cmp-settings.lua
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
-- ~/.config/nvim/lua/plugins/cmp.lua
|
||||
return {
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
dependencies = {
|
||||
"L3MON4D3/LuaSnip",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
-- Optional extras:
|
||||
-- "petertriho/cmp-git",
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
-- Load friendly snippets
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
-- documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
}),
|
||||
})
|
||||
|
||||
-- Git commits
|
||||
cmp.setup.filetype("gitcommit", {
|
||||
sources = cmp.config.sources({
|
||||
{ name = "git" }, -- if using petertriho/cmp-git
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
}),
|
||||
})
|
||||
|
||||
-- Search (/ and ?)
|
||||
cmp.setup.cmdline({ "/", "?" }, {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = "buffer" },
|
||||
},
|
||||
})
|
||||
|
||||
-- Command mode (:)
|
||||
cmp.setup.cmdline(":", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "path" },
|
||||
}, {
|
||||
{ name = "cmdline" },
|
||||
}),
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
43
lua/plugins/formatter.lua
Normal file
43
lua/plugins/formatter.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
return {
|
||||
'stevearc/conform.nvim',
|
||||
event = { 'BufWritePre' },
|
||||
cmd = { 'ConformInfo' },
|
||||
keys = {
|
||||
{
|
||||
-- Customize or remove this keymap to your liking
|
||||
'<leader>f',
|
||||
function()
|
||||
require('conform').format { async = true }
|
||||
end,
|
||||
mode = 'n',
|
||||
desc = 'Format buffer',
|
||||
},
|
||||
},
|
||||
-- This will provide type hinting with LuaLS
|
||||
---@module "conform"
|
||||
---@type conform.setupOpts
|
||||
opts = {
|
||||
-- Define your formatters
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
python = { 'isort', 'black' },
|
||||
javascript = { 'prettierd', 'prettier', stop_after_first = true },
|
||||
},
|
||||
-- Set default options
|
||||
default_format_opts = {
|
||||
lsp_format = 'fallback',
|
||||
},
|
||||
-- Set up format-on-save
|
||||
format_on_save = { timeout_ms = 500 },
|
||||
-- Customize formatters
|
||||
formatters = {
|
||||
shfmt = {
|
||||
prepend_args = { '-i', '2' },
|
||||
},
|
||||
},
|
||||
},
|
||||
init = function()
|
||||
-- If you want the formatexpr, here is the place to set it
|
||||
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
||||
end,
|
||||
}
|
||||
69
lua/plugins/lsp-settings.lua
Normal file
69
lua/plugins/lsp-settings.lua
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
-- ~/.config/nvim/lua/plugins/custom-lsp.lua
|
||||
return {
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
-- Setup Mason
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup()
|
||||
|
||||
-- LSPs to enable
|
||||
-- local servers = {
|
||||
-- "lua_ls",
|
||||
-- "ols",
|
||||
-- "zls",
|
||||
-- "clangd",
|
||||
-- "jsonls",
|
||||
-- "html",
|
||||
-- "rust_analyzer",
|
||||
-- "jdtls",
|
||||
-- "eslint",
|
||||
-- "pyright",
|
||||
-- }
|
||||
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
-- for _, server in ipairs(servers) do
|
||||
-- lspconfig[server].setup({
|
||||
-- capabilities = capabilities,
|
||||
-- })
|
||||
-- end
|
||||
|
||||
-- Autocommand for keymaps
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
local map = function(keys, func, desc)
|
||||
vim.keymap.set("n", keys, func, { buffer = ev.buf, desc = "Lsp: " .. desc })
|
||||
end
|
||||
|
||||
local tele = require("telescope.builtin")
|
||||
|
||||
map("gd", tele.lsp_definitions, "Goto Definition")
|
||||
map("<leader>fs", tele.lsp_document_symbols, "Doc Symbols")
|
||||
map("<leader>fS", tele.lsp_dynamic_workspace_symbols, "Dynamic Symbols")
|
||||
map("<leader>ft", tele.lsp_type_definitions, "Goto Type")
|
||||
map("<leader>fr", tele.lsp_references, "Goto References")
|
||||
map("<leader>fi", tele.lsp_implementations, "Goto Impl")
|
||||
|
||||
map("K", vim.lsp.buf.hover, "Hover Docs")
|
||||
map("<leader>E", vim.diagnostic.open_float, "Diagnostics")
|
||||
map("<leader>k", vim.lsp.buf.signature_help, "Signature Help")
|
||||
map("<leader>rn", vim.lsp.buf.rename, "Rename")
|
||||
map("<leader>ca", vim.lsp.buf.code_action, "Code Action")
|
||||
map("<leader>wf", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, "Format")
|
||||
|
||||
vim.keymap.set("v", "<leader>ca", vim.lsp.buf.code_action, { buffer = ev.buf, desc = "Lsp: Code Action" })
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
-- return {
|
||||
-- "mason-org/mason-lspconfig.nvim",
|
||||
-- opts = {
|
||||
-- ensure_installed = { "lua_ls", "rust_analyzer", "pyright" },
|
||||
-- },
|
||||
-- dependencies = {
|
||||
-- { "mason-org/mason.nvim", opts = {} },
|
||||
-- "neovim/nvim-lspconfig",
|
||||
-- },
|
||||
-- }
|
||||
return {
|
||||
"VonHeikemen/lsp-zero.nvim",
|
||||
branch = "v2.x",
|
||||
dependencies = {
|
||||
-- LSP Support
|
||||
{ "neovim/nvim-lspconfig" }, -- Required
|
||||
{ -- Optional
|
||||
"williamboman/mason.nvim",
|
||||
build = function()
|
||||
pcall(vim.cmd, "MasonUpdate")
|
||||
end,
|
||||
},
|
||||
{ "williamboman/mason-lspconfig.nvim" }, -- Optional
|
||||
|
||||
-- Autocompletion
|
||||
{ "hrsh7th/nvim-cmp" }, -- Required
|
||||
{ "hrsh7th/cmp-nvim-lsp" }, -- Required
|
||||
{ "L3MON4D3/LuaSnip" }, -- Required
|
||||
{ "rafamadriz/friendly-snippets" },
|
||||
{ "hrsh7th/cmp-buffer" },
|
||||
{ "hrsh7th/cmp-path" },
|
||||
{ "hrsh7th/cmp-cmdline" },
|
||||
{ "saadparwaiz1/cmp_luasnip" },
|
||||
},
|
||||
config = function()
|
||||
local lsp = require("lsp-zero")
|
||||
|
||||
lsp.on_attach(function(client, bufnr)
|
||||
local opts = { buffer = bufnr, remap = false }
|
||||
|
||||
vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Goto Reference" }))
|
||||
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Goto Definition" }))
|
||||
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Hover" }))
|
||||
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Workspace Symbol" }))
|
||||
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.setloclist() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Show Diagnostics" }))
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, vim.tbl_deep_extend("force", opts, { desc = "Next Diagnostic" }))
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, vim.tbl_deep_extend("force", opts, { desc = "Previous Diagnostic" }))
|
||||
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Code Action" }))
|
||||
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, vim.tbl_deep_extend("force", opts, { desc = "LSP References" }))
|
||||
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Rename" }))
|
||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, vim.tbl_deep_extend("force", opts, { desc = "LSP Signature Help" }))
|
||||
end)
|
||||
|
||||
require("mason").setup({})
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"eslint",
|
||||
"lua_ls",
|
||||
"jsonls",
|
||||
"html",
|
||||
"tailwindcss",
|
||||
-- "pylsp",
|
||||
"dockerls",
|
||||
"bashls",
|
||||
"gopls",
|
||||
"pyright",
|
||||
},
|
||||
handlers = {
|
||||
lsp.default_setup,
|
||||
lua_ls = function()
|
||||
local lua_opts = lsp.nvim_lua_ls()
|
||||
require("lspconfig").lua_ls.setup(lua_opts)
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
local cmp_action = require("lsp-zero").cmp_action()
|
||||
local cmp = require("cmp")
|
||||
local cmp_select = { behavior = cmp.SelectBehavior.Select }
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
-- `/` 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",
|
||||
option = {
|
||||
ignore_cmds = { "Man", "!" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip", keyword_length = 2 },
|
||||
{ name = "buffer", keyword_length = 3 },
|
||||
{ name = "path" },
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
|
||||
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-f>"] = cmp_action.luasnip_jump_forward(),
|
||||
["<C-b>"] = cmp_action.luasnip_jump_backward(),
|
||||
["<Tab>"] = cmp_action.luasnip_supertab(),
|
||||
["<S-Tab>"] = cmp_action.luasnip_shift_supertab(),
|
||||
}),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-buffer", -- Source for text in buffer
|
||||
"hrsh7th/cmp-path", -- Source for file system paths
|
||||
{
|
||||
"L3MON4D3/LuaSnip", -- Snippet Engine
|
||||
version = "v2.*",
|
||||
build = "make install_jsregexp", -- Allow lsp-snippet-transformations
|
||||
},
|
||||
"rafamadriz/friendly-snippets", -- Preconfigured snippets for different languages
|
||||
"onsails/lspkind.nvim", -- VS-Code like pictograms
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local lspkind = require("lspkind")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load() -- Required for friendly-snippets to work
|
||||
|
||||
-- Settings for the appearance of the completion window
|
||||
vim.api.nvim_set_hl(0, "CmpNormal", { bg = "#000000", fg = "#ffffff" })
|
||||
vim.api.nvim_set_hl(0, "CmpSelect", { bg = "#000000", fg = "#b5010f" })
|
||||
vim.api.nvim_set_hl(0, "CmpBorder", { bg = "#000000", fg = "#b5010f" })
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.close(),
|
||||
["<CR>"] = cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
}),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
window = {
|
||||
completion = {
|
||||
border = "rounded",
|
||||
winhighlight = "Normal:CmpNormal,CursorLine:CmpSelect,FloatBorder:CmpBorder",
|
||||
}
|
||||
},
|
||||
})
|
||||
vim.cmd([[
|
||||
set completeopt=menuone,noinsert,noselect
|
||||
highlight! default link CmpItemKind CmpItemMenuDefault
|
||||
]])
|
||||
end,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue