Hello, I am new to nvim-lsp and neovim 0.5 in general. My primary language server is tsserver. Sometimes (not always), after going to normal mode, it would take a couple of seconds (5, and sometimes even longer), to show diagnostics and/or errors (I check with LspInfo regularly, and the tsserver is always attached). On the autocomplete side of things, again, it takes more than a couple of seconds, to show up snippets, be it object properties, or anything else.
So what I wanted to ask was, is this a problem with my system? Or with my configuration. If the latter, could someone please link to me a post, or share their own config files, or help me out by pointing me in the right direction?
The primary files that I edit, are .jsx files, without a .tsconfig in the directory (could this be the reason)?
Please let me know if this is not the correct platform to ask this question. Thank you.
Posting my init.vim below, in case that would help:
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
if (has("termguicolors"))
set termguicolors
endif
call plug#begin()
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'kabouzeid/nvim-lspinstall'
Plug 'sbdchd/neoformat'
Plug 'sickill/vim-monokai'
Plug 'morhetz/gruvbox'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'sonph/onehalf', {'rtp': 'vim/'}
Plug 'sainnhe/everforest'
Plug 'sainnhe/gruvbox-material'
Plug 'junegunn/seoul256.vim'
Plug 'simrat39/symbols-outline.nvim'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'hoob3rt/lualine.nvim'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'ryanoasis/vim-devicons'
Plug 'glepnir/lspsaga.nvim'
Plug 'chrisbra/Colorizer'
call plug#end()
lua << EOF
require('telescope').setup{
defaults = {
vimgrep_arguments = {
'rg',
'--no-heading',
'--with-filename',
'--line-number',
'--column',
'--smart-case'
},
prompt_prefix = "> ",
selection_caret = "> ",
entry_prefix = " ",
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_config = {
horizontal = {
mirror = false,
},
width = 0.75,
preview_cutoff = 120,
prompt_position = "bottom",
vertical = {
mirror = false,
},
},
file_sorter = require'telescope.sorters'.get_fuzzy_file,
file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
winblend = 0,
border = {},
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' },
color_devicons = true,
use_less = true,
set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil,
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
-- Developer configurations: Not meant for general override
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker
},
extensions = {
fzy_native = {
override_generic_sorter = false,
override_file_sorter = true,
}
}
}
require('telescope').load_extension('fzy_native')
EOF
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
set completeopt=menuone,noinsert,noselect
let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy']
let g:completion_chain_complete_list = {
\ 'default' : {
\ 'default': [
\ {'complete_items': ['lsp', 'snippet']},
\ {'mode': '<c-p>'},
\ {'mode': '<c-n>'}],
\ 'comment': [],
\ 'string' : [
\ {'complete_items': ['path']}]
\ },
\}
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
lua << EOF
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 <c-x><c-o>
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', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
-- buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
-- buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
require('completion').on_attach(client)
end
local function make_config()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
return {
-- enable snippet support
capabilities = capabilities,
-- map buffer local keybindings when the language server attaches
on_attach = on_attach,
}
end
local function setup_servers()
require'lspinstall'.setup()
local servers = require'lspinstall'.installed_servers()
for _, server in pairs(servers) do
local config = make_config()
require'lspconfig'[server].setup(config)
end
end
setup_servers()
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
setup_servers() -- reload installed servers
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end
EOF
set background=dark
" let g:gruvbox_contrast_dark = 'hard'
" let g:gruvbox_bold = 1
" colorscheme gruvbox
" colorscheme onehalfdark
colorscheme gruvbox-material
let g:symbols_outline = {
\ "highlight_hovered_item": v:true,
\ "show_guides": v:true,
\ "position": 'right',
\ "auto_preview": v:true,
\ "show_numbers": v:false,
\ "show_relative_numbers": v:false,
\ "show_symbol_details": v:true,
\ "keymaps": {
\ "close": "<Esc>",
\ "goto_location": "<Cr>",
\ "focus_location": "o",
\ "hover_symbol": "<C-space>",
\ "rename_symbol": "r",
\ "code_actions": "a",
\ },
\ "lsp_blacklist": [],
\ }
nnoremap <Leader>o :SymbolsOutline<CR>
lua << EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = {
enable = true, -- false will disable the whole extension
},
indent = {
enable = true,
},
autopairs = {
enable = true,
},
rainbow = {
enable = true,
},
autotag = {
enable = true,
},
context_commentstring = {
enable = true,
}
}
EOF
lua << EOF
require'lualine'.setup {
options = {
icons_enabled = true,
theme = 'gruvbox',
component_separators = {'', ''},
section_separators = {'', ''},
disabled_filetypes = {},
options = {
icons_enabled = 1, -- displays icons in alongside component
padding = 1, -- adds padding to the left and right of components
left_padding = 1, -- adds padding to the left of components
right_padding = 1, -- adds padding to the right of components
upper = false, -- displays components in uppercase
lower = false, -- displays components in lowercase
}
},
sections = {
lualine_a = {'mode', { 'diff', colored = true }
},
lualine_b = {'branch'},
lualine_c = {{ 'filename', file_status = true, path = 2 }},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {{
'diagnostics',
sources = {'nvim_lsp'},
-- displays diagnostics from defined severity
sections = {'error', 'warn', 'info', 'hint'},
-- all colors are in format #rrggbb
-- color_error = '#E06C75', -- changes diagnostic's error foreground color
-- color_warn = '#E5C07B', -- changes diagnostic's warn foreground color
-- color_info = '#61AFEF', -- Changes diagnostic's info foreground color
-- color_hint = '#56B6C2', -- Changes diagnostic's hint foreground color
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
}}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {'progress'},
lualine_z = {}
},
tabline = {},
extensions = {}
}
EOF
lua << EOF
local saga = require 'lspsaga'
-- add your config value here
-- default value
-- use_saga_diagnostic_sign = true
-- error_sign = '',
-- warn_sign = '',
-- hint_sign = '',
-- infor_sign = '',
-- dianostic_header_icon = ' ',
-- code_action_icon = ' ',
-- code_action_prompt = {
-- enable = true,
-- sign = true,
-- sign_priority = 20,
-- virtual_text = true,
-- },
-- finder_definition_icon = ' ',
-- finder_reference_icon = ' ',
-- max_preview_lines = 10, -- preview lines of lsp_finder and definition preview
-- finder_action_keys = {
-- open = 'o', vsplit = 's',split = 'i',quit = 'q',scroll_down = '<C-f>', scroll_up = '<C-b>' -- quit can be a table
-- },
-- code_action_keys = {
-- quit = 'q',exec = '<CR>'
-- },
-- rename_action_keys = {
-- quit = '<C-c>',exec = '<CR>' -- quit can be a table
-- },
-- definition_preview_icon = ' '
-- "single" "double" "round" "plus"
-- border_style = "single"
-- rename_prompt_prefix = '➤',
-- if you don't use nvim-lspconfig you must pass your server name and
-- the related filetypes into this table
-- like server_filetype_map = {metals = {'sbt', 'scala'}}
-- server_filetype_map = {}
saga.init_lsp_saga()
EOF
nnoremap <silent>gh :Lspsaga lsp_finder<CR>
nnoremap <silent><leader>ca :Lspsaga code_action<CR>
vnoremap <silent><leader>ca :<C-U>Lspsaga range_code_action<CR>
nnoremap <silent>K :Lspsaga hover_doc<CR>
" -- scroll down hover doc or scroll in definition preview
nnoremap <silent><C-f> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(1)<CR>
" -- scroll up hover doc
nnoremap <silent><C-b> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1)<CR>
nnoremap <silent>gs :Lspsaga signature_help<CR>
nnoremap <leader>rn :Lspsaga rename<CR>