Jenkinsfile-vim-syntax icon indicating copy to clipboard operation
Jenkinsfile-vim-syntax copied to clipboard

Add autoindent support

Open chauncey-garrett opened this issue 8 years ago • 7 comments

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

chauncey-garrett avatar Aug 23 '17 20:08 chauncey-garrett

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 avatar Aug 29 '17 13:08 abest0

@abest0 I accepted PR #2, @chauncey-garrett if this fixes your problem please close the issue. Thanks!

martinda avatar Aug 29 '17 14:08 martinda

@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:

screenshot from 2017-09-08 10-28-13

Other Jenkinsfiles from that repo give similar issues.

chauncey-garrett avatar Sep 08 '17 15:09 chauncey-garrett

Here's another example where I get weirdness (from https://gist.github.com/abayer/925c68132b67254147efd8b86255fd76):

screenshot from 2017-09-08 10-39-51

chauncey-garrett avatar Sep 08 '17 15:09 chauncey-garrett

@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: screen shot 2017-09-08 at 12 04 44 pm

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

abest0 avatar Sep 08 '17 16:09 abest0

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.

docwhat avatar Mar 02 '18 04:03 docwhat

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.

joshzcold avatar Dec 06 '21 16:12 joshzcold