artur-shaik / vim-javacomplete2

DEPRECATED in favor of jc.nvim
Vim License
973 stars 83 forks source link

Fix gralde output parse #313

Closed wsdjeg closed 7 years ago

wsdjeg commented 7 years ago

@DonnieWest can you have a try?

DonnieWest commented 7 years ago

@wsdjeg it seems to be putting my Neovim into an infinite loop. Running :JCclasspathGenerate freezes my buffer until I exit

wsdjeg commented 7 years ago

Is there any example project? I want to test it.

DonnieWest commented 7 years ago

@wsdjeg I'll try to make one tonight when I have some time

DonnieWest commented 7 years ago

@wsdjeg looking at the code, it looks like it's getting caught on the while loop. Would something like this be better?

      let cp = ''
      let flag = 0
      for i in range(len(s:gradleOutput))
        if s:gradleOutput[i] =~ '^CLASSPATH:'
          let cp .= s:gradleOutput[i][10:]
          if s:gradleOutput[i] !~ '^\s*$'
            let cp .= s:gradleOutput[i]
          endif
        endif
      endfor

Edit: Fixed some stuff

wsdjeg commented 7 years ago

why do you add s:gradleOutput[i] twice? what I did means, check the output line by line, if a line beging with CLASSPATH, then add [10:] of this line into cp, then check the next line.

ok, I think I should not use while in it.

DonnieWest commented 7 years ago

Ah, yeah, that was probably silly. It's just me trying to show what I mean, there are probably big issues with what I'm doing there since I'm not in a place that I can test it

wsdjeg commented 7 years ago

I think it should be fixed.

DonnieWest commented 7 years ago

Got back around to be able to test this

https://github.com/DonnieWest/Dispatch here's a sample project

It looks like the output still includes the last few lines BUILD SUCCESSFUL and the timestamp. This is probably silly, but, this seems to work on my end

      let cp = ''
      for i in range(len(s:gradleOutput))
        if s:gradleOutput[i] =~ '^CLASSPATH:'
          let cp .= s:gradleOutput[i][10:]
          for j in range(i, len(s:gradleOutput) - 1)
            if s:gradleOutput[j] =~ '^BUILD'
              break
            endif
            if s:gradleOutput[j] !~ '^\s*$'
              let cp .= s:gradleOutput[j]
            else
              break
            endif
          endfor
          break
        endif
      endfor

I'm sure there's a better way to test for that though. My Vimscript skills are lacking :)

wsdjeg commented 7 years ago

as I know there is a black line before '^BUILD', I think the black line should not be added in to cp. I will test it.

wsdjeg commented 7 years ago

@DonnieWest can you post a example of gradle out put? I can not test in local.

DonnieWest commented 7 years ago

Here's a pastebin of it

http://pastebin.com/BXxbTbfA

wsdjeg commented 7 years ago

@DonnieWest I just test my PR, it works well for me.

DonnieWest commented 7 years ago

@wsdjeg I just tested and If I echom g:JavaComplete_LibsPath it says

/jars/classes.jarBUILD SUCCESSFULTotal time: 24.698 secs

At the very end. If we leave that, it'll cause the last .jar file in the CLASSPATH to not have completions, right?

wsdjeg commented 7 years ago

yes. but I do not know why. as you know there is a black line before BUILD SUCCESSFUL, so this line should not be added to cp.

DonnieWest commented 7 years ago

@wsdjeg I've found that there isn't a \n or other whitespace character before BUILD SUCCESSFUL. They seem to be removed by Neovim, otherwise we could do something like

let l:classpath = split(join(s:gradleOutput, ''), "\n")
let cp = filter(l:classpath, 'v:val =~ "^CLASSPATH:"')[0][10:]

and be done. Is checking for BUILD at the start of the line going to be the fix or should we have Gradle print something to let us know it's the end of the CLASSPATH?

wsdjeg commented 7 years ago

yes, good idea.

DonnieWest commented 7 years ago

@wsdjeg #315 builds on this PR - mind checking it out? It seems to work for me locally but probably still does some silly stuff

wsdjeg commented 7 years ago

nice work! It is ok to me.