dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.38k stars 211 forks source link

yaml templates using text/template and sprig #415

Open webframp opened 1 year ago

webframp commented 1 year ago

Hey there,

Sorry for making an issue if this seems unrelated or has been answered, I searched around and have asked other places to no avail so far.

I deal quite a bit with yaml template files that have inline template syntax, based on text/template and sprig, you can blame kubernetes.

Example snippet:

{{- if .featureflag}}
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app-operator
  name: app-operator
  namespace: app-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app-operator
  strategy:
    type: RollingUpdate
  template:
  ...

or another example:

      containers:
      - name: coredns
        {{- if regexMatch "^1\\.2[34]$" .k8sversion }}
        image: coredns:v1.8.7
        {{- end }}
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            memory: 170Mi
          requests:
            cpu: 100m
            memory: 70Mi

I have yet to find a great mode configuration for working with these and am wondering what people who use go-mode are using, if they have this same scenario.

What I've investigated:

First was of course yaml-mode of course, which is the best I can get so far, but occasionally breaks on some template syntax. This is what I'm currently using by default.

Next I found https://github.com/dominikh/go-mode.el/issues/184 which was talking about go template syntax in web files, but web-mode specifically does not support yaml syntax and it seems it will not be added: https://github.com/fxbois/web-mode/issues/934

Third I was directed to poly-ansible that uses polymode, which seems pretty promising but: 1) pulls in ansible-mode as a dependency and 2) is for jinja2 templates, which while similar are not quite the same as go templates.

Does anyone else using go-mode have this same problem?

No offense if you choose to just close but thanks for any info that might help