feat: Improve file path handling in contextCodeSelected

- Add fallback for relative path calculation
- Handle cases where workspaceDir is undefined
- Ensure fileSelected is used when no workspace folder exists
This commit is contained in:
bobo.yang 2024-12-02 14:39:13 +08:00
parent 32f078bac2
commit c25ef505b0

View File

@ -16,7 +16,9 @@ export async function handleCodeSelected(fileSelected: string, codeSelected: str
// get relative path of workspace // get relative path of workspace
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath(); const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
const relativePath = path.relative(workspaceDir!, fileSelected); const relativePath = workspaceDir
? path.relative(workspaceDir, fileSelected)
: fileSelected;
// convert fileContent to markdown code block with languageId and file path // convert fileContent to markdown code block with languageId and file path
const data = { const data = {