martinda / Jenkinsfile-vim-syntax

Jenkinsfile DSL vim syntax
MIT License
169 stars 26 forks source link

Add autoindent support #1

Open chauncey-garrett opened 7 years ago

chauncey-garrett commented 7 years ago

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

abest0 commented 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

martinda commented 7 years ago

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

chauncey-garrett commented 7 years ago

@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 commented 7 years ago

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

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

abest0 commented 7 years ago

@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

docwhat commented 6 years ago

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.

joshzcold commented 2 years ago

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.