Update package version to 0.0.8, add new configuration options for templates path, file overwrite behavior, input mode, and language selection. Remove old .vsix files and update README for improved usage instructions.

This commit is contained in:
S.Gromov
2025-07-15 09:22:48 +03:00
parent bcb2c381fb
commit 0842268f28
14 changed files with 82 additions and 58 deletions

View File

@@ -10,29 +10,28 @@ export interface MyTemplateGeneratorConfig {
language?: string;
}
export function getConfigPath(): string | undefined {
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length === 0) return undefined;
return path.join(folders[0].uri.fsPath, 'mycodegenerate.json');
}
export function readConfig(): MyTemplateGeneratorConfig {
const configPath = getConfigPath();
if (configPath && fs.existsSync(configPath)) {
const raw = fs.readFileSync(configPath, 'utf8');
return JSON.parse(raw);
}
// Значения по умолчанию
const config = vscode.workspace.getConfiguration('myTemplateGenerator');
return {
templatesPath: 'templates',
overwriteFiles: false,
inputMode: 'inputBox',
language: 'en',
templatesPath: config.get<string>('templatesPath', '.templates'),
overwriteFiles: config.get<boolean>('overwriteFiles', false),
inputMode: config.get<'webview' | 'inputBox'>('inputMode', 'webview'),
language: config.get<string>('language', 'en'),
};
}
export function writeConfig(config: MyTemplateGeneratorConfig) {
const configPath = getConfigPath();
if (!configPath) return;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8');
export async function writeConfig(newConfig: Partial<MyTemplateGeneratorConfig>) {
const config = vscode.workspace.getConfiguration('myTemplateGenerator');
if (newConfig.templatesPath !== undefined) {
await config.update('templatesPath', newConfig.templatesPath, vscode.ConfigurationTarget.Global);
}
if (newConfig.overwriteFiles !== undefined) {
await config.update('overwriteFiles', newConfig.overwriteFiles, vscode.ConfigurationTarget.Global);
}
if (newConfig.inputMode !== undefined) {
await config.update('inputMode', newConfig.inputMode, vscode.ConfigurationTarget.Global);
}
if (newConfig.language !== undefined) {
await config.update('language', newConfig.language, vscode.ConfigurationTarget.Global);
}
}

View File

@@ -41,7 +41,6 @@ export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "mytemplategenerator" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
@@ -56,25 +55,20 @@ export function activate(context: vscode.ExtensionContext) {
const config = readConfig();
const dict = I18N_DICTIONARIES[config.language || 'ru'] || I18N_DICTIONARIES['ru'];
const workspaceFolders = vscode.workspace.workspaceFolders;
console.log('[DEBUG] Запуск команды createFromTemplate');
if (!workspaceFolders || workspaceFolders.length === 0) {
vscode.window.showErrorMessage(dict.noFolders);
console.log('[DEBUG] Нет открытых папок рабочего пространства');
return;
}
const templatesDir = path.join(workspaceFolders[0].uri.fsPath, config.templatesPath);
if (!fs.existsSync(templatesDir) || !fs.statSync(templatesDir).isDirectory()) {
vscode.window.showErrorMessage(`${dict.templatesNotFound} ${templatesDir}`);
console.log('[DEBUG] Папка шаблонов не найдена:', templatesDir);
return;
}
let template: string | undefined;
let userVars: Record<string, string> | undefined;
if (config.inputMode === 'webview') {
vscode.window.showInformationMessage('[DEBUG] Вызов webview создания шаблона...');
console.log('[DEBUG] Вызов showTemplateAndVarsWebview', { templatesDir, uri: uri.fsPath, lang: config.language });
const result: { template: string, vars: Record<string, string> } | undefined = await showTemplateAndVarsWebview(context, templatesDir, uri.fsPath, config.language || 'ru');
console.log('[DEBUG] Результат showTemplateAndVarsWebview:', result);
if (!result) {
vscode.window.showInformationMessage('[DEBUG] Webview был закрыт или не вернул результат');
return;
@@ -104,7 +98,6 @@ export function activate(context: vscode.ExtensionContext) {
copyTemplateWithVars(templateDir, uri.fsPath, vars, config.overwriteFiles, dict, template);
} catch (e: any) {
vscode.window.showErrorMessage(`${dict.createError}: ${e.message}`);
console.log('[DEBUG] Ошибка при копировании шаблона:', e);
}
});
@@ -121,22 +114,7 @@ export function activate(context: vscode.ExtensionContext) {
clearDiagnosticsForTemplates(context); // <--- Очищаем diagnostics для шаблонов
// === Отслеживание изменений конфига ===
const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
const configPath = path.join(workspaceFolders[0].uri.fsPath, 'mycodegenerate.json');
if (fs.existsSync(configPath)) {
fs.watch(configPath, { persistent: false }, (eventType) => {
if (eventType === 'change' || eventType === 'rename') {
// Перерегистрируем провайдер подсветки
if (semanticHighlightDisposable) {
semanticHighlightDisposable.dispose();
}
semanticHighlightDisposable = registerTemplateSemanticHighlight(context);
console.log('[DEBUG] Провайдер семантической подсветки перерегистрирован после изменения конфига');
}
});
}
}
// (Удалено: теперь все настройки глобальные через VSCode settings)
}
// This method is called when your extension is deactivated

View File

@@ -20,8 +20,6 @@ export function registerTemplateSemanticHighlight(context: vscode.ExtensionConte
const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length === 0) return;
const templatesDir = path.join(workspaceFolders[0].uri.fsPath, templatesPath);
console.log('[DEBUG] semantic tokens called for', document.uri.fsPath);
console.log('[DEBUG] Проверка шаблонной папки:', document.uri.fsPath, templatesDir, isInTemplatesDir(document.uri.fsPath, templatesDir));
// Проверяем, что файл в папке шаблонов
if (!isInTemplatesDir(document.uri.fsPath, templatesDir)) {
return;

View File

@@ -120,16 +120,16 @@ export async function showConfigWebview(context: vscode.ExtensionContext) {
}
panel.webview.onDidReceiveMessage(
msg => {
async msg => {
if (msg.type === 'save') {
writeConfig(msg.data);
await writeConfig(msg.data);
vscode.window.showInformationMessage('Настройки сохранены!');
panel.dispose();
}
if (msg.type === 'setLanguage') {
// Сохраняем язык в конфиг и перерисовываем webview
config.language = msg.language;
writeConfig(config);
await writeConfig(config);
setHtml(msg.language === 'en' ? 'en' : 'ru');
}
},

View File

@@ -156,7 +156,7 @@ export async function showTemplateAndVarsWebview(
if (message.language) language = message.language;
// Сохраняем язык в конфиг
const oldConfig = readConfig();
writeConfig({ ...oldConfig, language });
await writeConfig({ ...oldConfig, language });
currentTemplate = message.template || templates[0] || '';
// Получаем переменные для выбранного шаблона
let baseVars: string[] = [];