prabirshrestha / vim-lsp

async language server protocol plugin for vim and neovim
MIT License
3.14k stars 305 forks source link

Lsp seems to cancel insert Mode #532

Closed Vitax closed 5 years ago

Vitax commented 5 years ago

Hello,

I am having issues using the language server protocols with nmc2. As you can see in the gif something seems to cancel the insert mode and I cannot figure out what. I recreated my init.vim to the bare minimum where I could write code again but no changes there.

nvim-lsp

I am gonna include my init.vim as well so maybe you can pin point the error:

"
" Plug-Ins
"
call plug#begin()

"
" Colorschemes
"
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline'

"
" Utilities
"
" Tree Explorer
Plug 'scrooloose/nerdtree'

" Fuzzy File Searcher
Plug 'junegunn/fzf'

"
" Programming
"
" Autocompletion framework
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'

" Language Protocol Servers
Plug 'ryanolsonx/vim-lsp-typescript'

" Default path and buffer completion
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'

" Snippet competion framework
Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'

" Language Server Protocol for nvim
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'ncm2/ncm2-vim-lsp'

" Language Protocol PlugIns
Plug 'ryanolsonx/vim-lsp-typescript'
Plug 'ryanolsonx/vim-lsp-javascript'

call plug#end()

"
" Color-scheme Settings
" 
set t_Co=256
set termguicolors
set background=dark
colorscheme gruvbox

"
" Editor Settings
"
" Enable syntax highlighting
syntax on

" Enable file type recognition for nvim and plug-ins
filetype on
filetype plugin on
filetype indent on

" Set text encofing
set encoding=utf-8

" Set guifont
set guifont="Iosevka\ Nerd\ Font\ Mono"

set tabstop=4
set shiftwidth=4
set textwidth=100
set expandtab
set hlsearch
set number
set ruler
set wrap
set linebreak

" setup usage of system clipboard
set clipboard=unnamedplus

" enable mosue
set mouse=a

" Ignore case sensitivity as long as there is not in the search string
set ignorecase
set smartcase

" Reduce shortcut delay to 500ms
set timeoutlen=500

" Deactivate spell checking by default
set nospell

" Buffer settings to make it easier working with them
set hidden
set confirm
set autowriteall
set wildmenu wildmode=full

set completeopt=noinsert,menuone,noselect
set shortmess+=c

" 
" Enable and setup Plugins here
"
" Register Language Protocol Servers
" Javascript
au User lsp_setup call lsp#register_server({
    \ 'name': 'javascript support using typescript-language-server',
    \ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
    \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json'))},
    \ 'whitelist': ['javascript', 'javascript.jsx', 'javascriptreact'],
\ })

" Typescript
"if executable('typescript-language-server')
"    au User lsp_setup call lsp#register_server({
"        \ 'name': 'typescript-language-server',
"        \ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
"        \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'tsconfig.json'))},
"        \ 'whitelist': ['typescript', 'typescript.tsx'],
"    \ })
"endif

" C++
"if executable('clangd')
"    au User lsp_setup call lsp#register_server({
"        \ 'name': 'clangd',
"        \ 'cmd': {server_info->['clangd', '-background-index']},
"        \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'],
"    \ })
"endif

" Moving in snippet with <C-j> <C-k>
let g:UltiSnipsExpandTrigger        = "<Plug>(ultisnips_expand)"
let g:UltiSnipsJumpForwardTrigger   = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger  = "<c-k>"
let g:UltiSnipsRemoveSelectModeMappings = 0

" Enable ncm2
autocmd BufEnter * call ncm2#enable_for_buffer()

"  Use fzf as fuzzy finder
set rtp+=/opt/fzf

" Setup Nerdtree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif

"
" Setup Keybinding
"
" Map leader
let mapleader="\<Space>"

" save file
nnoremap <leader>w :w<CR>

" delete buffer
nnoremap <leader>q :bdel<CR>

" next buffer
nnoremap <C-l> :bn<CR>

" previous buffer
nnoremap <C-h> :bp<CR>

" Bind iterration through elements with <Tab> and <S-Tab>
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

" Press enter key to trigger snippet expansion
inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')

" Alt Backspace to remove previous word
inoremap <A-BS> <C-w>

" Bind Nerdtree toggle
nnoremap <A-n> :NERDTreeToggle<CR>

" Start searching in the project
nnoremap <C-p> :FZF<CR>
thomasfaingnaert commented 5 years ago

@Vitax Can you post a minimal init.vim to reproduce? The one you posted is still quite long. @clason Seeing that you're also using ncm2, perhaps you have an idea what the problem could be?

Vitax commented 5 years ago

This only seems to happen with javascript / typescript on my side. Tryed using the language server protocol with C++ and it works fine there.

Vitax commented 5 years ago

Okay as you were probably expecting something up top seems to make ncm2 / lsp behave weirdly. With the one below everything seems to work fine. Gonna try adding things and see what makes it break.

call plug#begin()
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'

Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'

Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'ncm2/ncm2-vim-lsp'

Plug 'ryanolsonx/vim-lsp-typescript'
Plug 'ryanolsonx/vim-lsp-javascript'
call plug#end()

syntax on

filetype on
filetype plugin on
filetype indent on

set encoding=utf-8
set completeopt=noinsert,menuone,noselect
set shortmess+=c

au User lsp_setup call lsp#register_server({
    \ 'name': 'javascript support using typescript-language-server',
    \ 'cmd': {server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
    \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json'))},
    \ 'whitelist': ['javascript', 'javascript.jsx', 'javascriptreact'],
\ })

let g:UltiSnipsExpandTrigger        = "<Plug>(ultisnips_expand)"
let g:UltiSnipsJumpForwardTrigger   = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger  = "<c-k>"
let g:UltiSnipsRemoveSelectModeMappings = 0

autocmd BufEnter * call ncm2#enable_for_buffer()
hrsh7th commented 5 years ago

Please test with g:lsp_signature_help_enabled = v:false.

Vitax commented 5 years ago

The error / bug is happening when adding


" Setup Nerdtree
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
chengzeyi commented 5 years ago

Experienced the same problem, and vim became such a mess that :qa seemed to be the only solution! I write golang with the help of vim-lsp and use neocomplete to provide auto-completion popup.

Vitax commented 5 years ago

Actually let me correct myself the behavior from above does happen when NERDTree is active. When toggling nerdtree off the language server works fine. And weird enough it seem to only happen for javascript / typescript.

chengzeyi commented 5 years ago

I can also provide my .vimrc though it's kind of tedious. Hope to see this annoying problem got fixed soon because this also happens with golang.

https://github.com/chengzeyi/.vim_runtime/blob/master/my_config.vim

sekirocc commented 5 years ago

same here, I'm writing go code. When turning off NERDTree, this issue is gone.

rainsia commented 5 years ago

same problem with the C++ protocol server, ccls, when NERDTree is opened. When NERDTree is closed, everything is fine.

studiome commented 5 years ago

Hi, everyone! I think this is caused by the function "lsp#ui#vim#folding#foldtex" in folding.vim. Popup window in completion changes buffer or window number? Why dose it happen when we write go or typescript code? I do not know... I changed winnr() to bufwinnr(). It works. WHY???

studiome commented 5 years ago

When we open NERDTree, vim window is splitted? If it is OK, I submit Pull Request.

prabirshrestha commented 5 years ago

Feel free to submit PR

studiome commented 5 years ago

I am sorry. The function is function! s:handle_fold_request(server, data) . And bufwinnr() is bad call. Please wait.

studiome commented 5 years ago

Thank you, @prabirshrestha . I submitted PR.

prabirshrestha commented 5 years ago

Can other folks having issues verify this pr https://github.com/prabirshrestha/vim-lsp/pull/541

prabirshrestha commented 5 years ago

I have verified the PR works and have merged it to master. Please get the latest vim-lsp and try again.

Thanks to @studiome for the patch.