Add custom plugins

main
Atao 2024-01-08 19:53:30 +01:00
parent c20fc275ee
commit 17715e6d61
7 changed files with 110 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
plugin
custom
spell
ftplugin
syntax

View File

@ -7,6 +7,7 @@ I created this config with [NvChad](https://github.com/NvChad/NvChad).
## Golang
I added some plugins, check it out in `lua/custom/plugins.lua` and `lua/custom/mappings.lua`.
The list of the plugins:
- [gopls](https://github.com/golang/tools/tree/master/gopls) : Go langage server (Autocompletion)
- [gopher](https://github.com/olexsmir/gopher.nvim) : Add key mappings

7
lua/custom/chadrc.lua Normal file
View File

@ -0,0 +1,7 @@
---@type ChadrcConfig
local M = {}
M.ui = { theme = 'catppuccin' }
M.plugins = 'custom.plugins'
return M

View File

@ -0,0 +1,24 @@
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
local util = require "lspconfig/util"
lspconfig.gopls.setup{
on_attach = on_attach,
capabilities = capabilities,
cmd = {"gopls"},
filetypes = {"go", "gomod", "gowork", "gotmpl"},
root_dir = util.root_pattern("go.mod", "go.work", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
staticcheck = true,
gofumpt = true,
analyses = {
unusedparams = true,
}
}
}
}

View File

@ -0,0 +1,28 @@
local none_ls = require("none-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local opts = {
sources = {
none_ls.builtins.formatting.gofmt,
none_ls.builtins.formatting.goimports_reviser,
none_ls.builtins.formatting.golines,
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({
group = augroup,
buffer = bufnr,
})
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer= bufnr,
callback = function()
vim.lsp.buf.form({ bufnr = bufnr})
end,
})
end
end,
}
return opts

13
lua/custom/mappings.lua Normal file
View File

@ -0,0 +1,13 @@
local M = {}
M.gopher = {
plugins = true,
n = {
["<leader>gsj"] = {
"<cmd> GoTagAdd json <CR>",
"Add json tag to struct"
},
}
}
return M

37
lua/custom/plugins.lua Normal file
View File

@ -0,0 +1,37 @@
local plugins = {
{
"neovim/nvim-lspconfig",
config = function ()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end,
},
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"gopls",
"pyright",
}
}
},
{
"nvimtools/none-ls.nvim",
ft = "go",
opts = function ()
return require "custom.configs.none-ls"
end,
},
{
"olexsmir/gopher.nvim",
ft = "go",
config = function (_, opts)
require("gopher").setup(opts)
require("core.utils").load_mappings("gopher")
end,
build = function ()
vim.cmd [[silent! GoInstallDeps]]
end,
},
}
return plugins