@@ -250,6 +250,29 @@ extern "C" {
250
250
if (!got_newline) msg_stream << " \n " ;
251
251
msg_stream << string (msg_prefix.size (), ' ' );
252
252
msg_stream << " on line " << e.pstate .line +1 << " of " << rel_path << " \n " ;
253
+
254
+ // now create the code trace (ToDo: maybe have util functions?)
255
+ if (e.pstate .line != string::npos && e.pstate .column != string::npos) {
256
+ size_t line = e.pstate .line ;
257
+ const char * line_beg = e.pstate .src ;
258
+ while (line_beg && *line_beg && line) {
259
+ if (*line_beg == ' \n ' ) -- line;
260
+ ++ line_beg;
261
+ }
262
+ const char * line_end = line_beg;
263
+ while (line_end && *line_end && *line_end != ' \n ' ) {
264
+ if (*line_end == ' \n ' ) break ;
265
+ if (*line_end == ' \r ' ) break ;
266
+ line_end ++;
267
+ }
268
+ size_t max_left = 42 ; size_t max_right = 78 ;
269
+ size_t move_in = e.pstate .column > max_left ? e.pstate .column - max_left : 0 ;
270
+ size_t shorten = (line_end - line_beg) - move_in > max_right ?
271
+ (line_end - line_beg) - move_in - max_right : 0 ;
272
+ msg_stream << " >> " << string (line_beg + move_in, line_end - shorten) << " \n " ;
273
+ msg_stream << " " << string (e.pstate .column - move_in, ' -' ) << " ^\n " ;
274
+ }
275
+
253
276
c_ctx->error_json = json_stringify (json_err, " " );;
254
277
c_ctx->error_message = sass_strdup (msg_stream.str ().c_str ());
255
278
c_ctx->error_text = strdup (e.message .c_str ());
0 commit comments