/
outbreak
/
kilocode
Обзор
Документация
Войти
/
outbreak
/
kilocode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/utils/pathUtils.ts
24 строки
967 B
Matt Rubens
Additional checkbox for auto-approving reads and writes outside of the workspace (#1965)
25 мар 2025, 08:35
Не верифицирован
25 мар 2025, 08:35
1810efe
Код
Авторство
О чём код?
import * as vscode from "vscode" import * as path from "path" /** * Checks if a file path is outside all workspace folders * @param filePath The file path to check * @returns true if the path is outside all workspace folders, false otherwise */ export function isPathOutsideWorkspace(filePath: string): boolean { // If there are no workspace folders, consider everything outside workspace for safety if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) { return true } // Normalize and resolve the path to handle .. and . components correctly const absolutePath = path.resolve(filePath) // Check if the path is within any workspace folder return !vscode.workspace.workspaceFolders.some((folder) => { const folderPath = folder.uri.fsPath // Path is inside a workspace if it equals the workspace path or is a subfolder return absolutePath === folderPath || absolutePath.startsWith(folderPath + path.sep) }) }