ternjs / tern_for_vim

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

Tern js doesn't auto complete when expected #89

Closed StefanICT closed 9 years ago

StefanICT commented 9 years ago

I added two images of my problem. The first shows that Vim doesn't show to docs for whatever function, but when I prepend "this." it does? Why does this happen, am I missing some .tern-project setting?

screen shot 2015-03-31 at 23 41 07 screen shot 2015-03-31 at 23 41 21

My .tern-project

{"libs": ["browser", "ecma5"] }
marijnh commented 9 years ago

This sounds a bit like marijnh/tern#516, but once again, I can not reproduce it -- I do see (fn) after the name when I complete a global function (I had to add a second function starting with what, because my vim immediately completes when there is only a single match).

StefanICT commented 9 years ago

Could you show me a picture or something of the result you get? Also do you have extra stuff in the vimrc that could be the cause that mine completion is not working? I just reinstalled tern and YoucompleteMe but no luck. I love this plugin and I need it ;) Or show me how I can debug it?

marijnh commented 9 years ago

My .vimrc is simply this:

execute pathogen#infect()
syntax on
filetype plugin indent on

I just moved to a new machine and installed vim specifically to try to reproduce this issue. So the only plugin that I have installed is tern_for_vim. Does disabling other plugins make a difference?

StefanICT commented 9 years ago

I only got YouCompleteMe and without it does't work either. I also moved to new machine. My vimrc isn't much more then that:

set nocompatible

execute pathogen#infect()
syntax on
filetype plugin indent on

"Habit breaking, habit making
nnoremap <Up> :echoe "use k" <CR>
nnoremap <Down> :echoe "use j" <CR>
nnoremap <Left> :echoe "use h" <CR>
nnoremap <Right> :echoe "use l" <CR>

set rnu 
set nu
set ai
"Backspace not working for some reason this fixes it
set backspace=indent,eol,start
colo candycode
marijnh commented 9 years ago

Strange. Which Tern version are you using? (See the top of node_modules/tern/package.json)

StefanICT commented 9 years ago
"name": "tern",
  "license": "MIT",
  "version": "0.10.0",
  "author": {
    "name": "Marijn Haverbeke",
    "email": "marijnh@gmail.com"
  },
marijnh commented 9 years ago

Here's what completion on a simple file looks like, using Tern 0.10.0 and vim 7.4:

image

StefanICT commented 9 years ago

So the setup of the situation is:

main.js -code .tern-project

Right?

vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr  7 2015 21:44:25)
MacOS X (unix) version
Included patches: 1-658
Compiled by stefan@Stefans-iMac.local
Normal version without GUI.  Features included (+) or not (-):
+acl             -farsi           -mouse_netterm   +syntax
-arabic          +file_in_path    -mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           -mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
+builtin_terms   -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         -gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    -keymap          +postscript      +virtualedit
+comments        -langmap         +printer         +visual
-conceal         +libcall         -profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
-cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             -rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
-emacs_tags      -mouseshape      -sniff           -xsmp
+eval            -mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm

screen shot 2015-04-07 at 22 57 40 screen shot 2015-04-07 at 22 49 01

marijnh commented 9 years ago

I didn't create a .tern-project, just a foo.js in my home dir, but the effect should be the same.

You could see what you get when you start your tern server manually from the command line with the --verbose flag (kill existing servers first). Do the completions really have "?" as the type? If not, something is going wrong on the vim side. Next step would be to try and dig down into the the var type = val.getType() line in findCompletions in tern/lib/tern.js, and figure out why it isn't returning a type -- but this library is unfortunately not very easy to debug without a lot of background knowledge.

StefanICT commented 9 years ago

I appreciate the help. So i am digging right now. I will keep you posted, could be tomorrow though.

Couple things already.

EDIT:

Got the server problem working ;)

screen shot 2015-04-08 at 00 10 31 screen shot 2015-04-08 at 00 09 52 screen shot 2015-04-08 at 00 15 24

As a novice I would say vim is not asking for completion without the dot?

EDIT again: Just tried this on my work macbook above was done on a iMac at home. Both gave me the same 'wrong' result

stobenski commented 9 years ago

@StefanICT

I only got YouCompleteMe and without it does't work either.

This means that you've tried to complete 'what' manually with C-x C-o and it does not work? Strange, because C-x C-o works for me.

YCM and neocomplete do not complete global names without dot, I have created a dictionary for neocomplete with document, window, prompt, function and stuff like that, which works fine for me.

StefanICT commented 9 years ago

@barwinco w00t w000t...!!!!

I just tried disabling YCM and in the docs I read the C-space activates the completion and then it works! I guess vim is just in the way or something? I guess I need to find a way to let YCM handle the completion or something!

On the right track!!!

EDIT: So I enabled YCM again and vim still shows some kinds of hints but when I do C-space>it shows me the expecting results!

So I will keep you guys posted on my future trail and errors ;) Really appreciate the help!

StefanICT commented 9 years ago

I think I found the solution!

YouCompleteMe gives two types of completion. I want the semantics and stopped the other. YCM got this option to set triggers:

let g:ycm_semantic_triggers =  {
  \   'c' : ['->', '.'],
  \   'objc' : ['->', '.'],
  \   'ocaml' : ['.', '#'],
  \   'cpp,objcpp' : ['->', '.', '::'],
  \   'perl' : ['->'],
  \   'php' : ['->', '::'],
  \   'cs,java,javascript,d,python,perl6,scala,vb,elixir,go' : ['.'],
  \   'vim' : ['re![_a-zA-Z]+[_\w]*\.'],
  \   'ruby' : ['.', '::'],
  \   'lua' : ['.', ':'],
  \   'erlang' : [':'],
  \ }

I have to add a python regex to match any 3 letters, then it is fixed and this can be closed now I guess.

ruanyl commented 8 years ago

@StefanICT Hi, what regex did you add to make javascript auto trigger to work? I have the similar issue as you.

talkw-liu commented 6 years ago

@StefanICT Why it doesn't show the write function for me? 1533888332 1

My .tern-project: { "libs": [ "browser", "underscore", "jquery" ],

"plugins": { "node": {}, "requirejs": { "baseURL": "./", "paths": {} }
}
}

marijnh commented 6 years ago

@talkw-liu That's a different issue, fixed by https://github.com/ternjs/tern/commit/d43faf3a95ebc035697d78c89ca1e4080d85d6e4