t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 111 forks source link

arrow functions prevent consideration of function objects #986

Open jeffreysbrother opened 6 years ago

jeffreysbrother commented 6 years ago

The command cif (as well as other related actions such as vaf and daf) does not recognize the following function (presumably because it utilizes an ES6 arrow function):

$(window).on('focus', () => {
    document.title = originialTitle;
    clearTimeout(tabTimeout);
    switched = false;
});

If the arrow function is replaced with a standard (pre-ES6) anonymous function, the issue does not arise. However, even if no anonymous function is used, it will still fail if the body of the function is not indented.

$(window).on('focus', function () {
document.title = originialTitle;
clearTimeout(tabTimeout);
switched = false;
});

I believe the presence/absence of whitespace should not effect functionality because it is quite common to encounter source code that does not adhere to common coding conventions.

vim-mode-plus: 1.22.0 Atom: 1.22.1 Electron: 1.6.15 Chrome: 56.0.2924.87 Node: 7.4.0 MacOS: 10.12.6

t9md commented 6 years ago

@jeffreysbrother

You are right, and what you pointed out behaviors are both I already recognized.

For a f, i f cannot select arrow function

Once it's possible, but I excluded it, because

I understand that it's inconsistent. But to select arrow function, you can use fold text object as long as it's foldable arrow function. By such as y z(short hand of y a z), y a z, y i z etc..

For a f, i f should be able to select function regardless of how it's indented.

I agree, but currently vmp find function range from fold, fold is created based on indent. I have no plan to change this for now.

vmp provide very basic function text-object, and want to avoid language specific handling

Following are what I wrote in recent TextObject Function improvement PR. #984

I won't try to be perfectly detect function body by parsing. I will try to improve coverage of detection by supporting common multi-func-patterns used in different function. I want keep language specific handling as minimum as possible. So I will still get hint from indentation.

If user really want to make function detection super accurrate

Create vmp-plugin package.