Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into release-0.66.0
  • Loading branch information
TwitchBronBron committed Jul 5, 2023
2 parents 8d02c4d + 225b90b commit 4e5b637
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/DiagnosticCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('DiagnosticCollection', () => {
expect(actual).to.eql(expected);
}

it('does not crash for diagnostics with missing locations', () => {
const [d1] = addDiagnostics('file1.brs', ['I have no location']);
delete d1.range;
testPatch({
'file1.brs': ['I have no location']
});
});

it('returns full list of diagnostics on first call, and nothing on second call', () => {
addDiagnostics('file1.brs', ['message1', 'message2']);
addDiagnostics('file2.brs', ['message3', 'message4']);
Expand Down Expand Up @@ -96,8 +104,9 @@ describe('DiagnosticCollection', () => {
}

function addDiagnostics(srcPath: string, messages: string[]) {
const newDiagnostics = [];
for (const message of messages) {
diagnostics.push({
newDiagnostics.push({
file: {
srcPath: srcPath
} as BscFile,
Expand All @@ -107,5 +116,7 @@ describe('DiagnosticCollection', () => {
message: message
});
}
diagnostics.push(...newDiagnostics);
return newDiagnostics as typeof diagnostics;
}
});
12 changes: 8 additions & 4 deletions src/DiagnosticCollection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BsDiagnostic } from './interfaces';
import type { Project } from './LanguageServer';
import { util } from './util';

export class DiagnosticCollection {
private previousDiagnosticsByFile = {} as Record<string, KeyedDiagnostic[]>;
Expand Down Expand Up @@ -36,13 +37,16 @@ export class DiagnosticCollection {
}
const diagnosticMap = result[srcPath];

//fall back to a default range if missing
const range = diagnostic?.range ?? util.createRange(0, 0, 0, 0);

diagnostic.key =
srcPath.toLowerCase() + '-' +
diagnostic.code + '-' +
diagnostic.range.start.line + '-' +
diagnostic.range.start.character + '-' +
diagnostic.range.end.line + '-' +
diagnostic.range.end.character +
range.start.line + '-' +
range.start.character + '-' +
range.end.line + '-' +
range.end.character +
diagnostic.message;

//don't include duplicates
Expand Down

0 comments on commit 4e5b637

Please sign in to comment.