Merge pull request #74646 from mjbvz/dont-update-js-ts-diagnostics-if-they-have-not-changed

Don't update js ts diagnostics if they have not changed
This commit is contained in:
Matt Bierner 2019-06-03 11:35:48 -07:00 committed by GitHub
commit 5ce891fae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 17 deletions

View file

@ -6,6 +6,25 @@
import * as vscode from 'vscode';
import { ResourceMap } from '../utils/resourceMap';
import { DiagnosticLanguage, allDiagnosticLanguages } from '../utils/languageDescription';
import * as arrays from '../utils/arrays';
function diagnosticsEquals(a: vscode.Diagnostic, b: vscode.Diagnostic): boolean {
if (a === b) {
return true;
}
return a.code === b.code
&& a.message === b.message
&& a.severity === b.severity
&& a.source === b.source
&& a.range.isEqual(b.range)
&& arrays.equals(a.relatedInformation || arrays.empty, b.relatedInformation || arrays.empty, (a, b) => {
return a.message === b.message
&& a.location.range.isEqual(b.location.range)
&& a.location.uri.fsPath === b.location.uri.fsPath;
})
&& arrays.equals(a.tags || arrays.empty, b.tags || arrays.empty);
}
export const enum DiagnosticKind {
Syntax,
@ -31,12 +50,10 @@ class FileDiagnostics {
this.language = language;
}
if (diagnostics.length === 0) {
const existing = this._diagnostics.get(kind);
if (!existing || existing && existing.length === 0) {
// No need to update
return false;
}
const existing = this._diagnostics.get(kind);
if (arrays.equals(existing || arrays.empty, diagnostics, diagnosticsEquals)) {
// No need to update
return false;
}
this._diagnostics.set(kind, diagnostics);

View file

@ -2,20 +2,23 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function equals<T>(one: ReadonlyArray<T>, other: ReadonlyArray<T>, itemEquals: (a: T, b: T) => boolean = (a, b) => a === b): boolean {
if (one.length !== other.length) {
export const empty = Object.freeze([]);
export function equals<T>(
a: ReadonlyArray<T>,
b: ReadonlyArray<T>,
itemEquals: (a: T, b: T) => boolean = (a, b) => a === b
): boolean {
if (a === b) {
return true;
}
if (a.length !== b.length) {
return false;
}
for (let i = 0, len = one.length; i < len; i++) {
if (!itemEquals(one[i], other[i])) {
return false;
}
}
return true;
return a.every((x, i) => itemEquals(x, b[i]));
}
export function flatten<T>(arr: ReadonlyArray<T>[]): T[] {
return ([] as T[]).concat.apply([], arr);
return Array.prototype.concat.apply([], arr);
}