Skip to content

Commit d10327b

Browse files
authored
enable context transparency for folder case (#20)
1 parent dc13da9 commit d10327b

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export interface Manifest {
6161
targets: Target[]
6262
}[]
6363
}
64-
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
64+
const manifestUrl = 'https://ducvaeoffl85c.cloudfront.net/manifest-0.1.40.json'
6565
// this LSP client in Q extension is only going to work with these LSP server versions
66-
const supportedLspServerVersions = ['0.1.39']
66+
const supportedLspServerVersions = ['0.1.40']
6767

6868
const nodeBinName = process.platform === 'win32' ? 'node.exe' : 'node'
6969

packages/core/src/amazonq/lsp/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ export interface AdditionalContextPrompt {
113113
description: string
114114
startLine: number
115115
endLine: number
116+
filePath: string
117+
relativePath: string
116118
}

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -609,30 +609,32 @@ export class ChatController {
609609

610610
const absoluteFilePath = path.join(projectRoot, message.filePath)
611611

612-
// Open the file in VSCode
613-
const document = await workspace.openTextDocument(absoluteFilePath)
614-
const editor = await window.showTextDocument(document, ViewColumn.Active)
615-
616-
// Create multiple selections based on line ranges
617-
const selections: Selection[] = lineRanges
618-
.filter(({ first, second }) => first !== -1 && second !== -1)
619-
.map(({ first, second }) => {
620-
const startPosition = new Position(first - 1, 0) // Convert 1-based to 0-based
621-
const endPosition = new Position(second - 1, document.lineAt(second - 1).range.end.character)
622-
return new Selection(
623-
startPosition.line,
624-
startPosition.character,
625-
endPosition.line,
626-
endPosition.character
627-
)
628-
})
612+
try {
613+
// Open the file in VSCode
614+
const document = await workspace.openTextDocument(absoluteFilePath)
615+
const editor = await window.showTextDocument(document, ViewColumn.Active)
616+
617+
// Create multiple selections based on line ranges
618+
const selections: Selection[] = lineRanges
619+
.filter(({ first, second }) => first !== -1 && second !== -1)
620+
.map(({ first, second }) => {
621+
const startPosition = new Position(first - 1, 0) // Convert 1-based to 0-based
622+
const endPosition = new Position(second - 1, document.lineAt(second - 1).range.end.character)
623+
return new Selection(
624+
startPosition.line,
625+
startPosition.character,
626+
endPosition.line,
627+
endPosition.character
628+
)
629+
})
629630

630-
// Apply multiple selections to the editor using the new API
631-
if (selections.length > 0) {
632-
editor.selection = selections[0] // Set the first selection as active
633-
editor.selections = selections // Apply multiple selections
634-
editor.revealRange(selections[0], vscode.TextEditorRevealType.InCenter)
635-
}
631+
// Apply multiple selections to the editor
632+
if (selections.length > 0) {
633+
editor.selection = selections[0] // Set the first selection as active
634+
editor.selections = selections // Apply multiple selections
635+
editor.revealRange(selections[0], vscode.TextEditorRevealType.InCenter)
636+
}
637+
} catch (error) {}
636638
}
637639

638640
private processException(e: any, tabID: string) {
@@ -889,16 +891,16 @@ export class ChatController {
889891
for (const context of triggerPayload.context) {
890892
if (typeof context !== 'string' && context.route && context.route.length === 2) {
891893
contextCommands.push({
892-
workspaceFolder: context.route?.[0] || '',
894+
workspaceFolder: context.route[0] || '',
893895
type: context.icon === 'folder' ? 'folder' : 'file',
894-
relativePath: context.route?.[1] || '',
896+
relativePath: context.route[1] || '',
895897
})
896-
relativePaths.push(context.route[1])
897898
}
898899
}
899900
if (contextCommands.length === 0) {
900901
return []
901902
}
903+
const workspaceFolder = contextCommands[0].workspaceFolder
902904
const prompts = await LspClient.instance.getContextCommandPrompt(contextCommands)
903905
if (prompts.length > 0) {
904906
triggerPayload.additionalContents = []
@@ -910,6 +912,8 @@ export class ChatController {
910912
description: prompt.description.substring(0, aditionalContentNameLimit),
911913
innerContext: prompt.content.substring(0, additionalContentInnerContextLimit),
912914
})
915+
const relativePath = path.relative(workspaceFolder, prompt.filePath)
916+
relativePaths.push(relativePath)
913917
}
914918
}
915919
getLogger().info(

0 commit comments

Comments
 (0)