styled-components / vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
300 stars 24 forks source link

Autocomplete #35

Closed sQVe closed 6 years ago

sQVe commented 6 years ago

I'd like to first take the opportunity and thank everyone involved in this plugin. It's really nice having syntax highlighting. Over to the question...

Question: Is there currently any way to get autocomplete for styled-components? I know this is possible in VSCode but haven't found a proper way to do this in Vim.

fleischie commented 6 years ago

Hello @sQVe and thank you very much. :blush:

What do you mean with autocomplete? Do you mean automatic suggestions for attributes and properties?

Tl;dr: I have to implement a function to suggest words based on the given input. You need to setup how to trigger and interact with these suggestions yourself, though. (See details-section for an in-depth explanation. :smile:)

### Overly complicated, overthought initial answer: (I'm summarizing, even in case you know, just for future reference and get my thoughts straight on this) In general vim uses something called `omni completion`, which is a function, that is run on specific user input (` CTRL-X CTRL-O`) with some data on where this function was run. This function in turn retrieves a list of matches for the given user input. This is where I come in and implement a function, that returns a list of appropriate suggestions. This is actually on my Todo-list for a long time and I only gotten around to rewrite the whole syntax-highlighting/indenting. :stuck_out_tongue: If you need a tutorial on how to get suggestions for arbitrary stuff in vim for your specific filetype check out [Vim Wiki Tips - Omni completion](http://vim.wikia.com/wiki/Omni_completion). After this it gets really tricky really fast, because there are plugins for completion that are mostly two-fold: one plugin for an improved interaction with omnicomplete and one for the actual omnicompletion functions. This needs some effort on your end, as you need to specify your use cases for yourself, i.e. what kind of completion plugin you want, what keys you want to trigger the completion and what languages you want to complete. My advice would be to get acquainted with the built-in omnicomplete and only if you have large pain points advance to another library: - [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - [neocomplete](https://github.com/Shougo/neocomplete.vim) - [deoplete](https://github.com/Shougo/deoplete.nvim)
sQVe commented 6 years ago

@fleischie Yeah, that's exactly what I mean. It would be awesome if one could autocomplete exactly like how it works in a normal CSS file. I'm currently running deoplete, LanguageClient and nvim-typescript for auto/omni complete for a couple of languages.

I'd love to help but I'm far from well versed in VimScript.

BTW: It might be worth noting that this plugin currently does not support complete and only handles syntax highlighting.

fleischie commented 6 years ago

For everybody interested in that topic: check the latest develop branch, that contains the very first attempt of implementing this functionality. I didn't have much time to really test now, but it's there. :v:

sQVe commented 6 years ago

@fleischie Awesome. I've been forced to disable this plugin due to https://github.com/styled-components/vim-styled-components/issues/36 sadly.