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):
[x] Playground line/column highlighting should use these line/column numbers
[x] VSCode plugin should use these line/column numbers
[x] Discord bot should use these line/column numbers
Here's an example of it working in the CLI (improved error display to match Playground and bot):
Other changes:
Migrate from source/util.civet to Hera's source/sourcemap.civet. This was left as a TODO. Notably, changed the export from util to sourcemap.
SourceMap now directly exported
ParseError now exported
isCompileError checks for ParseError and ParseErrors
API change: Calling Civet.compile with errors: [] already in options will prevent ParseErrors from being thrown. This is important for e.g. the LSP which wants a compiled version in addition to the errors. Previously, you could achieve this behavior only by calling compile with ast: true and then calling generate separately.
CLI error display now shows where the error occurs with ^ instead of just line and column numbers (and no more stack trace)
Fixes #1251
(modulo TODOs below)The basic idea is, during
generate
, to translate an"Error"
node into aParseError
object with the current source-mapped location. This only works withsourceMap
enabled, so in some cases I callgenerate
a second time in case of error + no source maps. I also had to tweak the source mapping code to tracksrcLine
andsrcColumn
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 ofParseError
objects instead of"Error"
nodes. So far I've just consumed these inmain.civet
when buildingParseErrors
, which now has the array ofParseError
objects, and gives line/column feedback in the CLI ortestCase
.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:
Here's an example of it working in VSCode:
Here's an example of it working with Discord bot:
Here's an example of it working in the CLI (improved error display to match Playground and bot):
Other changes:
source/util.civet
to Hera'ssource/sourcemap.civet
. This was left as a TODO. Notably, changed the export fromutil
tosourcemap
.SourceMap
now directly exportedParseError
now exportedisCompileError
checks forParseError
andParseErrors
Civet.compile
witherrors: []
already inoptions
will preventParseErrors
from being thrown. This is important for e.g. the LSP which wants a compiled version in addition to the errors. Previously, you could achieve this behavior only by callingcompile
withast: true
and then callinggenerate
separately.^
instead of just line and column numbers (and no more stack trace)