julia-vim icon indicating copy to clipboard operation
julia-vim copied to clipboard

`ij` text object incorrect for multi-line signatures and single-line blocks

Open nick4f42 opened this issue 3 years ago • 2 comments

The ij text object includes some of a function signature if it spans multiple lines:

julia-vim-ij

It doesn't select anything if the entire block is on one line, like this:

if foo println(2) end

nick4f42 avatar Mar 03 '22 22:03 nick4f42

I have just pushed a fix for the issue in the first example. Unfortunately, fixing the one-line blocks and other cases is very, very hard. That's because that basically requires a full-fledged julia code parser. Examples of things that still create problems after the fix:

  1. Lines that continue due to a dangling operator, e.g.
    if x + y ==
       z + k
        println("yes")
    end
    
  2. Code that comes in the same line after the block header, e.g.
    if x == z + k println("yes")
        return
    end
    

In order to deal with those correctly, we'd need a parser that can tell when an expression is completed. Doing it with brackets is not too hard, but when the tokens that determine the parsing are in the middle (like for binary operators) and there is whitespace dependency (e.g. a [3] is not the same as a[3] in this context) then things become very complicated to implement in vim script. It might be doable by leveraging syntax highlighting (as we do with brackets) but that would likely make the syntax highlighting even more horribly slow than it is already.

carlobaldassi avatar Mar 04 '22 13:03 carlobaldassi

Thanks for the quick fix! For completeness, I'll give another example I found that still doesn't work:

  1. When the where statement of a function is on a different line, it's included in ij
function f(
        x::T
    ) where T
    return T
end

nick4f42 avatar Mar 06 '22 07:03 nick4f42