✨feature: Fold completed phases, open first phase with incomplete tasks by default
This commit is contained in:
@@ -1,17 +1,69 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { RoadmapTreeProvider } from './roadmapTree';
|
||||
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);
|
||||
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('roadmapView.refresh', () => roadmapProvider.refresh())
|
||||
vscode.commands.registerCommand('roadmap.toggleCheckbox', async (item: RoadmapItem) => {
|
||||
const doc = vscode.workspace.textDocuments.find(d => d.uri.fsPath === checklistFile);
|
||||
if (!doc) { return; }
|
||||
|
||||
const editor = await vscode.window.showTextDocument(doc, { preview: false });
|
||||
const lines = doc.getText().split('\n');
|
||||
|
||||
const labelRegex = new RegExp(`[-*]\\s+\\[(${item.checked ? 'x' : ' '})\\]\\s+${escapeRegex(item.label)}$`);
|
||||
const matchIndex = lines.findIndex(line => labelRegex.test(line.trim()));
|
||||
|
||||
if (matchIndex === -1) {
|
||||
vscode.window.showWarningMessage(`Could not find task "${item.label}" in the file.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const line = lines[matchIndex];
|
||||
const newCheck = item.checked ? '[ ]' : '[x]';
|
||||
const newLine = line.replace(/\[( |x)\]/, newCheck);
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const uri = doc.uri;
|
||||
|
||||
edit.replace(uri, doc.lineAt(matchIndex).range, newLine);
|
||||
|
||||
// If parent, toggle all children too
|
||||
if (item.children.length > 0) {
|
||||
const indentLevel = line.match(/^(\s*)/)?.[1].length || 0;
|
||||
|
||||
for (let i = matchIndex + 1; i < lines.length; i++) {
|
||||
const thisLine = lines[i];
|
||||
const currentIndent = thisLine.match(/^(\s*)/)?.[1].length || 0;
|
||||
|
||||
if (currentIndent <= indentLevel) { break; }
|
||||
if (/^\s*[-*]\s+\[( |x)\]/.test(thisLine)) {
|
||||
const toggled = thisLine.replace(/\[( |x)\]/, newCheck);
|
||||
edit.replace(uri, doc.lineAt(i).range, toggled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
await doc.save();
|
||||
}),
|
||||
vscode.commands.registerCommand('roadmapChecklist.reveal', async (item: RoadmapItem) => {
|
||||
treeView.reveal(item, { expand: true });
|
||||
})
|
||||
);
|
||||
|
||||
function escapeRegex(str: string) {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
|
||||
Reference in New Issue
Block a user