(
context: ExportContext,
configKey: string,
fileName: string,
options: ExportOptions = {},
)
| 27 | * 4. Default to just the filename (user's home/cwd) |
| 28 | */ |
| 29 | export function resolveDefaultSaveUri( |
| 30 | context: ExportContext, |
| 31 | configKey: string, |
| 32 | fileName: string, |
| 33 | options: ExportOptions = {}, |
| 34 | ): vscode.Uri { |
| 35 | const { useWorkspace = true, fallbackDir } = options |
| 36 | const lastExportPath = context.getValue(configKey) as string | undefined |
| 37 | |
| 38 | if (lastExportPath) { |
| 39 | // Use the directory from the last export |
| 40 | const lastDir = path.dirname(lastExportPath) |
| 41 | return vscode.Uri.file(path.join(lastDir, fileName)) |
| 42 | } else { |
| 43 | // Try workspace if enabled |
| 44 | const workspaceFolders = vscode.workspace.workspaceFolders |
| 45 | if (useWorkspace && workspaceFolders && workspaceFolders.length > 0) { |
| 46 | return vscode.Uri.file(path.join(workspaceFolders[0].uri.fsPath, fileName)) |
| 47 | } |
| 48 | |
| 49 | // Fallback |
| 50 | if (fallbackDir) { |
| 51 | return vscode.Uri.file(path.join(fallbackDir, fileName)) |
| 52 | } |
| 53 | |
| 54 | // Default to cwd/home |
| 55 | return vscode.Uri.file(fileName) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | export async function saveLastExportPath(context: ExportContext, configKey: string, uri: vscode.Uri) { |
| 60 | await context.setValue(configKey, uri.fsPath) |
no test coverage detected