From 1207fcb13539472a91169a3ac0adfc8739d5da1c Mon Sep 17 00:00:00 2001 From: Michael Ambrose Date: Tue, 22 Apr 2025 22:25:23 -0400 Subject: [PATCH 1/2] Fix issue with formatter attempting to format merge conflict markers (#850) --- src/formatter/textmate.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/formatter/textmate.ts b/src/formatter/textmate.ts index 5f804e08..046743dd 100644 --- a/src/formatter/textmate.ts +++ b/src/formatter/textmate.ts @@ -243,6 +243,10 @@ function is_comment(line: TextLine): boolean { return line.text[line.firstNonWhitespaceCharacterIndex] === "#"; } +function is_merge_conflict(line: TextLine): boolean { + return (line.startsWith('<<<<<<<') || line.startsWith('=======') || line.startsWith('>>>>>>>')); +} + export function format_document(document: TextDocument, _options?: FormatterOptions): TextEdit[] { // quit early if grammar is not loaded if (!grammar) { @@ -295,6 +299,11 @@ export function format_document(document: TextDocument, _options?: FormatterOpti continue; } + // skip merge conflicts markers + if (is_merge_conflict(line)) { + continue; + } + let nextLine = ""; lineTokens = grammar.tokenizeLine(line.text, lineTokens?.ruleStack ?? vsctm.INITIAL); From c6dae3c4f215769ec8d7e27d04f9485931aed378 Mon Sep 17 00:00:00 2001 From: Michael Ambrose Date: Thu, 24 Apr 2025 17:15:46 -0400 Subject: [PATCH 2/2] Fix issue where string checks are run on vsCode TextLine object and not actual contents of the line --- src/formatter/textmate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter/textmate.ts b/src/formatter/textmate.ts index 046743dd..5643b925 100644 --- a/src/formatter/textmate.ts +++ b/src/formatter/textmate.ts @@ -244,7 +244,7 @@ function is_comment(line: TextLine): boolean { } function is_merge_conflict(line: TextLine): boolean { - return (line.startsWith('<<<<<<<') || line.startsWith('=======') || line.startsWith('>>>>>>>')); + return (line.text.startsWith('<<<<<<<') || line.text.startsWith('=======') || line.text.startsWith('>>>>>>>')); } export function format_document(document: TextDocument, _options?: FormatterOptions): TextEdit[] {