UNPKG

lookatni-file-markers

Version:

Advanced file organization system with unique markers for code sharing and project management. Extract files from marked content, generate markers, and validate project integrity.

206 lines (205 loc) 8.44 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.ConfigurationManager = void 0; const vscode = __importStar(require("vscode")); class ConfigurationManager { constructor() { this.config = this.loadConfiguration(); this.setupConfigurationWatcher(); } static getInstance() { if (!ConfigurationManager.instance) { ConfigurationManager.instance = new ConfigurationManager(); } return ConfigurationManager.instance; } loadConfiguration() { try { const vscodeConfig = vscode.workspace.getConfiguration('lookatni'); return { visualMarkers: { readIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.readIcon', '✓'), unreadIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.unreadIcon', '●'), favoriteIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.favoriteIcon', '★'), importantIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.importantIcon', '!'), todoIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.todoIcon', '○'), customIcon: this.getSafeConfig(vscodeConfig, 'visualMarkers.customIcon', '◆'), autoSave: this.getSafeConfig(vscodeConfig, 'visualMarkers.autoSave', true), showInStatusBar: this.getSafeConfig(vscodeConfig, 'visualMarkers.showInStatusBar', true) }, defaultMaxFileSize: this.getSafeConfig(vscodeConfig, 'defaultMaxFileSize', 1000), showStatistics: this.getSafeConfig(vscodeConfig, 'showStatistics', true), autoValidate: this.getSafeConfig(vscodeConfig, 'autoValidate', false) }; } catch (error) { console.warn('Failed to load LookAtni configuration, using defaults:', error); return { ...ConfigurationManager.DEFAULT_CONFIG }; } } getSafeConfig(config, key, defaultValue) { try { const value = config.get(key); if (value !== undefined && value !== null) { if (typeof defaultValue === 'string' && typeof value === 'string') { const trimmedValue = value.trim(); return (trimmedValue || defaultValue); } return value; } return defaultValue; } catch (error) { console.warn(`Failed to get config for ${key}, using default:`, error); return defaultValue; } } setupConfigurationWatcher() { vscode.workspace.onDidChangeConfiguration((event) => { if (event.affectsConfiguration('lookatni')) { this.config = this.loadConfiguration(); this.notifyConfigurationChange(); } }); } notifyConfigurationChange() { vscode.commands.executeCommand('lookatni.internal.configChanged'); } getConfig() { return { ...this.config }; } getVisualMarkersConfig() { return { ...this.config.visualMarkers }; } getIconForMarkerType(type) { const config = this.config.visualMarkers; const iconMap = { 'read': config.readIcon, 'unread': config.unreadIcon, 'favorite': config.favoriteIcon, 'important': config.importantIcon, 'todo': config.todoIcon, 'custom': config.customIcon }; return iconMap[type] || config.customIcon; } async validateConfiguration() { const issues = []; const config = this.config; Object.entries(config.visualMarkers).forEach(([key, value]) => { if (key.endsWith('Icon') && typeof value === 'string' && !value.trim()) { issues.push(`Visual marker icon for ${key} is empty`); } }); if (config.defaultMaxFileSize <= 0) { issues.push('Default max file size must be greater than 0'); } const iconRegex = /^[\p{L}\p{N}\p{P}\p{S}\p{M}]+$/u; Object.entries(config.visualMarkers).forEach(([key, value]) => { if (key.endsWith('Icon') && typeof value === 'string' && value && !iconRegex.test(value)) { issues.push(`Invalid characters in ${key}: ${value}`); } }); return { isValid: issues.length === 0, issues }; } async resetToDefaults() { const config = vscode.workspace.getConfiguration('lookatni'); try { for (const [section, values] of Object.entries(ConfigurationManager.DEFAULT_CONFIG)) { if (typeof values === 'object' && values !== null) { for (const [key, defaultValue] of Object.entries(values)) { await config.update(`${section}.${key}`, defaultValue, vscode.ConfigurationTarget.Global); } } else { await config.update(section, values, vscode.ConfigurationTarget.Global); } } vscode.window.showInformationMessage('LookAtni configuration reset to defaults'); } catch (error) { vscode.window.showErrorMessage(`Failed to reset configuration: ${error}`); } } async exportConfiguration() { return JSON.stringify({ version: '1.0.0', exportDate: new Date().toISOString(), configuration: this.config }, null, 2); } async importConfiguration(configJson) { try { const importData = JSON.parse(configJson); const config = vscode.workspace.getConfiguration('lookatni'); if (importData.configuration) { for (const [section, values] of Object.entries(importData.configuration)) { if (typeof values === 'object' && values !== null) { for (const [key, value] of Object.entries(values)) { await config.update(`${section}.${key}`, value, vscode.ConfigurationTarget.Global); } } else { await config.update(section, values, vscode.ConfigurationTarget.Global); } } } vscode.window.showInformationMessage('Configuration imported successfully'); } catch (error) { throw new Error(`Failed to import configuration: ${error}`); } } } exports.ConfigurationManager = ConfigurationManager; ConfigurationManager.DEFAULT_CONFIG = { visualMarkers: { readIcon: '✓', unreadIcon: '●', favoriteIcon: '★', importantIcon: '!', todoIcon: '○', customIcon: '◆', autoSave: true, showInStatusBar: true }, defaultMaxFileSize: 1000, showStatistics: true, autoValidate: false };