Open chauncey-garrett opened 7 years ago
hey @chauncey-garrett I was irked by this too. A bit of digging and experimentation led to a solution. I submitted a PR #2 that should address the issue. You can check out the very simple solution in the meantime
@abest0 I accepted PR #2, @chauncey-garrett if this fixes your problem please close the issue. Thanks!
@abest0 and @martinda Thanks for the PR and acceptance, respectively!
Unfortunately, I've pulled in the latest changes but am still not good results with gg=G
. For example, this is the result when operating on https://github.com/jenkinsci/pipeline-examples/blob/master/jenkinsfile-examples/android-build-flavor-from-branch/JenkinsFile:
Other Jenkinsfile
s from that repo give similar issues.
Here's another example where I get weirdness (from https://gist.github.com/abayer/925c68132b67254147efd8b86255fd76):
@chauncey-garrett
You may have some wacky indents going on or no groovy specific indents at all. I'm using the groovy indent from here. Depending on the plugin manager, the groovy indent file should be added to the vim path so that it is accessible.
Open a Jenkinsfile
in a buffer and use :scriptnames
(or Scriptease) to see which groovy plugins have loaded. You should see something like the following:
Regarding your second screenshot. I pulled the same file down and formatted it. I did see a small bit of weirdness on the same lines. Something like that can always be rewritten to workaround the formatting i.e. https://gist.github.com/chinshr/aa87da01ec28335e3ffd#file-parallel-stage-groovy or you can make specific indents.
hth
Yeah, the groovy indentation is borked out of the box. Try using this: https://github.com/vim-scripts/groovyindent-unix
...and no, that's not perfect either.
Okay hear me out. I was just going down this rabbit hole since I work with Jenkinsfile alot for my job and indenting has always been a pain. The Javascript indent expression (coming from polygot, not sure if its also built in) works surprisingly good for Jenkinsfile.
echo 'runtime! indent/javascript.vim' > ~/.config/[vim, nvim]/indent/[groovy, Jenkinsfile].vim
I basically started by trying to do the same thing https://github.com/vim-scripts/groovyindent-unix is doing which is taking the java indent file and tweaking it for differences, but there were too many differences to tweak to make a stable indent using gg=G
Haven't tried it on regular groovy, but it makes great work of my pipelines.
The groovy fallback doesn't provide autoindent and vim falls back to C style indentation since Jenkinsfile doesn't typically include semicolons
;
.https://stackoverflow.com/a/31323902