summaryrefslogtreecommitdiff
path: root/lib/error_highlight/formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/error_highlight/formatter.rb')
-rw-r--r--lib/error_highlight/formatter.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb
new file mode 100644
index 0000000000..20ca78d468
--- /dev/null
+++ b/lib/error_highlight/formatter.rb
@@ -0,0 +1,23 @@
+module ErrorHighlight
+ class DefaultFormatter
+ def self.message_for(spot)
+ # currently only a one-line code snippet is supported
+ if spot[:first_lineno] == spot[:last_lineno]
+ indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
+ marker = indent + "^" * (spot[:last_column] - spot[:first_column])
+
+ "\n\n#{ spot[:snippet] }#{ marker }"
+ else
+ ""
+ end
+ end
+ end
+
+ def self.formatter
+ Ractor.current[:__error_highlight_formatter__] || DefaultFormatter
+ end
+
+ def self.formatter=(formatter)
+ Ractor.current[:__error_highlight_formatter__] = formatter
+ end
+end