add conform for formatting

This commit is contained in:
jc 2023-12-19 15:33:19 -05:00
commit 4b24a13263
No known key found for this signature in database
3 changed files with 152 additions and 135 deletions

View file

@ -1,18 +1,18 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ vim.fn.system({
"git", "git",
"clone", "clone",
"--filter=blob:none", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git", "https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release "--branch=stable", -- latest stable release
lazypath, lazypath,
}) })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("juancwu.config").setup({ require("juancwu.config").setup({
colorscheme = function() colorscheme = function()
require("tokyonight").load() require("tokyonight").load()
end, end,
}) })

View file

@ -1,6 +1,7 @@
{ {
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "57c9f5c31b3d712376c704673eac8e948c82e9c1" }, "LuaSnip": { "branch": "master", "commit": "57c9f5c31b3d712376c704673eac8e948c82e9c1" },
"catppuccin": { "branch": "main", "commit": "079500a625f3ae5aa6efb758f1a17fe4c7a57e52" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"fzf": { "branch": "master", "commit": "d21d5c9510170d74a7f959309da720b6df72ca01" }, "fzf": { "branch": "master", "commit": "d21d5c9510170d74a7f959309da720b6df72ca01" },
"fzf-lua": { "branch": "main", "commit": "a1a2d0f42eaec400cc6918a8e898fc1f9c4dbc5f" }, "fzf-lua": { "branch": "main", "commit": "a1a2d0f42eaec400cc6918a8e898fc1f9c4dbc5f" },
@ -35,6 +36,7 @@
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
"telescope.nvim": { "branch": "master", "commit": "6213322ab56eb27356fdc09a5078e41e3ea7f3bc" }, "telescope.nvim": { "branch": "master", "commit": "6213322ab56eb27356fdc09a5078e41e3ea7f3bc" },
"todo-comments.nvim": { "branch": "main", "commit": "4a6737a8d70fe1ac55c64dfa47fcb189ca431872" }, "todo-comments.nvim": { "branch": "main", "commit": "4a6737a8d70fe1ac55c64dfa47fcb189ca431872" },
"tokyonight.nvim": { "branch": "main", "commit": "f247ee700b569ed43f39320413a13ba9b0aef0db" },
"undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" }, "undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" },
"vim-closetag": { "branch": "master", "commit": "d0a562f8bdb107a50595aefe53b1a690460c3822" }, "vim-closetag": { "branch": "master", "commit": "d0a562f8bdb107a50595aefe53b1a690460c3822" },
"vim-floaterm": { "branch": "master", "commit": "3f01a623376957437f9376327637491b74719e38" }, "vim-floaterm": { "branch": "master", "commit": "3f01a623376957437f9376327637491b74719e38" },

View file

@ -1,144 +1,159 @@
return { return {
-- lspconfig -- lspconfig
{ {
'VonHeikemen/lsp-zero.nvim', "VonHeikemen/lsp-zero.nvim",
branch = 'v2.x', branch = "v2.x",
dependencies = { dependencies = {
-- LSP Support -- LSP Support
{ 'neovim/nvim-lspconfig' }, -- Required { "neovim/nvim-lspconfig" }, -- Required
{ {
-- Optional -- Optional
'williamboman/mason.nvim', "williamboman/mason.nvim",
build = function() build = function()
pcall(vim.cmd, 'MasonUpdate') pcall(vim.cmd, "MasonUpdate")
end, end,
}, },
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional { "williamboman/mason-lspconfig.nvim" }, -- Optional
-- Autocompletion -- Autocompletion
{ 'hrsh7th/nvim-cmp' }, -- Required { "hrsh7th/nvim-cmp" }, -- Required
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required { "hrsh7th/cmp-nvim-lsp" }, -- Required
{ 'L3MON4D3/LuaSnip' }, -- Required { "L3MON4D3/LuaSnip" }, -- Required
-- Neovim Plugin Development Completions -- Neovim Plugin Development Completions
{ {
'folke/neodev.nvim', "folke/neodev.nvim",
opts = {}, opts = {},
}, },
},
config = function()
-- required to setup neodev before lspconfig
require('neodev').setup({})
local lspzero = require("lsp-zero") -- formatting
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
lua = { "stylua" },
},
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
},
},
},
config = function()
-- required to setup neodev before lspconfig
require("neodev").setup({})
lspzero.preset({}) local lspzero = require("lsp-zero")
lspzero.on_attach(function(client, bufnr) lspzero.preset({})
lspzero.default_keymaps({
buffer = bufnr,
omit = {
'gr'
},
})
function nmap(key, action, desc) lspzero.on_attach(function(client, bufnr)
vim.keymap.set( lspzero.default_keymaps({
"n", buffer = bufnr,
key, omit = {
action, "gr",
{ },
desc = "LSP: " .. desc, })
}
)
end
nmap("[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Goto Prev Diagnostic"); function nmap(key, action, desc)
nmap("]d", "<cmd>lua vim.diagnostic.goto_next()<CR>", "Goto Next Diagnostic") vim.keymap.set("n", key, action, {
desc = "LSP: " .. desc,
})
end
local current_dir = vim.fn.expand("%:p:h") nmap("[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Goto Prev Diagnostic")
nmap("]d", "<cmd>lua vim.diagnostic.goto_next()<CR>", "Goto Next Diagnostic")
-- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', { buffer = true }) local current_dir = vim.fn.expand("%:p:h")
-- format with space + f -- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', { buffer = true })
-- vim.keymap.set("n", "<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>",
-- { desc = "[F]ormat [B]uffer" })
nmap("<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>", "[F]ormat [B]uffer")
end)
lspzero.ensure_installed({ -- format with space + f
"tsserver", -- vim.keymap.set("n", "<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>",
"eslint", -- { desc = "[F]ormat [B]uffer" })
"tailwindcss", nmap("<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>", "[F]ormat [B]uffer")
})
lspzero.format_on_save({ vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
format_ops = { require("conform").format({ bufnr = bufnr })
async = true, end, { desc = "Format current buffer with LSP" })
timeout_ms = 10000, end)
},
servers = {
["lua_ls"] = { "lua" },
["null-ls"] = {
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
"html",
"css",
},
},
})
local status, lspconfig = pcall(require, "lspconfig") lspzero.ensure_installed({
"tsserver",
"eslint",
"tailwindcss",
})
if status then -- lspzero.format_on_save({
lspconfig.tsserver.setup({}) -- format_ops = {
lspconfig.tailwindcss.setup({ -- async = true,
filetypes = { -- timeout_ms = 10000,
'templ', -- },
'html', -- servers = {
'javascript', -- ["lua_ls"] = { "lua" },
'typescript', -- ["null-ls"] = {
'javascriptreact', -- "javascript",
'typescriptreact', -- "typescript",
}, -- "javascriptreact",
init_options = { -- "typescriptreact",
userLanguages = { -- "html",
templ = "html" -- "css",
} -- },
} -- },
}) -- })
lspconfig.zls.setup({})
lspconfig.rust_analyzer.setup({})
lspconfig.gopls.setup({})
lspconfig.html.setup({})
vim.filetype.add({
extension = {
templ = "templ"
},
})
lspconfig.templ.setup({
filetypes = {
"templ",
},
})
end
lspzero.setup() local status, lspconfig = pcall(require, "lspconfig")
local cmp if status then
status, cmp = pcall(require, "cmp") lspconfig.tsserver.setup({})
lspconfig.tailwindcss.setup({
filetypes = {
"templ",
"html",
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
},
init_options = {
userLanguages = {
templ = "html",
},
},
})
lspconfig.zls.setup({})
lspconfig.rust_analyzer.setup({})
lspconfig.gopls.setup({})
lspconfig.html.setup({})
vim.filetype.add({
extension = {
templ = "templ",
},
})
lspconfig.templ.setup({
filetypes = {
"templ",
},
})
end
if not status then return end lspzero.setup()
cmp.setup({ local cmp
mapping = { status, cmp = pcall(require, "cmp")
-- press 'enter' to confirm completion/suggestion
['<CR>'] = cmp.mapping.confirm({ select = true }), if not status then
['<C-e>'] = cmp.mapping.abort(), return
}, end
})
end cmp.setup({
} mapping = {
-- press 'enter' to confirm completion/suggestion
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<C-e>"] = cmp.mapping.abort(),
},
})
end,
},
} }