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

View file

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