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

Indentation error after anonymous function block #79

Open
tek opened this issue Nov 8, 2014 · 6 comments
Open

Indentation error after anonymous function block #79

tek opened this issue Nov 8, 2014 · 6 comments

Comments

@tek
Copy link

tek commented Nov 8, 2014

object Foo {
  def foo {
    val bar = { item =>
    }
  wrong
  }
}

Looks like this on 7.4.491.

@andrewla
Copy link
Contributor

Oddly enough, this works for similar cases; the val has to the first thing in the block, and there has to be a parameter

def foo {
  val x = 1
  val bar = { item =>
...

indents the "wrong" line correctly, as does

def foo {
  val bar = {
...

I think even the first case above is behaving incorrectly; it's setting the indentation for the "wrong" line to be the same as the val x = 1 line, which just happens to result in correct behavior in that case. I think the problem lies in the regex of scala#MatchesIncompleteDefValr, which is failing to identify it as an incomplete line. My first attempts to fix it broke too many things though; this hint might help someone else debug the issue, though.

@derekwyatt
Copy link
Owner

We've seen this before. For some reason (it seems) that set virtualedit=all fixes the problem. (I don't see this when running in my config).

Can you set that and see if it fixes things?

@tek
Copy link
Author

tek commented Jan 28, 2015

nope, I had the setting on the (empty) default.

edit: virtualedit=all has no effect either.

@derekwyatt
Copy link
Owner

Hmm... interesting. I actually can reproduce this.

object Foo {
  def foo {
    val bar = { item =>
    }
  wrong
  }
}
object Foo {
  def foo {
    val bar = { item
    }
  wrong
  }
}
object Foo {
  def foo {
    val bar = {
    }
    right
  }
}

So it's something to do with the fact that { isn't on the end of the line (give or take spaces).

@tek
Copy link
Author

tek commented Jan 28, 2015

which fits the regex @andrewla pointed out.

@andrewla
Copy link
Contributor

The fix I tried is

diff --git a/indent/scala.vim b/indent/scala.vim
index 5d812e4..156c162 100644
--- a/indent/scala.vim
+++ b/indent/scala.vim
@@ -27,6 +27,7 @@ let s:typeSpecMatcher = '\%(\s*\[\_[^\]]*\]\)'
 let s:defArgMatcher = '\%((\_.\{-})\)'
 let s:returnTypeMatcher = '\%(:\s*\w\+' . s:typeSpecMatcher . '\?\)'
 let g:fullDefMatcher = '^\s*' . s:defMatcher . '\s\+' . s:funcNameMatcher . '\s*' . s:typeSpecMatcher . '\?\s*' . s:defArgMatcher . '\?\s*' . s:returnTypeMatcher . '\?\s*[={]'
+let s:incompleteEndingMatcher = '\([=({]\|{.*=>\)\s*$'

 function! scala#ConditionalConfirm(msg)
   if 0
@@ -185,7 +186,7 @@ function! scala#NumberOfBraceGroups(line)
 endfunction

 function! scala#MatchesIncompleteDefValr(line)
-  if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*[=({]\s*$'
+  if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*' . s:incompleteEndingMatcher
     return 1
   else
     return 0

I don't remember what it broke, though.

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

3 participants