From 504774a4c8762c8cec7e3cff3324162c7c39e79e Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 29 Apr 2024 15:49:42 +0200 Subject: [PATCH] Optimized diagnostics --- src/commands/Diagnostics.ts | 54 +++++++++++++++++++------------- src/providers/ContentProvider.ts | 2 -- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/commands/Diagnostics.ts b/src/commands/Diagnostics.ts index 0516a449..1c0a8c00 100644 --- a/src/commands/Diagnostics.ts +++ b/src/commands/Diagnostics.ts @@ -4,6 +4,7 @@ import ContentProvider from '../providers/ContentProvider'; import { join } from 'path'; import { ContentFolder } from '../models'; import { Settings } from '../helpers/SettingsHelper'; +import { DEFAULT_FILE_TYPES, SETTING_CONTENT_SUPPORTED_FILETYPES } from '../constants'; export class Diagnostics { public static async show() { @@ -18,27 +19,35 @@ export class Diagnostics { const all = await Diagnostics.allProjectFiles(); - const logging = `# Project name + const fileTypes = Diagnostics.getFileTypes(); + + const logging = `# Front Matter CMS - Diagnostics + +## Project name ${projectName} -# Folders +## Workspace folder -${folders.map((f) => `- ${f.title}: "${f.path}"`).join('\n')} +\`${wsFolder ? wsFolder.fsPath : 'No workspace folder'}\` -# Workspace folder - -${wsFolder ? wsFolder.fsPath : 'No workspace folder'} - -# Total files +## Total files ${all} -# Folders to search files +## Folders +| Title | Path | +| ----- | ---- | +${folders.map((f) => `| ${f.title} | \`${f.path}\` |`).join('\n')} + +### Files in folders + +| Project start length | Search in | ${fileTypes.join(` | `)} | +|--- | --- | --- | --- | --- | ${folderData.join('\n')} -# Complete frontmatter.json config +## Complete frontmatter.json config \`\`\`json ${JSON.stringify(Settings.globalConfig, null, 2)} @@ -48,6 +57,10 @@ ${JSON.stringify(Settings.globalConfig, null, 2)} ContentProvider.show(logging, `${projectName} diagnostics`, 'markdown', ViewColumn.One); } + private static getFileTypes = (): string[] => { + return Settings.get(SETTING_CONTENT_SUPPORTED_FILETYPES) || DEFAULT_FILE_TYPES; + }; + private static async allProjectFiles() { const allFiles = await workspace.findFiles(`**/*.*`); return `Total files found: ${allFiles.length}`; @@ -59,22 +72,19 @@ ${JSON.stringify(Settings.globalConfig, null, 2)} projectStart = projectStart?.replace(/\\/g, '/'); projectStart = projectStart?.startsWith('/') ? projectStart.substring(1) : projectStart; - const mdFiles = await workspace.findFiles( - join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.md') - ); - const mdxFiles = await workspace.findFiles( - join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.mdx') - ); - const markdownFiles = await workspace.findFiles( - join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.markdown') + const fileTypes = Diagnostics.getFileTypes(); + const fileTypeLengths = await Promise.all( + fileTypes.map(async (ft) => { + const path = join(projectStart || '', folder.excludeSubdir ? '/' : '**/', `*.${ft}`); + const files = await workspace.findFiles(path, '**/node_modules/**'); + return (files || []).length; + }) ); - return `- Project start length: ${projectStart.length} | Search in: "${join( + return `| ${projectStart.length} | \`${join( projectStart, folder.excludeSubdir ? '/' : '**/', '*.*' - )}" | mdFiles: ${mdFiles.length} | mdxFiles: ${mdxFiles.length} | markdownFiles: ${ - markdownFiles.length - }`; + )}\` | ${fileTypeLengths.join(` | `)} |`; } } diff --git a/src/providers/ContentProvider.ts b/src/providers/ContentProvider.ts index 094de663..a115f3a5 100644 --- a/src/providers/ContentProvider.ts +++ b/src/providers/ContentProvider.ts @@ -25,8 +25,6 @@ export default class ContentProvider implements TextDocumentContentProvider { outputType?: string, column: ViewColumn = ViewColumn.Beside ) { - const apiData = JSON.stringify(data, null, 2); - const uri = Uri.parse(`${ContentProvider.scheme}:${title} output`); const doc = await workspace.openTextDocument(uri);