@@ -117,13 +117,25 @@ private static int readNum(ByteArrayInputStream offsets) {
117
117
}
118
118
119
119
public static SourceSection getSourceSection (Source source , int startLine , int startColumn , int endLine , int endColumn ) {
120
- if (source == null || ! source . hasCharacters () ) {
120
+ if (source == null ) {
121
121
return null ;
122
+ } else if (!source .hasCharacters ()) {
123
+ return source .createUnavailableSection ();
124
+ }
125
+ try {
126
+ /* Truffle columns are 1-based */
127
+ startColumn = Math .max (startColumn + 1 , 1 );
128
+ endColumn = Math .max (endColumn + 1 , 1 );
129
+ /* Truffle doesn't consider the newline a part of the line */
130
+ if (endColumn == source .getLineLength (endLine ) + 1 ) {
131
+ endColumn --;
132
+ }
133
+ return source .createSection (startLine , startColumn , endLine , endColumn );
134
+ } catch (IllegalArgumentException e ) {
135
+ // TODO GR-40896 we don't track source ranges of f-strings correctly
136
+ // Also consider sources created from ast module
137
+ return source .createUnavailableSection ();
122
138
}
123
- /* Truffle columns are 1-based and it doesn't consider the newline a part of the line */
124
- startColumn = Math .max (startColumn + 1 , 1 );
125
- endColumn = Math .max (Math .min (endColumn + 1 , source .getLineLength (endLine )), 1 );
126
- return source .createSection (startLine , startColumn , endLine , endColumn );
127
139
}
128
140
129
141
public SourceSection getSourceSection (Source source , int bci ) {
0 commit comments