ngalaiko / tree-sitter-go-template

Golang template grammar for tree-sitter
MIT License
74 stars 27 forks source link

docs(README): add combined injections #11

Open baptman21 opened 9 months ago

baptman21 commented 9 months ago

Following #4 , we only need injections with the combined option to get a better result, this should fix most render issues, maybe even the ones in #10 but this needs to be checked.

In the mean time this injection gives a better render.

baptman21 commented 9 months ago

I also added the injections file, we need to check if adding it in the queries directory makes it usable without manually adding it.

qvalentin commented 9 months ago

I think I found a case where this does not work correctly:

{{ if .Values }}
        - name: {{ .Chart.Name }}-{{ $variable }}
          image: "test"
{{- end }}    

the yaml after $variable is not rendered correctly.

Can we fix this?

Edit: I guess i know, why this is not working, correct me if I'm wrong. The injected yaml looks like this, which is not highlighted correctly by the yaml grammar.


        - name:                  -               
          image: "test"

With the combined injections, this will break the yaml highlighting for the rest of the file, the old option would only break one line.

Other than that I can confirm that this fixes the issues described in https://github.com/ngalaiko/tree-sitter-go-template/issues/3, so https://github.com/ngalaiko/tree-sitter-go-template/pull/10 would not be needed anymore.

kmoschcau commented 8 months ago

@qvalentin I just tinkered around with this myself and it can be fixed by quoting the value like so:

- name: "{{ .Chart.Name }}-{{ $variable }}"

That should be good practice anyway and won't risk breaking the generated yaml, if the template values evaluate to whitespace.

qvalentin commented 8 months ago

I'm also fine with merging this, I just wanted to point out what I noticed.

qvalentin commented 8 months ago

Did I just find another case? I can't really explain this one.

spec:
  triggers:
  - type: prometheus
    metadata:
      query: sum(rate(http_requests_total{deployment="my-deployment"}[2m]))
      quer: test
      broken: highlight
cabrinha commented 3 months ago

Did I just find another case? I can't really explain this one.

spec:
  triggers:
  - type: prometheus
    metadata:
      query: sum(rate(http_requests_total{deployment="my-deployment"}[2m]))
      quer: test
      broken: highlight

the query should be wrapped in single quotes.

cabrinha commented 3 months ago

I think I found a case where this does not work correctly:

{{ if .Values }}
        - name: {{ .Chart.Name }}-{{ $variable }}
          image: "test"
{{- end }}    

the yaml after $variable is not rendered correctly.

Can we fix this?

Edit: I guess i know, why this is not working, correct me if I'm wrong. The injected yaml looks like this, which is not highlighted correctly by the yaml grammar.

        - name:                  -               
          image: "test"

With the combined injections, this will break the yaml highlighting for the rest of the file, the old option would only break one line.

Other than that I can confirm that this fixes the issues described in #3, so #10 would not be needed anymore.

This is expected and not an issue.

Screenshot 2024-05-16 at 3 52 38 PM

qvalentin commented 3 months ago

@baptman21 lets merge this, it is also already included in https://github.com/nvim-treesitter/nvim-treesitter like this already.