tern_for_vim icon indicating copy to clipboard operation
tern_for_vim copied to clipboard

Can install plugin, but autocompletion does not work.

Open nurzhanizbassov opened this issue 8 years ago • 8 comments

I installed the plugin tern_for_vim. Followed all the instructions from readme but it doesn't work. I don't have any autocompletion for javascript, the commands :TernDef and :TernDoc are not recognized in vim. I installed the tern server globally using npm and I can launch it in the terminal.

However, if I launch :call tern#Enable() it seems that the plugin gets loaded and I can see :TernDef and :TernDoc commands but still no autcompletion for javascript.

I tried to launch tern with the --verbose option but it did not output anything when I tried to use autocompletion in javascript files.

It seems that there is no communication between vim and the tern server if I understand it correctly.

Here are my plugins in .vimrc file:

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-syntastic/syntastic'
Plugin 'scrooloose/nerdtree'
" Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'nvie/vim-flake8'
" Plugin 'Valloric/YouCompleteMe'
Plugin 'davidhalter/jedi-vim'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'alvan/vim-closetag'
Plugin 'Valloric/MatchTagAlways'
Plugin 'ternjs/tern_for_vim'
Plugin 'lervag/vimtex'

I also setup a .tern-config file in the home directory:

{
    "libs": [
	"ecmascript",
	"browser",
	"jquery"
    ],
    "plugins": {
        "es_modules": {},
	"node": {}
    }
}

I could run ternjs when I set up YouCompleteMe for python autocompletion, but I didn't like it and chose jedi-vim (which is really nice). Now I want to setup javascript autocompletion but without no luck.

Is it possible that the plugin is in conflict with some of my other plugins?

OS: Xubuntu 16.04 LTS

nurzhanizbassov avatar Aug 25 '17 03:08 nurzhanizbassov

I had something similar. Tried adding loadEagerly? http://ternjs.net/doc/manual.html#configuration

akkerman avatar Aug 25 '17 06:08 akkerman

@akkerman Thanks, for the response. How do you trigger autocompletion. What shortcut?

nurzhanizbassov avatar Aug 25 '17 06:08 nurzhanizbassov

tern hook into omni completition, but your completion plugin may not, you can test whether your omni completion works by use <c-x><c-o>

chemzqm avatar Aug 25 '17 06:08 chemzqm

In hopefully what is considered a related note: I can't seem to confirm if the instance of tern started by the vim/nvim plugin is reading the defs files. I cannot find the defs directory for the tern instance the plugin starts. I'm motivated to do so because I have confirmed that tern does not find the third party libraries (react and ecma6) defs when I start the tern server from my z-shell.

Where should I expect to find the defs and plugins directories referenced in the terndocs when I installed tern using tern_for_vim?

Thank you!

EdmundsEcho avatar Sep 12 '17 16:09 EdmundsEcho

Where should I expect to find the defs and plugins directories referenced in the terndocs when I installed tern using tern_for_vim?

They are part of the tern package -- i.e. node_modules/tern/plugin/ under your tern_for_vim if you installed normally.

marijnh avatar Sep 12 '17 18:09 marijnh

Perfect. In my case (Mac OS, installing tern the normal, npm i -g tern way that is run by your config spec) the location for both the plugin and defs directories was /usr/local/lib/node_modules/tern/.

I was able to confirm that the globally installed tern server was accessing the required files. To do so, I manually fired up tern in the shell and got rid of any errors by manually copying the required files.

Specifically, I copied from the ternjs/tern github repo the required lib and plugin sources referenced in my .tern-config file.

Knowing what you shared was helpful because while this plugin takes care of the install, I still wanted to know where to put the extra source files that I'm referencing in the .tern-config file.

Am I defeating some project specific capacity/feature? I do know that my set-up is now working at a useful baseline level.

Thank you for your help.

EdmundsEcho avatar Sep 12 '17 21:09 EdmundsEcho

You can also put definition files and plugins in your project—if their name, interpreted as a filename relative to the .tern-project file, exists, that'll be used.

marijnh avatar Sep 12 '17 21:09 marijnh

Sorry for the late reply. My issue was resolved. Here is a link to vim stackexchange - https://vi.stackexchange.com/questions/13348/cannot-setup-tern-for-vim-plugin/13359#13359.

nurzhanizbassov avatar Sep 13 '17 11:09 nurzhanizbassov