UNPKG

w1-system-font-validator

Version:

VS Code extension for validating W1 System font variables (both fontConfig.json and localFontConfig.json)

142 lines 6.03 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.activate = activate; exports.deactivate = deactivate; const vscode = __importStar(require("vscode")); const unifiedValidator_1 = require("./validators/unifiedValidator"); let validator; function activate(context) { try { // Create the unified font validator validator = new unifiedValidator_1.UnifiedFontValidator(); } catch (error) { console.error("W1 Font Validator: Failed to initialize validator:", error); vscode.window.showErrorMessage("W1 Font Validator failed to initialize: " + error); return; } // Register commands const validateCommand = vscode.commands.registerCommand("w1FontValidator.validateFonts", () => { const activeEditor = vscode.window.activeTextEditor; if (activeEditor) { const fileName = activeEditor.document.fileName; const baseName = fileName.split(/[/\\]/).pop() || ""; const shouldValidate = shouldValidateDocument(activeEditor.document); if (shouldValidate) { validator.validateDocument(activeEditor.document); vscode.window.showInformationMessage("W1 Font validation complete!"); } else { vscode.window.showInformationMessage("No active CSS file to validate."); } } }); const refreshConfigCommand = vscode.commands.registerCommand("w1FontValidator.refreshConfig", () => { validator.refreshConfig(); vscode.window.showInformationMessage("Font configuration refreshed!"); }); // Register document change listener for real-time validation WITH DEBOUNCING const documentChangeListener = vscode.workspace.onDidChangeTextDocument((event) => { if (shouldValidateDocument(event.document)) { const config = vscode.workspace.getConfiguration("w1FontValidator"); if (config.get("validateOnType", true)) { validator.validateDocumentDebounced(event.document); } } }); // Register document open listener const documentOpenListener = vscode.workspace.onDidOpenTextDocument((document) => { if (shouldValidateDocument(document)) { validator.validateDocument(document); } }); // Register hover provider for font information const hoverProvider = vscode.languages.registerHoverProvider(["css", "scss", "less"], { provideHover(document, position, token) { const config = vscode.workspace.getConfiguration("w1FontValidator"); if (config.get("showHoverInfo", true)) { return validator.provideHover(document, position); } return undefined; }, }); // Register document close listener for cleanup const documentCloseListener = vscode.workspace.onDidCloseTextDocument((document) => { if (shouldValidateDocument(document)) { validator.cleanupDocument(document); } }); // Add to subscriptions for cleanup context.subscriptions.push(validateCommand, refreshConfigCommand, documentChangeListener, documentOpenListener, hoverProvider, documentCloseListener); // Validate all currently open documents vscode.workspace.textDocuments.forEach((document) => { if (shouldValidateDocument(document)) { validator.validateDocument(document); } }); } function deactivate() { // Proper cleanup of the validator if (validator) { validator.dispose(); } } /** * Check if document should be validated */ function shouldValidateDocument(document) { const fileName = document.fileName; // Exclude certain directories if (fileName.includes("node_modules") || fileName.includes(".vscode") || fileName.includes("dist")) { return false; } // Use path.basename for cross-platform compatibility const baseName = fileName.split(/[/\\]/).pop() || ""; // CSS Modules if (baseName.endsWith(".module.css") || baseName.endsWith(".module.scss") || baseName.endsWith(".module.less")) { return true; } // Global CSS files - Always validate regardless of location if (baseName === "globals.css" || baseName === "global.css" || baseName === "global.scss") { return true; } // Files in styles directories (check for both forward and back slashes) if ((fileName.includes("/styles/") || fileName.includes("\\styles\\")) && (baseName.endsWith(".css") || baseName.endsWith(".scss"))) { return true; } return false; } //# sourceMappingURL=extension.js.map