Skip to content

Commit c85adb2

Browse files
committed
Display error context in command-line tool.
1 parent 2814397 commit c85adb2

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎language_tool/__init__.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class Match:
8888
_SLOTS = ("fromy", "fromx", "toy", "tox", "frompos", "topos",
8989
"ruleId", "subId", "msg", "replacements",
9090
"context", "contextoffset", "errorlength")
91-
_INT_SLOTS = {"fromy", "fromx", "toy", "tox", "frompos", "topos"}
91+
_INT_SLOTS = {"fromy", "fromx", "toy", "tox", "frompos", "topos",
92+
"contextoffset", "errorlength"}
9293
_frompos_cache, _topos_cache = None, None
9394

9495
def __init__(self, attrib, text=None):
@@ -123,6 +124,11 @@ def __str__(self):
123124
s += "\nMessage: {}".format(self.msg)
124125
if self.replacements:
125126
s += "\nSuggestion: {}".format("; ".join(self.replacements))
127+
s += "\n{}\n{}".format(
128+
self.context,
129+
" " * self.contextoffset + "^" * self.errorlength +
130+
" " * (len(self.context) - self.contextoffset - self.errorlength)
131+
)
126132
return s
127133

128134
def __getattr__(self, name):

‎language_tool/__main__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def main():
9999
else:
100100
print()
101101
for n, match in enumerate(lang_tool.check(text)):
102-
print("{}.".format(n + 1), match)
102+
print("{}.)".format(n + 1), match)
103103
print()
104104

105105

0 commit comments

Comments
 (0)