From 1daf8fbdd9abcca7b52afabb67815fe9c0041f81 Mon Sep 17 00:00:00 2001 From: Darius Auding <Darius.auding@gmx.de> Date: Sun, 28 May 2023 15:49:18 +0200 Subject: [PATCH] Formatting some more, adding crates for crate autocompletion --- init.lua | 1 + lua/codecraft/plugin-setup.lua | 290 ++++++++++++------------ lua/codecraft/plugin/lsp/completion.lua | 83 +++---- lua/codecraft/plugin/lsp/crates.lua | 3 + 4 files changed, 194 insertions(+), 183 deletions(-) create mode 100644 lua/codecraft/plugin/lsp/crates.lua diff --git a/init.lua b/init.lua index b97237e..ce9e4b2 100644 --- a/init.lua +++ b/init.lua @@ -32,6 +32,7 @@ require("codecraft.plugin.lsp.lsp") require("codecraft.plugin.lsp.completion") require("codecraft.plugin.lsp.null-ls") require("codecraft.plugin.lsp.rust-tools") +require("codecraft.plugin.lsp.crates") -- DAP require("codecraft.plugin.dap.dap") diff --git a/lua/codecraft/plugin-setup.lua b/lua/codecraft/plugin-setup.lua index 3d0201e..3b3d6fb 100644 --- a/lua/codecraft/plugin-setup.lua +++ b/lua/codecraft/plugin-setup.lua @@ -1,156 +1,162 @@ -- Install packer -local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' +local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" local is_bootstrap = false if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - is_bootstrap = true - vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } - vim.cmd [[packadd packer.nvim]] + is_bootstrap = true + vim.fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) + vim.cmd([[packadd packer.nvim]]) end -require('packer').startup(function(use) - -- telescope filebrowser - use { - "nvim-telescope/telescope-file-browser.nvim", - requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" } - } - -- dashboard - use { - 'goolord/alpha-nvim', - requires = { 'nvim-tree/nvim-web-devicons' }, - config = function() - require("codecraft.plugin.alpha").setup() - end - } - -- navicons - use { - "SmiteshP/nvim-navic", - requires = "neovim/nvim-lspconfig" - } - -- Rust tools - use 'simrat39/rust-tools.nvim' - -- Project manager - use 'ahmedkhalf/project.nvim' - - use "alexghergh/nvim-tmux-navigation" - -- Package manager - use 'wbthomason/packer.nvim' - use 'jiangmiao/auto-pairs' - use 'alvan/vim-closetag' - - use 'tpope/vim-surround' - -- debugging - use 'mfussenegger/nvim-dap' - use 'jay-babu/mason-nvim-dap.nvim' - use { "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } } - use 'theHamsta/nvim-dap-virtual-text' - use 'nvim-telescope/telescope-dap.nvim' - -- BufferLine - use { 'akinsho/bufferline.nvim', tag = "v3.*", requires = 'nvim-tree/nvim-web-devicons' } - -- Markdownpreview - use 'nvim-lua/completion-nvim' - -- emmet - -- use 'mattn/emmet-vim' - -- Markdownpreview - use({ - "iamcco/markdown-preview.nvim", - run = function() vim.fn["mkdp#util#install"]() end, - }) - use { -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - requires = { - -- Automatically install LSPs to stdpath for neovim - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - - -- Useful status updates for LSP - 'j-hui/fidget.nvim', - - -- Additional lua configuration, makes nvim stuff amazing - 'folke/neodev.nvim', - }, - } - -- Undotree - use 'mbbill/undotree' - - -- Formatting & Lintig - use 'jose-elias-alvarez/null-ls.nvim' - use 'jayp0521/mason-null-ls.nvim' - - use { -- Autocompletion - 'hrsh7th/nvim-cmp', - requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, - } - - use { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - run = function() - pcall(require('nvim-treesitter.install').update { with_sync = true }) - end, - } - - use { -- Additional text objects via treesitter - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter', - } - - -- NVIMTREE - use { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional, for file icons - }, - } - -- Git related plugins - use 'tpope/vim-fugitive' - use 'tpope/vim-rhubarb' - use 'lewis6991/gitsigns.nvim' - - use 'navarasu/onedark.nvim' -- Theme inspired by Atom - use 'Mofiqul/dracula.nvim' -- dracula - use 'wojciechkepka/vim-github-dark' - use 'shaunsingh/nord.nvim' - use { "catppuccin/nvim", as = "catppuccin" } - use 'morhetz/gruvbox' - use 'folke/tokyonight.nvim' - use 'LunarVim/lunar.nvim' - use 'nvim-lualine/lualine.nvim' -- Fancier statusline - use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines - use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines - use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically - - -- Fuzzy Finder (files, lsp, etc) - use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } } - - -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available - use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 } - - -- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua - local has_plugins, plugins = pcall(require, 'custom.plugins') - if has_plugins then - plugins(use) - end - - if is_bootstrap then - require('packer').sync() - end +require("packer").startup(function(use) + -- telescope filebrowser + use({ + "nvim-telescope/telescope-file-browser.nvim", + requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }, + }) + -- dashboard + use({ + "goolord/alpha-nvim", + requires = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("codecraft.plugin.alpha").setup() + end, + }) + -- navicons + use({ + "SmiteshP/nvim-navic", + requires = "neovim/nvim-lspconfig", + }) + -- Rust tools + use("simrat39/rust-tools.nvim") + use({ + "saecki/crates.nvim", + tag = "v0.3.0", + requires = { "nvim-lua/plenary.nvim" }, + }) + -- Project manager + use("ahmedkhalf/project.nvim") + + use("alexghergh/nvim-tmux-navigation") + -- Package manager + use("wbthomason/packer.nvim") + use("jiangmiao/auto-pairs") + use("alvan/vim-closetag") + + use("tpope/vim-surround") + -- debugging + use("mfussenegger/nvim-dap") + use("jay-babu/mason-nvim-dap.nvim") + use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } }) + use("theHamsta/nvim-dap-virtual-text") + use("nvim-telescope/telescope-dap.nvim") + -- BufferLine + use({ "akinsho/bufferline.nvim", tag = "v3.*", requires = "nvim-tree/nvim-web-devicons" }) + -- Markdownpreview + use("nvim-lua/completion-nvim") + -- emmet + -- use 'mattn/emmet-vim' + -- Markdownpreview + use({ + "iamcco/markdown-preview.nvim", + run = function() + vim.fn["mkdp#util#install"]() + end, + }) + use({ -- LSP Configuration & Plugins + "neovim/nvim-lspconfig", + requires = { + -- Automatically install LSPs to stdpath for neovim + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + + -- Useful status updates for LSP + "j-hui/fidget.nvim", + + -- Additional lua configuration, makes nvim stuff amazing + "folke/neodev.nvim", + }, + }) + -- Undotree + use("mbbill/undotree") + + -- Formatting & Lintig + use("jose-elias-alvarez/null-ls.nvim") + use("jayp0521/mason-null-ls.nvim") + + use({ -- Autocompletion + "hrsh7th/nvim-cmp", + requires = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" }, + }) + + use({ -- Highlight, edit, and navigate code + "nvim-treesitter/nvim-treesitter", + run = function() + pcall(require("nvim-treesitter.install").update({ with_sync = true })) + end, + }) + + use({ -- Additional text objects via treesitter + "nvim-treesitter/nvim-treesitter-textobjects", + after = "nvim-treesitter", + }) + + -- NVIMTREE + use({ + "nvim-tree/nvim-tree.lua", + requires = { + "nvim-tree/nvim-web-devicons", -- optional, for file icons + }, + }) + -- Git related plugins + use("tpope/vim-fugitive") + use("tpope/vim-rhubarb") + use("lewis6991/gitsigns.nvim") + + use("navarasu/onedark.nvim") -- Theme inspired by Atom + use("Mofiqul/dracula.nvim") -- dracula + use("wojciechkepka/vim-github-dark") + use("shaunsingh/nord.nvim") + use({ "catppuccin/nvim", as = "catppuccin" }) + use("morhetz/gruvbox") + use("folke/tokyonight.nvim") + use("LunarVim/lunar.nvim") + use("nvim-lualine/lualine.nvim") -- Fancier statusline + use("lukas-reineke/indent-blankline.nvim") -- Add indentation guides even on blank lines + use("numToStr/Comment.nvim") -- "gc" to comment visual regions/lines + use("tpope/vim-sleuth") -- Detect tabstop and shiftwidth automatically + + -- Fuzzy Finder (files, lsp, etc) + use({ "nvim-telescope/telescope.nvim", branch = "0.1.x", requires = { "nvim-lua/plenary.nvim" } }) + + -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available + use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make", cond = vim.fn.executable("make") == 1 }) + + -- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua + local has_plugins, plugins = pcall(require, "custom.plugins") + if has_plugins then + plugins(use) + end + + if is_bootstrap then + require("packer").sync() + end end) - if is_bootstrap then - print '==================================' - print ' Plugins are being installed' - print ' Wait until Packer completes,' - print ' then restart nvim' - print '==================================' - return + print("==================================") + print(" Plugins are being installed") + print(" Wait until Packer completes,") + print(" then restart nvim") + print("==================================") + return end -- Automatically source and re-compile packer whenever you save this init.lua -local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) -vim.api.nvim_create_autocmd('BufWritePost', { - command = 'source <afile> | silent! LspStop | silent! LspStart | PackerCompile', - group = packer_group, - pattern = vim.fn.expand '$MYVIMRC', +local packer_group = vim.api.nvim_create_augroup("Packer", { clear = true }) +vim.api.nvim_create_autocmd("BufWritePost", { + command = "source <afile> | silent! LspStop | silent! LspStart | PackerCompile", + group = packer_group, + pattern = vim.fn.expand("$MYVIMRC"), }) -- When we are bootstrapping a configuration, it doesn't -- make sense to execute the rest of the init.lua. diff --git a/lua/codecraft/plugin/lsp/completion.lua b/lua/codecraft/plugin/lsp/completion.lua index 5d30b87..2c2b711 100644 --- a/lua/codecraft/plugin/lsp/completion.lua +++ b/lua/codecraft/plugin/lsp/completion.lua @@ -1,43 +1,44 @@ -- nvim-cmp setup -local cmp = require 'cmp' -local luasnip = require 'luasnip' - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert { - ['<C-d>'] = cmp.mapping.scroll_docs( -4), - ['<C-f>'] = cmp.mapping.scroll_docs(4), - ['<C-Space>'] = cmp.mapping.complete(), - ['<CR>'] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - ['<Tab>'] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - ['<S-Tab>'] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable( -1) then - luasnip.jump( -1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} +local cmp = require("cmp") +local luasnip = require("luasnip") +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), + ["<CR>"] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "crates" }, + }, +}) diff --git a/lua/codecraft/plugin/lsp/crates.lua b/lua/codecraft/plugin/lsp/crates.lua new file mode 100644 index 0000000..e99de99 --- /dev/null +++ b/lua/codecraft/plugin/lsp/crates.lua @@ -0,0 +1,3 @@ +require("crates").setup({}) + +require("crates").show() -- GitLab