Skip to content

Commit

Permalink
enable context transparency for folder case
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewyuq committed Feb 19, 2025
1 parent dc13da9 commit 2503119
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/amazonq/lsp/lspController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/amazonq/lsp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ export interface AdditionalContextPrompt {
description: string
startLine: number
endLine: number
filePath: string
relativePath: string
}
56 changes: 30 additions & 26 deletions packages/core/src/codewhispererChat/controllers/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = []
Expand All @@ -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(
Expand Down

0 comments on commit 2503119

Please sign in to comment.