4

There isn't much from VS Code I can't reproduce with neovim but working with javascript/node, I am quite jealous of the fact that the autocompletion works with any (or most?) libraries added to the node_modules folder...

Any idea of plugins allowing that? With youcompleteme, deoplete or language server protocol/ternjs based plugins, I've never been able to get it.

Thx!

4
  • It would be a big win if neovim have the same autocompletion as vscode for javascript (*.js, *.jsx). Surprisingly neovim does excellent job for (TypeScript) *.ts files
    – Eskinder
    Commented Nov 12, 2018 at 17:41
  • Thx for the info. Can you give me some details on your typescript configuration? Also, I have started testing Language Protocol for Python in neovim (using "ALE" and autozimu's "LanguageClient-neovim"'). The results are much better than for js...
    – godot
    Commented Nov 13, 2018 at 17:20
  • I tried LanguageClient-neovim. Even though the autocompletion works good for javascript, it takes more than 10 sec for each autocompletion to show up. The only autocompletion that is working for me now in neovim is Typscript and that is by using 'mhartington/nvim-typescript' not for javascript. here is my .vimrc github.com/eskinderg/.rc/blob/master/.vimrc. after you install 'mhartington/nvim-typescript', make sure to invoke :UpdateRemotePlugins. i always forget to do that. Let me know how the "LanguageClient-neovim" is working.
    – Eskinder
    Commented Nov 14, 2018 at 18:23
  • Also checkout github.com/neoclide/coc.nvim i haven't gotten it to work yet.
    – Eskinder
    Commented Nov 14, 2018 at 18:23

2 Answers 2

6

Ok, after years of trying many things, I finally found a viable solution! And the winner is: COC

"It's a completion framework and language server client which supports extension features of VSCode."

The only thing is that to get the "floating windows" (which is the really cool stuff) you need to a "Build neovim from master code or use nightly build"

But to get a nightly build version of neovim on osX works perfectly fine, so it's easy to do.


After trying (many) different plugins, the best one is definitely CoC!

It works well with js & python, also typescript.

The big plus is that it integrates many plugins from visual studio code. The minus is the documentation...

2

Edit: For TypeScript I would recommend trying COC. If you are using JavaScript and COC isn't helping, then Tern might be worth a try.

I have had some success with this plugin: https://github.com/ternjs/tern_for_vim

But it does require some setting up:

  1. After installing the plugin, you need to cd into the plugin folder and run npm install

  2. For each project you work on, you need to create a .tern-project file. (See below)

I also tweak some of the plugin's config in Vim:

" Don't keep locking up Vim (an issue if the codebase is large)
let g:tern_show_argument_hints = 'never'

let g:tern_show_signature_in_pum = 1

I make the K key use Tern to look up documentation:

autocmd BufReadPost  *.js  nnoremap <buffer> K :TernDoc<CR>

Here is an example .tern-project file you can start from:

{
  "ecmaVersion": 7,
  "libs": [],
  "loadEagerly": [
    "app.js",
    "lib/globals.js"
  ],
  "plugins": {
    "node": {
      "dontLoad": "",
      "load": "",
      "modules": ""
    },
    "node_resolve": {},
    "modules": {
      "dontLoad": "",
      "load": "",
      "modules": ""
    },
    "commonjs": {},
    "doc_comment": {}
  },
  "dependencyBudget": 2000
}

The dependencyBudget will stop waiting for a response if Tern cannot provide one quickly. But I have found that the server will continue loading scripts and inferring in the background, so you can wait a while and then try the completion again.

(I have completion on Tab but I can't see where that was configured!)

There are some more examples of .tern-project files here.

1
  • 2
    Thanks, I have used ternjs in the past, but from what I have seen, it is far from the efficiency and smartness of VS autocompletion...
    – godot
    Commented Jun 19, 2018 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.