feat: Improve file path handling in contextFileSelected

- Add fallback for relative path calculation
- Handle cases where workspaceDir is undefined
- Ensure fileSelected is always used as a fallback
This commit is contained in:
bobo.yang 2024-12-02 14:39:50 +08:00
parent c25ef505b0
commit 54b49389c5

View File

@ -19,7 +19,9 @@ export async function handleFileSelected(fileSelected: string) {
// 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 = {