Skip to content

Commit e2cf5d0

Browse files
Fixes
1 parent 6a78491 commit e2cf5d0

24 files changed

Lines changed: 77 additions & 222 deletions

coverage-thresholds.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"lines": 83.12,
3-
"functions": 81.41,
4-
"branches": 76.02,
5-
"statements": 83.12
2+
"lines": 83,
3+
"functions": 80.81,
4+
"branches": 76.9,
5+
"statements": 83
66
}

src/CommandTreeProvider.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { buildNestedFolderItems } from "./tree/folderTree";
99
import { createCommandNode, createCategoryNode } from "./tree/nodeFactory";
1010
import { getAllRows } from "./db/db";
1111
import type { CommandRow } from "./db/db";
12-
import { getDb } from "./db/lifecycle";
12+
import { getDbOrThrow } from "./db/lifecycle";
1313

1414
type SortOrder = "folder" | "name" | "type";
1515

@@ -49,11 +49,8 @@ export class CommandTreeProvider implements vscode.TreeDataProvider<CommandTreeI
4949
}
5050

5151
private loadSummaries(): void {
52-
const dbResult = getDb();
53-
if (!dbResult.ok) {
54-
return;
55-
}
56-
const rows = getAllRows(dbResult.value);
52+
const handle = getDbOrThrow();
53+
const rows = getAllRows(handle);
5754
const map = new Map<string, CommandRow>();
5855
for (const row of rows) {
5956
map.set(row.commandId, row);

src/QuickTasksProvider.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from "vscode";
88
import type { CommandItem, CommandTreeItem } from "./models/TaskItem";
99
import { isCommandItem } from "./models/TaskItem";
1010
import { TagConfig } from "./config/TagConfig";
11-
import { getDb } from "./db/lifecycle";
11+
import { getDbOrThrow } from "./db/lifecycle";
1212
import { getCommandIdsByTag, reorderTagCommands } from "./db/db";
1313
import { createCommandNode, createPlaceholderNode } from "./tree/nodeFactory";
1414

@@ -104,11 +104,8 @@ export class QuickTasksProvider
104104
* Sorts tasks by display_order from junction table.
105105
*/
106106
private sortByDisplayOrder(tasks: CommandItem[]): CommandItem[] {
107-
const dbResult = getDb();
108-
if (!dbResult.ok) {
109-
return tasks.sort((a, b) => a.label.localeCompare(b.label));
110-
}
111-
const orderedIds = getCommandIdsByTag({ handle: dbResult.value, tagName: QUICK_TAG });
107+
const handle = getDbOrThrow();
108+
const orderedIds = getCommandIdsByTag({ handle, tagName: QUICK_TAG });
112109
return [...tasks].sort((a, b) => {
113110
const indexA = orderedIds.indexOf(a.id);
114111
const indexB = orderedIds.indexOf(b.id);
@@ -147,10 +144,6 @@ export class QuickTasksProvider
147144
}
148145

149146
const orderedIds = this.fetchOrderedQuickIds();
150-
if (orderedIds === undefined) {
151-
return;
152-
}
153-
154147
const reordered = this.computeReorder({ orderedIds, draggedTask, target });
155148
if (reordered === undefined) {
156149
return;
@@ -163,12 +156,9 @@ export class QuickTasksProvider
163156
/**
164157
* Fetches ordered command IDs for the quick tag from the DB.
165158
*/
166-
private fetchOrderedQuickIds(): string[] | undefined {
167-
const dbResult = getDb();
168-
if (!dbResult.ok) {
169-
return undefined;
170-
}
171-
return getCommandIdsByTag({ handle: dbResult.value, tagName: QUICK_TAG });
159+
private fetchOrderedQuickIds(): string[] {
160+
const handle = getDbOrThrow();
161+
return getCommandIdsByTag({ handle, tagName: QUICK_TAG });
172162
}
173163

174164
/**
@@ -205,11 +195,8 @@ export class QuickTasksProvider
205195
* Persists display_order for each command in the reordered list.
206196
*/
207197
private persistDisplayOrder(reordered: string[]): void {
208-
const dbResult = getDb();
209-
if (!dbResult.ok) {
210-
return;
211-
}
212-
reorderTagCommands({ handle: dbResult.value, tagName: QUICK_TAG, orderedCommandIds: reordered });
198+
const handle = getDbOrThrow();
199+
reorderTagCommands({ handle, tagName: QUICK_TAG, orderedCommandIds: reordered });
213200
}
214201

215202
/**

src/config/TagConfig.ts

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import type { CommandItem } from "../models/TaskItem";
8-
import { getDb } from "../db/lifecycle";
8+
import { getDbOrThrow } from "../db/lifecycle";
99
import {
1010
addTagToCommand,
1111
removeTagFromCommand,
@@ -22,16 +22,12 @@ export class TagConfig {
2222
* Loads all tag assignments from SQLite junction table.
2323
*/
2424
public load(): void {
25-
const dbResult = getDb();
26-
if (!dbResult.ok) {
27-
this.commandTagsMap = new Map();
28-
return;
29-
}
25+
const handle = getDbOrThrow();
3026

31-
const tagNames = getAllTagNames(dbResult.value);
27+
const tagNames = getAllTagNames(handle);
3228
const map = new Map<string, string[]>();
3329
for (const tagName of tagNames) {
34-
const commandIds = getCommandIdsByTag({ handle: dbResult.value, tagName });
30+
const commandIds = getCommandIdsByTag({ handle, tagName });
3531
for (const commandId of commandIds) {
3632
const tags = map.get(commandId) ?? [];
3733
tags.push(tagName);
@@ -57,23 +53,17 @@ export class TagConfig {
5753
* Gets all tag names.
5854
*/
5955
public getTagNames(): string[] {
60-
const dbResult = getDb();
61-
if (!dbResult.ok) {
62-
return [];
63-
}
64-
return getAllTagNames(dbResult.value);
56+
const handle = getDbOrThrow();
57+
return getAllTagNames(handle);
6558
}
6659

6760
/**
6861
* SPEC: tagging/management
6962
* Adds a task to a tag by creating junction record with exact command ID.
7063
*/
7164
public addTaskToTag(task: CommandItem, tagName: string): void {
72-
const dbResult = getDb();
73-
if (!dbResult.ok) {
74-
return;
75-
}
76-
addTagToCommand({ handle: dbResult.value, commandId: task.id, tagName });
65+
const handle = getDbOrThrow();
66+
addTagToCommand({ handle, commandId: task.id, tagName });
7767
this.load();
7868
}
7969

@@ -82,11 +72,8 @@ export class TagConfig {
8272
* Removes a task from a tag by deleting junction record.
8373
*/
8474
public removeTaskFromTag(task: CommandItem, tagName: string): void {
85-
const dbResult = getDb();
86-
if (!dbResult.ok) {
87-
return;
88-
}
89-
removeTagFromCommand({ handle: dbResult.value, commandId: task.id, tagName });
75+
const handle = getDbOrThrow();
76+
removeTagFromCommand({ handle, commandId: task.id, tagName });
9077
this.load();
9178
}
9279

@@ -95,23 +82,17 @@ export class TagConfig {
9582
* Gets ordered command IDs for a tag (ordered by display_order).
9683
*/
9784
public getOrderedCommandIds(tagName: string): string[] {
98-
const dbResult = getDb();
99-
if (!dbResult.ok) {
100-
return [];
101-
}
102-
return getCommandIdsByTag({ handle: dbResult.value, tagName });
85+
const handle = getDbOrThrow();
86+
return getCommandIdsByTag({ handle, tagName });
10387
}
10488

10589
/**
10690
* SPEC: quick-launch
10791
* Reorders commands for a tag by updating display_order in junction table.
10892
*/
10993
public reorderCommands(tagName: string, orderedCommandIds: string[]): void {
110-
const dbResult = getDb();
111-
if (!dbResult.ok) {
112-
return;
113-
}
114-
reorderTagCommands({ handle: dbResult.value, tagName, orderedCommandIds });
94+
const handle = getDbOrThrow();
95+
reorderTagCommands({ handle, tagName, orderedCommandIds });
11596
this.load();
11697
}
11798
}

src/discovery/ant.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile } from "../utils/fileUtils";
5+
import { readFileContent } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = {
88
icon: "symbol-constructor",
@@ -27,12 +27,7 @@ export async function discoverAntTargets(workspaceRoot: string, excludePatterns:
2727
const commands: CommandItem[] = [];
2828

2929
for (const file of files) {
30-
const result = await readFile(file);
31-
if (!result.ok) {
32-
continue; // Skip files we can't read
33-
}
34-
35-
const content = result.value;
30+
const content = await readFileContent(file);
3631
const antDir = path.dirname(file.fsPath);
3732
const category = simplifyPath(file.fsPath, workspaceRoot);
3833
const targets = parseAntTargets(content);

src/discovery/cargo.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile } from "../utils/fileUtils";
5+
import { readFileContent } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = { icon: "package", color: "terminal.ansiRed" };
88
export const CATEGORY_DEF: CategoryDef = {
@@ -41,12 +41,7 @@ export async function discoverCargoTasks(workspaceRoot: string, excludePatterns:
4141
const commands: CommandItem[] = [];
4242

4343
for (const file of files) {
44-
const result = await readFile(file);
45-
if (!result.ok) {
46-
continue; // Skip files we can't read
47-
}
48-
49-
const content = result.value;
44+
const content = await readFileContent(file);
5045
const cargoDir = path.dirname(file.fsPath);
5146
const category = simplifyPath(file.fsPath, workspaceRoot);
5247

src/discovery/composer.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, MutableCommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile, parseJson } from "../utils/fileUtils";
5+
import { readFileContent } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = {
88
icon: "symbol-interface",
@@ -70,17 +70,8 @@ function buildCommandItem(params: BuildCommandItemParams): CommandItem {
7070
}
7171

7272
async function extractScriptsFromFile(file: vscode.Uri, workspaceRoot: string): Promise<CommandItem[]> {
73-
const contentResult = await readFile(file);
74-
if (!contentResult.ok) {
75-
return [];
76-
}
77-
78-
const composerResult = parseJson<ComposerJson>(contentResult.value);
79-
if (!composerResult.ok) {
80-
return [];
81-
}
82-
83-
const composer = composerResult.value;
73+
const content = await readFileContent(file);
74+
const composer = JSON.parse(content) as ComposerJson;
8475
if (composer.scripts === undefined || typeof composer.scripts !== "object") {
8576
return [];
8677
}

src/discovery/csharp-script.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, MutableCommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile, parseFirstLineComment } from "../utils/fileUtils";
5+
import { readFileContent, parseFirstLineComment } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = {
88
icon: "file-code",
@@ -28,13 +28,9 @@ export async function discoverCsharpScripts(workspaceRoot: string, excludePatter
2828
const commands: CommandItem[] = [];
2929

3030
for (const file of files) {
31-
const result = await readFile(file);
32-
if (!result.ok) {
33-
continue;
34-
}
35-
31+
const content = await readFileContent(file);
3632
const name = path.basename(file.fsPath);
37-
const description = parseFirstLineComment(result.value, COMMENT_PREFIX);
33+
const description = parseFirstLineComment(content, COMMENT_PREFIX);
3834

3935
const task: MutableCommandItem = {
4036
id: generateCommandId("csharp-script", file.fsPath, name),

src/discovery/deno.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, MutableCommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile, parseJson, removeJsonComments } from "../utils/fileUtils";
5+
import { readFileContent, removeJsonComments } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = {
88
icon: "symbol-namespace",
@@ -39,19 +39,9 @@ export async function discoverDenoTasks(workspaceRoot: string, excludePatterns:
3939
const commands: CommandItem[] = [];
4040

4141
for (const file of allFiles) {
42-
const contentResult = await readFile(file);
43-
if (!contentResult.ok) {
44-
continue; // Skip unreadable files
45-
}
46-
47-
// Remove JSONC comments
48-
const cleanJson = removeJsonComments(contentResult.value);
49-
const denoResult = parseJson<DenoJson>(cleanJson);
50-
if (!denoResult.ok) {
51-
continue; // Skip malformed deno.json
52-
}
53-
54-
const deno = denoResult.value;
42+
const content = await readFileContent(file);
43+
const cleanJson = removeJsonComments(content);
44+
const deno = JSON.parse(cleanJson) as DenoJson;
5545
if (deno.tasks === undefined || typeof deno.tasks !== "object") {
5646
continue;
5747
}

src/discovery/docker.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import * as path from "path";
33
import type { CommandItem, MutableCommandItem, IconDef, CategoryDef } from "../models/TaskItem";
44
import { generateCommandId, simplifyPath } from "../models/TaskItem";
5-
import { readFile } from "../utils/fileUtils";
5+
import { readFileContent } from "../utils/fileUtils";
66

77
export const ICON_DEF: IconDef = {
88
icon: "server-environment",
@@ -31,12 +31,7 @@ export async function discoverDockerComposeServices(
3131
const commands: CommandItem[] = [];
3232

3333
for (const file of allFiles) {
34-
const result = await readFile(file);
35-
if (!result.ok) {
36-
continue; // Skip files we can't read
37-
}
38-
39-
const content = result.value;
34+
const content = await readFileContent(file);
4035
const dockerDir = path.dirname(file.fsPath);
4136
const category = simplifyPath(file.fsPath, workspaceRoot);
4237
const services = parseDockerComposeServices(content);

0 commit comments

Comments
 (0)