diff --git a/CHANGELOG.md b/CHANGELOG.md
index db9bc4fb..79d459d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,11 @@
- Optimized the `getMedia` call from the webview
- Keep the dashboard its context when switching tabs
- [#205](https://github.com/estruyf/vscode-front-matter/issues/205): Define a logging level setting
+- [#206](https://github.com/estruyf/vscode-front-matter/issues/206): Add front matter issues to the diagnostic tab
+
+### 🐞 Fixes
+
+- [#207](https://github.com/estruyf/vscode-front-matter/issues/207): Fix the quick picks for content creation
## [5.7.0] - 2021-12-07 - [Release Notes](https://beta.frontmatter.codes/updates/v5.7.0)
diff --git a/README.beta.md b/README.beta.md
index e5649abd..fb5916bc 100644
--- a/README.beta.md
+++ b/README.beta.md
@@ -106,7 +106,7 @@ If you have the courage to test out the beta features, we made available a beta
-## 🖤 Sponsors 👇 🤘
+## 🖤 Backers & Sponsors 👇 🤘
diff --git a/README.md b/README.md
index 28be793d..76f6cb36 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,7 @@ If you have the courage to test out the beta features, we made available a beta
-## 🖤 Sponsors 👇 🤘
+## 🖤 Backers & Sponsors 👇 🤘
diff --git a/src/commands/Template.ts b/src/commands/Template.ts
index c7cdecd1..1bd112bc 100644
--- a/src/commands/Template.ts
+++ b/src/commands/Template.ts
@@ -11,6 +11,7 @@ import { Project } from './Project';
import { Folders } from './Folders';
import { ContentType } from '../helpers/ContentType';
import { ContentType as IContentType } from '../models';
+import { PagesListener } from '../listeners';
export class Template {
@@ -176,6 +177,9 @@ export class Template {
}
Notifications.info(`Your new content has been created.`);
+
+ // Trigger a refresh for the dashboard
+ PagesListener.refresh();
}
/**
diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts
index 6a4057cd..1304218f 100644
--- a/src/helpers/ArticleHelper.ts
+++ b/src/helpers/ArticleHelper.ts
@@ -1,3 +1,4 @@
+import { MarkdownFoldingProvider } from './../providers/MarkdownFoldingProvider';
import { DEFAULT_CONTENT_TYPE, DEFAULT_CONTENT_TYPE_NAME } from './../constants/ContentType';
import * as vscode from 'vscode';
import * as matter from "gray-matter";
@@ -5,7 +6,7 @@ import * as fs from "fs";
import { DefaultFields, SETTING_COMMA_SEPARATED_FIELDS, SETTING_DATE_FIELD, SETTING_DATE_FORMAT, SETTING_INDENT_ARRAY, SETTING_REMOVE_QUOTES, SETTING_TAXONOMY_CONTENT_TYPES, SETTING_TEMPLATES_PREFIX } from '../constants';
import { DumpOptions } from 'js-yaml';
import { TomlEngine, getFmLanguage, getFormatOpts } from './TomlEngine';
-import { Settings } from '.';
+import { Extension, Settings } from '.';
import { format, parse } from 'date-fns';
import { Notifications } from './Notifications';
import { Article } from '../commands';
@@ -15,6 +16,7 @@ import sanitize from '../helpers/Sanitize';
import { existsSync, mkdirSync } from 'fs';
import { ContentType } from '../models';
import { DateHelper } from './DateHelper';
+import { Diagnostic, DiagnosticSeverity, Position, window, Range } from 'vscode';
export class ArticleHelper {
private static notifiedFiles: string[] = [];
@@ -33,9 +35,9 @@ export class ArticleHelper {
* Retrieve the file's front matter by its path
* @param filePath
*/
- public static getFrontMatterByPath(filePath: string, surpressNotification: boolean = false) {
+ public static getFrontMatterByPath(filePath: string) {
const file = fs.readFileSync(filePath, { encoding: "utf-8" });
- return ArticleHelper.parseFile(file, filePath, surpressNotification);
+ return ArticleHelper.parseFile(file, filePath);
}
/**
@@ -226,7 +228,7 @@ export class ArticleHelper {
* @param fileContents
* @returns
*/
- private static parseFile(fileContents: string, fileName: string, surpressNotification: boolean = false): matter.GrayMatterFile | null {
+ private static parseFile(fileContents: string, fileName: string): matter.GrayMatterFile | null {
try {
const commaSeparated = Settings.get(SETTING_COMMA_SEPARATED_FIELDS);
@@ -249,6 +251,10 @@ export class ArticleHelper {
this.notifiedFiles = this.notifiedFiles.filter(n => n !== fileName);
+ if (window.activeTextEditor?.document.uri) {
+ Extension.getInstance().diagnosticCollection.delete(window.activeTextEditor.document.uri);
+ }
+
return article;
}
}
@@ -260,18 +266,25 @@ export class ArticleHelper {
}
}];
- if (!surpressNotification) {
- if (this.notifiedFiles.indexOf(fileName) === -1) {
- Notifications.error(`There seems to be an issue parsing the content its front matter. FileName: ${basename(fileName)}. ERROR: ${error.message || error}`, ...items).then((result: any) => {
- if (result?.title) {
- const item = items.find(i => i.title === result.title);
- if (item) {
- item.action();
- }
- }
- });
+ const editor = window.activeTextEditor;
+ if (editor?.document.uri) {
+ let fmRange = null;
- this.notifiedFiles.push(fileName);
+ if (error?.mark && typeof error.mark.line !== "undefined") {
+ const curLineText = editor.document.lineAt(error.mark.line - 1);
+ const lastCharPos = new Position(error.mark.line - 1, Math.max(curLineText.text.length, 0));
+ fmRange = new Range(new Position(error.mark.line - 1, 0), lastCharPos);
+ } else {
+ fmRange = MarkdownFoldingProvider.getFrontMatterRange(editor.document);
+ }
+
+
+ if (fmRange) {
+ Extension.getInstance().diagnosticCollection.set(editor.document.uri, [{
+ severity: DiagnosticSeverity.Error,
+ message: `${error.name ? `${error.name}: ` : ""}Error parsing the front matter of ${fileName}`,
+ range: fmRange
+ }]);
}
}
}
diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts
index 6a7cc15c..55fc33ec 100644
--- a/src/helpers/ContentType.ts
+++ b/src/helpers/ContentType.ts
@@ -1,3 +1,4 @@
+import { PagesListener } from './../listeners/PagesListener';
import { ArticleHelper, Settings } from ".";
import { SETTINGS_CONTENT_DRAFT_FIELD, SETTING_TAXONOMY_CONTENT_TYPES } from "../constants";
import { ContentType as IContentType, DraftField } from '../models';
@@ -128,5 +129,8 @@ export class ContentType {
}
Notifications.info(`Your new content has been created.`);
+
+ // Trigger a refresh for the dashboard
+ PagesListener.refresh();
}
}
\ No newline at end of file
diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts
index 1d06e679..ad0501f0 100644
--- a/src/helpers/CustomScript.ts
+++ b/src/helpers/CustomScript.ts
@@ -67,7 +67,7 @@ export class CustomScript {
if (folder.lastModified.length > 0) {
for await (const file of folder.lastModified) {
try {
- const article = ArticleHelper.getFrontMatterByPath(file.filePath, true);
+ const article = ArticleHelper.getFrontMatterByPath(file.filePath);
if (article) {
const crntOutput = await CustomScript.runScript(wsPath, article, file.filePath, script);
if (crntOutput) {
diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts
index 264bec97..0900ed54 100644
--- a/src/helpers/Extension.ts
+++ b/src/helpers/Extension.ts
@@ -1,6 +1,6 @@
import { existsSync, renameSync } from "fs";
import { basename, join } from "path";
-import { extensions, Uri, ExtensionContext, window, workspace, commands, ExtensionMode } from "vscode";
+import { extensions, Uri, ExtensionContext, window, workspace, commands, ExtensionMode, DiagnosticCollection, languages } from "vscode";
import { Folders, WORKSPACE_PLACEHOLDER } from "../commands/Folders";
import { EXTENSION_NAME, GITHUB_LINK, SETTINGS_CONTENT_FOLDERS, SETTINGS_CONTENT_PAGE_FOLDERS, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTING_TAXONOMY_CONTENT_TYPES, DEFAULT_CONTENT_TYPE_NAME, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, DefaultFields, LocalStore, SETTING_TEMPLATES_FOLDER } from "../constants";
import { ContentType } from "../models";
@@ -11,8 +11,11 @@ import { Settings } from "./SettingsHelper";
export class Extension {
private static instance: Extension;
+ private _collection: DiagnosticCollection;
- private constructor(private ctx: ExtensionContext) {}
+ private constructor(private ctx: ExtensionContext) {
+ this._collection = languages.createDiagnosticCollection(this.title);
+ }
/**
* Creates the singleton instance for the panel
@@ -88,6 +91,10 @@ export class Extension {
return this.ctx.extensionMode === ExtensionMode.Production;
}
+ public get diagnosticCollection(): DiagnosticCollection {
+ return this._collection;
+ }
+
/**
* Set the current version information for the extension
*/
diff --git a/src/helpers/Questions.ts b/src/helpers/Questions.ts
index 1051dfd3..2252fd8a 100644
--- a/src/helpers/Questions.ts
+++ b/src/helpers/Questions.ts
@@ -45,7 +45,8 @@ export class Questions {
let selectedFolder: string | undefined;
if (folders.length > 1) {
selectedFolder = await window.showQuickPick(folders.map(f => f.title), {
- placeHolder: `Select where you want to create your content`
+ placeHolder: `Select where you want to create your content`,
+ ignoreFocusOut: true
});
} else {
selectedFolder = folders[0].title;
diff --git a/src/listeners/PagesListener.ts b/src/listeners/PagesListener.ts
index a837bc11..7296a9f5 100644
--- a/src/listeners/PagesListener.ts
+++ b/src/listeners/PagesListener.ts
@@ -124,4 +124,8 @@ export class PagesListener extends BaseListener {
this.sendMsg(DashboardCommand.pages, pages);
}
+
+ public static refresh() {
+ this.getPagesData();
+ }
}
\ No newline at end of file
diff --git a/src/providers/MarkdownFoldingProvider.ts b/src/providers/MarkdownFoldingProvider.ts
index 17d0fb1f..f3e5e6e2 100644
--- a/src/providers/MarkdownFoldingProvider.ts
+++ b/src/providers/MarkdownFoldingProvider.ts
@@ -13,31 +13,15 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
public async provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken): Promise {
const ranges: FoldingRange[] = [];
- const lines = document.getText().split('\n');
- let start: number | null = null;
- let end: number | null = null;
+ const range = MarkdownFoldingProvider.getFrontMatterRange(document);
+ if (range) {
+ MarkdownFoldingProvider.start = null;
+ MarkdownFoldingProvider.end = null;
+ MarkdownFoldingProvider.endLine = null;
- MarkdownFoldingProvider.start = null;
- MarkdownFoldingProvider.end = null;
- MarkdownFoldingProvider.endLine = null;
+ MarkdownFoldingProvider.triggerHighlighting();
- for (let i = 0; i < lines.length; i++) {
- const line = lines[i];
- if (line.startsWith('---')) {
- if (i === 0 && start === null) {
- start = i;
- MarkdownFoldingProvider.start = start;
- } else if (start !== null && end === null) {
- end = i;
- MarkdownFoldingProvider.end = end;
- MarkdownFoldingProvider.endLine = line.length;
-
- MarkdownFoldingProvider.triggerHighlighting();
-
- ranges.push(new FoldingRange(start, end, FoldingRangeKind.Region));
- return ranges;
- }
- }
+ ranges.push(new FoldingRange(range.start.line, range.end.line, FoldingRangeKind.Region));
}
return ranges;
@@ -46,9 +30,9 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
public static triggerHighlighting() {
const fmHighlight = Settings.get(SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT);
- if (MarkdownFoldingProvider.start !== null && MarkdownFoldingProvider.end !== null && MarkdownFoldingProvider.endLine !== null) {
- const range = new Range(new Position(MarkdownFoldingProvider.start, 0), new Position(MarkdownFoldingProvider.end, MarkdownFoldingProvider.endLine));
+ const range = this.getFrontMatterRange();
+ if (range) {
if (MarkdownFoldingProvider.decType !== null) {
MarkdownFoldingProvider.decType.dispose();
}
@@ -59,4 +43,43 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
}
}
}
+
+ /**
+ * Retrieve the range of the current Front Matter page
+ * @param document
+ * @returns
+ */
+ public static getFrontMatterRange(document?: TextDocument) {
+ if (document) {
+ const lines = document.getText().split('\n');
+
+ let start = null;
+ let end = null;
+ let endLine = null;
+
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i];
+ if (line.startsWith('---')) {
+ if (i === 0 && start === null) {
+ start = i;
+ } else if (start !== null && end === null) {
+ end = i;
+ endLine = line.length;
+
+ MarkdownFoldingProvider.triggerHighlighting();
+
+ return new Range(new Position(start, 0), new Position(end, endLine));
+ }
+ }
+ }
+ }
+
+ if (MarkdownFoldingProvider.start !== null && MarkdownFoldingProvider.end !== null && MarkdownFoldingProvider.endLine !== null) {
+ const range = new Range(new Position(MarkdownFoldingProvider.start, 0), new Position(MarkdownFoldingProvider.end, MarkdownFoldingProvider.endLine));
+
+ return range;
+ }
+
+ return null;
+ }
}
\ No newline at end of file