diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2021-11-25 00:05:34 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2021-11-25 00:05:59 +0100 |
| commit | 412f51cd7ad4ce610ecaf13210b52709fb3e0232 (patch) | |
| tree | bf6475830cc0df42b671bf7ce9a1b33fe70f0e37 /lua | |
| parent | 31efe743072b868d4bb86ed709b85253db0b1f60 (diff) | |
| download | nvim-conf-412f51cd7ad4ce610ecaf13210b52709fb3e0232.tar.gz nvim-conf-412f51cd7ad4ce610ecaf13210b52709fb3e0232.zip | |
Move config to lua. Add laravel snippets
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/alpha/completition.lua | 32 | ||||
| -rw-r--r-- | lua/alpha/global.lua | 13 | ||||
| -rw-r--r-- | lua/alpha/init.lua | 4 | ||||
| -rw-r--r-- | lua/alpha/lsp.lua | 47 | ||||
| -rw-r--r-- | lua/alpha/snippets.lua | 29 | ||||
| -rw-r--r-- | lua/alpha/snippets/config.lua | 34 | ||||
| -rw-r--r-- | lua/alpha/snippets/init.lua | 1 | ||||
| -rw-r--r-- | lua/alpha/snippets/php.lua | 122 | ||||
| -rw-r--r-- | lua/alpha/treesitter.lua | 50 | ||||
| -rw-r--r-- | lua/plugins.lua | 4 |
10 files changed, 300 insertions, 36 deletions
diff --git a/lua/alpha/completition.lua b/lua/alpha/completition.lua index d91dccc..98a2c86 100644 --- a/lua/alpha/completition.lua +++ b/lua/alpha/completition.lua @@ -3,6 +3,8 @@ lspkind.init() local luasnip = require("luasnip") local cmp = require "cmp" +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) cmp.setup { mapping = { @@ -17,6 +19,15 @@ cmp.setup { fallback() end end, { "i", "s" }), + ["<C-n>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), ["<C-y>"] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Insert, select = true, @@ -25,11 +36,10 @@ cmp.setup { }, sources = { { name = "nvim_lua" }, - { name = "nvim_lsp" }, { name = "path" }, { name = "luasnip" }, - { name = "buffer", keyword_length = 5 }, + { name = "buffer", keyword_length = 3 }, }, snippet = { @@ -41,11 +51,13 @@ cmp.setup { formatting = { format = lspkind.cmp_format { with_text = true, - buffer = "[buf]", - nvim_lsp = "[LSP]", - nvim_lua = "[api]", - path = "[path]", - luasnip = "[snip]", + menu = { + buffer = "[buf]", + nvim_lsp = "[LSP]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + } } }, @@ -55,6 +67,12 @@ cmp.setup { ghost_text = true, } } +-- Setup lspconfig. + local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled. + require('lspconfig')['emmet_ls'].setup { + capabilities = capabilities + } -- local Group = require("colorbuddy.group").Group -- local g = require("colorbuddy.group").groups diff --git a/lua/alpha/global.lua b/lua/alpha/global.lua new file mode 100644 index 0000000..5fcee70 --- /dev/null +++ b/lua/alpha/global.lua @@ -0,0 +1,13 @@ +P = function (v) + print(vim.inspect(v)) + return v +end + +RELOAD = function (...) + return require("plenary.reload").reload_module(...) +end + +R = function (name) + RELOAD(name) + return require(name) +end diff --git a/lua/alpha/init.lua b/lua/alpha/init.lua index 2ab9a0f..7b58612 100644 --- a/lua/alpha/init.lua +++ b/lua/alpha/init.lua @@ -1,6 +1,10 @@ +require("alpha.global") require("alpha.telescope") require("alpha.refactoring") require("alpha.snippets") require("alpha.harpoon") require("alpha.refactor") require("alpha.completition") +require("alpha.lsp") +require("alpha.treesitter") +require("alpha.status-line") diff --git a/lua/alpha/lsp.lua b/lua/alpha/lsp.lua new file mode 100644 index 0000000..c164846 --- /dev/null +++ b/lua/alpha/lsp.lua @@ -0,0 +1,47 @@ +local function on_attach() + -- keymaps for lsp + vim.api.nvim_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<cr>', {noremap = true}) + vim.api.nvim_set_keymap('n', '<leader>vd', ':lua vim.lsp.buf.definition()<cr>', {noremap = true}) + + + vim.api.nvim_set_keymap('n', '<leader>vo', ':LspRestart<cr>', {noremap = true}) + + -- diagnostics to move between info and errors + vim.api.nvim_set_keymap('n', '<leader>vn', ':lua vim.lsp.diagnostic.goto_next()<cr>', {noremap = true}) + vim.api.nvim_set_keymap('n', '<leader>vp', ':lua vim.lsp.diagnostic.goto_prev()<cr>', {noremap = true}) + + vim.api.nvim_set_keymap('n', '<leader>vp', ':lua vim.lsp.diagnostic.goto_prev()<cr>', {noremap = true}) + + vim.api.nvim_set_keymap('n', '<leader>vca', ':lua vim.lsp.buf.code_action()<cr>', {noremap = true}) + vim.api.nvim_set_keymap('n', '<leader>vf', ':lua vim.lsp.buf.formatting()<cr>', {noremap = true}) + + vim.api.nvim_set_keymap('n', '<leader>vi', ':lua vim.lsp.buf.implementation()<cr>', {noremap = true}) + vim.api.nvim_set_keymap('n', '<leader>vrn', ':lua vim.lsp.buf.rename()<cr>', {noremap = true}) + + -- not sure since when I need signature help cant access this, maybe move to normal, but already have + -- the new snippet for the floating + -- vim.api.nvim_set_keymap('n', '<leader>vsh', ':lua vim.lsp.buf.signature_help()<cr>', {noremap = true}) + require "lsp_signature".on_attach() + + vim.cmd [[au Filetype php setl omnifunc=v:lua.vim.lsp.omnifunc]] + vim.cmd [[autocmd FileType go setlocal omnifunc=v:lua.vim.lsp.omnifunc]] + + vim.g.completion_matching_strategy_list = { 'exact', 'substring', 'fuzzy' } + +end + +local lsp_installer = require("nvim-lsp-installer") + +lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + if server.name == "emmet_ls" then + opts.filetypes = {"html", "css", "blade"} + end + + opts.on_attach = on_attach + -- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart) + server:setup(opts) + vim.cmd [[ do User LspAttachBuffers ]] +end) diff --git a/lua/alpha/snippets.lua b/lua/alpha/snippets.lua deleted file mode 100644 index bdf217b..0000000 --- a/lua/alpha/snippets.lua +++ /dev/null @@ -1,29 +0,0 @@ -local ls = require"luasnip" -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node -local i = ls.insert_node -local f = ls.function_node -local c = ls.choice_node -local d = ls.dynamic_node - -ls.snippets = { - php = { - s("$", { - t("$this->"), - }), - s("v", { - t({ "/**", " * @var " }), - i(1, "types"), - t({""," */", "private $"}), - i(2, "name"), - t(";", ""), - }), - s("pf", { - t("public function"), i(1, "name"), t("("), i(2, "$arg"), t(")"), - t({"", "{"}), - i(0, " "), - t({"", "}"}) - }), - } -} diff --git a/lua/alpha/snippets/config.lua b/lua/alpha/snippets/config.lua new file mode 100644 index 0000000..ff438c2 --- /dev/null +++ b/lua/alpha/snippets/config.lua @@ -0,0 +1,34 @@ +local ls = require"luasnip" +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +-- local types = require("luasnip.util.types") + +-- Every unspecified option will be set to the default. +ls.config.set_config({ + history = true, + -- Update more often, :h events for more info. + updateevents = "TextChanged,TextChangedI", + -- ext_opts = { + -- [types.choiceNode] = { + -- active = { + -- virt_text = { { "choiceNode", "Comment" } }, + -- }, + -- }, + -- }, + -- treesitter-hl has 100, use something higher (default is 200). + ext_base_prio = 300, + -- minimal increase in priority. + ext_prio_increase = 1, + enable_autosnippets = true, +}) + +-- ls.snippets = { +-- php = require('alpha.snippets.php') +-- } + +vim.api.nvim_set_keymap("i", "<c-k>", "<Plug>luasnip-expand-or-jump", {}) diff --git a/lua/alpha/snippets/init.lua b/lua/alpha/snippets/init.lua new file mode 100644 index 0000000..8318486 --- /dev/null +++ b/lua/alpha/snippets/init.lua @@ -0,0 +1 @@ +require('alpha.snippets.config') diff --git a/lua/alpha/snippets/php.lua b/lua/alpha/snippets/php.lua new file mode 100644 index 0000000..c8c2053 --- /dev/null +++ b/lua/alpha/snippets/php.lua @@ -0,0 +1,122 @@ +local ls = require"luasnip" +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local d = ls.dynamic_node + +-- visibility allows to reuse it pasing the first option to show for the +-- snippet +local visibility +visibility = function (_, _, _, initial_text) + local possibles = {'private', 'public', 'protected'} + local options = {} + + for _, value in pairs(possibles) do + if value == initial_text then + table.insert(options, 1, t(value .. ' ') ) + else + table.insert(options, t(value .. ' ')) + end + end + + return sn(nil, { c(1, options) }) +end + +local promo_property +promo_property = function() + return sn( + nil, + c(1, { + -- Order is important, sn(...) first would cause infinite loop of expansion. + t(""), + sn(nil, { + t({ "", "\t" }), + d(1, visibility, {}, "private"), + i(2, '$var'), + t(","), + d(3, promo_property, {}) + }), + }) + ) +end + +ls.snippets = { + php = { + -- variable + s("v", { + t({ "/**", " * @var " }), + i(1, "types"), + t({""," */", "private $"}), + i(2, "name"), + t(";", ""), + }), + + -- __construct + s("_c", { + d(1, visibility, {}), + t('function __construct('), + c(2, { + sn(nil, { + i(1, '$var'), + t({")", "{", "\t"}), + i(2, ''), + t({"", "}"}), + }), + sn(nil, { + d(1, promo_property, {}), + t({"",") {", "}"}), + }), + }), + }), + + -- function + s("fn", { + d(1, visibility, {}, "public"), + t("function "), + i(2, "name"), + t("("), + i(3, "$arg"), + t(")"), + c(4, { + sn(nil, { + t(': '), + i(1, "void"), + }), + t(""), + }), + t({"", "{", ""}), + t("\t"), i(0, ""), + t({"", "}"}) + }), + + -- Route + s("ro", { + t("Route::"), + c(1, { + t("get"), + t("post"), + t("put"), + t("view"), + }), + t("('"), + i(2, "uri"), + t("', "), + c(3, { + sn(nil, { + t({'function () {', ' '}), + i(1, ''), + t({'', '});'}), + }), + sn(nil, { + t('['), + i(1, 'Controller'), + t('::class, \''), + i(2, 'method'), + t('\']);'), + }) + }), + }), + } +} diff --git a/lua/alpha/treesitter.lua b/lua/alpha/treesitter.lua new file mode 100644 index 0000000..a88b6db --- /dev/null +++ b/lua/alpha/treesitter.lua @@ -0,0 +1,50 @@ +require "nvim-treesitter.configs".setup { + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true, + }, + refactor = { + highlight_definitions = { enable = true }, + smart_rename = { + enable = true, + keymaps = { + smart_rename = "grr", + }, + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@conditional.outer", + ["ic"] = "@conditional.inner", + ["al"] = "@loop.outer", + ["il"] = "@loop.inner", + } + } + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = false, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = 'o', + toggle_hl_groups = 'i', + toggle_injected_languages = 't', + toggle_anonymous_nodes = 'a', + toggle_language_display = 'I', + focus_language = 'f', + unfocus_language = 'F', + update = 'R', + goto_node = '<cr>', + show_help = '?', + }, + } +} diff --git a/lua/plugins.lua b/lua/plugins.lua index c0ab19a..e75d0fe 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -27,6 +27,7 @@ return require('packer').startup(function(use) use 'tpope/vim-dispatch' + -- Completition use "hrsh7th/nvim-cmp" use "hrsh7th/cmp-buffer" use "hrsh7th/cmp-path" @@ -34,6 +35,9 @@ return require('packer').startup(function(use) use "hrsh7th/cmp-nvim-lsp" use "saadparwaiz1/cmp_luasnip" use "onsails/lspkind-nvim" + use "hrsh7th/cmp-nvim-lsp-signature-help" + use "windwp/nvim-autopairs" + use "ray-x/lsp_signature.nvim" |