From 4cce42b832f1e5ef000594f07c3947fd423da309 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Wed, 7 May 2025 22:46:21 +0530 Subject: [PATCH 1/9] prevent markdown table from breaking on formatted nodes --- .../StyledMarkdownPreview/markdown.css | 7 +++++ .../utils/remarkTables.tsx | 26 ++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gui/src/components/StyledMarkdownPreview/markdown.css b/gui/src/components/StyledMarkdownPreview/markdown.css index c2e79b3a6..f975286ba 100644 --- a/gui/src/components/StyledMarkdownPreview/markdown.css +++ b/gui/src/components/StyledMarkdownPreview/markdown.css @@ -1037,3 +1037,10 @@ body[data-color-mode*="light"] { .token.entity { cursor: help; } +/* +.markdown-table th { + background-color: var(--color-fg-muted); +} +.markdown-table td { + background-color: var(--color-fg-subtle); +} */ \ No newline at end of file diff --git a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx index f22542c2f..e5c1ea2f5 100644 --- a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx +++ b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx @@ -22,8 +22,11 @@ import { visit } from "unist-util-visit"; */ export function remarkTables() { return (tree: any) => { - visit(tree, "text", (node, index, parent) => { - const { value } = node; + visit(tree, "paragraph", (paragraphNode, index, parentOfParagraphNode) => { + let buffer = ""; + visit(paragraphNode, "text", (textNode) => { + buffer += textNode.value; + }); const tableRegex = /((?:\| *[^|\r\n]+ *)+\|)(?:\r?\n)((?:\|[ :]?-+[ :]?)+\|)((?:(?:\r?\n)(?:\| *[^|\r\n]+ *)+\|)+)/g; @@ -33,7 +36,8 @@ export function remarkTables() { let lastIndex = 0; const newNodes = []; let failed = false; - while ((match = tableRegex.exec(value)) !== null) { + + while ((match = tableRegex.exec(buffer)) !== null) { const fullTableString = match[0]; const headerGroup = match[1]; const separatorGroup = match[2]; @@ -62,6 +66,11 @@ export function remarkTables() { const tableNode = { type: "table", align: alignments, + data: { + hProperties: { + class: "markdown-table", + }, + }, children: [ { type: "tableRow", @@ -77,7 +86,6 @@ export function remarkTables() { type: "tableRow", data: { hProperties: { - class: "markdown-table", key: i, }, }, @@ -95,7 +103,7 @@ export function remarkTables() { if (match.index > lastIndex) { newNodes.push({ type: "text", - value: value.slice(lastIndex, match.index), + value: buffer.slice(lastIndex, match.index), }); } @@ -117,16 +125,16 @@ export function remarkTables() { } // Add any remaining text after the last table - if (lastIndex < value.length) { + if (lastIndex < buffer.length) { newNodes.push({ type: "text", - value: value.slice(lastIndex), + value: buffer.slice(lastIndex), }); } - // Replace the original text node with the new nodes + // Replace the original paragraph node with the new nodes if (newNodes.length > 0) { - parent.children.splice(index, 1, ...newNodes); + parentOfParagraphNode.children.splice(index, 1, ...newNodes); } }); }; From c8f22f21dd838932ae61df84a90427f17b983821 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Sat, 17 May 2025 17:35:44 +0530 Subject: [PATCH 2/9] debug the message --- extensions/vscode/e2e/selectors/GUI.selectors.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index 773e3cfab..f2e69bbbf 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -148,6 +148,14 @@ export class GUISelectors { } public static getThreadMessageByText(view: WebView, text: string) { + void view.findElement(By.xpath(`//*[@class="thread-message"]`)).then(e=>{ + console.log('debug1 thread element: ', e); + }); + + void view.findElement(By.xpath(`//*[@class="thread-message"]`)).getText().then(e=>{ + console.log('debug1 thread message: ', e); + }); + return view.findWebElement( By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), ); From 46f088162b529acbd9c8c2f80d5c45a8d27522f4 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Sat, 17 May 2025 17:51:35 +0530 Subject: [PATCH 3/9] try skipping the test --- extensions/vscode/e2e/tests/GUI.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index b05302226..be5d43118 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -381,7 +381,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); }); - describe("Repeat back the system message", () => { + describe.skip("Repeat back the system message", () => { it("should repeat back the system message", async () => { await GUIActions.selectModelFromDropdown(view, "SYSTEM MESSAGE MOCK LLM"); const [messageInput] = await GUISelectors.getMessageInputFields(view); From ace7d9fae31d1ba3ad20b58bc74f7a5dca56d106 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Sat, 17 May 2025 18:01:47 +0530 Subject: [PATCH 4/9] increase timeout --- extensions/vscode/e2e/tests/GUI.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index be5d43118..62dc81245 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -381,8 +381,9 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); }); - describe.skip("Repeat back the system message", () => { - it("should repeat back the system message", async () => { + describe("Repeat back the system message", () => { + it("should repeat back the system message", async function () { + this.timeout(DEFAULT_TIMEOUT.XL); await GUIActions.selectModelFromDropdown(view, "SYSTEM MESSAGE MOCK LLM"); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From b971c0fb49482122f6c0b890846bdc338251ec6a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 20 May 2025 17:35:13 +0530 Subject: [PATCH 6/9] check the test with main branch --- .../vscode/e2e/selectors/GUI.selectors.ts | 8 ------ extensions/vscode/e2e/tests/GUI.test.ts | 2 +- .../utils/remarkTables.tsx | 26 +++++++------------ 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index f2e69bbbf..773e3cfab 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -148,14 +148,6 @@ export class GUISelectors { } public static getThreadMessageByText(view: WebView, text: string) { - void view.findElement(By.xpath(`//*[@class="thread-message"]`)).then(e=>{ - console.log('debug1 thread element: ', e); - }); - - void view.findElement(By.xpath(`//*[@class="thread-message"]`)).getText().then(e=>{ - console.log('debug1 thread message: ', e); - }); - return view.findWebElement( By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), ); diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 62dc81245..fad13db4a 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -389,7 +389,7 @@ describe("GUI Test", () => { await messageInput.sendKeys("Hello"); await messageInput.sendKeys(Key.ENTER); await TestUtils.waitForSuccess(() => - GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG"), + GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG2"), ); }); }); diff --git a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx index e5c1ea2f5..f22542c2f 100644 --- a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx +++ b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx @@ -22,11 +22,8 @@ import { visit } from "unist-util-visit"; */ export function remarkTables() { return (tree: any) => { - visit(tree, "paragraph", (paragraphNode, index, parentOfParagraphNode) => { - let buffer = ""; - visit(paragraphNode, "text", (textNode) => { - buffer += textNode.value; - }); + visit(tree, "text", (node, index, parent) => { + const { value } = node; const tableRegex = /((?:\| *[^|\r\n]+ *)+\|)(?:\r?\n)((?:\|[ :]?-+[ :]?)+\|)((?:(?:\r?\n)(?:\| *[^|\r\n]+ *)+\|)+)/g; @@ -36,8 +33,7 @@ export function remarkTables() { let lastIndex = 0; const newNodes = []; let failed = false; - - while ((match = tableRegex.exec(buffer)) !== null) { + while ((match = tableRegex.exec(value)) !== null) { const fullTableString = match[0]; const headerGroup = match[1]; const separatorGroup = match[2]; @@ -66,11 +62,6 @@ export function remarkTables() { const tableNode = { type: "table", align: alignments, - data: { - hProperties: { - class: "markdown-table", - }, - }, children: [ { type: "tableRow", @@ -86,6 +77,7 @@ export function remarkTables() { type: "tableRow", data: { hProperties: { + class: "markdown-table", key: i, }, }, @@ -103,7 +95,7 @@ export function remarkTables() { if (match.index > lastIndex) { newNodes.push({ type: "text", - value: buffer.slice(lastIndex, match.index), + value: value.slice(lastIndex, match.index), }); } @@ -125,16 +117,16 @@ export function remarkTables() { } // Add any remaining text after the last table - if (lastIndex < buffer.length) { + if (lastIndex < value.length) { newNodes.push({ type: "text", - value: buffer.slice(lastIndex), + value: value.slice(lastIndex), }); } - // Replace the original paragraph node with the new nodes + // Replace the original text node with the new nodes if (newNodes.length > 0) { - parentOfParagraphNode.children.splice(index, 1, ...newNodes); + parent.children.splice(index, 1, ...newNodes); } }); }; From 6ad23f0879405421236fd66abff0dc2f8c9be234 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 20 May 2025 17:44:09 +0530 Subject: [PATCH 7/9] Revert "check the test with main branch" This reverts commit b971c0fb49482122f6c0b890846bdc338251ec6a. --- .../vscode/e2e/selectors/GUI.selectors.ts | 8 ++++++ extensions/vscode/e2e/tests/GUI.test.ts | 2 +- .../utils/remarkTables.tsx | 26 ++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index 773e3cfab..f2e69bbbf 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -148,6 +148,14 @@ export class GUISelectors { } public static getThreadMessageByText(view: WebView, text: string) { + void view.findElement(By.xpath(`//*[@class="thread-message"]`)).then(e=>{ + console.log('debug1 thread element: ', e); + }); + + void view.findElement(By.xpath(`//*[@class="thread-message"]`)).getText().then(e=>{ + console.log('debug1 thread message: ', e); + }); + return view.findWebElement( By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), ); diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index fad13db4a..62dc81245 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -389,7 +389,7 @@ describe("GUI Test", () => { await messageInput.sendKeys("Hello"); await messageInput.sendKeys(Key.ENTER); await TestUtils.waitForSuccess(() => - GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG2"), + GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG"), ); }); }); diff --git a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx index f22542c2f..e5c1ea2f5 100644 --- a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx +++ b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx @@ -22,8 +22,11 @@ import { visit } from "unist-util-visit"; */ export function remarkTables() { return (tree: any) => { - visit(tree, "text", (node, index, parent) => { - const { value } = node; + visit(tree, "paragraph", (paragraphNode, index, parentOfParagraphNode) => { + let buffer = ""; + visit(paragraphNode, "text", (textNode) => { + buffer += textNode.value; + }); const tableRegex = /((?:\| *[^|\r\n]+ *)+\|)(?:\r?\n)((?:\|[ :]?-+[ :]?)+\|)((?:(?:\r?\n)(?:\| *[^|\r\n]+ *)+\|)+)/g; @@ -33,7 +36,8 @@ export function remarkTables() { let lastIndex = 0; const newNodes = []; let failed = false; - while ((match = tableRegex.exec(value)) !== null) { + + while ((match = tableRegex.exec(buffer)) !== null) { const fullTableString = match[0]; const headerGroup = match[1]; const separatorGroup = match[2]; @@ -62,6 +66,11 @@ export function remarkTables() { const tableNode = { type: "table", align: alignments, + data: { + hProperties: { + class: "markdown-table", + }, + }, children: [ { type: "tableRow", @@ -77,7 +86,6 @@ export function remarkTables() { type: "tableRow", data: { hProperties: { - class: "markdown-table", key: i, }, }, @@ -95,7 +103,7 @@ export function remarkTables() { if (match.index > lastIndex) { newNodes.push({ type: "text", - value: value.slice(lastIndex, match.index), + value: buffer.slice(lastIndex, match.index), }); } @@ -117,16 +125,16 @@ export function remarkTables() { } // Add any remaining text after the last table - if (lastIndex < value.length) { + if (lastIndex < buffer.length) { newNodes.push({ type: "text", - value: value.slice(lastIndex), + value: buffer.slice(lastIndex), }); } - // Replace the original text node with the new nodes + // Replace the original paragraph node with the new nodes if (newNodes.length > 0) { - parent.children.splice(index, 1, ...newNodes); + parentOfParagraphNode.children.splice(index, 1, ...newNodes); } }); }; From 0a498817665dcf31e3fd862039ae745b5c005221 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 20 May 2025 17:50:19 +0530 Subject: [PATCH 8/9] add early return --- .../components/StyledMarkdownPreview/utils/remarkTables.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx index e5c1ea2f5..2e0a2cd76 100644 --- a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx +++ b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx @@ -32,6 +32,10 @@ export function remarkTables() { /((?:\| *[^|\r\n]+ *)+\|)(?:\r?\n)((?:\|[ :]?-+[ :]?)+\|)((?:(?:\r?\n)(?:\| *[^|\r\n]+ *)+\|)+)/g; //// header // newline // |:---|----:| // new line // table rows + if(!buffer.match(tableRegex)) { + return; + } + let match: RegExpExecArray | null; let lastIndex = 0; const newNodes = []; From 699e3b6260c897b20de1c1ff0b05251b0f44bf62 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 20 May 2025 17:59:08 +0530 Subject: [PATCH 9/9] cleanup --- extensions/vscode/e2e/selectors/GUI.selectors.ts | 8 -------- extensions/vscode/e2e/tests/GUI.test.ts | 3 +-- gui/src/components/StyledMarkdownPreview/markdown.css | 7 ------- .../StyledMarkdownPreview/utils/remarkTables.tsx | 1 + 4 files changed, 2 insertions(+), 17 deletions(-) diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index f2e69bbbf..773e3cfab 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -148,14 +148,6 @@ export class GUISelectors { } public static getThreadMessageByText(view: WebView, text: string) { - void view.findElement(By.xpath(`//*[@class="thread-message"]`)).then(e=>{ - console.log('debug1 thread element: ', e); - }); - - void view.findElement(By.xpath(`//*[@class="thread-message"]`)).getText().then(e=>{ - console.log('debug1 thread message: ', e); - }); - return view.findWebElement( By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), ); diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 62dc81245..b05302226 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -382,8 +382,7 @@ describe("GUI Test", () => { }); describe("Repeat back the system message", () => { - it("should repeat back the system message", async function () { - this.timeout(DEFAULT_TIMEOUT.XL); + it("should repeat back the system message", async () => { await GUIActions.selectModelFromDropdown(view, "SYSTEM MESSAGE MOCK LLM"); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); diff --git a/gui/src/components/StyledMarkdownPreview/markdown.css b/gui/src/components/StyledMarkdownPreview/markdown.css index f975286ba..c2e79b3a6 100644 --- a/gui/src/components/StyledMarkdownPreview/markdown.css +++ b/gui/src/components/StyledMarkdownPreview/markdown.css @@ -1037,10 +1037,3 @@ body[data-color-mode*="light"] { .token.entity { cursor: help; } -/* -.markdown-table th { - background-color: var(--color-fg-muted); -} -.markdown-table td { - background-color: var(--color-fg-subtle); -} */ \ No newline at end of file diff --git a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx index 2e0a2cd76..5958d28fb 100644 --- a/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx +++ b/gui/src/components/StyledMarkdownPreview/utils/remarkTables.tsx @@ -32,6 +32,7 @@ export function remarkTables() { /((?:\| *[^|\r\n]+ *)+\|)(?:\r?\n)((?:\|[ :]?-+[ :]?)+\|)((?:(?:\r?\n)(?:\| *[^|\r\n]+ *)+\|)+)/g; //// header // newline // |:---|----:| // new line // table rows + // prevent modifying if no markdown tables are present if(!buffer.match(tableRegex)) { return; }