mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-06-28 05:52:07 +02:00
#190 - More diagnostic values
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import { Folders } from "./Folders";
|
||||
import { window } from "vscode";
|
||||
import { ViewColumn, workspace } from "vscode";
|
||||
import ContentProvider from "../providers/ContentProvider";
|
||||
import { join } from "path";
|
||||
import { ContentFolder } from "../models";
|
||||
|
||||
|
||||
export class Diagnostics {
|
||||
|
||||
public static show() {
|
||||
public static async show() {
|
||||
const folders = Folders.get();
|
||||
const projectName = Folders.getProjectFolderName();
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
|
||||
const folderData = [];
|
||||
for (const folder of folders) {
|
||||
folderData.push(await Diagnostics.processFolder(folder, projectName));
|
||||
}
|
||||
|
||||
const logging = `# Project name
|
||||
|
||||
${projectName}
|
||||
@@ -25,14 +31,21 @@ ${wsFolder ? wsFolder.fsPath : "No workspace folder"}
|
||||
|
||||
# Folders to search files
|
||||
|
||||
${folders.map(folder => {
|
||||
let projectStart = folder.path.split(projectName).pop();
|
||||
projectStart = projectStart?.replace(/\\/g, '/');
|
||||
projectStart = projectStart?.startsWith('/') ? projectStart.substr(1) : projectStart;
|
||||
return `- ${join(projectStart || "", folder.excludeSubdir ? '/' : '**/', '*.md')}`;
|
||||
}).join("\n")}
|
||||
${folderData.join("\n")}
|
||||
`;
|
||||
|
||||
ContentProvider.show(logging, `${projectName} diagnostics`, "markdown");
|
||||
ContentProvider.show(logging, `${projectName} diagnostics`, "markdown", ViewColumn.One);
|
||||
}
|
||||
|
||||
private static async processFolder(folder: ContentFolder, projectName: string) {
|
||||
let projectStart = folder.path.split(projectName).pop();
|
||||
projectStart = projectStart || "";
|
||||
projectStart = projectStart?.replace(/\\/g, '/');
|
||||
projectStart = projectStart?.startsWith('/') ? projectStart.substr(1) : projectStart;
|
||||
|
||||
const mdFiles = await workspace.findFiles(join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.md'));
|
||||
const mdxFiles = await workspace.findFiles(join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.mdx'));
|
||||
|
||||
return `- Project start length: ${projectStart.length} | Search in: "${join(projectStart, folder.excludeSubdir ? '/' : '**/', '*.*')}" | mdFiles: ${mdFiles.length} | mdxFiles: ${mdxFiles.length}`;
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,14 @@ export default class ContentProvider implements TextDocumentContentProvider {
|
||||
return uri.query;
|
||||
}
|
||||
|
||||
public static async show(data: string, title: string, outputType?: string) {
|
||||
public static async show(data: string, title: string, 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);
|
||||
|
||||
await window.showTextDocument(doc, { preview: true, viewColumn: ViewColumn.Beside, preserveFocus: true });
|
||||
await window.showTextDocument(doc, { preview: true, viewColumn: column, preserveFocus: true });
|
||||
|
||||
const workEdits = new WorkspaceEdit();
|
||||
workEdits.replace(doc.uri, new Range(new Position(0, 0), new Position(doc.lineCount, 0)), data);
|
||||
|
||||
Reference in New Issue
Block a user