grafana / vscode-jsonnet

Full code support (formatting, highlighting, navigation, etc) for Jsonnet
Apache License 2.0
66 stars 7 forks source link

Tanka support #27

Closed Almenon closed 1 year ago

Almenon commented 1 year ago

I was evaluating Tanka, following the tutorial, but jsonnet doesn't appear to work with tanka out of the box. In the environments/default/grafana.jsonnet file I see this error:

image

My main.jsonnet looks like so. As you can see, the _config field does exist.

// Think of `import` as copy-pasting the contents
// of ./grafana.jsonnet here
(import "grafana.jsonnet") +
(import "prometheus.jsonnet") +
{
  _config:: {
    grafana: {
      port: 3000,
      name: "grafana",
    },
    prometheus: {
      port: 9090,
      name: "prometheus"
    }
  }
}

This is a two-part issue: 1) Feedback: it would be beneficial for this to work out-of-the-box 2) Feature request / Question: How do I configure the extension to avoid the error above?

julienduchesne commented 1 year ago

Using $ is a flawed way to work, there is no easy way to fix this to my knowledge (one would involve scanning all files in a workspace but that is a pretty cpu intensive process)

The reason is that grafana.libsonnet has no knowledge that the other file exists, therefore we cannot know that the config exists. if you were to import grafana.libsonnet from two different main files, the config would be two different values

What I would recommend instead is to not use the global ´$´ and instead inject what you need through function parameters, like you would do in a programming language. Here’s a jsonnet tutorial that has some very good examples: https://jsonnet-libs.github.io/jsonnet-training-course/lesson3.html

julienduchesne commented 1 year ago

I agree that the Tanka docs are outdated, they should reflect the new best practices, from the learnings of years with jsonnet at Grafana Labs

Almenon commented 1 year ago

Thanks! I'll open up a new issue in the Tanka repo then.