Add support for diff3-style conflict

This commit is contained in:
Kate Miháliková 2017-05-29 13:40:41 +02:00
parent bcf84f4958
commit e3e81b8673
No known key found for this signature in database
GPG key ID: 1514D3C02EC152B0
2 changed files with 22 additions and 10 deletions

View file

@ -429,6 +429,7 @@ namespace ts {
case CharacterCodes.slash:
// starts of normal trivia
case CharacterCodes.lessThan:
case CharacterCodes.bar:
case CharacterCodes.equals:
case CharacterCodes.greaterThan:
// Starts of conflict marker trivia
@ -496,6 +497,7 @@ namespace ts {
break;
case CharacterCodes.lessThan:
case CharacterCodes.bar:
case CharacterCodes.equals:
case CharacterCodes.greaterThan:
if (isConflictMarkerTrivia(text, pos)) {
@ -562,12 +564,12 @@ namespace ts {
}
}
else {
Debug.assert(ch === CharacterCodes.equals);
// Consume everything from the start of the mid-conflict marker to the start of the next
// end-conflict marker.
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
// Consume everything from the start of a ||||||| or ======= marker to the start
// of the next ======= or >>>>>>> marker.
while (pos < len) {
const ch = text.charCodeAt(pos);
if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) {
const currentChar = text.charCodeAt(pos);
if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
break;
}
@ -1562,6 +1564,16 @@ namespace ts {
pos++;
return token = SyntaxKind.OpenBraceToken;
case CharacterCodes.bar:
if (isConflictMarkerTrivia(text, pos)) {
pos = scanConflictMarkerTrivia(text, pos, error);
if (skipTrivia) {
continue;
}
else {
return token = SyntaxKind.ConflictMarkerTrivia;
}
}
if (text.charCodeAt(pos + 1) === CharacterCodes.bar) {
return pos += 2, token = SyntaxKind.BarBarToken;
}

View file

@ -685,9 +685,9 @@ namespace ts {
continue;
}
// for the ======== add a comment for the first line, and then lex all
// subsequent lines up until the end of the conflict marker.
Debug.assert(ch === CharacterCodes.equals);
// for the ||||||| and ======== markers, add a comment for the first line,
// and then lex all subsequent lines up until the end of the conflict marker.
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
classifyDisabledMergeCode(text, start, end);
}
}
@ -782,8 +782,8 @@ namespace ts {
}
function classifyDisabledMergeCode(text: string, start: number, end: number) {
// Classify the line that the ======= marker is on as a comment. Then just lex
// all further tokens and add them to the result.
// Classify the line that the ||||||| or ======= marker is on as a comment.
// Then just lex all further tokens and add them to the result.
let i: number;
for (i = start; i < end; i++) {
if (isLineBreak(text.charCodeAt(i))) {