Skip to content

Commit 0b9dd9e

Browse files
committed
during file update request only changed portion of the text from the host
1 parent eaee9ec commit 0b9dd9e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/services/services.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,34 @@ module ts {
18281828
if (version !== sourceFile.version) {
18291829
// Once incremental parsing is ready, then just call into this function.
18301830
if (!disableIncrementalParsing) {
1831-
let newSourceFile = updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange, aggressiveChecks);
1831+
let newText: string;
1832+
1833+
// grab the fragment from the beginning of the original text to the beginning of the span
1834+
let prefix = textChangeRange.span.start !== 0
1835+
? sourceFile.text.substr(0, textChangeRange.span.start)
1836+
: "";
1837+
1838+
// grab the fragment from the end of the span till the end of the original text
1839+
let suffix = textChangeRange.span.start + textChangeRange.span.length !== sourceFile.text.length
1840+
? sourceFile.text.substr(textChangeRange.span.start + textChangeRange.span.length)
1841+
: "";
1842+
1843+
if (textChangeRange.newLength === 0) {
1844+
// edit was a deletion - just combine prefix and suffix
1845+
newText = prefix && suffix ? prefix + suffix : prefix || suffix;
1846+
}
1847+
else {
1848+
// it was actual edit, fetch the fragment of new text that correspond to new span
1849+
let changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength);
1850+
// combine prefix, changed text and suffix
1851+
newText = prefix && suffix
1852+
? prefix + changedText + suffix
1853+
: prefix
1854+
? (prefix + changedText)
1855+
: (changedText + suffix);
1856+
}
1857+
1858+
let newSourceFile = updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
18321859
setSourceFileFields(newSourceFile, scriptSnapshot, version);
18331860
// after incremental parsing nameTable might not be up-to-date
18341861
// drop it so it can be lazily recreated later

0 commit comments

Comments
 (0)