mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 01:13:08 +02:00
Address code review feedback and improve validation
Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
This commit is contained in:
@@ -203,14 +203,19 @@ export class StatusListener {
|
||||
|
||||
const text = editor.document.getText();
|
||||
const schemaDiagnostics: vscode.Diagnostic[] = [];
|
||||
|
||||
// Find the front matter section (between --- markers)
|
||||
const frontMatterMatch = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
||||
const frontMatterEnd = frontMatterMatch ? frontMatterMatch[0].length : text.length;
|
||||
|
||||
for (const error of errors) {
|
||||
// Find the field in the document
|
||||
const fieldPath = error.field.split('.');
|
||||
const fieldName = fieldPath[fieldPath.length - 1];
|
||||
|
||||
// Try to find the field location in the document
|
||||
const fieldIdx = text.indexOf(fieldName);
|
||||
// Try to find the field location in the front matter section only
|
||||
const searchText = text.substring(0, frontMatterEnd);
|
||||
const fieldIdx = searchText.indexOf(fieldName);
|
||||
|
||||
if (fieldIdx !== -1) {
|
||||
const posStart = editor.document.positionAt(fieldIdx);
|
||||
@@ -238,7 +243,7 @@ export class StatusListener {
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently fail validation errors to not disrupt the user experience
|
||||
console.error('Schema validation error:', error);
|
||||
// Logger can be used here if needed for debugging
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ export class ContentTypeSchemaGenerator {
|
||||
}
|
||||
|
||||
const fieldGroupIds = Array.isArray(field.fieldGroup) ? field.fieldGroup : [field.fieldGroup];
|
||||
const fieldGroups = Settings.get(SETTING_TAXONOMY_FIELD_GROUPS) as any[];
|
||||
const fieldGroups = Settings.get(SETTING_TAXONOMY_FIELD_GROUPS) as { id: string; fields: Field[] }[] | undefined;
|
||||
|
||||
if (!fieldGroups || fieldGroups.length === 0) {
|
||||
return schemas;
|
||||
|
||||
@@ -28,4 +28,3 @@ export * from './sleep';
|
||||
export * from './sortPages';
|
||||
export * from './unlinkAsync';
|
||||
export * from './writeFileAsync';
|
||||
export * from '../helpers/ContentTypeSchemaGenerator';
|
||||
|
||||
Reference in New Issue
Block a user