Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nick4f42 opened this issue Mar 3, 2022 · 2 comments

Comments

@nick4f42
Copy link

nick4f42 commented Mar 3, 2022

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 nick4f42 changed the title ij text object selects part of multi-line signature ij text object always ignores first line of block Mar 3, 2022
@nick4f42 nick4f42 changed the title ij text object always ignores first line of block ij text object always and only ignores first line of block Mar 3, 2022
@nick4f42 nick4f42 changed the title ij text object always and only ignores first line of block ij text object incorrect for multi-line signatures and single-line blocks Mar 3, 2022
carlobaldassi added a commit that referenced this issue Mar 4, 2022
Addresses part of #286, dealing with multi-line brackets.

Still doesn't work well when the block header is multi-line because of
other types of incomplete expressions, e.g. because of dangling binary
operators at the end of a line:

  if x + y ==
      z
      println("yes")
  end

Another case which is not covered is if code continues in the same line
as the header:

  if x println("yes")
      return
  end
@carlobaldassi
Copy link
Contributor

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.

@nick4f42
Copy link
Author

nick4f42 commented Mar 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants