From 06ce5180cfea7e717797f7fff4fd7a8c81cace6e Mon Sep 17 00:00:00 2001 From: Max Hegler Date: Fri, 29 Nov 2024 12:22:23 -0800 Subject: [PATCH 1/4] moved file to mvt folder --- server/src/miva-features.ts | 2 +- server/src/{data/MVT => mvt}/validation.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename server/src/{data/MVT => mvt}/validation.json (100%) diff --git a/server/src/miva-features.ts b/server/src/miva-features.ts index 457fbaf..ed8646e 100644 --- a/server/src/miva-features.ts +++ b/server/src/miva-features.ts @@ -27,7 +27,6 @@ import { TextDocument } from 'vscode-languageserver-textdocument'; import { URI, Utils } from 'vscode-uri'; -import validationTests from './data/MVT/validation.json'; import builtinFunctionData from './data/functions-builtin.json'; import merchantFunctionFiles from './data/functions-merchant.json'; import mvOperatorData from './mv/operators'; @@ -36,6 +35,7 @@ import { mvSnippetData, mvTagData } from './mv/tags'; import mvtEntityData from './mvt/entities'; import mvtItemData from './mvt/items'; import { generateMvtSnippets, generateMvtTags } from './mvt/tags'; +import validationTests from './mvt/validation.json'; import { filterTagData, formatDoValueCompletion, diff --git a/server/src/data/MVT/validation.json b/server/src/mvt/validation.json similarity index 100% rename from server/src/data/MVT/validation.json rename to server/src/mvt/validation.json From 8228ce7a1764ec5dfc38f43ce90bebfb73e567f4 Mon Sep 17 00:00:00 2001 From: Max Hegler Date: Fri, 29 Nov 2024 13:35:45 -0800 Subject: [PATCH 2/4] moved function to util folder --- server/src/miva-features.ts | 22 +++++++++++++++++++++- server/src/util/functions.ts | 14 ++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/server/src/miva-features.ts b/server/src/miva-features.ts index ed8646e..ccecec1 100644 --- a/server/src/miva-features.ts +++ b/server/src/miva-features.ts @@ -38,6 +38,7 @@ import { generateMvtSnippets, generateMvtTags } from './mvt/tags'; import validationTests from './mvt/validation.json'; import { filterTagData, + findOpenTag, formatDoValueCompletion, formatGenericDocumentation, formatItemParamDocumentation, @@ -374,13 +375,28 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro doValidation( document: TextDocument, settings: Settings ) { + buildTagCompletionData( settings, document.languageId ); + const {document: mvtDocument} = mvtDocuments.get( document ); // get full text of the document const text = mvtDocument.getText(); + // Check if any mvt tags are mismatched + const mismatchedTags: Diagnostic[] = []; + const parsedDocument = htmlLanguageService.parseHTMLDocument(document); + const blockTagList = Object.values(mvtTagData).filter(td => !td?.selfClosing).map(td => td?.label?.toLowerCase()); + const openTag = findOpenTag(parsedDocument.roots, blockTagList); + if (openTag) { + mismatchedTags.push({ + range: Range.create(document.positionAt(openTag.start), document.positionAt(openTag.startTagEnd)), + message: `Missing closing ${openTag.tag} tag.`, + source: 'Miva IDE' + }); + } + // build diagnostics array - return validationTests.reduce(( diagnostics: Diagnostic[], validation: any ) => { + const validationJsonDiagnostics = validationTests.reduce(( diagnostics: Diagnostic[], validation: any ) => { // validate configured setting to check - exit if not valid if ( validation.checkSetting != null && !_get( settings, validation.checkSetting ) ) { @@ -409,6 +425,10 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro }, []); + return [ + ...validationJsonDiagnostics, + ...mismatchedTags + ]; }, doCodeAction( document, codeActionRange, context ) { diff --git a/server/src/util/functions.ts b/server/src/util/functions.ts index 39bb00f..99e03bf 100644 --- a/server/src/util/functions.ts +++ b/server/src/util/functions.ts @@ -526,6 +526,20 @@ export function getNodeAtOffset (offset: number, parsedDocument: HTMLDocument): } } +export function findOpenTag (nodes: Node[], blockTagList: string[]): Node { + for (let node of nodes) { + // @ts-expect-error + if (!node.closed && blockTagList.includes(node.tag.toLowerCase())) { + return node; + } + + const found = findOpenTag(node.children, blockTagList); + if (found) { + return found; + } + } +} + export function uriToFsPath (uri: URI | string) { if (typeof uri === 'string') { return URI.parse(uri).fsPath; From 3c7449e48f3b264311570dfd390d7d8a63a00969 Mon Sep 17 00:00:00 2001 From: Max Hegler Date: Fri, 29 Nov 2024 13:38:06 -0800 Subject: [PATCH 3/4] explicitly define severity --- server/src/miva-features.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/miva-features.ts b/server/src/miva-features.ts index ccecec1..7593f07 100644 --- a/server/src/miva-features.ts +++ b/server/src/miva-features.ts @@ -390,6 +390,7 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro if (openTag) { mismatchedTags.push({ range: Range.create(document.positionAt(openTag.start), document.positionAt(openTag.startTagEnd)), + severity: DiagnosticSeverity.Error, message: `Missing closing ${openTag.tag} tag.`, source: 'Miva IDE' }); From d884ec113fc0ef1da41408f9676951d046443a40 Mon Sep 17 00:00:00 2001 From: Max Hegler Date: Fri, 29 Nov 2024 13:39:01 -0800 Subject: [PATCH 4/4] bumped version and added changelog --- CHANGELOG.md | 6 +++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67de830..d5d5b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Miva IDE CHANGELOG -## v1.26.0 (latest) +## v1.27.0 (latest) + +* Added tag mismatch validation for mvt tags. + +## v1.26.0 * Added document linking support for the following items: * `templatefeed` diff --git a/package-lock.json b/package-lock.json index a025122..4e60558 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-miva-ide", - "version": "1.26.0", + "version": "1.27.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscode-miva-ide", - "version": "1.26.0", + "version": "1.27.0", "workspaces": [ "client", "server" diff --git a/package.json b/package.json index e1cdb74..85d3b84 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-miva-ide", "displayName": "Miva IDE", "description": "Syntax highlighting, snippets and tools for building websites with Miva.", - "version": "1.26.0", + "version": "1.27.0", "engines": { "vscode": "^1.77.0", "node": ">=16"