apple / pkl-intellij

JetBrains editor plugins providing Pkl language support
https://pkl-lang.org/intellij/current/index.html
Apache License 2.0
48 stars 10 forks source link

"Reformat" breaks the pkl file validity #26

Open asm0dey opened 4 months ago

asm0dey commented 4 months ago

Let's say I have a poorly-formatted, but working file:

x = new Dynamic {
  modno = 33
  version = 1
  host = "blog"
  repos {
    new Dynamic {
      id = "ban-bot"
      uri = "url:/restic/ban-bot"
      password = "redacted"prunePolicy {
        maxFrequencyDays = 7
        maxUnusedPercent = 25
      }
    }
 };
 plans { new Dynamic { id = "ban-bot";
 repo = "ban-bot";
 paths { "xxx" };
 cron = "50 0 * * *";
 retention { policyTimeBucketed { hourly = 24;
 daily = 7;
 weekly = 4;
 monthly = 6;
 yearly = 2 } };
 hooks { new Dynamic { conditions { "CONDITION_ANY_ERROR" };
 actionGotify { baseUrl = "gotify";
 token = "redacted";
 template = "{{ .Summary }}";
 titleTemplate = "Backrest {{ .EventName .Event }} in plan {{ .Plan.Id }}" } } } };
 };
 auth { users { new Dynamic { name = "asm0dey";
 passwordBcrypt = "redacted" } } } }

When I run the command

pkl eval -f json test.pkl

It successfully compiles an expected json. However, when I execute a "Reformat" action (and I do it all the time), I get the following:

x = new Dynamic {
  modno = 33
  version = 1
  host = "blog"
  repos {
    new Dynamic {
      id = "ban-bot"
      uri = "url:/restic/ban-bot"
      password = "redacted"prunePolicy {
        maxFrequencyDays = 7
        maxUnusedPercent = 25
      }
    }
  }plans { new Dynamic { id = "ban-bot"repo = "ban-bot"paths { "xxx" }cron = "50 0 * * *"retention { policyTimeBucketed { hourly = 24daily = 7weekly = 4monthly = 6yearly = 2 } }hooks { new Dynamic { conditions { "CONDITION_ANY_ERROR" }actionGotify { baseUrl = "gotify"token = "redacted"template = "{{ .Summary }}"titleTemplate = "Backrest {{ .EventName .Event }} in plan {{ .Plan.Id }}" } } } } }auth { users { new Dynamic { name = "asm0dey"passwordBcrypt = "redacted" } } } }

This file cannot be compiled to JSON anymore.

I would expect the "Reformat" to not break my code and, if possible, align it.

My environment:

IntelliJ IDEA 2024.1 (Ultimate Edition)
Build #IU-241.14494.240, built on March 28, 2024
...
Runtime version: 17.0.10+8-b1207.12 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.6.27-1-lts
...
Memory: 4040M
Cores: 16
Registry:
  debugger.auto.attach.from.console=true
  ide.experimental.ui=true
  llm.generate.commit.summary=true
  terminal.new.ui=true
  markdown.open.vcs.log.link=true
  search.everywhere.preview=true
  ide.smart.update=true
  editor.minimap.enabled=true
  jetbrains.tbe.show.error.popup=true
  shared.indexes.download.auto.consent=true
  jetbrains.tbe.branding.icon.show=false
Non-Bundled Plugins:
  com.intellij.grazie.pro (0.3.298)
  DevKit (241.14494.247)
  org.jetbrains.plugins.hocon (2024.1.0)
  org.pkl (0.26.0)
  woaini.liquibase.plugin (1.3-SNAPSHOT)
  com.intellij.ml.llm (241.14494.320)
  kotest-plugin-intellij (1.3.74-241.9959-EAP-CANDIDATE-SNAPSHOT)
  org.jetbrains.toolbox-enterprise-client (2024.3.0.2860-ij241)
  com.intellij.git.instant (1.3.8)
Kotlin: 241.14494.240-IJ
Current Desktop: KDE
bioball commented 4 months ago

Whew, that's a pretty ugly result from formatting. Thanks for the report.

thefallentree commented 2 months ago

the problem here is semicollon.

If you remove all the semicollons it should format correctly

asm0dey commented 2 months ago

Thanks for the answer! According to the docs, semicolon is an allowed delimiter. If it's not supported, I would expect it to be highlighted by the IDE. Also, IIRC, I got this ill-formatted pkl from the json module during import.

asm0dey commented 2 months ago

Just checked, when I use the following command:

pkl eval -p input="$(cat my.json)" -x 'new Parser {}.parse(read("prop:input"))' pkl:json

I've got an output that cannot be formatted by IDEA

bioball commented 2 months ago

Semicolons are treated as whitespace in Pkl. FYI; our style guide is to use them to separate inline object members--if object members are on their own line, semicolons should be omitted.

asm0dey commented 2 months ago

Got you, thanks! I think they should be underlined as incorrect then

thefallentree commented 2 months ago

Don’t get me wrong: I am just pointing out the problem that case formattter to act up is semicolon, it can be worked around by just removing every thing, but it’s better to be fixed .