Vim: add nvim lsps

This commit is contained in:
Akemi Izuko 2024-08-11 16:03:29 -06:00
parent a3bbda0975
commit cb50fda51a
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
5 changed files with 144 additions and 34 deletions

View file

@ -405,6 +405,30 @@ call <sid>hi("StartifySpecial", s:gui03, "", s:cterm03, "", "", "")
" Java highlighting
call <sid>hi("javaOperator", s:gui0D, "", s:cterm0D, "", "", "")
" LSP highlighting
call <sid>hi("LspReferenceText", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "")
call <sid>hi("LspReferenceRead", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "")
call <sid>hi("LspReferenceWrite", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "")
call <sid>hi("LspSignatureActiveParameter", s:gui0D, s:gui02, s:cterm0D, s:cterm02, "bold", "")
call <sid>hi("DiagnosticError", s:gui08, "", s:cterm08, "", "", "")
call <sid>hi("DiagnosticWarn", s:gui09, "", s:cterm09, "", "", "")
call <sid>hi("DiagnosticInfo", s:gui05, "", s:cterm05, "", "", "")
call <sid>hi("DiagnosticHint", s:gui03, "", s:cterm03, "", "", "")
call <sid>hi("DiagnosticUnderlineError", s:gui08, "", s:cterm08, "", "undercurl", s:gui08)
call <sid>hi("DiagnosticUnderlineWarn", s:gui09, "", s:cterm09, "", "undercurl", s:gui09)
call <sid>hi("DiagnosticUnderlineInfo", s:gui05, "", s:cterm05, "", "undercurl", s:gui05)
call <sid>hi("DiagnosticUnderlineHint", s:gui03, "", s:cterm03, "", "undercurl", s:gui03)
" Floating windows
call <sid>hi("NormalFloat", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "")
call <sid>hi("FloatBorder", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "")
" Popup menu
call <sid>hi("Pmenu", s:gui05, s:gui01, s:cterm05, s:cterm01, "none", "")
call <sid>hi("PmenuSel", s:gui01, s:gui05, s:cterm01, s:cterm05, "", "")
call <sid>hi("PmenuSbar", s:gui05, s:gui01, s:cterm05, s:cterm01, "", "")
call <sid>hi("PmenuThumb", s:gui05, s:gui02, s:cterm05, s:cterm02, "", "")
" Remove functions
delf <sid>hi

View file

@ -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 = '<Tab>'
let g:tabby_trigger_mode = 'auto'

View file

@ -127,7 +127,10 @@ nnoremap <leader><leader>= :vertical resize 84<CR>
nnoremap <C-g> 1<C-g>
" Change cwd to current buffer's
nnoremap gf :cd %:p:h<CR>
nnoremap gf :cd %:p:h<CR>:pwd<CR>
" Change to project root of file
nnoremap gr :cd %:p:h<CR>:Rooter<CR>:pwd<CR>
" Editing remaps ========================================
" Uppercase previous word from Insert mode
@ -176,3 +179,9 @@ nnoremap <leader>opretty :echom "use :Pretty{rs,py,css}"<cr>
" Open with vifm
nnoremap <leader>onet :EditVifm getcwd()<CR>
nnoremap <leader>otnet :exe 'TabVifm' getcwd()<CR>
" Lsp toggling
nnoremap <leader>oaleu :ALEEnable<CR>
nnoremap <leader>oaled :ALEDisable<CR>
nnoremap <leader>olspu :LspUp<CR>
nnoremap <leader>olspd :LspDown<CR>

80
vim/nvim/init.lua Normal file
View file

@ -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 <c-x><c-o>
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', '<C-k>', 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,
})

View file

@ -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 $MYVIMRC<CR><C-w>H
command! Nims :normal! :w<CR>:source $MYVIMRC<CR>:x<CR>
" 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