Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JavaScript in VimBox Awesome For Once. #36

Open
jordwalke opened this issue Dec 17, 2016 · 9 comments
Open

Make JavaScript in VimBox Awesome For Once. #36

jordwalke opened this issue Dec 17, 2016 · 9 comments

Comments

@jordwalke
Copy link
Owner

VimBox should come with the most common integrations out of the box, such that all the plugins(syntastic) work well together. I'd really appreciate if someone would share/test what you know to work well, and include it in VimBox so others can benefit.

@oriSomething
Copy link

In other computer I have installed YouCompleteMe that uses TernJS which has quiet nice autocomplete. But I'm quite sure with some configurations FlowType or TypeScript can provide a better autocomplete

@jordwalke
Copy link
Owner Author

Yes, it would be nice to support either TS, or Flow. I could never get YouCompleteMe to behave like all the other modern IDEs' autocomplete (where you can hit enter to accept a result). Maybe they've added that feature? I should check again.

@farazcsk-zz
Copy link

After some messing around I managed to get JS liniting up and running, but the linter didn't underline exact area of the error, just the first character which is really hard to spot.
Also my current eslint config throws trailing spaces errors, which were no where to be seen in the editor.

@jordwalke
Copy link
Owner Author

What plugins/technologies do you use? It would be great to be able to use typescript or flow.

@prabirshrestha
Copy link

asyncomplete.vim is an asynchronous autocomplete plugin written in pure vimscript and works on vim8 and neovim in mac, linux and windows and is very easy to setup.

There is already a source for Flow https://github.com/prabirshrestha/asyncomplete-flow.vim and TypeScript https://github.com/prabirshrestha/asyncomplete-tscompletejob.vim. I have been using TypeScript autocomplete for couple of months now at work.

@jordwalke
Copy link
Owner Author

Very interesting, thanks for reporting. How does it work with Ultisnips, and repeat. ?
Can you use <CR> to accept an entry? This is how many modern editors work and so VimBox wants to recreate that effect.

@prabirshrestha
Copy link

Ultisnips is supported by https://github.com/prabirshrestha/asyncomplete-ultisnips.vim and neosnippet is supported by https://github.com/prabirshrestha/asyncomplete-neosnippet.vim

If you are using tab to select completion you can set let g:UltiSnipsExpandTrigger="<c-e>" so it expands via <c-e>. For neosnippet you can do something similar to xmap <C-k> <Plug>(neosnippet_expand_target). Theoretically you could use timers and add support for fast double tab to expand snippets like in VS and VSCode by internally using UltiSnips#ExpandSnippet() but this isn't something I have it yet. There are other features I want to get first.

Could you give an example of how you want to use repeat operator? If you are looking to try how this works, it should take you less than a minute to set it up. I highly recommend you to give it a try. This is the setting I use (minus some of the other sources) and mimics what VS does (Tab, S-Tab, Ctrl-Space, CR works exactly like VS). Some people don't prefer autopopup features like VS and want to change they the key-bindings. Disabling autopopup is an example. End of the day it is up to you to setup what <CR> should do and not asyncomplete plugin, same for Tab and S-Tab.

Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-buffer.vim'

set completeopt+=noinsert,noselect
set completeopt-=preview     " Disable autocomplete preview. CompleteDone doesn't work properly so I prefer to disable it.

imap <c-space> <Plug>(asyncomplete_force_refresh)
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<cr>"
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif

au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
    \ 'name': 'buffer',
    \ 'whitelist': ['*'],
    \ 'completor': function('asyncomplete#sources#buffer#completor'),
    \ }))

Caching and popup logic is actually very similar to how VsCode shows autocomplete. More details at prabirshrestha/asyncomplete.vim#3 and algorithm is mentioned at roxma/nvim-completion-manager#30 (comment) if you want to dig deeper.

Currently the biggest feature asyncomplete is missing is ranking and (fuzzy) suggestion algorithm. I tried https://github.com/tpope/vim-haystack but it made vim too slow. I'm waiting for an official neovim lua support so I can work on a better matcher algorithm that is fast. Vim 8 would fallback to current algorithm.

@jordwalke
Copy link
Owner Author

jordwalke commented Apr 7, 2017

Thanks! This is helpful information. I'll have to try this, it might make a good choice for VimBox. Unfortunately, VimBox isn't set up for me to easily try stuff on my (currently) hacked / forked setup of VimBox (trying out some new window management for a while before upstreaming).

I would love it if someone could make VimBox load from arbitrary forks/local-clones of VimBox instead of having a setup that redirects your symlinks. I'm sure this is possible.

I will definitely check this out though.

@prabirshrestha
Copy link

FYI: asyncomplete.vim now supports the Language Server Protocol. It is still work in progress (hence in dev branch) but you should be able to use it for completion as well as go to definition, finding workspaces and document symbols.

It is fully async and works in both vim8 and neovim as well as on Max, Linux and Windows.

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp', { 'branch': 'dev' }
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'

if executable('pyls')
    " pip install python-language-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pyls',
        \ 'cmd': {server_info->['pyls']},
        \ 'whitelist': ['python'],
        \ })
endif

if executable('rls')
    " https://github.com/rust-lang-nursery/rls#setup
    au User lsp_setup call lsp#register_server({
        \ 'name': 'rls',
        \ 'cmd': {server_info->['rustup', 'run', 'nightly', 'rls']},
        \ 'whitelist': ['rust'],
        \ })
endif

if executable('flow-language-server')
    " https://github.com/flowtype/flow-language-server#building-an-editor-integration
    au User lsp_setup call lsp#register_server({
        \ 'name': 'flow-language-server',
        \ 'cmd': {server_info->['flow-language-server', '--stdio']},
        \ 'whitelist': ['javsacript'],
        \ })
endif

For javascript, one could try flow-language-server but I faced with some bugs on windows. facebookarchive/flow-language-server#48. cmd is a function, so you can return empty array if you there is no .flowconfig and you don't want to start the flow server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants