summaryrefslogtreecommitdiff
path: root/lib/error_highlight
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-07-13 16:47:35 +0900
committergit <svn-admin@ruby-lang.org>2021-07-13 16:51:02 +0900
commit23c8bc367c6d700789a4059b831606966efb674c (patch)
tree1bf9d11d155292e6be55cf66a27043ad720973c9 /lib/error_highlight
parentb18f6fff69c4a3904f6714ab107ba48745df42f7 (diff)
[ruby/error_highlight] Support hard tabs
Now, the highlight line is created by replacing non-tab characters with spaces, and keeping all hard tabs as-is. This means the highlight line has the completely same indentation as the code snippet line. Fixes #7 https://github.com/ruby/error_highlight/commit/38f20fa542
Diffstat (limited to 'lib/error_highlight')
-rw-r--r--lib/error_highlight/formatter.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb
index a3d6510dc2..ce687fb2a2 100644
--- a/lib/error_highlight/formatter.rb
+++ b/lib/error_highlight/formatter.rb
@@ -3,7 +3,8 @@ module ErrorHighlight
def message_for(spot)
# currently only a one-line code snippet is supported
if spot[:first_lineno] == spot[:last_lineno]
- marker = " " * spot[:first_column] + "^" * (spot[:last_column] - spot[:first_column])
+ indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
+ marker = indent + "^" * (spot[:last_column] - spot[:first_column])
"\n\n#{ spot[:snippet] }#{ marker }"
else