apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
9.85k stars 258 forks source link

better source listing for IntelliJ to include line numbers? #479

Closed jstrachan closed 1 month ago

jstrachan commented 1 month ago

when running pkl test inside IntelliJ as a command we get nice links to source files in the output when things fail

e.g. the output is something like this...

at something.orOther (file://someFileURL, line 34) 

clicking on those file URLs work and the source is opened - at line 1

if we modified the output ever so slightly to be....

at something.orOther (file://someFileURL:34) 

then IntelliJ would open the file at the line 34 if you click on the above link which would help folks navigate to the source of an error/test failure more quickly

bioball commented 1 month ago

You can use a settings file to modify how stack frames get presented. This will produce links that will get opened in IntelliJ:

amends "pkl:settings"

editor = Idea

Here's my personal one, which outputs anchors (supported by iTerm 2, not sure about other terminals)

amends "pkl:settings"

local schema: String = "idea"

// https://iterm2.com/documentation-escape-codes.html
local ESC: String = "\u{1B}"
local OSC8: String = "\(ESC)]8"
local ST: String = "\(ESC)\\"
local COLOR_DIM_BLUE: String = "\(ESC)[2;34m"
local COLOR_RESET: String = "\(ESC)[0m"

editor {
  urlScheme = "\(COLOR_DIM_BLUE)\(OSC8);;\(schema)://open?file=%{path}&line=%{line}\(ST)%{path}:%{line}\(OSC8);;\(ST)\(COLOR_RESET)"
}

Screenshot 2024-05-07 at 7 45 03 AM

jstrachan commented 1 month ago

love that! would be good to add to the docs