Skip to content

Commit df6ebb0

Browse files
authored
fix(amazonq): path resolution incorrectness in windows for .amazonq/rules (aws#6722)
## Problem In Windows, the rules under .amazonq/rules were not send in the chat prompt because of path resolution failure. ## Solution ![Screenshot 2025-03-04 at 3 34 34 PM](https://github.com/user-attachments/assets/649c4f40-365e-4b67-9bff-48a2a8a6c450) Use path.join instead of vscode.Uri.joinPath --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent e810220 commit df6ebb0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,23 +881,23 @@ export class ChatController {
881881
/**
882882
* @returns A Uri array of prompt files in each workspace root's .amazonq/rules directory
883883
*/
884-
private async collectWorkspaceRules(): Promise<vscode.Uri[]> {
885-
const rulesFiles: vscode.Uri[] = []
884+
private async collectWorkspaceRules(): Promise<string[]> {
885+
const rulesFiles: string[] = []
886886

887887
if (!vscode.workspace.workspaceFolders) {
888888
return rulesFiles
889889
}
890890

891891
for (const folder of vscode.workspace.workspaceFolders) {
892-
const rulesPath = vscode.Uri.joinPath(folder.uri, '.amazonq', 'rules')
892+
const rulesPath = path.join(folder.uri.fsPath, '.amazonq', 'rules')
893893
const folderExists = await fs.exists(rulesPath)
894894

895895
if (folderExists) {
896896
const entries = await fs.readdir(rulesPath)
897897

898898
for (const [name, type] of entries) {
899899
if (type === vscode.FileType.File && name.endsWith(promptFileExtension)) {
900-
rulesFiles.push(vscode.Uri.joinPath(rulesPath, name))
900+
rulesFiles.push(path.join(rulesPath, name))
901901
}
902902
}
903903
}
@@ -918,11 +918,12 @@ export class ChatController {
918918
if (workspaceRules.length > 0) {
919919
contextCommands.push(
920920
...workspaceRules.map((rule) => {
921-
const workspaceFolderPath = vscode.workspace.getWorkspaceFolder(rule)?.uri?.path || ''
921+
const workspaceFolderPath =
922+
vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(rule))?.uri?.path || ''
922923
return {
923924
workspaceFolder: workspaceFolderPath,
924925
type: 'file' as ContextCommandItemType,
925-
relativePath: path.relative(workspaceFolderPath, rule.path),
926+
relativePath: path.relative(workspaceFolderPath, rule),
926927
}
927928
})
928929
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
import * as path from 'path'
56
import { UserIntent } from '@amzn/codewhisperer-streaming'
67
import {
78
AmazonqAddMessage,
@@ -147,7 +148,7 @@ export class CWCTelemetryHelper {
147148
}
148149

149150
public getContextType(prompt: AdditionalContextPrompt): string {
150-
if (prompt.relativePath.startsWith('.amazonq/rules')) {
151+
if (prompt.relativePath.startsWith(path.join('.amazonq', 'rules'))) {
151152
return 'rule'
152153
} else if (prompt.filePath.startsWith(getUserPromptsDirectory())) {
153154
return 'prompt'

0 commit comments

Comments
 (0)