@@ -56,7 +56,7 @@ def message(self):
56
56
"""
57
57
return self .reason .format (** self .arguments )
58
58
59
- def render (self ):
59
+ def render (self , only_line = False ):
60
60
"""
61
61
Returns the human-readable location of the diagnostic in the source,
62
62
the formatted message, the source line corresponding
@@ -66,9 +66,11 @@ def render(self):
66
66
67
67
For example: ::
68
68
69
- <input>:1:8: error: cannot add integer and string
69
+ <input>:1:8-9 : error: cannot add integer and string
70
70
x + (1 + "a")
71
71
~ ^ ~~~
72
+
73
+ :param only_line: (bool) If true, only print line number, not line and column range
72
74
"""
73
75
source_line = self .location .source_line ().rstrip ("\n " )
74
76
highlight_line = bytearray (" " , "utf-8" ) * len (source_line )
@@ -83,11 +85,16 @@ def render(self):
83
85
rgt = lft + 1
84
86
highlight_line [lft :rgt ] = bytearray ("^" , "utf-8" ) * (rgt - lft )
85
87
88
+ if only_line :
89
+ location = "%s:%s" % (self .location .source_buffer .name , self .location .line ())
90
+ else :
91
+ location = str (self .location )
92
+
86
93
return [
87
- "%s: %s: %s" % (str ( self . location ) , self .level , self .message ()),
94
+ "%s: %s: %s" % (location , self .level , self .message ()),
88
95
source_line ,
89
96
highlight_line .decode ("utf-8" )
90
- ] + reduce (list .__add__ , [note .render () for note in self .notes ], [])
97
+ ] + reduce (list .__add__ , [note .render (only_line ) for note in self .notes ], [])
91
98
92
99
93
100
class Error (Exception ):
0 commit comments