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!

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.

  • 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 Jun 19 at 22:32

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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