Skip to content

Commit 43f314b

Browse files
committed
Change missing code snippet handling in UI
Also, simplify sarif tests.
1 parent 4bdf579 commit 43f314b

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

extensions/ql-vscode/src/remote-queries/view/FileCodeSnippet.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ const FileCodeSnippet = ({
188188
messageChildren?: React.ReactNode,
189189
}) => {
190190

191-
const code = codeSnippet?.text.split('\n') || [];
192-
193191
const startingLine = codeSnippet?.startLine || 0;
194192
const endingLine = codeSnippet?.endLine || 0;
195193

@@ -198,6 +196,18 @@ const FileCodeSnippet = ({
198196
startingLine,
199197
endingLine);
200198

199+
if (!codeSnippet) {
200+
return (
201+
<Container>
202+
<TitleContainer>
203+
<Link href={titleFileUri}>{fileLink.filePath}</Link>
204+
</TitleContainer>
205+
</Container>
206+
);
207+
}
208+
209+
const code = codeSnippet.text.split('\n');
210+
201211
return (
202212
<Container>
203213
<TitleContainer>

extensions/ql-vscode/test/pure-tests/sarif-processing.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ describe('SARIF processing', () => {
438438
expect(actualCodeSnippet).to.deep.equal(expectedCodeSnippet);
439439
});
440440

441-
it('should not return errors for result locations with no contextRegion', () => {
441+
it('should use highlightedRegion for result locations with no contextRegion', () => {
442442
const sarif = buildValidSarifLog();
443443
sarif.runs![0]!.results![0]!.locations![0]!.physicalLocation!.contextRegion = undefined;
444444

@@ -623,8 +623,8 @@ describe('SARIF processing', () => {
623623
expect(msg.startsWith('Error when processing SARIF result')).to.be.true;
624624
}
625625

626-
function expectNoParsingError(result: { errors: string[] | undefined }) {
627-
const array = result.errors || [];
626+
function expectNoParsingError(result: { errors: string[] }) {
627+
const array = result.errors;
628628
expect(array.length, array.join()).to.equal(0);
629629
}
630630

0 commit comments

Comments
 (0)