From 8d72f0845a16c27a666b27ba6fc288ba68d972f0 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Tue, 11 Jul 2023 10:53:08 +0200 Subject: [PATCH] Feedback: Hugo with partial content in modules vs. Dashboard #602 --- CHANGELOG.md | 1 + src/commands/Folders.ts | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d27de8..359bb4ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - [#591](https://github.com/estruyf/vscode-front-matter/issues/591): Support for date format in the `datetime` field - [#593](https://github.com/estruyf/vscode-front-matter/issues/593): Add support for date formatting in the preview path - [#599](https://github.com/estruyf/vscode-front-matter/issues/599): Add a placeholder when the base panel view is empty +- [#602](https://github.com/estruyf/vscode-front-matter/issues/602): Find content outside the Front Matter workspace folder ### ⚡️ Optimizations diff --git a/src/commands/Folders.ts b/src/commands/Folders.ts index 8c3701b9..b4e86f3b 100644 --- a/src/commands/Folders.ts +++ b/src/commands/Folders.ts @@ -272,7 +272,8 @@ export class Folders { for (const folder of folders) { try { const folderPath = parseWinPath(folder.path); - let projectStart = parseWinPath(folder.path).replace(wsFolder, ''); + // let projectStart = parseWinPath(folder.path).replace(wsFolder, ''); + let projectStart = folderPath; if (typeof projectStart === 'string') { projectStart = projectStart.replace(/\\/g, '/'); @@ -291,7 +292,8 @@ export class Folders { filePath = `*${fileType.startsWith('.') ? '' : '.'}${fileType}`; } - let foundFiles = await workspace.findFiles(filePath, '**/node_modules/**'); + let foundFiles = await Folders.findFiles(filePath); + // Make sure these file are coming from the folder path (this could be an issue in multi-root workspaces) foundFiles = foundFiles.filter((f) => parseWinPath(f.fsPath).startsWith(folderPath)); @@ -461,6 +463,11 @@ export class Folders { const isWindows = process.platform === 'win32'; let absPath = folder.path.replace(WORKSPACE_PLACEHOLDER, parseWinPath(wsFolder?.fsPath || '')); absPath = isWindows ? absPath.split('/').join('\\') : absPath; + + if (absPath.includes('../')) { + absPath = join(absPath); + } + return parseWinPath(absPath); } @@ -577,4 +584,18 @@ export class Folders { }); }); } + + /** + * Find all files + * @param pattern + * @returns + */ + private static async findFiles(pattern: string): Promise { + return new Promise((resolve) => { + glob(pattern, { ignore: '**/node_modules/**' }, (err, files) => { + const allFiles = files.map((file) => Uri.file(file)); + resolve(allFiles); + }); + }); + } }