ncm2 / ncm2-vim-lsp

MIT License
13 stars 2 forks source link

Duplicate result when using with Typescript Lang Server #5

Closed kyoz closed 5 years ago

kyoz commented 5 years ago

This is my config


call plug#begin('~/.config/nvim/plugged') "---------------------- Start vim plug

Plug 'ncm2/ncm2' "------------------------------ Slim, Fast Completion Framework
Plug 'roxma/nvim-yarp' "----------------------- Remote Plugin Framework for ncm2

Plug 'ncm2/ncm2-bufword' "----------------------------------------------- Buffer
Plug 'fgrsnau/ncm2-otherbuf' "---------------------------------------- Other Buf
Plug 'ncm2/ncm2-path' "---------------------------------------------------- Path
Plug 'ncm2/ncm2-tagprefix' "------------------------------------ Html Tag Prefix
Plug 'ncm2/ncm2-syntax' | Plug 'Shougo/neco-syntax' "------------- Syntax source
Plug 'ncm2/ncm2-neoinclude' | Plug 'Shougo/neoinclude.vim' "--------- NeoInclude

" Languages
Plug 'ncm2/ncm2-cssomni' "-------------------------------------------------- CSS
Plug 'ncm2/ncm2-tern', {'do': 'npm install'} "----------------------- Javascript
Plug 'mhartington/nvim-typescript', {'do': ':!install.sh \| UpdateRemotePlugins'}
Plug 'ncm2/ncm2-vim' | Plug 'Shougo/neco-vim' "----------------------- Vimscript
Plug 'ncm2/ncm2-vim-lsp' "----------- To connect completion between lsp and ncm2

" Language Server Protocol
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp', {
  \  'do': 'npm install -g typescript
     \ typescript-language-server
     \'}
  \
Plug 'ncm2/ncm2-neosnippet'
Plug 'Shougo/neosnippet.vim'

call plug#end() "---------------------------------------- End of Vim-Plug define

" Sign
let g:lsp_signs_enabled = 1         " enable signs
let g:lsp_diagnostics_echo_cursor = 1 " enable echo under cursor when in normal mode

let g:lsp_signs_error = {'text': 'x'}
let g:lsp_signs_warning = {'text': '!'}
let g:lsp_signs_hint = {'text': '.'}

" Mapping
function! LSP_Register(fileType)
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gd :LspDefinition<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gD :LspDocumentDiagnostics<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gh :LspHover<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gf :LspDocumentFormat<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gr :LspRename<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> ge :LspNextError<CR>'
  exec 'au FileType '. a:fileType .' nnoremap <buffer><silent> gE :LspPreviousError<CR>'
endfunction

let registerList = [
  \ 'html',
  \ 'css',
  \ 'scss',
  \ 'less',
  \ 'sass',
  \ 'typescript',
  \ 'javascript',
  \ 'json'
  \ ]

for item in registerList
  call LSP_Register(item)
endfor

" Typescript
if executable('typescript-language-server')
  au User lsp_setup call lsp#register_server({
    \ 'name': 'lsp-ts',
    \ '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

" Javascript
if executable('typescript-language-server')
  au User lsp_setup call lsp#register_server({
    \ 'name': 'lsp-js',
    \ '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', 'html'],
    \ })
endif

The result:

image

I think this is cause by typescript language server, right? Do we have any way to fix it.

Btw. Is ncm2-vim-lsp support auto import ? It'd be great if we have that.

Thanks you very much, @roxma

roxma commented 5 years ago

You should enable vim-lsp logging https://github.com/prabirshrestha/vim-lsp#debugging to prove that lsp server is not generating duplicate results.

Btw. Is ncm2-vim-lsp support auto import ? It'd be great if we have that.

Yes, as shown in https://github.com/ncm2/ncm2/issues/36#issuecomment-408623275

But I cannot get it to work with typescript-language-server. Maybe some configuration is missing for typescript-language-server, the completionItem returned by it does not contain auto import. I don't have time to debug typescript-language-server. (EDIT: be aware that some language server has bad default behavior, as mentioned in https://github.com/ncm2/ncm2/issues/114#issuecomment-450481800)

kyoz commented 5 years ago

Thank you @roxma, i'v tried to see the log file but it look normally (Sorry i'm not familiar with language server)

There is it, please help me take a look in to it when you have free time, thanks...

Thu 21 Feb 2019 09:42:39 AM +07:["s:on_text_document_did_change()", 1]
Thu 21 Feb 2019 09:42:39 AM +07:["s:send_didchange_queue() will be triggered"]
Thu 21 Feb 2019 09:42:40 AM +07:["s:send_event_queue()"]
Thu 21 Feb 2019 09:42:40 AM +07:[{"response": {"data": {"__data__": "vim-lsp", "server_name": "lsp-ts"}, "message": "server already started"}}]
Thu 21 Feb 2019 09:42:40 AM +07:[{"response": {"data": {"__data__": "vim-lsp", "init_result": {"id": 1, "jsonrpc": "2.0", "result": {"capabilities": {"executeCommandProvider": {"commands": ["_typescript.applyWorkspaceEdit", "_typescript.applyCodeAction", "_typescript.applyRefactoring", "_typescript.organizeImports", "_typescript.applyRenameFile"]}, "documentHighlightProvider": true, "hoverProvider": true, "typeDefinitionProvider": true, "definitionProvider": true, "referencesProvider": true, "signatureHelpProvider": {"triggerCharacters": ["(", ",", "<"]}, "foldingRangeProvider": true, "codeActionProvider": true, "textDocumentSync": 2, "callsProvider": true, "implementationProvider": true, "workspaceSymbolProvider": true, "documentFormattingProvider": true, "documentSymbolProvider": true, "renameProvider": true, "completionProvider": {"resolveProvider": true, "triggerCharacters": [".", "\"", "'", "/", "@", "<"]}}}}, "server_name": "lsp-ts"}, "message": "lsp server already initialized"}}]
Thu 21 Feb 2019 09:42:40 AM +07:[{"response": {"data": {"__data__": "vim-lsp", "server_name": "lsp-ts"}, "message": "configuration sent"}}]
Thu 21 Feb 2019 09:42:40 AM +07:[{"response": {"data": {"path": "file:///home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "__data__": "vim-lsp", "server_name": "lsp-ts"}, "message": "already opened"}}]
Thu 21 Feb 2019 09:42:40 AM +07:["s:update_file_content()", 1]
Thu 21 Feb 2019 09:42:40 AM +07:["--->", 7, "lsp-ts", {"method": "textDocument/didChange", "params": {"contentChanges": [{"range": {"end": {"character": 43, "line": 50}, "start": {"character": 43, "line": 50}}, "text": "e", "rangeLength": 0}], "textDocument": {"uri": "file:///home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "version": 14}}}]
Thu 21 Feb 2019 09:42:40 AM +07:[{"response": {"data": {"path": "file:///home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "__data__": "vim-lsp", "server_name": "lsp-ts"}, "message": "textDocument/didChange sent"}}]
Thu 21 Feb 2019 09:42:40 AM +07:["<---", 7, "lsp-ts", {"response": {"method": "textDocument/publishDiagnostics", "jsonrpc": "2.0", "params": {"uri": "file:///home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "diagnostics": [{"source": "typescript", "range": {"end": {"character": 44, "line": 50}, "start": {"character": 30, "line": 50}}, "code": 2304, "message": "Cannot find name 'DataApiService'.", "severity": 1}]}}}]
Thu 21 Feb 2019 09:42:40 AM +07:["add signs"]

Another example for this issue:

screenshot from 2019-02-21 09-48-27

roxma commented 5 years ago

I don't see any completion request in the log.

You should post the log after reproducing the issue.

kyoz commented 5 years ago

I'v added

let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')

Clean the log. reproducing the issue.

And this is the full log i got in vim-lsp.log vim-lsp.log

roxma commented 5 years ago

line 87:

{"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}, {"label": "MatDialog", "commitCharacters": [".", ",", "("], "data": {"file": "/home/kyoz/Documents/Projects/ux/src/lib/charts/box-plot-chart/box-plot-chart.component.ts", "entryNames": [{"name": "MatDialog", "source": "/home/kyoz/Documents/Projects/ux/node_modules/@angular/material/material"}], "offset": 35, "line": 51}, "sortText": "\uFFFF0", "kind": 7}

This is typescript-language-server issue.

roxma commented 5 years ago

workaround:


call ncm2#override_source('lsp-ts', {'filter': [{'name': 'set_dup', 'value': 0}]}) 
kyoz commented 5 years ago

Thanks @roxma, it work