ternjs / tern_for_vim

Tern plugin for Vim
MIT License
1.83k stars 100 forks source link

Can global `tern` binary be use? #178

Closed wizzup closed 7 years ago

wizzup commented 7 years ago

I am on NixOS and neovim.

I have tern available in my development shell (nix-shell).

$ which tern
/nix/store/n8in6vzvpklf1qpnrygz1dpqypqjab4f-node-tern-0.21.0/bin/tern

I get following error in vim when run :TernDoc

Failed to start server:                                                                                                                                                                                
module.js:471                                                                                                                                                                                          
    throw err;                                                                                                                                                                                         
    ^                                                                                                                                                                                                  
Error: Cannot find module '/home/wizzup/.config/nvim/plugged/tern_for_vim/node_modules/tern/bin/tern'                                                                                                  
    at Function.Module._resolveFilename (module.js:469:15)                                                                                                                                             
    at Function.Module._load (module.js:417:25)                                                                                                                                                        
    at Module.runMain (module.js:604:10)                                                                                                                                                               
    at run (bootstrap_node.js:389:7)                                                                                                                                                                   
    at startup (bootstrap_node.js:149:9)                                                                                                                                                               
    at bootstrap_node.js:504:3                                                                                                                                                                         

Press ENTER or type command to continue 

Is there any configuration can I set to make use of tern in my $PATH instead of the one in plugin directory so I can have only single tern installation?

This is how I install plugin in $MYVIMRC using vim-plug.

    Plug 'ternjs/tern_for_vim', { 'for': 'javascript' }
wizzup commented 7 years ago

If I run tern in another terminal,

$ tern                                           
Listening on port 34195 

The error is gone, and completion is working. 2017-09-01-190143_410x320_scrot

but trun keep shutting down due to idling. I have to run it again and again.

$ tern                                           
Listening on port 34195                          
Was idle for 5 minutes. Shutting down. 
chemzqm commented 7 years ago

You could use somthing like let g:tern#command = ['node', expand('~').'/lib/tern/bin/tern'] in your .vimrc

wizzup commented 7 years ago

solved by let g:tern#command = ['tern']

jlangloisp commented 6 years ago

Sorry to revive this, but you can also do:

let g:tern#command = [ '${pkgs.nodePackages.tern}/bin/tern' ]

if you don't want to rely on your user environment and you're using vim_configurable.