From 8196752a49720747a226cbdadc89d42cc1c1cf2b Mon Sep 17 00:00:00 2001 From: n-s-s-p-k Date: Tue, 21 Nov 2023 23:03:47 +0530 Subject: [PATCH] feat(go): Added go plugins and conf --- .gitignore | 4 +- lua/core/default_config.lua | 2 +- lua/custom/README.md | 3 + lua/custom/chadrc.lua | 22 +++++++ lua/custom/configs/lspconfig.lua | 32 +++++++++++ lua/custom/configs/null-ls.lua | 46 +++++++++++++++ lua/custom/configs/overrides.lua | 59 +++++++++++++++++++ lua/custom/highlights.lua | 19 +++++++ lua/custom/init.lua | 7 +++ lua/custom/mappings.lua | 15 +++++ lua/custom/plugins.lua | 98 ++++++++++++++++++++++++++++++++ 11 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 lua/custom/README.md create mode 100644 lua/custom/chadrc.lua create mode 100644 lua/custom/configs/lspconfig.lua create mode 100644 lua/custom/configs/null-ls.lua create mode 100644 lua/custom/configs/overrides.lua create mode 100644 lua/custom/highlights.lua create mode 100644 lua/custom/init.lua create mode 100644 lua/custom/mappings.lua create mode 100644 lua/custom/plugins.lua diff --git a/.gitignore b/.gitignore index d8a93d9..b068540 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -plugin -custom +# plugin +# custom spell ftplugin syntax diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 639916a..eae9da7 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -27,7 +27,7 @@ M.ui = { selected_item_bg = "colored", -- colored / simple }, - telescope = { style = "borderless" }, -- borderless / bordered + telescope = { style = "bordered" }, -- borderless / bordered ------------------------------- nvchad_ui modules ----------------------------- statusline = { diff --git a/lua/custom/README.md b/lua/custom/README.md new file mode 100644 index 0000000..0cc616c --- /dev/null +++ b/lua/custom/README.md @@ -0,0 +1,3 @@ +# Example_config + +This can be used as an example custom config for NvChad. Do check the https://github.com/NvChad/nvcommunity diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua new file mode 100644 index 0000000..9257743 --- /dev/null +++ b/lua/custom/chadrc.lua @@ -0,0 +1,22 @@ +---@type ChadrcConfig +local M = {} + +-- Path to overriding theme and highlights files +local highlights = require "custom.highlights" +M.ui = { + theme = "catppuccin", + theme_toggle = { "catppuccin", "one_light" }, + hl_override = highlights.override, + hl_add = highlights.add, + transparency = true, + statusline = { + theme = "default" + } +} + +M.plugins = "custom.plugins" + +-- check core.mappings for table structure +M.mappings = require "custom.mappings" + +return M diff --git a/lua/custom/configs/lspconfig.lua b/lua/custom/configs/lspconfig.lua new file mode 100644 index 0000000..d9bce7a --- /dev/null +++ b/lua/custom/configs/lspconfig.lua @@ -0,0 +1,32 @@ +local on_attach = require("plugins.configs.lspconfig").on_attach +local capabilities = require("plugins.configs.lspconfig").capabilities + +local lspconfig = require "lspconfig" + +-- if you just want default config for the servers then put them in a table +local servers = { "html", "cssls", "tsserver", "clangd", "pyright" , "ymlls", "gopls" } + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end +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.work", "go.mod", ".git"), + settings = { + gopls = { + completeUnimported = true, + usePlaceholders = true, + analyses = { + unusedparams = true, + }, + }, + }, +-- +-- lspconfig.pyright.setup { blabla} diff --git a/lua/custom/configs/null-ls.lua b/lua/custom/configs/null-ls.lua new file mode 100644 index 0000000..ce20d4c --- /dev/null +++ b/lua/custom/configs/null-ls.lua @@ -0,0 +1,46 @@ +local null_ls = require "null-ls" + +local b = null_ls.builtins +-- auto format on save +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +local sources = { + + -- webdev stuff + b.formatting.deno_fmt, -- choosed deno for ts/js files cuz its very fast! + b.formatting.prettier.with { filetypes = { "html", "markdown", "css" } }, -- so prettier works only on these filetypes + + -- Lua + b.formatting.stylua, + + -- cpp + b.formatting.clang_format, + + -- golang + b.formatting.gofumpt, + b.formatting.goimports_reviser, + b.formatting.golines, + + -- auto format on save + 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.format({ bufnr = bufnr }) + end, + }) + end + end, + +} + +null_ls.setup { + debug = true, + sources = sources, +} diff --git a/lua/custom/configs/overrides.lua b/lua/custom/configs/overrides.lua new file mode 100644 index 0000000..c4cd2c7 --- /dev/null +++ b/lua/custom/configs/overrides.lua @@ -0,0 +1,59 @@ +local M = {} + +M.treesitter = { + ensure_installed = { + "vim", + "lua", + "html", + "css", + "javascript", + "typescript", + "tsx", + "c", + "markdown", + "markdown_inline", + }, + indent = { + enable = true, + -- disable = { + -- "python" + -- }, + }, +} + +M.mason = { + ensure_installed = { + -- lua stuff + "lua-language-server", + "stylua", + + -- web dev stuff + "css-lsp", + "html-lsp", + "typescript-language-server", + "deno", + "prettier", + + -- c/cpp stuff + "clangd", + "clang-format", + }, +} + +-- git support in nvimtree +M.nvimtree = { + git = { + enable = true, + }, + + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, +} + +return M diff --git a/lua/custom/highlights.lua b/lua/custom/highlights.lua new file mode 100644 index 0000000..ebf2dfb --- /dev/null +++ b/lua/custom/highlights.lua @@ -0,0 +1,19 @@ +-- To find any highlight groups: " Telescope highlights" +-- Each highlight group can take a table with variables fg, bg, bold, italic, etc +-- base30 variable names can also be used as colors + +local M = {} + +---@type Base46HLGroupsList +M.override = { + Comment = { + italic = true, + }, +} + +---@type HLTable +M.add = { + NvimTreeOpenedFolderName = { fg = "green", bold = true }, +} + +return M diff --git a/lua/custom/init.lua b/lua/custom/init.lua new file mode 100644 index 0000000..608a8d9 --- /dev/null +++ b/lua/custom/init.lua @@ -0,0 +1,7 @@ +-- local autocmd = vim.api.nvim_create_autocmd + +-- Auto resize panes when resizing nvim window +-- autocmd("VimResized", { +-- pattern = "*", +-- command = "tabdo wincmd =", +-- }) diff --git a/lua/custom/mappings.lua b/lua/custom/mappings.lua new file mode 100644 index 0000000..17cf06a --- /dev/null +++ b/lua/custom/mappings.lua @@ -0,0 +1,15 @@ +---@type MappingsTable +local M = {} + +M.general = { + n = { + [";"] = { ":", "enter command mode", opts = { nowait = true } }, + }, + v = { + [">"] = { ">gv", "indent"}, + }, +} + +-- more keybinds! + +return M diff --git a/lua/custom/plugins.lua b/lua/custom/plugins.lua new file mode 100644 index 0000000..eeafc5f --- /dev/null +++ b/lua/custom/plugins.lua @@ -0,0 +1,98 @@ +local overrides = require("custom.configs.overrides") + +---@type NvPluginSpec[] +local plugins = { + + -- Override plugin definition options + + { + "neovim/nvim-lspconfig", + dependencies = { + -- format & linting + { + "jose-elias-alvarez/null-ls.nvim", + config = function() + require "custom.configs.null-ls" + end, + }, + }, + config = function() + require "plugins.configs.lspconfig" + require "custom.configs.lspconfig" + end, -- Override to setup mason-lspconfig + }, + + -- override plugin configs + { + "williamboman/mason.nvim", + opts = overrides.mason, + }, + + { + "nvim-treesitter/nvim-treesitter", + opts = overrides.treesitter, + { + ensure_installed = { + -- defaults + "vim", + "lua", + + -- web dev + "html", + "css", + "javascript", + "typescript", + "tsx", + "json", + -- "vue", "svelte", + + -- low level + "c", + "zig" + }, + }, + }, + + { + "nvim-tree/nvim-tree.lua", + opts = overrides.nvimtree, + }, + + -- Install a plugin + { + "max397574/better-escape.nvim", + event = "InsertEnter", + config = function() + require("better_escape").setup() + end, + }, + + -- for golang + -- generate the boiler plate go code + { + "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, + }, + -- To make a plugin not be loaded + -- { + -- "NvChad/nvim-colorizer.lua", + -- enabled = false + -- }, + + -- All NvChad plugins are lazy-loaded by default + -- For a plugin to be loaded, you will need to set either `ft`, `cmd`, `keys`, `event`, or set `lazy = false` + -- If you want a plugin to load on startup, add `lazy = false` to a plugin spec, for example + -- { + -- "mg979/vim-visual-multi", + -- lazy = false, + -- } +} + +return plugins