change copilot plugin and add tailwind plugins

This commit is contained in:
Gustavo Silva (es00679121_prosegur) 2024-02-20 19:18:36 +01:00
parent 63f64af2af
commit d22d6e5acb
7 changed files with 204 additions and 21 deletions

View File

@ -1,10 +1,15 @@
-- If you want insert `(` after select function or method item -- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp') local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp') local cmp = require('cmp')
cmp.event:on( cmp.event:on(
'confirm_done', 'confirm_done',
cmp_autopairs.on_confirm_done() cmp_autopairs.on_confirm_done()
) )
-- cmp.config.formatting = {
-- format = require("tailwindcss-colorizer-cmp").formatter
-- }
-- cmp.setup { -- cmp.setup {
-- completion = { -- completion = {
-- autocomplete = true, -- autocomplete = true,

View File

@ -16,10 +16,9 @@ sign({ name = 'DiagnosticSignInfo', text = '»' })
-- lspconfig = require 'lspconfig' -- lspconfig = require 'lspconfig'
-- lspconfig.tailwindcss.setup({ -- lspconfig.tailwindcss.setup({
-- on_attach = on_attach, -- -- on_attach = on_attach,
-- capabilities = capabilities, -- -- capabilities = capabilities,
-- filetypes = { "templ", "astro", "javascript", "typescript", "react" }, -- filetypes = { "html", "templ", "astro", "javascript", "typescript", "react" },
-- init_options = { userLanguages = { templ = "html" } },
-- }) -- })
vim.filetype.add({ extension = { templ = "templ" } }) vim.filetype.add({ extension = { templ = "templ" } })

View File

@ -96,11 +96,23 @@ require('lazy').setup({
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
dependencies = { dependencies = {
-- Snippet Engine & its associated nvim-cmp source -- 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', 'saadparwaiz1/cmp_luasnip',
-- Adds LSP completion capabilities -- Adds LSP completion capabilities
'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
-- Adds a number of user-friendly snippets -- Adds a number of user-friendly snippets
'rafamadriz/friendly-snippets', 'rafamadriz/friendly-snippets',
@ -319,6 +331,42 @@ require('telescope').setup {
-- Enable telescope fzf native, if installed -- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf') 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` -- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
@ -329,6 +377,7 @@ vim.keymap.set('n', '<leader>/', function()
previewer = false, previewer = false,
}) })
end, { desc = '[/] Fuzzily search in current buffer' }) end, { desc = '[/] Fuzzily search in current buffer' })
local function telescope_live_grep_open_files() local function telescope_live_grep_open_files()
require('telescope.builtin').live_grep { require('telescope.builtin').live_grep {
grep_open_files = true, grep_open_files = true,
@ -345,7 +394,6 @@ vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' }) vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
-- [[ Configure Treesitter ]] -- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter` -- See `:help nvim-treesitter`
-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}'
@ -370,11 +418,20 @@ vim.defer_fn(function()
"yaml", "yaml",
"css", "css",
"html", "html",
"templ",
"terraform",
"hcl"
}, },
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = true, 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 }, highlight = { enable = true },
indent = { enable = true }, indent = { enable = true },
incremental_selection = { incremental_selection = {
@ -608,14 +665,16 @@ local servers = {
filetypes = { 'templ' }, filetypes = { 'templ' },
}, },
html = { html = {
filetypes = { 'html', 'templ' }, filetypes = { 'html', 'gohtml', 'templ' },
},
htmx = {
filetypes = { 'html', 'templ' },
}, },
htmx = {},
tailwindcss = { tailwindcss = {
filetypes = { 'html', 'css', 'scss', 'javascript', 'typescript', 'templ' }, filetypes = { 'html', 'css', 'scss', 'javascript', 'typescript', 'templ', 'gohtml' },
init_options = { userLanguages = { templ = "html" } }, },
tflint = {
},
terraform = {
filetypes = { 'terraform', 'tf', 'tfvars' },
}, },
} }
@ -640,7 +699,7 @@ mason_lspconfig.setup_handlers {
on_attach = on_attach, on_attach = on_attach,
settings = servers[server_name], settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes, filetypes = (servers[server_name] or {}).filetypes,
init_options = (servers[server_name] or {}).init_options, -- init_options = (servers[server_name] or {}).init_options,
} }
end, end,
} }
@ -658,10 +717,13 @@ cmp.setup {
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
completion = {
completeopt = 'menu,menuone,noinsert',
},
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item(), ['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(), ['<C-p>'] = cmp.mapping.select_prev_item(),
['<Down>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {}, ['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
@ -690,6 +752,7 @@ cmp.setup {
sources = { sources = {
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'luasnip' }, { name = 'luasnip' },
{ name = 'path' },
}, },
} }

View File

@ -3,8 +3,9 @@
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" }, "LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"copilot.vim": { "branch": "release", "commit": "315c6d2b16e018cb8020f20aaa7081ebc4070828" }, "copilot.lua": { "branch": "master", "commit": "03f825956ec49e550d07875d867ea6e7c4dc8c00" },
"fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" },
"friendly-snippets": { "branch": "main", "commit": "5cc1f45c6aac699ad008fb85f6ae03236062667d" }, "friendly-snippets": { "branch": "main", "commit": "5cc1f45c6aac699ad008fb85f6ae03236062667d" },
"gen.nvim": { "branch": "main", "commit": "4e24c86daa4fcfe9fc0a03cf3eb3d4f4fe0d4194" }, "gen.nvim": { "branch": "main", "commit": "4e24c86daa4fcfe9fc0a03cf3eb3d4f4fe0d4194" },
@ -16,6 +17,7 @@
"indent-blankline.nvim": { "branch": "master", "commit": "12e92044d313c54c438bd786d11684c88f6f78cd" }, "indent-blankline.nvim": { "branch": "master", "commit": "12e92044d313c54c438bd786d11684c88f6f78cd" },
"lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" },
"live-server.nvim": { "branch": "main", "commit": "a2becf0d0aca59da85c3870e8eab6bf61f61e8d9" }, "live-server.nvim": { "branch": "main", "commit": "a2becf0d0aca59da85c3870e8eab6bf61f61e8d9" },
"lspkind-nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "0954d7730e749d606ddf8d7ae8846848be435d53" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "0954d7730e749d606ddf8d7ae8846848be435d53" },
@ -29,6 +31,7 @@
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },
"nvim-autopairs": { "branch": "master", "commit": "096d0baecc34f6c5d8a6dd25851e9d5ad338209b" }, "nvim-autopairs": { "branch": "master", "commit": "096d0baecc34f6c5d8a6dd25851e9d5ad338209b" },
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
"nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" },
"nvim-dap": { "branch": "master", "commit": "780fd4dd06b0744b235a520d71660c45279d9447" }, "nvim-dap": { "branch": "master", "commit": "780fd4dd06b0744b235a520d71660c45279d9447" },
"nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" }, "nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" },
"nvim-dap-ui": { "branch": "master", "commit": "d845ebd798ad1cf30aa4abd4c4eff795cdcfdd4f" }, "nvim-dap-ui": { "branch": "master", "commit": "d845ebd798ad1cf30aa4abd4c4eff795cdcfdd4f" },
@ -41,6 +44,7 @@
"onedark.nvim": { "branch": "master", "commit": "1230aaf2a427b2c5b73aba6e4a9a5881d3e69429" }, "onedark.nvim": { "branch": "master", "commit": "1230aaf2a427b2c5b73aba6e4a9a5881d3e69429" },
"plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" },
"rest.nvim": { "branch": "main", "commit": "8b62563cfb19ffe939a260504944c5975796a682" }, "rest.nvim": { "branch": "main", "commit": "8b62563cfb19ffe939a260504944c5975796a682" },
"tailwindcss-colorizer-cmp.nvim": { "branch": "main", "commit": "bc25c56083939f274edcfe395c6ff7de23b67c50" },
"telescope-dap.nvim": { "branch": "master", "commit": "8c88d9716c91eaef1cdea13cb9390d8ef447dbfe" }, "telescope-dap.nvim": { "branch": "master", "commit": "8c88d9716c91eaef1cdea13cb9390d8ef447dbfe" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
"telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, "telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },

View File

@ -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,
},
}

View File

@ -1,9 +1,65 @@
-- return {
-- "github/copilot.vim",
-- config = function()
-- vim.api.nvim_set_keymap("i", "<C-l>", 'copilot#Accept("<CR>")', { silent = true, expr = true })
-- vim.keymap.set('i', '<C-j>', '<Plug>(copilot-next)', { noremap = false })
-- vim.keymap.set('i', '<C-k>', '<Plug>(copilot-previous)', { noremap = false })
-- vim.keymap.set('i', '<M-.>', '<Plug>(copilot-suggest)', { noremap = false })
-- end
-- }
return { return {
"github/copilot.vim", "zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
config = function() config = function()
vim.api.nvim_set_keymap("i", "<C-l>", 'copilot#Accept("<CR>")', { silent = true, expr = true }) require("copilot").setup({
vim.keymap.set('i', '<C-j>', '<Plug>(copilot-next)', { noremap = false }) panel = {
vim.keymap.set('i', '<C-k>', '<Plug>(copilot-previous)', { noremap = false }) enabled = true,
vim.keymap.set('i', '<M-.>', '<Plug>(copilot-suggest)', { noremap = false }) auto_refresh = true,
end keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>"
},
layout = {
position = "bottom", -- | top | left | right
ratio = 0.4
},
},
suggestion = {
enabled = true,
auto_trigger = true,
debounce = 75,
keymap = {
accept = "<M-l>",
accept_word = false,
accept_line = false,
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
},
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,
} }

View File

@ -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
}