Skip to content

Commit

Permalink
Merge pull request #128 from mghdotdev/feature/matching-tag-validation
Browse files Browse the repository at this point in the history
Feature/matching tag validation
  • Loading branch information
mghdotdev authored Nov 29, 2024
2 parents c70114b + d884ec1 commit 2f790e8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 23 additions & 2 deletions server/src/miva-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,8 +35,10 @@ 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,
findOpenTag,
formatDoValueCompletion,
formatGenericDocumentation,
formatItemParamDocumentation,
Expand Down Expand Up @@ -374,13 +375,29 @@ 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)),
severity: DiagnosticSeverity.Error,
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 ) ) {
Expand Down Expand Up @@ -409,6 +426,10 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro

}, []);

return [
...validationJsonDiagnostics,
...mismatchedTags
];
},

doCodeAction( document, codeActionRange, context ) {
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions server/src/util/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2f790e8

Please sign in to comment.