DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.55k stars 33 forks source link

Error nodes, ParseErrors get source-mapped location #1262

Closed edemaine closed 6 months ago

edemaine commented 6 months ago

Fixes #1251 (modulo TODOs below)

The basic idea is, during generate, to translate an "Error" node into a ParseError object with the current source-mapped location. This only works with sourceMap enabled, so in some cases I call generate a second time in case of error + no source maps. I also had to tweak the source mapping code to track srcLine and srcColumn too. (Early versions of this PR confused the source and output line/column numbers, but this is now resolved.)

Now options.errors becomes a list of ParseError objects instead of "Error" nodes. So far I've just consumed these in main.civet when building ParseErrors, which now has the array of ParseError objects, and gives line/column feedback in the CLI or testCase.

TODO (possibly in future PRs):

Prerequisite:

Relies on https://github.com/DanielXMoore/Hera/pull/18 so tests won't work without npm link until that gets released.

Examples:

Here's an example of it working in Playground:

image

Here's an example of it working in VSCode:

image

Here's an example of it working with Discord bot:

image

Here's an example of it working in the CLI (improved error display to match Playground and bot):

image

Other changes:

edemaine commented 6 months ago

Or a separate @danielx/sourcemap package? But yeah, Hera already depends on Civet, so makes sense to just use in that way.