carlitux / deoplete-ternjs

deoplete.nvim source for javascript
MIT License
277 stars 24 forks source link

Addes extra single quote when completing imports #25

Closed razor-x closed 8 years ago

razor-x commented 8 years ago

With deoplete: extra leading '

import React from '|
# (why?) Have to press <Tab> to trigger deoplete#manual_complete()
# select from popup: 'react'
# result is
import React from ''react'

With <C-X><C-O>: works

import React from '|
# <C-X><C-O>
# select from popup: 'react'
# result is
import React 'react'

Related: if using something that automatically adds quote pairs.

With deoplete: extra leading '

import React from '|'
# (why?) Have to press <Tab> to trigger deoplete#manual_complete()
# select from popup: 'react'
# result is
import React from ''react'

With <C-X><C-O>: extra trailing '

import React from '|'
# <C-X><C-O>
# select from popup: 'react'
# result is
import React 'react''

Tern config:

{
  "plugins": {
    "node": {},
    "node_resolve": {},
    "modules": {},
    "es_modules": {}
  }
}
carlitux commented 8 years ago

Could you send minimal init.vim config file

razor-x commented 8 years ago

@carlitux Sure, right after lunch :apple:

razor-x commented 8 years ago
call plug#begin('~/.config/nvim/plugged.test')

" Set Python 3 host (optional: based on environment).
" let g:python3_host_prog = '/bin/python3'

function! DoRemote(arg)
  UpdateRemotePlugins
endfunction

Plug 'shougo/deoplete.nvim',
     \ { 'do': function('DoRemote') }

Plug 'ternjs/tern_for_vim',
     \ { 'for': 'javascript' }

Plug 'carlitux/deoplete-ternjs',
     \ { 'for': 'javascript' }

let g:deoplete#enable_at_startup = 1
let g:tern#command = ['tern']
let g:tern#arguments = ['--persistent']

call plug#end()

set omnifunc=syntaxcomplete#Complete

inoremap <silent><expr> <Tab>
  \ pumvisible() ? 
  \ deoplete#manual_complete() : 
  \ deoplete#manual_complete()

Note I'm using Tab to trigger completion for this example.

razor-x commented 8 years ago

Another thing that is broken: assume I'm editing index.js and mylib.js is in same directory.

import './|
# Have to press <Tab> to trigger deoplete#manual_complete()
# select from popup: './mylib'
# result is
import './'./mylib'

This too:

import './m|
# Try to press <Tab> to trigger deoplete#manual_complete()
# No [ternjs] items in popup, so cannot select './mylib'

Normal completion works for those cases.

I also don't get why I have to trigger manual completion to see [ternjs] options for these examples.

carlitux commented 8 years ago

Well I think this is related with your setup, using pumvisible and with manual_complete... this issue should be on https://github.com/Shougo/deoplete.nvim

To get working deoplate just setup the basic one and install this source with the plugin.

razor-x commented 8 years ago

@carlitux Do you have a working example then?

I only put the last mapping there so I'd have a way to trigger [ternjs] sources appearing in the popup. If I don't have a mapping to trigger manual completion, then the popup will never appear for the examples I gave. I actually use the mapping

inoremap <expr> <C-Space> deoplete#manual_complete()

in my main config, but that was not working for me when testing it for some reason.

If I understand you correctly, then the following works for you?

call plug#begin('~/.config/nvim/plugged.test')

function! DoRemote(arg)
  UpdateRemotePlugins
endfunction

Plug 'shougo/deoplete.nvim', { 'do': function('DoRemote') }

Plug 'carlitux/deoplete-ternjs'

let g:deoplete#enable_at_startup = 1

call plug#end()

If I use that, then

import '|

will not show a popup and I never get any [ternjs] completions to appear

carlitux commented 8 years ago

https://github.com/linkux-it/linkux-dev/blob/master/conf/osx/nvimrc this for osx https://github.com/linkux-it/linkux-dev/blob/master/conf/ubuntu/nvimrc this for ubuntu you can only see the deoplete setup

Popup will appear as you type, and also ternjs depends on your setup to start serving the autocomplete.

razor-x commented 8 years ago

Sorry @carlitux I don't want to run such a large vim config on my system as I don't know what side effects it may have. Do you have a minimal example? From what I can see, the only references to deoplete and ternjs in that config are

call dein#add('Shougo/deoplete.nvim', {'on_i': 1}) "{{{
  let g:deoplete#enable_at_startup = 1
" }}}

call dein#add('zchee/deoplete-jedi', )
call dein#add('carlitux/deoplete-ternjs')

which seems about the same as what I just added.

Any thoughts on this one @Shougo?

For ternjs, I know it works for other input cases, for example, using

call plug#begin('~/.config/nvim/plugged.test')

function! DoRemote(arg)
  UpdateRemotePlugins
endfunction

Plug 'shougo/deoplete.nvim', { 'do': function('DoRemote') }

Plug 'carlitux/deoplete-ternjs'

let g:deoplete#enable_at_startup = 1

call plug#end()

then

function myFunc () {
}

my|

will show the popup automatically with [ternjs] completion option for myFunc.

carlitux commented 8 years ago

Yes, those should works.

On Tue, Aug 9, 2016, 9:06 PM Evan Sosenko notifications@github.com wrote:

Sorry @carlitux https://github.com/carlitux I don't want to run such a large vim config on my system as I don't know what side effects it may have. Do you have a minimal example? From what I can see, the only references to deoplete and ternjs in that config are

call dein#add('Shougo/deoplete.nvim', {'on_i': 1}) "{{{

let g:deoplete#enable_at_startup = 1" }}}

call dein#add('zchee/deoplete-jedi', ) call dein#add('carlitux/deoplete-ternjs')

which seems about the same as what I just added.

Any thoughts on this one @Shougo https://github.com/Shougo?

For ternjs, I know it works for other input cases, for example, using

call plug#begin('~/.config/nvim/plugged.test')

function! DoRemote(arg) UpdateRemotePlugins endfunction

Plug 'shougo/deoplete.nvim', { 'do': function('DoRemote') }

Plug 'carlitux/deoplete-ternjs'

let g:deoplete#enable_at_startup = 1

call plug#end()

then

function myFunc () { }

my|

will show the popup automatically with [ternjs] completion option for myFunc.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/carlitux/deoplete-ternjs/issues/25#issuecomment-238738523, or mute the thread https://github.com/notifications/unsubscribe-auth/AACeWhCMPdUNmgL0BgEindOP0Wu-5Vqaks5qeSQWgaJpZM4JgdZJ .

razor-x commented 8 years ago

Right, so with that working, the popup does not appear on import '| so I have to open it by triggering deoplete#manual_complete() but then I get the extra quote issue as I reported. Compare with using <C-X><C-O> with tern_for_vim and I get the other behaviour (no extra quote for the first case).

carlitux commented 8 years ago

I see, I don't think ternjs has support to work on imports yet... If you have docs would be good

On Tue, Aug 9, 2016, 9:15 PM Evan Sosenko notifications@github.com wrote:

Right, so with that working, the popup does not appear on import '| so I have to open it by triggering deoplete#manual_complete() but then I get the extra quote issue as I reported. Compare with using with tern_for_vim and I get the other behaviour (no extra quote for the first case).

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/carlitux/deoplete-ternjs/issues/25#issuecomment-238739804, or mute the thread https://github.com/notifications/unsubscribe-auth/AACeWqIVkHOL4pxeTrBUJJhJCWrtAmBpks5qeSZEgaJpZM4JgdZJ .

razor-x commented 8 years ago

As far as I can tell it works well with imports via the official plugins. I am using

{
  "plugins": {
    "node": {},
    "node_resolve": {},
    "modules": {},
    "es_modules": {}
  }
}

but those may not all be needed for it to work.

The key point is that tern is giving me correct module completion for local modules and modules in node_modules, but the result after selecting one differs depending on if I select from the omni list populated by tern_for_vim vs. the [ternjs] source provided here, per my comments:

https://github.com/carlitux/deoplete-ternjs/issues/25#issue-170256206 https://github.com/carlitux/deoplete-ternjs/issues/25#issuecomment-238719760

razor-x commented 8 years ago

Here is the first case: https://asciinema.org/a/1d8jq2va1dpp4uat2e8nb4y3p

Here is the local module issue: https://asciinema.org/a/brkv2of697nhbigcmy7k749f5

carlitux commented 8 years ago

try to change your config to user another key instead of tab.

razor-x commented 8 years ago

Sure, I'm actually using <C-Space> in the videos, but running say

:inoremap <expr> <C-Q> deoplete#manual_complete()

and using that makes no difference.

carlitux commented 8 years ago

I can't reproduce it with the setup, config

razor-x commented 8 years ago

The extra quote issue, or getting the module completion to appear at all?

You would need to put a .tern-project in your working directory with

{
  "plugins": {
    "node": {},
    "node_resolve": {},
    "modules": {},
    "es_modules": {}
  }
}
carlitux commented 8 years ago

Both, I tested with big project and as you did on test... In both I can't get working neither issues.

On Tue, Aug 9, 2016, 10:38 PM Evan Sosenko notifications@github.com wrote:

The extra quote issue, or getting the module completion to appear at all?

You would need to put a .tern-project in your working directory with

{ "plugins": { "node": {}, "node_resolve": {}, "modules": {}, "es_modules": {} } }

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/carlitux/deoplete-ternjs/issues/25#issuecomment-238750472, or mute the thread https://github.com/notifications/unsubscribe-auth/AACeWhdjnpALivXvsl3DzNoBEizzwfY1ks5qeTmFgaJpZM4JgdZJ .

carlitux commented 8 years ago

http://ternjs.net/doc/demo/#ES6 looks like the module adds the closing quote, so if you have a plugin that add the closing quote that should be the issue.

Maybe you need to setup tern plugin to avoid add the quote.

razor-x commented 8 years ago

Well, yes, the closing quote issue is only for omni, so I expected it to be from tern, but the opening quote issue is only for this source.

As long this source gets the behaviour correct, I don't need to use omni. Even if you are not using a autoclose type plugin, it should still produce correct output in the case import '|'.

I can't work on this until possibly tomorrow, but I'd love to get this fixed since importing stuff is so frequent.

I'll make a minimal repo which reproduces it for me and include my Neovim, tern, and node versions.

razor-x commented 8 years ago

Ok, see here: https://github.com/rxbugs/vim-ternjs-imports

Let me know if that lets you reproduce it.

Can anyone else try too?

wavded commented 8 years ago

@razor-x did you ever get this working?

razor-x commented 8 years ago

No, the project on rxbugs to reproduce the issue is where I stopped working on it (since carlitux closed it and couldn't reproduce).

Can you confirm this is an issue for you, in particular can you reproduce it on https://github.com/rxbugs/vim-ternjs-imports ?

wavded commented 8 years ago

I can confirm it does not work for me. If I use C-x C-o it works fine, just doesn't do it through deoplete.

carlitux commented 7 years ago

@razor-x @wavded please see https://github.com/carlitux/deoplete-ternjs/issues/32 sorry to be late