From cb50fda51a6a8ca9bf3eb76e1af8f6873c12a572 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 11 Aug 2024 16:03:29 -0600 Subject: [PATCH] Vim: add nvim lsps --- vim/.vim/colors/base16-github.vim | 24 +++++++ vim/.vim/init_scripts/external_plugins.vim | 40 ++++++++--- vim/.vim/init_scripts/key_mappings.vim | 11 ++- vim/nvim/init.lua | 80 ++++++++++++++++++++++ vim/nvim/init.vim | 23 ------- 5 files changed, 144 insertions(+), 34 deletions(-) create mode 100644 vim/nvim/init.lua delete mode 100644 vim/nvim/init.vim diff --git a/vim/.vim/colors/base16-github.vim b/vim/.vim/colors/base16-github.vim index 41d2f6c..1c647f9 100644 --- a/vim/.vim/colors/base16-github.vim +++ b/vim/.vim/colors/base16-github.vim @@ -405,6 +405,30 @@ call hi("StartifySpecial", s:gui03, "", s:cterm03, "", "", "") " Java highlighting call hi("javaOperator", s:gui0D, "", s:cterm0D, "", "", "") +" LSP highlighting +call hi("LspReferenceText", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "") +call hi("LspReferenceRead", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "") +call hi("LspReferenceWrite", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "") +call hi("LspSignatureActiveParameter", s:gui0D, s:gui02, s:cterm0D, s:cterm02, "bold", "") +call hi("DiagnosticError", s:gui08, "", s:cterm08, "", "", "") +call hi("DiagnosticWarn", s:gui09, "", s:cterm09, "", "", "") +call hi("DiagnosticInfo", s:gui05, "", s:cterm05, "", "", "") +call hi("DiagnosticHint", s:gui03, "", s:cterm03, "", "", "") +call hi("DiagnosticUnderlineError", s:gui08, "", s:cterm08, "", "undercurl", s:gui08) +call hi("DiagnosticUnderlineWarn", s:gui09, "", s:cterm09, "", "undercurl", s:gui09) +call hi("DiagnosticUnderlineInfo", s:gui05, "", s:cterm05, "", "undercurl", s:gui05) +call hi("DiagnosticUnderlineHint", s:gui03, "", s:cterm03, "", "undercurl", s:gui03) + +" Floating windows +call hi("NormalFloat", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "") +call hi("FloatBorder", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "") + +" Popup menu +call hi("Pmenu", s:gui05, s:gui01, s:cterm05, s:cterm01, "none", "") +call hi("PmenuSel", s:gui01, s:gui05, s:cterm01, s:cterm05, "", "") +call hi("PmenuSbar", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "") +call hi("PmenuThumb", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "") + " Remove functions delf hi diff --git a/vim/.vim/init_scripts/external_plugins.vim b/vim/.vim/init_scripts/external_plugins.vim index b98fc5a..be4b58b 100644 --- a/vim/.vim/init_scripts/external_plugins.vim +++ b/vim/.vim/init_scripts/external_plugins.vim @@ -63,7 +63,7 @@ Plug 'untitled-ai/jupyter_ascending.vim' " Language specific ================================================= " Syntax support ==== Plug 'rust-lang/rust.vim' -Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} +"Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} "Plug 'arzg/vim-rust-syntax-ext' Plug 'JuliaEditorSupport/julia-vim' Plug 'evanleck/vim-svelte', {'branch': 'main'} @@ -72,24 +72,18 @@ Plug 'dracula/vim', { 'as': 'dracula' } Plug 'RRethy/nvim-base16' Plug 'waycrate/swhkd-vim' Plug 'wuelnerdotexe/vim-astro' +Plug 'nfnty/vim-nftables' " Python ==== " Shows line indent guides Plug 'Yggdroot/indentLine' " More highlights -"Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins' } Plug 'sheerun/vim-polyglot' -"Plug 'hdima/python-syntax' -" Latex ==== - " LaTeX support -"Plug 'lervag/vimtex' - " LaTex snippets. Requires python -"Plug 'SirVer/ultisnips', { 'tag': '*3.2' } - -" Language server =================================================== +" Language servers ================================================== Plug 'w0rp/ale' Plug 'TabbyML/vim-tabby' +Plug 'neovim/nvim-lspconfig' call plug#end() @@ -215,6 +209,32 @@ let g:ale_sign_error = '❌' let g:ale_sign_warning = '⚠️' let g:ale_fix_on_save = 0 + +lua << EOF +local status, nvim_lsp = pcall(require, "lspconfig") +if (not status) then return end + +local protocol = require('vim.lsp.protocol') + +local on_attach = function(client, bufnr) + -- format on save + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("Format", { clear = true }), + buffer = bufnr, + callback = function() vim.lsp.buf.formatting_seq_sync() end + }) + end +end + +-- TypeScript +nvim_lsp.tsserver.setup { + on_attach = on_attach, + filetypes = { "typescript", "typescriptreact", "typescript.tsx" }, + cmd = { "typescript-language-server", "--stdio" } +} +EOF + " Tabby llama completion ================================= let g:tabby_keybinding_accept = '' let g:tabby_trigger_mode = 'auto' diff --git a/vim/.vim/init_scripts/key_mappings.vim b/vim/.vim/init_scripts/key_mappings.vim index ec4d79a..2626e7e 100644 --- a/vim/.vim/init_scripts/key_mappings.vim +++ b/vim/.vim/init_scripts/key_mappings.vim @@ -127,7 +127,10 @@ nnoremap = :vertical resize 84 nnoremap 1 " Change cwd to current buffer's -nnoremap gf :cd %:p:h +nnoremap gf :cd %:p:h:pwd + + " Change to project root of file +nnoremap gr :cd %:p:h:Rooter:pwd " Editing remaps ======================================== " Uppercase previous word from Insert mode @@ -176,3 +179,9 @@ nnoremap opretty :echom "use :Pretty{rs,py,css}" " Open with vifm nnoremap onet :EditVifm getcwd() nnoremap otnet :exe 'TabVifm' getcwd() + + " Lsp toggling +nnoremap oaleu :ALEEnable +nnoremap oaled :ALEDisable +nnoremap olspu :LspUp +nnoremap olspd :LspDown diff --git a/vim/nvim/init.lua b/vim/nvim/init.lua new file mode 100644 index 0000000..bffa183 --- /dev/null +++ b/vim/nvim/init.lua @@ -0,0 +1,80 @@ +-- Sync vim configs to neovim +vim.opt.runtimepath:prepend("~/.vim") +vim.opt.runtimepath:append("~/.vim/after") +-- vim.opt.packpath = vim.opt.runtimepath +vim.cmd("source ~/.vim/init_scripts/init.vim") + +-- Astolfo-inspired welcome prompt +print("UwU") + +vim.opt.guicursor = "n-v-c:block-Cursor/lCursor-blinkon0,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor" +vim.opt.inccommand = "nosplit" + +if not vim.fn.has('python3') then + print('Warning: No python 3 support. UltiSnips won\'t be available') + print('Run: $ python3 -m pip install --user --upgrade pynvim') +end + +-- Only load this in Neovim +if vim.fn.has('nvim') == 1 then + local lspconfig = require('lspconfig') + + lspconfig.tsserver.setup{ + autostart = false, + } + + lspconfig.cssls.setup{ + autostart = false, + } + + lspconfig.html.setup{ + autostart = false, + } + + -- React Native + lspconfig.flow.setup{ + autostart = false, + } + + -- Function to start LSP + function LspUp() + vim.cmd[[LspStart]] + end + + function LspDown() + vim.cmd[[LspStop]] + vim.cmd("echo 'lsp is down >~<'") + end + + -- Command to call ComposeUp + vim.cmd[[command! LspUp lua LspUp()]] + vim.cmd[[command! LspDown lua LspDown()]] +end + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + -- Add more mappings as needed + local client = vim.lsp.get_client_by_id(ev.data.client_id) + client.server_capabilities.semanticTokensProvider = nil + vim.cmd("echo 'lsp is UP >ᴗ<'") + end, +}) + + +vim.api.nvim_create_autocmd("BufRead", { + callback = function() + vim.treesitter.stop() + end, +}) diff --git a/vim/nvim/init.vim b/vim/nvim/init.vim deleted file mode 100644 index 96b77a1..0000000 --- a/vim/nvim/init.vim +++ /dev/null @@ -1,23 +0,0 @@ -" Sync vim configs to neovim -set runtimepath^=~/.vim runtimepath+=~/.vim/after -let &packpath = &runtimepath -source ~/.vim/init_scripts/init.vim - -" Astolfo-inspired welcome prompt -echom "UwU" - -" Open nvim/init.vim for quick editing -command! Nim :normal! :vsplit $MYVIMRCH -command! Nims :normal! :w:source $MYVIMRC:x - -" Reset cursor to vertical bar when leaving -"au VimLeave * set guicursor=a:ver0-blinkon0 -"au VimLeave * call nvim_cursor_set_shape("vertical-bar") - -set guicursor=n-v-c:block-Cursor/lCursor-blinkon0,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor -set inccommand=nosplit - -if !has('python3') - echom 'Warning: No python 3 support. UltiSnips won''t be available' - echom 'Run: $ python3 -m pip install --user --upgrade pynvim' -endif