fix schema compare diff script formatting (#5486)

This commit is contained in:
kisantia
2019-05-15 09:03:14 -07:00
committed by GitHub
parent cc397a012f
commit 8c05c6e122
2 changed files with 21 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "1.5.0-alpha.91",
"version": "1.5.0-alpha.93",
"downloadFileNames": {
"Windows_86": "win-x86-netcoreapp2.2.zip",
"Windows_64": "win-x64-netcoreapp2.2.zip",

View File

@@ -237,8 +237,8 @@ export class SchemaCompareResult {
this.differencesTable.onRowSelected(() => {
let difference = this.comparisonResult.differences[this.differencesTable.selectedRows[0]];
if (difference !== undefined) {
sourceText = difference.sourceScript === null ? '\n' : this.getAggregatedScript(difference, true);
targetText = difference.targetScript === null ? '\n' : this.getAggregatedScript(difference, false);
sourceText = this.getFormattedScript(difference, true);
targetText = this.getFormattedScript(difference, false);
this.diffEditor.updateProperties({
contentLeft: sourceText,
@@ -264,15 +264,29 @@ export class SchemaCompareResult {
return data;
}
private getFormattedScript(diffEntry: azdata.DiffEntry, getSourceScript: boolean): string {
// if there is no entry, the script has to be \n because an empty string shows up as a difference but \n doesn't
if ((getSourceScript && diffEntry.sourceScript === null)
|| (!getSourceScript && diffEntry.targetScript === null)) {
return '\n';
}
let script = this.getAggregatedScript(diffEntry, getSourceScript);
return script;
}
private getAggregatedScript(diffEntry: azdata.DiffEntry, getSourceScript: boolean): string {
let script = '';
if (diffEntry !== null) {
script += getSourceScript ? diffEntry.sourceScript : diffEntry.targetScript;
let diffEntryScript = getSourceScript ? diffEntry.sourceScript : diffEntry.targetScript;
if (diffEntryScript) {
// add a blank line between each statement
script += diffEntryScript + '\n\n';
}
diffEntry.children.forEach(child => {
let childScript = this.getAggregatedScript(child, getSourceScript);
if (childScript !== 'null') {
script += childScript;
}
script += childScript;
});
}
return script;