carlitux / deoplete-ternjs

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

Autocomplete for require/import statements does not work properly #32

Closed AlexMasterov closed 7 years ago

AlexMasterov commented 7 years ago

deoplete-ternjs

deoplete-ternjs

tern_for_vim

tern_for_vim

carlitux commented 7 years ago

@AlexMasterov could you paste your config?

Also take a look at this https://github.com/carlitux/deoplete-ternjs/issues/25 most of the errors on this is about how your plugins works. Many developers install plugins to pair quotes or snippets that modify source code.

The source only has to return candidacies and deoplete insert into the buffer. Maybe we can try to find a way to hack this and implement some way to pair the quotes.

AlexMasterov commented 7 years ago

@carlitux thanks for such a quick reply.

With <C-x><C-o>: modules not showing in suggestions. With deoplete#manual_complete() trigger: only '| and 'react-| works, but adds quote pairs.

Minimal config for testing:

nvim

" deoplete.nvim
inoremap <silent> <expr> <Tab> pumvisible() ? "\<C-n>" : deoplete#mappings#manual_complete()

" deoplete-ternjs
let g:deoplete#sources = {}
let g:deoplete#sources.javascript = ['ternjs']

" tern_for_vim
let g:deoplete#omni#functions = {}
let g:deoplete#omni#functions.javascript = ['tern#Complete']
let g:deoplete#omni_patterns = {}
let g:deoplete#omni_patterns.javascript = '\h\w*\|\h\w*\.\%(\h\w*\)\|[^. \t]\.\%(\h\w*\)'

.tern-project

{
  "libs": [
    "ecmascript",
    "browser"
  ],
  "plugins": {
    "es_modules": {},
    "node_resolve": {},
    "requirejs": {
      "baseURL": "./",
      "paths": {}
    },
    "doc_comment": {}
  },
  "loadEagerly": [
    "src/*.js"
  ]
}
carlitux commented 7 years ago

@AlexMasterov @razor-x @wavded

Please update and review, looking at https://github.com/zchee/deoplete-jedi/blob/master/rplugin/python3/deoplete/sources/deoplete_jedi.py I found the way to enable import and require autocomplete so you don't need to call deoplete#manual_complete() any more.

Please test and let me know if something is wrong, few times is not autocompleting for me maybe something missed on regular expression if any of you have time to review the REs please do a pull request.

Here is where you can see the regular expresions.

https://github.com/carlitux/deoplete-ternjs/blob/5500ae246aa1421a0e578c2c7e1b00d858b2fab2/rplugin/python3/deoplete/sources/ternjs.py#L47

https://github.com/carlitux/deoplete-ternjs/blob/5500ae246aa1421a0e578c2c7e1b00d858b2fab2/rplugin/python3/deoplete/sources/ternjs.py#L351

carlitux commented 7 years ago

@AlexMasterov on your screenshoots I see you are using react. The issue I found happens when

I have it works

import React from 'rea

and here it stops working (most the time)

import React from 'reac

But when deleting with backspace start completing again.

Please confirm

AlexMasterov commented 7 years ago

Works fine :+1: Thank you!