From d305d4d18746f06f4eeac23cfb77a54e013b55a7 Mon Sep 17 00:00:00 2001 From: Nydragon <6582485n@proton.me> Date: Mon, 13 Feb 2023 01:11:34 +0100 Subject: [PATCH] format lua code --- git | 2 + nvim/init.vim | 1 + nvim/lua/nightfox-config.lua | 13 +++-- nvim/lua/nvim-cmp-config.lua | 92 +++++++++++++++++++++++++++++++++ nvim/lua/nvim-lsp-config.lua | 43 ++++++++++++++++ nvim/lua/nvim-tree-config.lua | 1 - nvim/lua/plugins.lua | 95 ++++++++++++++++++----------------- terminatorrc | 2 +- 8 files changed, 195 insertions(+), 54 deletions(-) create mode 100644 nvim/lua/nvim-cmp-config.lua create mode 100644 nvim/lua/nvim-lsp-config.lua diff --git a/git b/git index 3df55c5..2aba32f 100644 --- a/git +++ b/git @@ -8,3 +8,5 @@ autoSetupRemote = True [pull] rebase = true +[core] + editor = nvim diff --git a/nvim/init.vim b/nvim/init.vim index 423447e..2c709c1 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -7,6 +7,7 @@ set tabstop=4 set expandtab set shiftwidth=4 set autoindent +set completeopt=menu,menuone,noselect filetype plugin on lua require('plugins') diff --git a/nvim/lua/nightfox-config.lua b/nvim/lua/nightfox-config.lua index d23bad8..3256b66 100644 --- a/nvim/lua/nightfox-config.lua +++ b/nvim/lua/nightfox-config.lua @@ -1,12 +1,11 @@ require('nightfox').setup({ - options = { - styles = { - comments = "italic", - keywords = "bold", - types = "italic,bold", + options = { + styles = { + comments = "italic", + keywords = "bold", + types = "italic,bold", + } } - } }) vim.cmd("colorscheme carbonfox") - diff --git a/nvim/lua/nvim-cmp-config.lua b/nvim/lua/nvim-cmp-config.lua new file mode 100644 index 0000000..bf97d4c --- /dev/null +++ b/nvim/lua/nvim-cmp-config.lua @@ -0,0 +1,92 @@ +local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil +end + +local cmp = require 'cmp' + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + + [''] = function(fallback) + if not cmp.select_next_item() then + if vim.bo.buftype ~= 'prompt' and has_words_before() then + cmp.complete() + else + fallback() + end + end + end, + + [''] = function(fallback) + if not cmp.select_prev_item() then + if vim.bo.buftype ~= 'prompt' and has_words_before() then + cmp.complete() + else + fallback() + end + end + end, + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + }) +}) + +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = 'buffer' }, + }) +}) + +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) +}) + +-- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() +-- Replace with each lsp server you've enabled. +require('lspconfig')['pyright'].setup { + capabilities = capabilities +} diff --git a/nvim/lua/nvim-lsp-config.lua b/nvim/lua/nvim-lsp-config.lua new file mode 100644 index 0000000..89a6366 --- /dev/null +++ b/nvim/lua/nvim-lsp-config.lua @@ -0,0 +1,43 @@ +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap = true, silent = true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + + +local lsp_flags = { + -- This is the default in Nvim 0.7+ + debounce_text_changes = 150, +} +require('lspconfig')['pyright'].setup { + on_attach = on_attach, + flags = lsp_flags, +} diff --git a/nvim/lua/nvim-tree-config.lua b/nvim/lua/nvim-tree-config.lua index 2850924..d13bcd0 100644 --- a/nvim/lua/nvim-tree-config.lua +++ b/nvim/lua/nvim-tree-config.lua @@ -4,7 +4,6 @@ vim.g.loaded_netrwPlugin = 1 require("nvim-tree").setup() local function open_nvim_tree(data) - -- buffer is a real file on the disk local real_file = vim.fn.filereadable(data.file) == 1 diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 4bff35f..5c4efad 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -1,68 +1,73 @@ local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) - vim.cmd [[packadd packer.nvim]] - return true - end - return false + local fn = vim.fn + local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) + vim.cmd [[packadd packer.nvim]] + return true + end + return false end local packer_bootstrap = ensure_packer() return require('packer').startup(function(use) - use 'wbthomason/packer.nvim' - - use { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional, for file icons + use 'wbthomason/packer.nvim' + + use { + 'nvim-tree/nvim-tree.lua', + requires = { + 'nvim-tree/nvim-web-devicons', -- optional, for file icons + } } - } - use { - 'nvim-lualine/lualine.nvim', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional, for file icons + use { + 'nvim-lualine/lualine.nvim', + requires = { + 'nvim-tree/nvim-web-devicons', -- optional, for file icons + } + } - - } - use {'romgrk/barbar.nvim', requires = 'nvim-web-devicons'} + use { 'romgrk/barbar.nvim', requires = 'nvim-web-devicons' } - use 'nvim-treesitter/nvim-treesitter' + use 'nvim-treesitter/nvim-treesitter' - use 'neovim/nvim-lspconfig' -- Configurations for Nvim LSP - use 'preservim/nerdcommenter' + use 'neovim/nvim-lspconfig' -- Configurations for Nvim LSP + use 'preservim/nerdcommenter' - use "lukas-reineke/indent-blankline.nvim" + use "lukas-reineke/indent-blankline.nvim" - use "EdenEast/nightfox.nvim" + use "EdenEast/nightfox.nvim" - use "lukas-reineke/virt-column.nvim" + use "lukas-reineke/virt-column.nvim" - -- Autocompletion - use 'hrsh7th/cmp-nvim-lsp' - use 'hrsh7th/nvim-cmp' - use 'hrsh7th/cmp-path' - use 'hrsh7th/cmp-cmdline' - use 'hrsh7th/cmp-buffer' + use({ + "hrsh7th/nvim-cmp", + requires = { + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lua", + "onsails/lspkind-nvim", + } + }) - vim.cmd([[ + vim.cmd([[ augroup packer_user_config autocmd! autocmd BufWritePost plugins.lua source | PackerCompile augroup end ]]) - - -- init configs - require('nightfox-config') - require('nvim-tree-config') - require('lualine').setup() - require("virt-column").setup() - if packer_bootstrap then - require('packer').sync() - end -end) + -- init configs + require('nightfox-config') + require('nvim-lsp-config') + require('nvim-tree-config') + require('lualine').setup() + require("virt-column").setup() + require('nvim-cmp-config') + if packer_bootstrap then + require('packer').sync() + end + end) diff --git a/terminatorrc b/terminatorrc index 24c6822..df21d48 100644 --- a/terminatorrc +++ b/terminatorrc @@ -2,7 +2,7 @@ window_state = fullscreen borderless = True extra_styling = False - tab_position = bottom + tab_position = hidden inactive_color_offset = 0.9 suppress_multiple_term_dialog = True [keybindings]