Closed Aloso closed 1 year ago
Will have to check if IntelliJ supports the way you plan on reporting offsets.
I'll probably need to find a way to map the byte offsets to editor offsets.
Why not use a UTF-8 char offset instead of byte offset?
Because it's expensive to convert, and I'm not even sure this would be more useful for everyone. Some tools using the JSON output might need UTF-16 code units instead, or grapheme clusters, or rows and columns. The conversion to code point indices would be wasted when users have to convert them to something else again.
@lppedd this is now implemented on the master branch. You can try it out by installing Rust and running cargo install --path pomsky-bin
. I won't release a new version right away, I first need to write tests for the new functionality.
Is your feature request related to a problem? Please describe.
Tools such as IDE plugins need Pomsky's output in a machine-readable format. There are multiple ways to achieve this:
pomsky
crate and distribute it as part of their toolThe solution I'm proposing is number 3 since I think it offers the best experience both for users and tool authors: Users need to have the CLI installed, but they don't have to download anything else, and tool authors don't need to update their tools every time a new Pomsky version is released.
Describe the solution you'd like
Add a
--json
flag to print all compilation results as JSON rather than plain text. The JSON is written to stdout on a single line. It's an object with the following structure:Example when running
pomsky '\b' --json
Byte offsets are zero-indexed, e.g. the first byte has the span
{ "start": 0, "end": 1 }
.The input is always treated as UTF-8, so the characters in the string
a💩ø
have the spans{ "start": 0, "end": 1 }
,{ "start": 1, "end": 5 }
and{ "start": 5, "end": 7 }
.Describe alternatives you've considered
There are other formats than JSON, like XML and MessagePack, but they're less widely supported, and JSON should be fast enough.
Instead of reporting byte offsets, Pomsky could return row and column positions. However, that requires more work, and may not even work for every tool, since different IDEs have different plugin interfaces. Furthermore, UTF-8 has an exact definition, whereas rows and columns aren't well defined in the context of Unicode.
Future possibilities
We can keep the CLI running in the background, so tools can write to stdin and get a response at stdout, without having to spawn a process each time.
We can add a
--check
flag that returns diagnostics but doesn't actually compile the expression, which should be faster. This could then be used to report errors on every keystroke.