feat: init command and improve project structure

This commit is contained in:
2026-09-28 19:14:58 +02:00
parent f0b75e1241
commit 58f4bda910
8 changed files with 99 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
# vscode extension for tatr
see: https://github.com/tsoding/tatr
This extension doesn't require the tatr executable.

View File

@@ -22,7 +22,11 @@
"commands": [
{
"command": "tatr-vsc.healthCheck",
"title": "Tatr Health Check"
"title": "Tatr: Health Check"
},
{
"command": "tatr-vsc.init",
"title": "Tatr: Initialize Tasks Folder"
}
]
},

View File

@@ -0,0 +1,5 @@
import { window } from "vscode";
export const healthCheckCommand = () => {
window.showInformationMessage("TBD");
};

36
src/commands/init.ts Normal file
View File

@@ -0,0 +1,36 @@
import { FileSystemError, FileType, Uri, window, workspace, type FileStat } from "vscode";
import { pickWorkspaceFolder } from "../utils/workspace";
export const initCommand = async () => {
const folder = await pickWorkspaceFolder("Select the folder to create tasks/ in");
if (!folder) { return; }
const tasksUri = Uri.joinPath(folder.uri, "tasks");
let stat: FileStat | undefined;
try {
stat = await workspace.fs.stat(tasksUri);
} catch (e) {
if (!(e instanceof FileSystemError && e.code === "FileNotFound")) {
window.showErrorMessage(`Tatr: failed to access ${tasksUri.fsPath}: ${e}`);
return;
}
}
if (stat) {
if (stat.type & FileType.Directory) {
window.showInformationMessage("Tatr: tasks/ already exists");
} else {
window.showErrorMessage(`Tatr: ${tasksUri.fsPath} exists but is not a directory`);
}
return;
}
try {
await workspace.fs.createDirectory(tasksUri);
} catch (e) {
window.showErrorMessage(`Tatr: failed to create ${tasksUri.fsPath}: ${e}`);
return;
}
window.showInformationMessage(`Tatr: created ${tasksUri.fsPath}`);
};

View File

@@ -1,13 +1,14 @@
import * as vscode from "vscode";
import { commands, type ExtensionContext } from "vscode";
import { healthCheckCommand } from "./commands/health-check";
import { initCommand } from "./commands/init";
export const activate = (context: ExtensionContext) => {
context.subscriptions.push(
commands.registerCommand("tatr-vsc.healthCheck", healthCheckCommand),
commands.registerCommand("tatr-vsc.init", initCommand),
);
export const activate = (context: vscode.ExtensionContext) => {
console.log("Extension ready");
const disposable = vscode.commands.registerCommand("tatr-vsc.healthCheck", () => {
vscode.window.showInformationMessage("Ok");
});
context.subscriptions.push(disposable);
};
export const deactivate = () => {};

15
src/utils/workspace.ts Normal file
View File

@@ -0,0 +1,15 @@
import { window, workspace, type WorkspaceFolder } from "vscode";
export const pickWorkspaceFolder = async (placeHolder: string): Promise<WorkspaceFolder | undefined> => {
const folders = workspace.workspaceFolders;
if (!folders || folders.length === 0) {
window.showErrorMessage("Tatr: open a folder first");
return undefined;
}
if (folders.length === 1) {
return folders[0];
}
return window.showWorkspaceFolderPick({ placeHolder });
};

View File

@@ -0,0 +1,10 @@
# Implement basic editor commands
- STATUS: OPEN
- PRIORITY: 100
- TAGS:
- [x] Create `tasks/` if missing
- [ ] Create a new task from the TODO at cursor
- [ ] Go to task from the Task ID at cursor
- [ ] Find references to the Task ID at cursor

17
tasks/README.md Normal file
View File

@@ -0,0 +1,17 @@
# Tasks
This folder contains tasks as defined by the specificiation of [Tatr](https://github.com/tsoding/tatr).
<img src="https://raw.githubusercontent.com/tsoding/tatr/main/cover/cover-512.png" width=512>
## Quick Start on Linux
```console
$ git clone https://github.com/tsoding/tatr
$ cd tatr
$ cc -o nob nob.c
$ ./nob
$ sudo cp ./build/tatr /usr/local/bin/
```
After that run `tatr ls` anywhere within this repo to get the list of currently opened tasks. Use `tatr help` to list all the available subcommands of the tool.