All files / ollama-view/src/providers framingProvider.ts

70% Statements 56/80
75% Branches 6/8
83.33% Functions 5/6
70% Lines 56/80

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 811x 1x 1x 1x 1x 1x 1x 1x 1x 1x                             1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 32x 32x 1x 1x 8x 8x 8x 8x 8x                     1x  
import * as vscode from 'vscode';
 
import { FramingSource, FramingTag, ModelFraming } from '../models/modelFraming';
import { FramingService } from '../services/framingService';
 
/**
 * Represents a framing in the tree view.
 */
export class FramingItem extends vscode.TreeItem {
    constructor(public readonly framing: ModelFraming) {
        super(framing.name, vscode.TreeItemCollapsibleState.None);

        this.tooltip = framing.description || framing.name;
        this.description = framing.source === FramingSource.BuiltIn ? 'Built-in' : '';
        this.contextValue = framing.source === FramingSource.BuiltIn ? 'framing-builtin' : 'framing-user';
        this.iconPath = new vscode.ThemeIcon('file-code');

        // Command to open the framing editor
        this.command = {
            command: 'ollamaView.editFraming',
            title: 'Edit Model Framing',
            arguments: [this],
        };
    }
}
 
/**
 * Represents a tag folder in the tree view.
 */
export class FramingTagItem extends vscode.TreeItem {
    constructor(public readonly tag: FramingTag) {
        super(tag.name, vscode.TreeItemCollapsibleState.Collapsed);
 
        this.tooltip = `Tag: ${tag.name}`;
        this.contextValue = tag.isReserved ? 'tag-reserved' : 'tag-custom';
        this.iconPath = new vscode.ThemeIcon('tag');
    }
}
 
export type FramingTreeItem = FramingItem | FramingTagItem;
 
/**
 * TreeDataProvider for the Model Framings sidebar view.
 */
export class FramingProvider implements vscode.TreeDataProvider<FramingTreeItem> {
    private _onDidChangeTreeData: vscode.EventEmitter<FramingTreeItem | undefined | null | void> =
        new vscode.EventEmitter<FramingTreeItem | undefined | null | void>();
    readonly onDidChangeTreeData: vscode.Event<FramingTreeItem | undefined | null | void> =
        this._onDidChangeTreeData.event;
 
    constructor(private framingService: FramingService) {}
 
    /**
     * Refreshes the tree view.
     */
    refresh(): void {
        this._onDidChangeTreeData.fire();
    }
 
    getTreeItem(element: FramingTreeItem): vscode.TreeItem {
        return element;
    }
 
    async getChildren(element?: FramingTreeItem): Promise<FramingTreeItem[]> {
        if (!element) {
            // Root level: Show Tags
            const tags = this.framingService.getAllTags();
            return tags.map((tag) => new FramingTagItem(tag));
        }

        if (element instanceof FramingTagItem) {
            // Tag level: Show Framings under this tag
            const framings = this.framingService.getFramingsByTag(element.tag.name);
            return framings.map((f) => new FramingItem(f));
        }

        // Framings (leaf nodes) have no children
        return [];
    }
}