mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-24 17:31:37 +01:00
333d9a4053
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
27 lines
665 B
TypeScript
27 lines
665 B
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import * as vscode from 'vscode';
|
|
|
|
export async function findParentFolder(relativeFilePath: string): Promise<string | null> {
|
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
|
|
|
if (!workspaceFolders) {
|
|
console.error('No workspace folders found');
|
|
return null;
|
|
}
|
|
|
|
for (const folder of workspaceFolders) {
|
|
const fullPath = path.join(folder.uri.fsPath, relativeFilePath);
|
|
|
|
try {
|
|
const stats = await fs.promises.stat(fullPath);
|
|
if (stats.isFile()) {
|
|
return folder.uri.fsPath;
|
|
}
|
|
} catch (err) {
|
|
// File does not exist in this folder, continue to next
|
|
}
|
|
}
|
|
|
|
return null;
|
|
} |