@@ -127,35 +127,49 @@ export function parseSarifLocation(
127127 userVisibleFile
128128 } as ParsedSarifLocation ;
129129 } else {
130- const region = physicalLocation . region ;
131- // We assume that the SARIF we're given always has startLine
132- // This is not mandated by the SARIF spec, but should be true of
133- // SARIF output by our own tools.
134- const startLine = region . startLine ! ;
135-
136- // These defaults are from SARIF 2.1.0 spec, section 3.30.2, "Text Regions"
137- // https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/sarif-v2.1.0-cs01.html#_Ref493492556
138- const endLine = region . endLine === undefined ? startLine : region . endLine ;
139- const startColumn = region . startColumn === undefined ? 1 : region . startColumn ;
140-
141- // We also assume that our tools will always supply `endColumn` field, which is
142- // fortunate, since the SARIF spec says that it defaults to the end of the line, whose
143- // length we don't know at this point in the code.
144- //
145- // It is off by one with respect to the way vscode counts columns in selections.
146- const endColumn = region . endColumn ! - 1 ;
130+ const region = parseSarifRegion ( physicalLocation . region ) ;
147131
148132 return {
149133 uri : effectiveLocation ,
150134 userVisibleFile,
151- startLine,
152- startColumn,
153- endLine,
154- endColumn,
135+ ...region
155136 } ;
156137 }
157138}
158139
140+ export function parseSarifRegion (
141+ region : Sarif . Region
142+ ) : {
143+ startLine : number ,
144+ endLine : number ,
145+ startColumn : number ,
146+ endColumn : number
147+ } {
148+ // The SARIF we're given should have a startLine, but we
149+ // fall back to 1, just in case something has gone wrong.
150+ const startLine = region . startLine ?? 1 ;
151+
152+ // These defaults are from SARIF 2.1.0 spec, section 3.30.2, "Text Regions"
153+ // https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/sarif-v2.1.0-cs01.html#_Ref493492556
154+ const endLine = region . endLine === undefined ? startLine : region . endLine ;
155+ const startColumn = region . startColumn === undefined ? 1 : region . startColumn ;
156+
157+ // Our tools should always supply `endColumn` field, which is fortunate, since
158+ // the SARIF spec says that it defaults to the end of the line, whose
159+ // length we don't know at this point in the code. We fall back to 1,
160+ // just in case something has gone wrong.
161+ //
162+ // It is off by one with respect to the way vscode counts columns in selections.
163+ const endColumn = ( region . endColumn ?? 1 ) - 1 ;
164+
165+ return {
166+ startLine,
167+ startColumn,
168+ endLine,
169+ endColumn
170+ } ;
171+ }
172+
159173export function isNoLocation ( loc : ParsedSarifLocation ) : loc is NoLocation {
160174 return 'hint' in loc ;
161175}
0 commit comments