Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prevent crash when diagnostic is missing range
  • Loading branch information
TwitchBronBron committed Jul 5, 2023
commit b16ef4f6504d511abc01aefdafdb937d39b17aff
26 changes: 26 additions & 0 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as fsExtra from 'fs-extra';
import { createSandbox } from 'sinon';
import { DiagnosticMessages } from './DiagnosticMessages';
import { tempDir, rootDir } from './testHelpers.spec';
import { Program } from './Program';

const sinon = createSandbox();

Expand Down Expand Up @@ -38,6 +39,31 @@ describe('util', () => {
});
});

describe('diagnosticIsSuppressed', () => {
it('does not crash when diagnostic is missing location information', () => {
const program = new Program({});
const file = program.setFile('source/main.brs', '');
const diagnostic = {
file: file,
message: 'crash',
//important part of the test. range must be missing
range: undefined
};

file.commentFlags.push({
affectedRange: util.createRange(1, 2, 3, 4),
codes: [1, 2, 3],
file: file,
range: util.createRange(1, 2, 3, 4)
});
file.diagnostics.push(diagnostic);

util.diagnosticIsSuppressed(diagnostic);

//test passes if there's no crash
});
});

describe('getRokuPkgPath', () => {
it('replaces more than one windows slash in a path', () => {
expect(util.getRokuPkgPath('source\\folder1\\folder2\\file.brs')).to.eql('pkg:/source/folder1/folder2/file.brs');
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export class Util {
const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
for (let flag of diagnostic.file?.commentFlags ?? []) {
//this diagnostic is affected by this flag
if (this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
if (diagnostic.range && this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
//if the flag acts upon this diagnostic's code
if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
return true;
Expand Down