Browse Source

lsp formatting

imac
Juni Kim 2 years ago
parent
commit
f913fce8ee
  1. 26
      after/plugin/lsp.lua
  2. 9
      lua/junikim/options.lua
  3. 3
      lua/junikim/remap.lua

26
after/plugin/lsp.lua

@ -75,16 +75,28 @@ null_ls.setup({
}) })
end, end,
sources = { sources = {
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.autopep8,
null_ls.builtins.formatting.gofmt,
null_ls.builtins.diagnostics.eslint,
null_ls.builtins.diagnostics.shellcheck,
} }
}) })
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.go", "*.py", "*.lua", "*.rs" },
callback = function(args)
vim.lsp.buf.format {
timeout_ms = 5000
}
end
})
vim.keymap.set("n", "<leader>ft", function()
vim.lsp.buf.format()
end)
require('mason').setup()
require('mason-null-ls').setup({ require('mason-null-ls').setup({
ensure_installed = nil,
ensure_installed = { "prettier", "autopep8", "eslint", "gofmt", "rustfmt", "shellcheck" },
automatic_installation = true, automatic_installation = true,
automatic_setup = false,
automatic_setup = true,
}) })
require('mason-null-ls').setup_handlers()

9
lua/junikim/options.lua

@ -21,7 +21,6 @@ vim.opt.undofile = true
vim.opt.hlsearch = false vim.opt.hlsearch = false
vim.opt.incsearch = true vim.opt.incsearch = true
vim.opt.nu = true vim.opt.nu = true
vim.opt.rnu = true vim.opt.rnu = true
vim.opt.termguicolors = true vim.opt.termguicolors = true
@ -76,14 +75,6 @@ vim.api.nvim_create_autocmd("FileType", {
vim.bo.softtabstop = 4 vim.bo.softtabstop = 4
vim.bo.preserveindent = true vim.bo.preserveindent = true
vim.bo.copyindent = true vim.bo.copyindent = true
vim.bo.formatprg = "gofmt -e -w"
vim.api.nvim_set_keymap("n", "<F4>", ":w|:!cpgo test<CR>", { noremap = true }) vim.api.nvim_set_keymap("n", "<F4>", ":w|:!cpgo test<CR>", { noremap = true })
end end
}) })
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.go", "*.py", "*.lua", "*.ts", "*.tsx", "*.js", "*.md", "*.json", "*.rs" },
callback = function(args)
vim.lsp.buf.formatting_sync()
end
})

3
lua/junikim/remap.lua

@ -38,9 +38,6 @@ vim.keymap.set("n", "<leader>e", "<cmd>!%:p<CR>", { silent = true })
vim.keymap.set("n", "<leader>vz", "<cmd>e ~/.zshrc<CR>"); vim.keymap.set("n", "<leader>vz", "<cmd>e ~/.zshrc<CR>");
vim.keymap.set("n", "<leader>vc", "<cmd>e ~/.config/nvim<CR>"); vim.keymap.set("n", "<leader>vc", "<cmd>e ~/.config/nvim<CR>");
vim.keymap.set("n", "<leader>fmt", function()
vim.lsp.buf.format()
end)
if os.getenv("TMUX") ~= nil then if os.getenv("TMUX") ~= nil then
vim.keymap.set("n", "<C-f>", [[<cmd>silent !tmux neww tmuxs\; setenv WORKSPACES $WORKSPACES \;<CR>]]) vim.keymap.set("n", "<C-f>", [[<cmd>silent !tmux neww tmuxs\; setenv WORKSPACES $WORKSPACES \;<CR>]])

Loading…
Cancel
Save