Merge pull request #728 from pulumi/hideGoop
Elide our serialized function preamble and postamble when printing user code
This commit is contained in:
commit
3311d32c2d
|
@ -1014,8 +1014,12 @@ func getTextChangeString(old string, new string) string {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
shaRegexp = regexp.MustCompile("__[a-zA-Z0-9]{40}")
|
shaRegexp = regexp.MustCompile("__[a-zA-Z0-9]{40}")
|
||||||
withRegexp = regexp.MustCompile(` with\(\{ .* \}\) \{`)
|
withRegexp = regexp.MustCompile(` with\({ .* }\) {`)
|
||||||
environmentRegexp = regexp.MustCompile(` }\).apply\(.*\).apply\(this, arguments\);`)
|
environmentRegexp = regexp.MustCompile(` }\).apply\(.*\).apply\(this, arguments\);`)
|
||||||
|
preambleRegexp = regexp.MustCompile(
|
||||||
|
`function __shaHash\(\) {\n return \(function\(\) {\n with \(__closure\) {\n\nreturn \(`)
|
||||||
|
postambleRegexp = regexp.MustCompile(
|
||||||
|
`\)\n\n }\n }\).apply\(__environment\).apply\(this, arguments\);\n}`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// massageText takes the text for a function and cleans it up a bit to make the user visible diffs
|
// massageText takes the text for a function and cleans it up a bit to make the user visible diffs
|
||||||
|
@ -1041,19 +1045,28 @@ func massageText(text string) string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
replaceNewlines := func() {
|
||||||
newText := strings.Replace(text, "\n\n\n", "\n\n", -1)
|
for {
|
||||||
if len(newText) == len(text) {
|
newText := strings.Replace(text, "\n\n\n", "\n\n", -1)
|
||||||
break
|
if len(newText) == len(text) {
|
||||||
}
|
break
|
||||||
|
}
|
||||||
|
|
||||||
text = newText
|
text = newText
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replaceNewlines()
|
||||||
|
|
||||||
text = shaRegexp.ReplaceAllString(text, "__shaHash")
|
text = shaRegexp.ReplaceAllString(text, "__shaHash")
|
||||||
text = withRegexp.ReplaceAllString(text, " with (__closure) {")
|
text = withRegexp.ReplaceAllString(text, " with (__closure) {")
|
||||||
text = environmentRegexp.ReplaceAllString(text, " }).apply(__environment).apply(this, arguments);")
|
text = environmentRegexp.ReplaceAllString(text, " }).apply(__environment).apply(this, arguments);")
|
||||||
|
|
||||||
|
text = preambleRegexp.ReplaceAllString(text, "")
|
||||||
|
text = postambleRegexp.ReplaceAllString(text, "")
|
||||||
|
|
||||||
|
replaceNewlines()
|
||||||
|
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1099,25 +1112,27 @@ func diffToPrettyString(diffs []diffmatchpatch.Diff, indent int) string {
|
||||||
}
|
}
|
||||||
lines = trimmedLines
|
lines = trimmedLines
|
||||||
|
|
||||||
|
const contextLines = 2
|
||||||
|
|
||||||
// Show the unchanged text in white.
|
// Show the unchanged text in white.
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
// First chunk of the file.
|
// First chunk of the file.
|
||||||
if len(lines) > 4 {
|
if len(lines) > contextLines+1 {
|
||||||
writeDiff(deploy.OpSame, "...\n")
|
writeDiff(deploy.OpSame, "...\n")
|
||||||
printLines(deploy.OpSame, len(lines)-3, len(lines))
|
printLines(deploy.OpSame, len(lines)-contextLines, len(lines))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else if index == len(diffs)-1 {
|
} else if index == len(diffs)-1 {
|
||||||
if len(lines) > 4 {
|
if len(lines) > contextLines+1 {
|
||||||
printLines(deploy.OpSame, 0, 3)
|
printLines(deploy.OpSame, 0, contextLines)
|
||||||
writeDiff(deploy.OpSame, "...\n")
|
writeDiff(deploy.OpSame, "...\n")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(lines) > 7 {
|
if len(lines) > (2*contextLines + 1) {
|
||||||
printLines(deploy.OpSame, 0, 3)
|
printLines(deploy.OpSame, 0, contextLines)
|
||||||
writeDiff(deploy.OpSame, "...\n")
|
writeDiff(deploy.OpSame, "...\n")
|
||||||
printLines(deploy.OpSame, len(lines)-3, len(lines))
|
printLines(deploy.OpSame, len(lines)-contextLines, len(lines))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue