From 17715e6d613831b192f395c27c373a171d74d5e6 Mon Sep 17 00:00:00 2001 From: Atao Date: Mon, 8 Jan 2024 19:53:30 +0100 Subject: [PATCH] Add custom plugins --- .gitignore | 2 -- README.md | 1 + lua/custom/chadrc.lua | 7 ++++++ lua/custom/configs/lspconfig.lua | 24 +++++++++++++++++++++ lua/custom/configs/none-ls.lua | 28 ++++++++++++++++++++++++ lua/custom/mappings.lua | 13 +++++++++++ lua/custom/plugins.lua | 37 ++++++++++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 lua/custom/chadrc.lua create mode 100644 lua/custom/configs/lspconfig.lua create mode 100644 lua/custom/configs/none-ls.lua create mode 100644 lua/custom/mappings.lua create mode 100644 lua/custom/plugins.lua diff --git a/.gitignore b/.gitignore index d8a93d9..ea870e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -plugin -custom spell ftplugin syntax diff --git a/README.md b/README.md index eb3d7e6..5d9cbd6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua new file mode 100644 index 0000000..f118e23 --- /dev/null +++ b/lua/custom/chadrc.lua @@ -0,0 +1,7 @@ +---@type ChadrcConfig +local M = {} + +M.ui = { theme = 'catppuccin' } +M.plugins = 'custom.plugins' + +return M diff --git a/lua/custom/configs/lspconfig.lua b/lua/custom/configs/lspconfig.lua new file mode 100644 index 0000000..ad201eb --- /dev/null +++ b/lua/custom/configs/lspconfig.lua @@ -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, + } + } + } +} diff --git a/lua/custom/configs/none-ls.lua b/lua/custom/configs/none-ls.lua new file mode 100644 index 0000000..b030b62 --- /dev/null +++ b/lua/custom/configs/none-ls.lua @@ -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 diff --git a/lua/custom/mappings.lua b/lua/custom/mappings.lua new file mode 100644 index 0000000..876b95a --- /dev/null +++ b/lua/custom/mappings.lua @@ -0,0 +1,13 @@ +local M = {} + +M.gopher = { + plugins = true, + n = { + ["gsj"] = { + " GoTagAdd json ", + "Add json tag to struct" + }, + } +} + +return M diff --git a/lua/custom/plugins.lua b/lua/custom/plugins.lua new file mode 100644 index 0000000..5d38796 --- /dev/null +++ b/lua/custom/plugins.lua @@ -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