Skip to content

Commit d8d0925

Browse files
authored
fix: declare statements breaking query key parsing (#522)
* fix: declare statements breaking query key parsing * improve assertion * update explain prompt
1 parent e947b12 commit d8d0925

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

e2e/tests/console/aiAssistant.spec.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,16 +1206,34 @@ describe("ai assistant", () => {
12061206

12071207
it("should move glyph icons when query position changes", () => {
12081208
// Given - Type a query starting at line 1
1209-
cy.typeQuery("SELECT 1;")
1209+
cy.typeQuery("DECLARE @myVar := 'shift-this' select @myVar;")
12101210

12111211
// Then - AI icon should be on line 1
1212-
cy.getAIIconInLine(1, "noChat").should("be.visible")
1212+
cy.getAIIconInLine(1, "noChat").should("be.visible").click()
1213+
1214+
cy.getByDataHook("ai-chat-window").should("be.visible")
1215+
cy.getByDataHook("chat-input-textarea").should("be.visible")
1216+
cy.getByDataHook("chat-context-badge").should("be.visible")
1217+
1218+
interceptAIChatRequest("openai")
1219+
cy.getByDataHook("chat-input-textarea").type("Explain this query", {
1220+
force: true,
1221+
})
1222+
cy.getByDataHook("chat-send-button").click()
1223+
cy.getAIIconInLine(1, "highlight").should("be.visible")
1224+
1225+
cy.wait("@openaiChatRequest")
1226+
cy.getByDataHook("chat-message-assistant").should("be.visible")
1227+
cy.getAIIconInLine(1, "active").should("be.visible")
1228+
1229+
cy.getByDataHook("chat-window-close").click()
1230+
cy.getByDataHook("ai-chat-window").should("not.exist")
12131231

12141232
// When - Add empty lines before the query (press Home, then Enter twice)
1215-
cy.get(".monaco-editor textarea").type("{home}{enter}{enter}")
1233+
cy.typeQuery("{home}{enter}{enter}")
12161234

12171235
// Then - AI icon should move to line 3
1218-
cy.getAIIconInLine(3, "noChat").should("be.visible")
1236+
cy.getAIIconInLine(3, "active").should("be.visible")
12191237

12201238
// And - Line 1 should not have an AI icon
12211239
cy.get(".glyph-widget-1 .glyph-ai-icon").should("not.exist")

src/components/ExplainQueryButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const ExplainQueryButton = ({
6666
const currentModel = currentModelValue!
6767
const apiKey = apiKeyValue!
6868
void (async () => {
69-
const fullApiMessage = `Explain this SQL query with 2-4 sentences:\n\n\`\`\`sql\n${queryText}\n\`\`\``
69+
const fullApiMessage = `Using your tools when necessary, explain this SQL query in detail.:\n\n\`\`\`sql\n${queryText}\n\`\`\``
7070

7171
addMessage({
7272
role: "user",

src/scenes/Editor/Monaco/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,11 @@ export const createQueryKey = (
11181118
export const parseQueryKey = (
11191119
queryKey: QueryKey,
11201120
): { queryText: string; startOffset: number; endOffset: number } => {
1121-
const [queryText, offsets] = queryKey.split("@")
1121+
const separatorIndex = queryKey.lastIndexOf("@")
1122+
1123+
const queryText = queryKey.slice(0, separatorIndex)
1124+
const offsets = queryKey.slice(separatorIndex + 1)
1125+
11221126
const [startOffset, endOffset] = offsets.split("-")
11231127
return {
11241128
queryText,

0 commit comments

Comments
 (0)