diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2023-12-10 11:55:41 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2023-12-10 11:55:41 +0300 |
commit | bd7d56290d0a8cf8e3b1d5f3cb272df62025866a (patch) | |
tree | 8f85164dc304fa866339693b463a9701676495c5 | |
parent | 7e86db99b40aa92b290b106a4875b5cc25c2a8e3 (diff) |
Tried to fix crates completion but failed
-rw-r--r-- | .config/nvim/init.lua | 8 | ||||
-rw-r--r-- | .config/nvim/lazy-lock.json | 1 | ||||
-rw-r--r-- | .config/nvim/lua/user/lsp/common.lua | 78 | ||||
-rw-r--r-- | .config/nvim/lua/user/lspinit.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/user/plugins.lua | 107 |
5 files changed, 154 insertions, 42 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index f372955..f4fe98e 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,4 +2,10 @@ require "user.beautiful" require "user.options" require "user.plugins" require "user.remaps" -require "user.lspinit" + +-- require "user.lspinit" +-- TODO: OPTIMIZE SO THAT IT LOADS ONLY THE FIRST TIME + +vim.api.nvim_exec([[ + autocmd InsertEnter * lua require 'user.lspinit' +]], false) diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index f5311ec..a335715 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -13,6 +13,7 @@ "friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, "nerdtree": { "branch": "master", "commit": "9ec27d45a863aeb82fea56cebcb8a75a4e369fc9" }, + "nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-lspconfig": { "branch": "master", "commit": "511609ae0311abfcfaed3c398429a147e895ce2c" }, "nvim-treesitter": { "branch": "master", "commit": "1b5bbb54b385c4eae217113f72df5284bc3cc94b" }, diff --git a/.config/nvim/lua/user/lsp/common.lua b/.config/nvim/lua/user/lsp/common.lua index acc3a64..7873752 100644 --- a/.config/nvim/lua/user/lsp/common.lua +++ b/.config/nvim/lua/user/lsp/common.lua @@ -1,17 +1,19 @@ -- this file contains setup for snippets and common LSP options +-- WHY THE FUCK DID THE PROTECTED CALL SOLVE THE ISSUE UGH local cmp_status, cmp = pcall(require, 'cmp') --- vim.api.nvim_echo({{"Hello!", "Normal"}}, true, {}) if not cmp_status then vim.api.nvim_err_writeln(string.format("shit! error status: %s", cmp_status)) return end +autopairs_cmp = require 'nvim-autopairs.completion.cmp' luasnip = require 'luasnip' luasnip.setup() local expnoresilent = {expr = true, noremap = true, silent = true} local noresilent = {noremap = true, silent = true} local map = cmp.mapping +local inselect = {"i", "s"} -- stolen from https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance local kind_icons = { @@ -27,7 +29,7 @@ local kind_icons = { Folder = "", EnumMember = "", Constant = "", Struct = "", Event = "", Operator = "", - TypeParameter = "", + TypeParameter = "", Crate = "" } -- from https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip @@ -37,27 +39,71 @@ local stolen_function = function() -- to check whether there are words before cu return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end +local supertabforward = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + -- elseif stolen_function() then + -- cmp.complete() + else + fallback() + end +end + +local supertabbackward = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end +end + +local superenterconfirm = function(fallback) + -- if cmp.visible and cmp.get_active_entry() then + if cmp.visible() then + cmp.confirm{ behavior = cmp.ConfirmBehavior.Replace, select = false } + else + fallback() + end +end + cmp.setup { - snippet = { - expand = function(args) - -- vim.fn["vsnip#anonymous"](args.body) -- for vsnip (i left it) - luasnip.lsp_expand(args.body) -- for luasnip cause i like it more - end, - }, + snippet = { expand = function(args) luasnip.lsp_expand(args.body) end }, mapping = { + ["<CR>"] = map{ + i = superenterconfirm, + s = map.confirm{ select = true }, + c = map.confirm{ select = true }, + }, + ["<Tab>"] = map(supertabforward, inselect), + ["<S-Tab>"] = map(supertabbackward, inselect), + ["<C-k>"] = map(supertabforward, inselect), + ["<C-j>"] = map(supertabbackward, inselect), + ["<C-l>"] = map(superenterconfirm, inselect), + ["<C-h>"] = map(function(fallback) + if cmp.visible() then + cmp.close() + else + fallback() + end + end, inselect), ["<C-n>"] = map.select_next_item(), ["<C-p>"] = map(map.select_prev_item({ behavior = cmp.SelectBehavior.Insert })), - ["<C-Space>"] = map.complete(), + ["<C-Space>"] = map.confirm{ select = false }, -- setting select to true does not seem to change anything }, -- NOTE: ordering or this table affects completions ordering sources = { -- TODO: Add keyword_length to some of them ?????? - { name = 'nvim_lsp' }, { name = 'luasnip' }, - { name = 'buffer' }, - { name = 'path' }, - { name = 'calc' }, - { name = 'nvim_lua' }, - { name = 'nvim_lsp_signature_help' }, + { name = 'nvim_lsp' }, + { name = 'buffer', keyword_length = 3 }, + { name = 'crates' }, + { name = 'path', keyword_length = 2 }, -- will not be triggered if does not start with / + { name = 'nvim_lua', keyword_length = 3 }, + { name = 'nvim_lsp_signature_help', keyword_length = 3 }, + { name = 'calc', keyword_length = 4 }, -- I don't even know what this is }, formatting = { fields = { "kind", "abbr", "menu" }, @@ -73,6 +119,7 @@ cmp.setup { nvim_lua = "[Lua]", calc = "[(x)dx]", nvim_lsp_signature_help = "[Lsp-help]", + crates = "[Crate]", })[entry.source.name] return vim_item end, @@ -84,3 +131,4 @@ cmp.setup { experimental = { ghost_text = true }, } +cmp.event:on( 'confirm_done', autopairs_cmp.on_confirm_done() ) diff --git a/.config/nvim/lua/user/lspinit.lua b/.config/nvim/lua/user/lspinit.lua index 38b8eb0..61f203b 100644 --- a/.config/nvim/lua/user/lspinit.lua +++ b/.config/nvim/lua/user/lspinit.lua @@ -1,3 +1,5 @@ + +require'nvim-autopairs'.setup{} require 'user.lsp.common' require 'user.lsp.haskell' require 'user.lsp.python' diff --git a/.config/nvim/lua/user/plugins.lua b/.config/nvim/lua/user/plugins.lua index 2e52200..57fcef1 100644 --- a/.config/nvim/lua/user/plugins.lua +++ b/.config/nvim/lua/user/plugins.lua @@ -2,39 +2,93 @@ -- plugins to be installed plugins = { - { "folke/lazy.nvim" }, -- plugin manager - -- "williamboman/mason.nvim", -- plugin manager for LSP - -- "williamboman/mason-lspconfig.nvim", -- mason add-ons for lspconfig + { "folke/lazy.nvim" }, -- plugin manager - { "nvim-lua/popup.nvim" }, -- some functions for other plugins - { "nvim-lua/plenary.nvim" }, -- some functions for other plugins - { "folke/which-key.nvim" }, -- pretty self-descriptive name + { "nvim-lua/popup.nvim" }, -- some functions for other plugins + { "nvim-lua/plenary.nvim" }, -- some functions for other plugins + { "folke/which-key.nvim" }, -- pretty self-descriptive name - { "rafi/awesome-vim-colorschemes" }, -- colorschemes - { "lunarvim/colorschemes" }, -- colorschemes - { "folke/tokyonight.nvim" }, -- colorschemes + { "rafi/awesome-vim-colorschemes" }, -- colorschemes + { "lunarvim/colorschemes" }, -- colorschemes + { "folke/tokyonight.nvim" }, -- colorschemes - { "tpope/vim-commentary" }, -- gc & gcc for commenting - { "tpope/vim-surround" }, -- replace quotes e.t.c - { "preservim/nerdtree" }, -- file explorer - { "nvim-treesitter/nvim-treesitter" }, -- folding code, advanced syntax highlighting & sitting on a tree - { "neovim/nvim-lspconfig" }, -- LSP configuration + { "tpope/vim-commentary" }, -- gc & gcc for commenting + { "preservim/nerdtree" }, -- file explorer + { + "windwp/nvim-autopairs", + event = { "InsertEnter" }, -- automatically pair brackets and quotes + + }, + { + "tpope/vim-surround", -- replace quotes e.t.c + event = { "InsertEnter" }, + }, + + + { + "nvim-treesitter/nvim-treesitter", -- folding code, advanced syntax highlighting & sitting on a tree + event = { "InsertEnter" }, + }, + { + "neovim/nvim-lspconfig", -- LSP configuration + event = { "InsertEnter" }, + }, - -- { "hrsh7th/vim-vsnip" }, -- snippet engine - { "L3MON4D3/LuaSnip" }, -- better snippet engine - { "saadparwaiz1/cmp_luasnip" }, -- for luasnip - { "rafamadriz/friendly-snippets" }, -- predefined snippets + + -- { "hrsh7th/vim-vsnip" }, -- snippet engine + { + "L3MON4D3/LuaSnip", -- better snippet engine + event = { "InsertEnter" }, + }, + { + "saadparwaiz1/cmp_luasnip", -- for luasnip + event = { "InsertEnter" }, + }, + { + "rafamadriz/friendly-snippets", -- predefined snippets + event = { "InsertEnter" }, + }, + -- Autocompletion framework - { "hrsh7th/nvim-cmp" }, -- the framework - { "hrsh7th/cmp-nvim-lua" }, -- lua config - { "hrsh7th/cmp-nvim-lsp-signature-help" }, -- ?????????? a monster - { "hrsh7th/cmp-nvim-lsp" }, -- LSP completion - { "hrsh7th/cmp-path" }, -- /mnt/D/media/audio_sync/term_download_mp3/HELLO_I_AM_EMU_OTORI.mp3 - { "hrsh7th/cmp-buffer" }, -- current buffer - { "hrsh7th/cmp-cmdline" }, -- command line tools - { "Saecki/crates.nvim" }, -- rust packages from crates.io + { + "hrsh7th/nvim-cmp", -- the framework + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-nvim-lua", -- lua config + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-nvim-lsp-signature-help", -- ?????????? a monsterature-help" + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-nvim-lsp", -- LSP completion + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-path", -- /mnt/D/media/audio_sync/term_download_mp3/HELLO_I_AM_EMU_OTORI.mp3 + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-buffer", -- current buffer + event = { "InsertEnter" }, + }, + { + "hrsh7th/cmp-cmdline", -- command line tools + event = { "InsertEnter" }, + }, + { + "Saecki/crates.nvim", -- rust packages from crates.io + event = { "BufRead Cargo.toml" }, + setup = function() + require('crates').setup() + end, + }, + + --{ "lvimuser/lsp-inlayhints.nvim" } -- saved for the better times } @@ -63,3 +117,4 @@ lazy = require("lazy") lazy.setup(plugins, opts) -- lazy.load('nerdtree') + |