(filePath: string)
| 7 | * @returns true if the path is outside all workspace folders, false otherwise |
| 8 | */ |
| 9 | export function isPathOutsideWorkspace(filePath: string): boolean { |
| 10 | // If there are no workspace folders, consider everything outside workspace for safety |
| 11 | if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) { |
| 12 | return true |
| 13 | } |
| 14 | |
| 15 | // Normalize and resolve the path to handle .. and . components correctly |
| 16 | const absolutePath = path.resolve(filePath) |
| 17 | |
| 18 | // Check if the path is within any workspace folder |
| 19 | return !vscode.workspace.workspaceFolders.some((folder) => { |
| 20 | const folderPath = folder.uri.fsPath |
| 21 | // Path is inside a workspace if it equals the workspace path or is a subfolder |
| 22 | return absolutePath === folderPath || absolutePath.startsWith(folderPath + path.sep) |
| 23 | }) |
| 24 | } |
no outgoing calls
no test coverage detected