47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { RoadmapTreeProvider, RoadmapItem } from './roadmapTree';
|
|
import * as path from 'path';
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
const checklistFile = path.join(vscode.workspace.workspaceFolders?.[0].uri.fsPath || '', 'Development Checklist.md');
|
|
console.log('[Extension] Using checklist path:', checklistFile);
|
|
|
|
const roadmapProvider = new RoadmapTreeProvider(checklistFile, context);
|
|
vscode.window.registerTreeDataProvider('roadmapChecklist', roadmapProvider);
|
|
const treeView = vscode.window.createTreeView('roadmapChecklist', {
|
|
treeDataProvider: roadmapProvider
|
|
});
|
|
|
|
context.subscriptions.push(
|
|
vscode.commands.registerCommand('roadmap.toggleCheckbox', async (item: RoadmapItem) => {
|
|
const doc = vscode.workspace.textDocuments.find(d => d.uri.fsPath === checklistFile);
|
|
if (!doc) { return; }
|
|
|
|
const edit = new vscode.WorkspaceEdit();
|
|
const lines = doc.getText().split('\n');
|
|
const index = lines.findIndex(line =>
|
|
line.trim().match(/^[-*]\s+\[[ xX]\]/) &&
|
|
line.includes(item.label)
|
|
);
|
|
if (index === -1) { return; }
|
|
|
|
const line = lines[index];
|
|
const toggledLine = line.replace(/\[(x| )\]/i, item.checked ? '[ ]' : '[x]');
|
|
const range = new vscode.Range(new vscode.Position(index, 0), new vscode.Position(index, line.length));
|
|
edit.replace(doc.uri, range, toggledLine);
|
|
|
|
await vscode.workspace.applyEdit(edit);
|
|
await doc.save(); // ✅ Triggers the existing onDidSaveTextDocument → refresh()
|
|
}),
|
|
vscode.commands.registerCommand('roadmapChecklist.reveal', async (item: RoadmapItem) => {
|
|
treeView.reveal(item, { expand: true });
|
|
})
|
|
);
|
|
|
|
function escapeRegex(str: string) {
|
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
}
|
|
}
|
|
|
|
export function deactivate() {}
|