diff --git a/after/plugin/cmp.lua b/after/plugin/cmp.lua index e338b780..d3583ac7 100644 --- a/after/plugin/cmp.lua +++ b/after/plugin/cmp.lua @@ -1,10 +1,15 @@ -- If you want insert `(` after select function or method item local cmp_autopairs = require('nvim-autopairs.completion.cmp') local cmp = require('cmp') + cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done() ) + +-- cmp.config.formatting = { +-- format = require("tailwindcss-colorizer-cmp").formatter +-- } -- cmp.setup { -- completion = { -- autocomplete = true, diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 7826ee1c..993ca0a4 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -16,10 +16,9 @@ sign({ name = 'DiagnosticSignInfo', text = 'ยป' }) -- lspconfig = require 'lspconfig' -- lspconfig.tailwindcss.setup({ --- on_attach = on_attach, --- capabilities = capabilities, --- filetypes = { "templ", "astro", "javascript", "typescript", "react" }, --- init_options = { userLanguages = { templ = "html" } }, +-- -- on_attach = on_attach, +-- -- capabilities = capabilities, +-- filetypes = { "html", "templ", "astro", "javascript", "typescript", "react" }, -- }) vim.filetype.add({ extension = { templ = "templ" } }) diff --git a/init.lua b/init.lua index 3c931641..3dec38e8 100644 --- a/init.lua +++ b/init.lua @@ -96,11 +96,23 @@ require('lazy').setup({ 'hrsh7th/nvim-cmp', dependencies = { -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', + { + 'L3MON4D3/LuaSnip', + build = (function() + -- Build Step is needed for regex support in snippets + -- This step is not supported in many windows environments + -- Remove the below condition to re-enable on windows + if vim.fn.has 'win32' == 1 then + return + end + return 'make install_jsregexp' + end)(), + }, 'saadparwaiz1/cmp_luasnip', -- Adds LSP completion capabilities 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', -- Adds a number of user-friendly snippets 'rafamadriz/friendly-snippets', @@ -319,6 +331,42 @@ require('telescope').setup { -- Enable telescope fzf native, if installed pcall(require('telescope').load_extension, 'fzf') +-- Telescope live_grep in git root +-- Function to find the git root directory based on the current buffer's path +local function find_git_root() + -- Use the current buffer's path as the starting point for the git search + local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() + -- If the buffer is not associated with a file, return nil + if current_file == '' then + current_dir = cwd + else + -- Extract the directory from the current file's path + current_dir = vim.fn.fnamemodify(current_file, ':h') + end + + -- Find the Git root directory from the current file's path + local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] + if vim.v.shell_error ~= 0 then + print 'Not a git repository. Searching on current working directory' + return cwd + end + return git_root +end + +-- Custom live_grep function to search in git root +local function live_grep_git_root() + local git_root = find_git_root() + if git_root then + require('telescope.builtin').live_grep { + search_dirs = { git_root }, + } + end +end + +vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) + -- See `:help telescope.builtin` vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) @@ -329,6 +377,7 @@ vim.keymap.set('n', '/', function() previewer = false, }) end, { desc = '[/] Fuzzily search in current buffer' }) + local function telescope_live_grep_open_files() require('telescope.builtin').live_grep { grep_open_files = true, @@ -345,7 +394,6 @@ vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) - -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' @@ -370,11 +418,20 @@ vim.defer_fn(function() "yaml", "css", "html", + "templ", + "terraform", + "hcl" }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = true, + -- Install languages synchronously (only applied to `ensure_installed`) + sync_install = false, + -- List of parsers to ignore installing + ignore_install = {}, + -- You can specify additional Treesitter modules here: -- For example: -- playground = {--enable = true,-- }, + modules = {}, highlight = { enable = true }, indent = { enable = true }, incremental_selection = { @@ -608,14 +665,16 @@ local servers = { filetypes = { 'templ' }, }, html = { - filetypes = { 'html', 'templ' }, - }, - htmx = { - filetypes = { 'html', 'templ' }, + filetypes = { 'html', 'gohtml', 'templ' }, }, + htmx = {}, tailwindcss = { - filetypes = { 'html', 'css', 'scss', 'javascript', 'typescript', 'templ' }, - init_options = { userLanguages = { templ = "html" } }, + filetypes = { 'html', 'css', 'scss', 'javascript', 'typescript', 'templ', 'gohtml' }, + }, + tflint = { + }, + terraform = { + filetypes = { 'terraform', 'tf', 'tfvars' }, }, } @@ -640,7 +699,7 @@ mason_lspconfig.setup_handlers { on_attach = on_attach, settings = servers[server_name], filetypes = (servers[server_name] or {}).filetypes, - init_options = (servers[server_name] or {}).init_options, + -- init_options = (servers[server_name] or {}).init_options, } end, } @@ -658,10 +717,13 @@ cmp.setup { luasnip.lsp_expand(args.body) end, }, + completion = { + completeopt = 'menu,menuone,noinsert', + }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { @@ -690,6 +752,7 @@ cmp.setup { sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, + { name = 'path' }, }, } diff --git a/lazy-lock.json b/lazy-lock.json index fedb09a7..8efba0a6 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -3,8 +3,9 @@ "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, "LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "copilot.vim": { "branch": "release", "commit": "315c6d2b16e018cb8020f20aaa7081ebc4070828" }, + "copilot.lua": { "branch": "master", "commit": "03f825956ec49e550d07875d867ea6e7c4dc8c00" }, "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, "friendly-snippets": { "branch": "main", "commit": "5cc1f45c6aac699ad008fb85f6ae03236062667d" }, "gen.nvim": { "branch": "main", "commit": "4e24c86daa4fcfe9fc0a03cf3eb3d4f4fe0d4194" }, @@ -16,6 +17,7 @@ "indent-blankline.nvim": { "branch": "master", "commit": "12e92044d313c54c438bd786d11684c88f6f78cd" }, "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, "live-server.nvim": { "branch": "main", "commit": "a2becf0d0aca59da85c3870e8eab6bf61f61e8d9" }, + "lspkind-nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "0954d7730e749d606ddf8d7ae8846848be435d53" }, @@ -29,6 +31,7 @@ "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, "nvim-autopairs": { "branch": "master", "commit": "096d0baecc34f6c5d8a6dd25851e9d5ad338209b" }, "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, "nvim-dap": { "branch": "master", "commit": "780fd4dd06b0744b235a520d71660c45279d9447" }, "nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" }, "nvim-dap-ui": { "branch": "master", "commit": "d845ebd798ad1cf30aa4abd4c4eff795cdcfdd4f" }, @@ -41,6 +44,7 @@ "onedark.nvim": { "branch": "master", "commit": "1230aaf2a427b2c5b73aba6e4a9a5881d3e69429" }, "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, "rest.nvim": { "branch": "main", "commit": "8b62563cfb19ffe939a260504944c5975796a682" }, + "tailwindcss-colorizer-cmp.nvim": { "branch": "main", "commit": "bc25c56083939f274edcfe395c6ff7de23b67c50" }, "telescope-dap.nvim": { "branch": "master", "commit": "8c88d9716c91eaef1cdea13cb9390d8ef447dbfe" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, diff --git a/lua/custom/plugins/cmp.lua b/lua/custom/plugins/cmp.lua new file mode 100644 index 00000000..70bb5120 --- /dev/null +++ b/lua/custom/plugins/cmp.lua @@ -0,0 +1,39 @@ +return { + "hrsh7th/nvim-cmp", + dependencies = { + "onsails/lspkind-nvim", + { "roobert/tailwindcss-colorizer-cmp.nvim", config = true }, + }, + config = function() + local cmp = require("cmp") + local lspkind = require("lspkind") + lspkind.init({ + mode = "symbol_text", + preset = "codicons", + }) + + cmp.setup({ + formatting = { + format = function(entry, item) + item.kind = lspkind.presets.default[item.kind] + item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + buffer = "[Buffer]", + path = "[Path]", + calc = "[Calc]", + look = "[Dict]", + })[entry.source.name] + return require("tailwindcss-colorizer-cmp").formatter(entry, item) + end, + }, + }) + end, + experimental = { + -- I like the new menu better! Nice work hrsh7th + native_menu = false, + + -- Let's play with this for a day or two + ghost_text = false, + }, +} diff --git a/lua/custom/plugins/copilot.lua b/lua/custom/plugins/copilot.lua index 7bc66055..1722e061 100644 --- a/lua/custom/plugins/copilot.lua +++ b/lua/custom/plugins/copilot.lua @@ -1,9 +1,65 @@ +-- return { +-- "github/copilot.vim", +-- config = function() +-- vim.api.nvim_set_keymap("i", "", 'copilot#Accept("")', { silent = true, expr = true }) +-- vim.keymap.set('i', '', '(copilot-next)', { noremap = false }) +-- vim.keymap.set('i', '', '(copilot-previous)', { noremap = false }) +-- vim.keymap.set('i', '', '(copilot-suggest)', { noremap = false }) +-- end +-- } + return { - "github/copilot.vim", + "zbirenbaum/copilot.lua", + cmd = "Copilot", + event = "InsertEnter", config = function() - vim.api.nvim_set_keymap("i", "", 'copilot#Accept("")', { silent = true, expr = true }) - vim.keymap.set('i', '', '(copilot-next)', { noremap = false }) - vim.keymap.set('i', '', '(copilot-previous)', { noremap = false }) - vim.keymap.set('i', '', '(copilot-suggest)', { noremap = false }) - end + require("copilot").setup({ + panel = { + enabled = true, + auto_refresh = true, + keymap = { + jump_prev = "[[", + jump_next = "]]", + accept = "", + refresh = "gr", + open = "" + }, + layout = { + position = "bottom", -- | top | left | right + ratio = 0.4 + }, + }, + suggestion = { + enabled = true, + auto_trigger = true, + debounce = 75, + keymap = { + accept = "", + accept_word = false, + accept_line = false, + next = "", + prev = "", + dismiss = "", + }, + }, + filetypes = { + yaml = true, + markdown = true, + help = false, + gitcommit = true, + gitrebase = false, + hgcommit = false, + terraform = true, + go = true, + html = true, + templ = true, + javascript = true, + svn = false, + cvs = false, + ["."] = true, + }, + copilot_node_command = 'node', -- Node.js version must be > 18.x + server_opts_overrides = {}, + }) + end, } diff --git a/lua/custom/plugins/nvim_colorizer.lua b/lua/custom/plugins/nvim_colorizer.lua new file mode 100644 index 00000000..5af73310 --- /dev/null +++ b/lua/custom/plugins/nvim_colorizer.lua @@ -0,0 +1,17 @@ +return { + "NvChad/nvim-colorizer.lua", + config = function() + require("colorizer").setup({ + user_default_options = { + tailwind = true, + }, + }) + end, + -- "roobert/tailwindcss-colorizer-cmp.nvim", + -- -- optionally, override the default options: + -- config = function() + -- require("tailwindcss-colorizer-cmp").setup({ + -- color_square_width = 2, + -- }) + -- end +}