From 2503119d29d4e712826f6bd544e6f3a908811af8 Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Wed, 19 Feb 2025 14:55:11 -0800 Subject: [PATCH] enable context transparency for folder case --- .../core/src/amazonq/lsp/lspController.ts | 4 +- packages/core/src/amazonq/lsp/types.ts | 2 + .../controllers/chat/controller.ts | 56 ++++++++++--------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/packages/core/src/amazonq/lsp/lspController.ts b/packages/core/src/amazonq/lsp/lspController.ts index 162f7d6ff5c..7d1e49b9aba 100644 --- a/packages/core/src/amazonq/lsp/lspController.ts +++ b/packages/core/src/amazonq/lsp/lspController.ts @@ -61,9 +61,9 @@ export interface Manifest { targets: Target[] }[] } -const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json' +const manifestUrl = 'https://ducvaeoffl85c.cloudfront.net/manifest-0.1.40.json' // this LSP client in Q extension is only going to work with these LSP server versions -const supportedLspServerVersions = ['0.1.39'] +const supportedLspServerVersions = ['0.1.40'] const nodeBinName = process.platform === 'win32' ? 'node.exe' : 'node' diff --git a/packages/core/src/amazonq/lsp/types.ts b/packages/core/src/amazonq/lsp/types.ts index 59e1e069287..1da8dfb00de 100644 --- a/packages/core/src/amazonq/lsp/types.ts +++ b/packages/core/src/amazonq/lsp/types.ts @@ -113,4 +113,6 @@ export interface AdditionalContextPrompt { description: string startLine: number endLine: number + filePath: string + relativePath: string } diff --git a/packages/core/src/codewhispererChat/controllers/chat/controller.ts b/packages/core/src/codewhispererChat/controllers/chat/controller.ts index a570dbfd2a0..a23ee8739a9 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/controller.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/controller.ts @@ -609,30 +609,32 @@ export class ChatController { const absoluteFilePath = path.join(projectRoot, message.filePath) - // Open the file in VSCode - const document = await workspace.openTextDocument(absoluteFilePath) - const editor = await window.showTextDocument(document, ViewColumn.Active) - - // Create multiple selections based on line ranges - const selections: Selection[] = lineRanges - .filter(({ first, second }) => first !== -1 && second !== -1) - .map(({ first, second }) => { - const startPosition = new Position(first - 1, 0) // Convert 1-based to 0-based - const endPosition = new Position(second - 1, document.lineAt(second - 1).range.end.character) - return new Selection( - startPosition.line, - startPosition.character, - endPosition.line, - endPosition.character - ) - }) + try { + // Open the file in VSCode + const document = await workspace.openTextDocument(absoluteFilePath) + const editor = await window.showTextDocument(document, ViewColumn.Active) + + // Create multiple selections based on line ranges + const selections: Selection[] = lineRanges + .filter(({ first, second }) => first !== -1 && second !== -1) + .map(({ first, second }) => { + const startPosition = new Position(first - 1, 0) // Convert 1-based to 0-based + const endPosition = new Position(second - 1, document.lineAt(second - 1).range.end.character) + return new Selection( + startPosition.line, + startPosition.character, + endPosition.line, + endPosition.character + ) + }) - // Apply multiple selections to the editor using the new API - if (selections.length > 0) { - editor.selection = selections[0] // Set the first selection as active - editor.selections = selections // Apply multiple selections - editor.revealRange(selections[0], vscode.TextEditorRevealType.InCenter) - } + // Apply multiple selections to the editor + if (selections.length > 0) { + editor.selection = selections[0] // Set the first selection as active + editor.selections = selections // Apply multiple selections + editor.revealRange(selections[0], vscode.TextEditorRevealType.InCenter) + } + } catch (error) {} } private processException(e: any, tabID: string) { @@ -889,16 +891,16 @@ export class ChatController { for (const context of triggerPayload.context) { if (typeof context !== 'string' && context.route && context.route.length === 2) { contextCommands.push({ - workspaceFolder: context.route?.[0] || '', + workspaceFolder: context.route[0] || '', type: context.icon === 'folder' ? 'folder' : 'file', - relativePath: context.route?.[1] || '', + relativePath: context.route[1] || '', }) - relativePaths.push(context.route[1]) } } if (contextCommands.length === 0) { return [] } + const workspaceFolder = contextCommands[0].workspaceFolder const prompts = await LspClient.instance.getContextCommandPrompt(contextCommands) if (prompts.length > 0) { triggerPayload.additionalContents = [] @@ -910,6 +912,8 @@ export class ChatController { description: prompt.description.substring(0, aditionalContentNameLimit), innerContext: prompt.content.substring(0, additionalContentInnerContextLimit), }) + const relativePath = path.relative(workspaceFolder, prompt.filePath) + relativePaths.push(relativePath) } } getLogger().info(