From 7fe941a103a43699a7b4d935b1f4c2b68f258245 Mon Sep 17 00:00:00 2001 From: Nicholas Novak Date: Sat, 26 Feb 2022 23:54:37 -0800 Subject: [PATCH] Added readme and a lot of rust config --- README.md | 12 ++++ nvim/.config/nvim/init.vim | 129 ++++++++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c021aa6 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Dotfiles + +My configuration files for the various tools that I use + +# Setup + +## Arch: + +``` +sudo pacman -S python-pynvim wl-clipboard rust-analyzer +paru -S google-java-format +``` diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 44e2608..6eaf47d 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -13,9 +13,6 @@ Plug 'google/vim-glaive' " Go development Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } -" Better python syntax -Plug 'vim-python/python-syntax' - " Formatter for Python Plug 'psf/black' @@ -32,6 +29,20 @@ Plug 'SirVer/ultisnips' Plug 'lervag/vimtex' Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' } +" LSP Config +Plug 'neovim/nvim-lspconfig' +Plug 'nvim-lua/lsp_extensions.nvim' +Plug 'hrsh7th/cmp-nvim-lsp', {'branch': 'main'} +Plug 'hrsh7th/cmp-buffer', {'branch': 'main'} +Plug 'hrsh7th/cmp-path', {'branch': 'main'} +Plug 'hrsh7th/nvim-cmp', {'branch': 'main'} +Plug 'ray-x/lsp_signature.nvim' + +" More syntax +Plug 'rust-lang/rust.vim' +Plug 'plasticboy/vim-markdown' +Plug 'vim-python/python-syntax' + call plug#end() set autowrite @@ -70,6 +81,118 @@ let g:python_highlight_all = 1 let g:vimtex_view_method = 'zathura' let g:vimtex_quickfix_mode=0 +" LSP configuration +lua << END +local cmp = require'cmp' + +local lspconfig = require'lspconfig' +cmp.setup({ + snippet = { + -- REQUIRED by nvim-cmp. get rid of it once we can + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + -- Tab immediately completes. C-n/C-p to select. + [''] = cmp.mapping.confirm({ select = true }) + }, + sources = cmp.config.sources({ + -- TODO: currently snippets from lsp end up getting prioritized -- stop that! + { name = 'nvim_lsp' }, + }, { + { name = 'path' }, + }), + experimental = { + ghost_text = true, + }, +}) + +-- Enable completing paths in : +cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }) +}) + +-- Setup lspconfig. +local on_attach = function(client, 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 + + --Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + 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', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'r', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'a', '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.diagnostic.open_float()', opts) + buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.diagnostic.set_loclist()', opts) + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + + -- Get signatures (and _only_ signatures) when in argument lists. + require "lsp_signature".on_attach({ + doc_lines = 0, + handler_opts = { + border = "none" + }, + }) +end + +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +lspconfig.rust_analyzer.setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + completion = { + postfix = { + enable = false, + }, + }, + }, + }, + capabilities = capabilities, +} + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = true, + signs = true, + update_in_insert = true, + } +) +END + +let g:rustfmt_autosave = 1 +let g:rustfmt_emit_files = 1 +let g:rustfmt_fail_silently = 0 + +set completeopt=menuone,noinsert,noselect + +" Proper search +set incsearch +set ignorecase +set smartcase +set gdefault + set cc=80 set tw=792034 set background=dark