diff --git a/README.md b/README.md index 688ae34..6cc2b5b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # vscode extension for tatr see: https://github.com/tsoding/tatr + +This extension doesn't require the tatr executable. diff --git a/package.json b/package.json index cf12d07..7556d12 100644 --- a/package.json +++ b/package.json @@ -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" } ] }, diff --git a/src/commands/health-check.ts b/src/commands/health-check.ts new file mode 100644 index 0000000..0c4b902 --- /dev/null +++ b/src/commands/health-check.ts @@ -0,0 +1,5 @@ +import { window } from "vscode"; + +export const healthCheckCommand = () => { + window.showInformationMessage("TBD"); +}; diff --git a/src/commands/init.ts b/src/commands/init.ts new file mode 100644 index 0000000..bc67c44 --- /dev/null +++ b/src/commands/init.ts @@ -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}`); +}; diff --git a/src/extension.ts b/src/extension.ts index d0baf37..ac55cb9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 = () => {}; diff --git a/src/utils/workspace.ts b/src/utils/workspace.ts new file mode 100644 index 0000000..4ae2983 --- /dev/null +++ b/src/utils/workspace.ts @@ -0,0 +1,15 @@ +import { window, workspace, type WorkspaceFolder } from "vscode"; + +export const pickWorkspaceFolder = async (placeHolder: string): Promise => { + 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 }); +}; diff --git a/tasks/20260928-150820/TASK.md b/tasks/20260928-150820/TASK.md new file mode 100644 index 0000000..4210446 --- /dev/null +++ b/tasks/20260928-150820/TASK.md @@ -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 diff --git a/tasks/README.md b/tasks/README.md new file mode 100644 index 0000000..92ba518 --- /dev/null +++ b/tasks/README.md @@ -0,0 +1,17 @@ +# Tasks + +This folder contains tasks as defined by the specificiation of [Tatr](https://github.com/tsoding/tatr). + + + +## 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.