Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Completion is one character behind in neovim #432

Closed
kyrisu opened this issue Feb 19, 2018 · 30 comments
Closed

Completion is one character behind in neovim #432

kyrisu opened this issue Feb 19, 2018 · 30 comments

Comments

@kyrisu
Copy link

kyrisu commented Feb 19, 2018

I have installed the plugin together with LanguageClient-neovim and Deoplete, but for some reason I get the following warning (in neovim messages) for multiple files:

[Warning] readFile <full_project_path>/node_modules/react/package.json requested by TypeScript but content not available

Files exist as I can access them by copying & pasting the path into the console.

Any help help would be appreciated - it seems to be something on my machine as I didn't find similar issue on github but looking at traces from the langserver I do not see other warnings or errors.

I'm happy to provide logs / traces but the -t switch doesn't seem to work with stdio version of the server (file pass to -l switch is empty).

@felixfbecker
Copy link
Contributor

Since it's just a warning, does it impact the functionality in any way?

@kyrisu
Copy link
Author

kyrisu commented Feb 19, 2018

In a sample file like this:

import React from 'react';

React.

There's no completion after the dot (I have it set as a trigger, manually triggering the completion also doesn't work). Heres a dump of the requests to the server:

https://gist.github.com/kyrisu/8420bc5d289b530caa4813c656fe64c3

@felixfbecker
Copy link
Contributor

I don't see any textDocument/completion request in those logs

@kyrisu
Copy link
Author

kyrisu commented Feb 20, 2018

You are right - by accident I've cut the logs short :/ After running it few more times and I realize there are times when I don't see these warnings.

After commenting out my deoplete config I got to the point where I'm experiencing the same issue as in #423

Interestingly enough when I type this:

const a = [];
a.

The first time I type the dot I get the proper completion options, then I try to remove it and retype it again and I get the invalid ones.

https://gist.github.com/kyrisu/3797ace47fe2cfa7d32da5685aa73791

(line 630 is when I got the proper completion)

@felixfbecker
Copy link
Contributor

So you're saying you get no completions? Because I don't see a textDocument/completion request in the logs with an empty response

@kyrisu
Copy link
Author

kyrisu commented Feb 20, 2018

I think you might be looking at the first gist - I've created a new one (linked in the previous comment).
I'm getting correct completions initially and then invalid ones (after I triger the completions for the same text).

You can see I get correct completion on line 598 in the logs:

2018-02-20T00:09:51.177908318+00:00 INFO languageclient::languageclient - End textDocument/completion
2018-02-20T00:09:51.178065175+00:00 INFO languageclient::languageclient - End languageClient/omniComplete
2018-02-20T00:09:51.178196892+00:00 INFO languageclient::languageclient - => {"jsonrpc":"2.0","result":[{"abbr":"length","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"m","menu":"","word":"length"},{"abbr":"toString","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"toString"},{"abbr":"toLocaleString","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"toLocaleString"},{"abbr":"push","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"push"},{"abbr":"pop","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"pop"},{"abbr":"concat","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"concat"},{"abbr":"join","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"join"},{"abbr":"reverse","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"reverse"},{"abbr":"shift","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"shift"},{"abbr":"slice","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"slice"},{"abbr":"sort","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"sort"},{"abbr":"splice","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"splice"},{"abbr":"unshift","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"unshift"},{"abbr":"indexOf","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"indexOf"},{"abbr":"lastIndexOf","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"lastIndexOf"},{"abbr":"every","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"every"},{"abbr":"some","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"some"},{"abbr":"forEach","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"forEach"},{"abbr":"map","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"map"},{"abbr":"filter","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"filter"},{"abbr":"reduce","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"reduce"},{"abbr":"reduceRight","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"f","menu":"","word":"reduceRight"},{"abbr":"a","additionalTextEdits":null,"dup":1,"icase":1,"info":"","kind":"","menu":"","word":"a"}],"id":4}
2018-02-20T00:09:51.329984985+00:00 INFO languageclient::languageclient - <= {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/kyrisu/tmp/cpltest/index.js","diagnostics":[{"range":{"start":{"character":0,"line":0},"end":{"character":0,"line":0}},"message":"Identifier expected.","severity":1,"code":1003,"source":"ts"}]}}

Unfortunately then on line 649 I get random suggestions without context.

@felixfbecker
Copy link
Contributor

Sorry, but I don't know what suggestions you would expect?

According to the last textDocument/didChange in L637:

2018-02-20T00:10:44.541757859+00:00 INFO languageclient::languageclient - => {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":null,"rangeLength":null,"text":"const a = [];\na"}],"textDocument":{"uri":"file:///home/kyrisu/tmp/cpltest/index.js","version":14}}}

This is the content of the file:

const a = [];
a

With the cursor being at a, so you get completion for globals like NaN etc.

@felixfbecker
Copy link
Contributor

If that is not the file content you were seeing on screen then that's a bug in the client

@kyrisu
Copy link
Author

kyrisu commented Feb 20, 2018

Maybe it is. I just tried this:

a.
nvim index js_210
a..
nvim index js_211

It's like the completion is one character behind.

@kyrisu
Copy link
Author

kyrisu commented Feb 20, 2018

Thank you very much for your help today - I will tinker with this tomorrow and hopefully find what's wrong.

@sQVe
Copy link

sQVe commented Feb 22, 2018

I'm seeing this too on Vim and it makes it impossible to use the langserver, sadly.

As far as I can tell I only see these issues when the project has a node_modules folder.

@kyrisu
Copy link
Author

kyrisu commented Feb 23, 2018

@sQVe try adding jsconfig.json file to the project directory (example contents)

{
  "compilerOptions": {
    "target": "es2017",
    "checkJs": true,
    "allowSyntheticDefaultImports": true
  },
  "exclude": ["node_modules"]
}

This should force the language server to ignore node_modules if this is the issue in your case.

@sQVe
Copy link

sQVe commented Feb 23, 2018

@kyrisu That made it somewhat better. It still started complaining about not being able to find external modules though, which I guess is kinda obvious. The #423 issue is problematic too, noting it pretty much everywhere.

@kyrisu
Copy link
Author

kyrisu commented Feb 23, 2018

@sQVe for external modules try npm install @types/<module_name> this helped me (although didn't fix the issue completely unfortunately )

@sQVe
Copy link

sQVe commented Feb 24, 2018

@kyrisu How does that make a difference? I've installed all dependencies the regular way. I don't really have the freedom to change the whole package.json just got it to work on my machine.

@kyrisu
Copy link
Author

kyrisu commented Feb 25, 2018

@sQVe For me, it solved the issue of not being able to find external modules. Editors like VS Code download types for us but it seems that language servers do not. You don't need to modify your package.json - just install them without saving in dependencies. As I've mentioned before - it's not the full solution but just something that may be worth trying.

Btw - I've since switched to nvim-typescript with javascript support enabled which seems to work.

@sQVe
Copy link

sQVe commented Feb 25, 2018

@kyrisu I'm currently running tern instead. Have you tried that? If so what is an improvement with nvim-typescript?

@kyrisu
Copy link
Author

kyrisu commented Feb 25, 2018

@sQVe - tern works great, unfortunately, it is not actively developed and is not supporting newer ECMAScript features. I'm trying to make typescript servers work because I often break tern completions - for example by using static class properties in react :(

nvim-typescript (or any other typescript completion engine) gives you completion that supports newer language features but you need to have types for specific library installed.

@sQVe
Copy link

sQVe commented Feb 28, 2018

@kyrisu nvim-typescript works nicely and seems better than tern for sure. I still think this project is the future though and hope there's improvements and fixes coming. I especially miss having document and workspace symbols.

@felixfbecker
Copy link
Contributor

Closing this issue since it seems to be a bug in the neovim client (#432 (comment))

@kreedz
Copy link

kreedz commented Apr 8, 2018

@felixfbecker,
by neovim client you mean something like LanguageClient-neovim?
I use it with javascript-typescript-langserver and have the same issue as descibed in the top post.

@kyrisu
Copy link
Author

kyrisu commented Apr 8, 2018

@kreedz - probably so as I was using LanguageClient-neovim when I have opened this issue. I have also opened an issue there: autozimu/LanguageClient-neovim#316 but it was closed with:

This is a problem with language server.

so I gave up :)

@kreedz
Copy link

kreedz commented Apr 8, 2018

Made a gif where you can see:
[LC] completion doesn't appear
requested by TypeScript but content not available messages shows in the statusline
[LC] completion starts to show only after <C-X> <C-O>

final3

nvim --version:
NVIM v0.2.3-579-ge2afcfb
init.vim:

call plug#begin('~/.local/share/nvim/plugged')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }
call plug#end()
let g:deoplete#enable_at_startup = 1
language messages C
let g:python_host_prog = '/usr/bin/python'
let g:python3_host_prog = '/usr/bin/python3'

" LanguageClient
let g:LanguageClient_serverCommands = {
    \ 'javascript': ['javascript-typescript-stdio'],
    \ 'javascript.jsx': ['javascript-typescript-stdio'],
    \ 'typescript': ['javascript-typescript-stdio'],
    \ }

nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>

autocmd BufNewFile,BufRead *.ts set filetype=typescript
au BufNewFile,BufRead *.tsx set filetype=typescript

nnoremap <silent><CR> :noh<CR><CR>

@felixfbecker
Copy link
Contributor

@kreedz this issue has already been debugged above, please read the thread. The warning messages are only warnings, they are unrelated to completion. The client didn't sync the most up-to-date document content before requesting completion.

@kreedz
Copy link

kreedz commented Apr 8, 2018

Thank you for the quick response!

Warnings are related to javascript-typescript-langserver?
If so, even if they are only warnings how can I fix them? Because they are completely fillling :messages window with a lot of warnings (not just one string).

@felixfbecker felixfbecker changed the title Completion fails with - readFile <full_project_path>/node_modules/react/package.json requested by TypeScript but content not available Completion is one character behind Apr 8, 2018
@felixfbecker
Copy link
Contributor

You can fix them by doing a PR that makes sure the files requested by TS are fetched before initializing TS. But you should expect the logging window to always have a lot of output, that's the point of logs...

@felixfbecker
Copy link
Contributor

Anyway it's not the cause of OP's issue so please open a new issue to not clutter this thread more.

@kreedz
Copy link

kreedz commented Apr 8, 2018

But you should expect the logging window to always have a lot of output, that's the point of logs...

If I see something like an error or a warning in the logs, I'm trying to figure out what it is and how to fix it, rather than just leaving it if it does not even impact the functionality.

@piersy
Copy link

piersy commented Feb 14, 2019

@kyrisu I have also been facing this problem, so I thought I would have a look in the logs of the typescript server.

I'm using javascript-typescript-langserver v2.11.2 and
LanguageClient-neovim 0.1.140

Changing my g:LanguageClient_serverCommands from this

'javascript': ['node', '/home/piers/programs/javascript-typescript-langserver/lib/language-server-stdio']

to this (I added a log)

'javascript': ['node', '/home/piers/programs/javascript-typescript-langserver/lib/language-server-stdio', '-l', 'logggg']

Has fixed the problem for me. @felixfbecker it makes me wonder if there is an issue with the javascript-typescript-langserver?

@omeid
Copy link

omeid commented Mar 13, 2019

@piersy suggestion worked for me too. It is possible that javascript-typescript-langserver stdio is not handled properly without logging?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants