t9md / atom-vim-mode-plus

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

tryout to make text-object "function" correctly detect multiline-args function #984

Closed t9md closed 6 years ago

t9md commented 6 years ago

983

https://github.com/t9md/atom-vim-mode-plus/issues/819#issuecomment-318629360

Heuristically find function range.

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.

What is commonalities in samples in following Objective section?

Still vmp function text object greatly depends on fold info.

Objective

PHP: OK

<?php
class Kernel extends ConsoleKernel
{
  protected function schedule(Schedule $schedule)
  {
      // $schedule->command('inspire')
      //          ->hourly();
  }
}

Python: OK


## WONT support
class Rectangle(Blob):

    def __init__(self, width, height,
                 color='black', emphasis=None, highlight=0):

## will support
class Rectangle(Blob):

    def __init__(
        self, width, height,
        color='black', emphasis=None, highlight=0
    ):
      # body

c: OK

    int
get_beval_info(
    BalloonEval *beval,
    int     getword,
    win_T   **winp,
    linenr_T    *lnump,
    char_u  **textp,
    int     *colp)
{
    win_T   *wp;
    int     row, col;
    char_u  *lbuf;
    linenr_T    lnum;
}

coffee: SKIP BECAUSE COST NOT PAY FOR ME

f1 = (a, b) ->
  console.log a, b

f2 = (
  a,
  b
) ->
  console.log a, b

js: OK

function f1(a1, a2) {
  console.log(a1, a2)
}

function f2(
  a1,
  a2
) {
  console.log(a1, a2)
}

rust: OK

fn f1(arg1: i64, arg2: u64, arg3: String) -> i64 {
    let sum = 1 + 1;
    sum + 2
}

fn f2(
    arg1: i64,
    arg2: u64,
    arg3: String,
) -> i64 {
    let sum = 1 + 1;
    sum + 2
}