From a8818ea92a024889bea388c9b8508a08542b6199 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Thu, 13 Oct 2022 17:31:11 +0200 Subject: [PATCH] I honestly don't know anymore --- edit.sh | 5 --- init.lua | 2 +- lua/commands.lua | 10 +++-- lua/maps.lua | 3 +- lua/plugins.lua | 74 +++++++++++++++++-------------- lua/settings/completion.lua | 73 +++++++++++++++++++++++++++++++ lua/settings/init.lua | 3 ++ lua/settings/lsp.lua | 86 ++++++++++++++++++++----------------- lua/settings/theme.lua | 5 +++ lua/settings/tree.lua | 60 ++++++++++++++++++++++++++ 10 files changed, 238 insertions(+), 83 deletions(-) delete mode 100755 edit.sh create mode 100644 lua/settings/completion.lua create mode 100644 lua/settings/tree.lua diff --git a/edit.sh b/edit.sh deleted file mode 100755 index 008e36e..0000000 --- a/edit.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -nvim -u init.lua ${1:-.} diff --git a/init.lua b/init.lua index 5652627..33b3892 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,6 @@ -- init.lua -require'plugins'.init() +require'plugins' require'settings'.init() require'maps'.init() require'commands' diff --git a/lua/commands.lua b/lua/commands.lua index cbdc598..367e904 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -1,8 +1,10 @@ -- commands.lua -vim.cmd'autocmd! User GoyoEnter Limelight' -vim.cmd'autocmd! User GoyoLeave Limelight!' +vim.cmd 'autocmd! User GoyoEnter Limelight' +vim.cmd 'autocmd! User GoyoLeave Limelight!' -vim.cmd'autocmd BufRead,BufNewFile *.wiki,*.md,*.tex set wrap' +vim.cmd 'autocmd BufRead,BufNewFile *.wiki,*.md,*.tex set wrap' -vim.cmd'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!' +vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] + +vim.cmd 'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!' diff --git a/lua/maps.lua b/lua/maps.lua index 23e59ab..f7119cd 100644 --- a/lua/maps.lua +++ b/lua/maps.lua @@ -11,6 +11,7 @@ end function maps.toggleGoyo() map('n', '', ':Goyo', {noremap = false}) end + function maps.term() -- Open and move to resized terminal map('n', 't', 'sj :terminal:res 5i', {noremap = false}) @@ -65,7 +66,7 @@ function maps.init() maps.fixIndent() maps.moveByRow() maps.centeredSearch() - maps.moveToWindow() + -- maps.moveToWindow() end return maps diff --git a/lua/plugins.lua b/lua/plugins.lua index 139315b..3bbb459 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,49 +1,59 @@ -- plugin.lua -local plugins = {} -function plugins.load(pluginList) - for _, plugin in pairs(pluginList) do - require'paq-nvim'.paq(plugin) - end -end - -local pluginList = { +require "paq" { -- Handle itself - {'savq/paq-nvim', opt=true}, + 'savq/paq-nvim'; -- Theme - 'kyazdani42/nvim-web-devicons', - 'rktjmp/lush.nvim', - 'briones-gabriel/darcula-solid.nvim', + 'kyazdani42/nvim-web-devicons'; + 'rktjmp/lush.nvim'; + 'briones-gabriel/darcula-solid.nvim'; -- treesitter - 'nvim-treesitter/nvim-treesitter', + 'nvim-treesitter/nvim-treesitter'; + 'nvim-treesitter/playground'; -- Utils - 'akinsho/nvim-bufferline.lua', - 'hoob3rt/lualine.nvim', - 'airblade/vim-gitgutter', - 'nvim-lua/popup.nvim', - 'nvim-lua/plenary.nvim', + 'akinsho/nvim-bufferline.lua'; + 'hoob3rt/lualine.nvim'; + 'j-hui/fidget.nvim'; + 'airblade/vim-gitgutter'; + 'nvim-lua/popup.nvim'; + 'nvim-lua/plenary.nvim'; -- File Navigation - 'kyazdani42/nvim-tree.lua', - 'nvim-telescope/telescope.nvim', + 'kyazdani42/nvim-tree.lua'; + 'nvim-telescope/telescope.nvim'; -- lsp - 'neovim/nvim-lspconfig', - 'williamboman/nvim-lsp-installer', + 'williamboman/mason.nvim'; + 'williamboman/mason-lspconfig.nvim'; + 'neovim/nvim-lspconfig'; + 'onsails/lspkind-nvim'; -- pictograms + 'simrat39/rust-tools.nvim'; + + -- completion + 'hrsh7th/cmp-nvim-lsp'; + 'hrsh7th/cmp-nvim-lsp-signature-help'; + 'hrsh7th/cmp-buffer'; + 'hrsh7th/cmp-path'; + 'hrsh7th/cmp-nvim-lua'; + 'hrsh7th/cmp-cmdline'; + 'hrsh7th/nvim-cmp'; + + -- snippets needed for cmp + 'L3MON4D3/LuaSnip'; + 'saadparwaiz1/cmp_luasnip'; + + -- autopair + 'windwp/nvim-autopairs'; + + -- Linting & formtatting + 'jose-elias-alvarez/null-ls.nvim'; -- writing - 'vimwiki/vimwiki', - 'junegunn/goyo.vim', - 'junegunn/limelight.vim', + 'vimwiki/vimwiki'; + 'junegunn/goyo.vim'; + 'junegunn/limelight.vim'; } - -function plugins.init() - vim.cmd 'packadd paq-nvim' - plugins.load(pluginList) -end - -return plugins diff --git a/lua/settings/completion.lua b/lua/settings/completion.lua new file mode 100644 index 0000000..a610a2d --- /dev/null +++ b/lua/settings/completion.lua @@ -0,0 +1,73 @@ +-- Completion + +local completion = {} +local cmp = require'cmp' +local lspkind = require'lspkind' + +vim.opt.shortmess:append 'c' + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert }, + [""] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }, + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true + }), + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lua' }, + { name = 'nvim_lsp' }, + { name = 'path' }, + { name = 'luasnip' }, + { name = 'nvim_lsp_signature_help' }, + }, { + { name = 'buffer', keyword_length = 5 }, + }), + formatting = { + format = lspkind.cmp_format { + with_text = true, + menu = { + buffer = "[buf]", + nvim_lsp = "[LSP]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + } + } + } +}) + +-- Use buffer source for `/` (basically search words in buffer) +cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } +}) + +-- Use cmdline & path source for ':' +cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) +}) + +-- autopair +require('nvim-autopairs').setup {} + +return completion diff --git a/lua/settings/init.lua b/lua/settings/init.lua index a3f5b02..553d62c 100644 --- a/lua/settings/init.lua +++ b/lua/settings/init.lua @@ -28,6 +28,7 @@ function settings.initMisc() vim.opt.softtabstop = 4 vim.opt.expandtab = false vim.opt.autoindent = true + vim.opt.completeopt = { "menu", "menuone", "noselect" } end function settings.initVimWiki() @@ -39,6 +40,8 @@ function settings.init() settings.initVimWiki() require'settings.theme'.init() require'settings.lsp'.init() + require'settings.completion' + require'settings.tree' end return settings diff --git a/lua/settings/lsp.lua b/lua/settings/lsp.lua index d25e71b..97d21ec 100644 --- a/lua/settings/lsp.lua +++ b/lua/settings/lsp.lua @@ -2,54 +2,60 @@ local lsp = {} -local on_attach = function(_, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end +local lsp_attach = function(client, buf) + vim.api.nvim_buf_set_option(buf, "formatexpr", "v:lua.vim.lsp.formatexpr()") + vim.api.nvim_buf_set_option(buf, "omnifunc", "v:lua.vim.lsp.omnifunc") + vim.api.nvim_buf_set_option(buf, "tagfunc", "v:lua.vim.lsp.tagfunc") - -- Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - - local opts = { noremap=true, silent=true } - - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workleader_folder()', opts) - buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workleader_folder()', opts) - buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workleader_folders()))', opts) - buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + local bufopts = { noremap=true, silent=true, buffer=buf } + 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', '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) end function lsp.init() - local lsp_installer = require'nvim-lsp-installer' + require'mason'.setup() + require'mason-lspconfig'.setup() - lsp_installer.on_server_ready(function(server) - local opts = {} - if server.name == 'sumneko_lua' then - opts.settings = { - Lua = { - diagnostics = { - globals = { 'vim' } - } + local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + local lspconfig = require'lspconfig' + + lspconfig.sumneko_lua.setup { + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } } } - end - opts.on_attach = on_attach - opts.flags = { - debounce_text_changes = 150, + }, + on_attach = lsp_attach + } + lspconfig.tsserver.setup { + capabilities = capabilities, + on_attach = lsp_attach + } + lspconfig.gopls.setup { + capabilities = capabilities, + on_attach = lsp_attach + } + --lspconfig.rust_analyzer.setup { + -- capabilities = capabilities, + -- on_attach = lsp_attach + --} + require("rust-tools").setup({ + server = { + capabilities = capabilities, + on_attach = lsp_attach, + standalone = false } - server:setup(opts) - end) + }) end return lsp diff --git a/lua/settings/theme.lua b/lua/settings/theme.lua index 2460e1f..c348df1 100644 --- a/lua/settings/theme.lua +++ b/lua/settings/theme.lua @@ -6,6 +6,10 @@ function theme.initFont() vim.opt.guifont = 'Source Code Pro for Powerline' end +function theme.lsp_status() + require'fidget'.setup {} +end + function theme.initStatusline() require'lualine'.setup { options = { @@ -28,6 +32,7 @@ end function theme.init() theme.initFont() + theme.lsp_status() theme.initStatusline() theme.initBufferline() theme.initColorscheme() diff --git a/lua/settings/tree.lua b/lua/settings/tree.lua new file mode 100644 index 0000000..a107fdd --- /dev/null +++ b/lua/settings/tree.lua @@ -0,0 +1,60 @@ +-- Tree + +local tree = {} + +require'nvim-tree'.setup { + disable_netrw = true, + hijack_netrw = true, + open_on_setup = false, + ignore_ft_on_setup = {}, + open_on_tab = false, + hijack_cursor = false, + update_cwd = false, + hijack_directories = { + enable = true, + auto_open = true, + }, + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + } + }, + update_focused_file = { + enable = false, + update_cwd = false, + ignore_list = {} + }, + system_open = { + cmd = nil, + args = {} + }, + filters = { + dotfiles = false, + custom = {} + }, + git = { + enable = true, + ignore = true, + timeout = 500, + }, + view = { + width = 30, + hide_root_folder = false, + side = 'left', + mappings = { + custom_only = false, + list = {} + } + }, + actions = { + open_file = { + resize_window = false + } + } +} + +return tree