sunaku / vim-dasht

:information_desk_person: (Neo)Vim plugin for dasht integration
https://github.com/sunaku/dasht
133 stars 4 forks source link

Plugin doesn't recognize word under cursor properly #7

Closed petRUShka closed 7 years ago

petRUShka commented 7 years ago

Suppose I have following code in Ruby:

@answers.rotate!(rand(3))

I place my cursor in the middle of the word rotate:

@answers.rot<|>ate!(rand(3))

where <|> is the position of cursor. And then I press <Leader> K configured as in your README.

After pressing the key I see documentation on rand and not on rotate! which I expected.

sunaku commented 7 years ago

This happens because we currently only split function calls on parentheses, ignoring OOP dot notation. :neckbeard:

To support OOP dot notation, the "dot" might be language-specific :fearful: so I'm thinking of doing this in a language-agnostic way using Vim's iskeyword setting to tell me which characters are safe to split on. :camel:

petRUShka commented 7 years ago

iskeyword is probably the solution. But honestly I always thought that VimL has its own built-in function for word under cursor, hasn't it?

sunaku commented 7 years ago

Yes, we already use Vim's built-in <cword> facility for this purpose. :+1: And here is the root cause:

nnoremap <silent> <Leader>K :call Dasht([expand('<cWORD>'), expand('<cword>')])<Return>

The mapping searches for cWORD first and then falls back to searching cword, which is the opposite of what you want. :face_with_head_bandage: I don't remember why I chose this particular order, but it feels counter-intuitive now.

This issue can be solved by changing the order of cwords in the above mapping to this:

nnoremap <silent> <Leader>K :call Dasht([expand('<cword>'), expand('<cWORD>')])<Return>
sunaku commented 7 years ago

README has been updated accordingly. :books: Thanks for reporting this issue. :+1: Closing.