<commit_before>package vshaxe.view.methods;

import vshaxe.server.LanguageServer;
import vshaxe.server.HaxeMethodResult;
import vshaxe.helper.CopyPaste;
import js.Date;

class MethodTreeView {
    final context:ExtensionContext;
    final server:LanguageServer;

    var enabled:Bool;
    var methods:Array<MethodTreeItem> = [];
    var treeView:TreeView<MethodTreeItem>;
    var _onDidChangeTreeData = new EventEmitter<MethodTreeItem>();

    public var onDidChangeTreeData:Event<MethodTreeItem>;

    public function new(context:ExtensionContext, server:LanguageServer) {
        this.context = context;
        this.server = server;

        server.onDidRunHaxeMethod(onDidRunHaxeMethod);
        workspace.onDidChangeConfiguration(_ -> update());
        onDidChangeTreeData = _onDidChangeTreeData.event;
        update();

        window.registerTreeDataProvider("haxe.methods", this);
        treeView = window.createTreeView("haxe.methods", {treeDataProvider: this});
        context.registerHaxeCommand(Methods_CollapseAll, collapseAll);
        context.registerHaxeCommand(Methods_Copy, copy);
    }

    function onDidRunHaxeMethod(data:HaxeMethodResult) {
        if (!enabled) {
            return;
        }

        var rootTimer = data.response.timers;
        if (rootTimer == null) {
            rootTimer = makeTimer("", 0, []);
        }
        rootTimer.children.push(createAdditionalTimers(data));

        var method = data.method;
        methods = methods.filter(item -> item.method != method);
        var item = new MethodTreeItem(context, null, rootTimer, data.method);
        methods.push(item);
        methods.sort((item1, item2) -> Reflect.compare(item1.method, item2.method));
        _onDidChangeTreeData.fire();
        // this is awkward... https://github.com/Microsoft/vscode/issues/47153
        // haxe.Timer.delay(() -> treeView.reveal(item, {select: false}), 250);
    }

    function createAdditionalTimers(data:HaxeMethodResult):Timer {
        var transmissionTime = data.arrivalDate - data.response.timestamp;
        var processingTime = data.processedDate - data.arrivalDate;
        var totalTime = transmissionTime + processingTime;
        return makeTimer("vshaxe", totalTime, [
            makeTimer("transmission", transmissionTime),
            makeTimer("processing", processingTime)
        ]);
    }

    function makeTimer(name:String, time:Float, ?children:Array<Timer>):Timer {
        var date = new Date(time);
        return {
            name: name,
            time: date.getSeconds() + (date.getMilliseconds() / 1000.0),
            children: children
        };
    }

    function update() {
        enabled = workspace.getConfiguration("haxe").get("enableMethodsView");
        commands.executeCommand("setContext", "enableHaxeMethodsView", enabled);
    }

    public function getTreeItem(element:MethodTreeItem):MethodTreeItem {
        return element;
    }

    public function getChildren(?element:MethodTreeItem):Array<MethodTreeItem> {
        return if (element == null) methods else element.children;
    }<commit_msg>Haxe timestamp is in seconds<commit_after>package vshaxe.view.methods;

import vshaxe.server.LanguageServer;
import vshaxe.server.HaxeMethodResult;
import vshaxe.helper.CopyPaste;
import js.Date;

class MethodTreeView {
    final context:ExtensionContext;
    final server:LanguageServer;

    var enabled:Bool;
    var methods:Array<MethodTreeItem> = [];
    var treeView:TreeView<MethodTreeItem>;
    var _onDidChangeTreeData = new EventEmitter<MethodTreeItem>();

    public var onDidChangeTreeData:Event<MethodTreeItem>;

    public function new(context:ExtensionContext, server:LanguageServer) {
        this.context = context;
        this.server = server;

        server.onDidRunHaxeMethod(onDidRunHaxeMethod);
        workspace.onDidChangeConfiguration(_ -> update());
        onDidChangeTreeData = _onDidChangeTreeData.event;
        update();

        window.registerTreeDataProvider("haxe.methods", this);
        treeView = window.createTreeView("haxe.methods", {treeDataProvider: this});
        context.registerHaxeCommand(Methods_CollapseAll, collapseAll);
        context.registerHaxeCommand(Methods_Copy, copy);
    }

    function onDidRunHaxeMethod(data:HaxeMethodResult) {
        if (!enabled) {
            return;
        }

        var rootTimer = data.response.timers;
        if (rootTimer == null) {
            rootTimer = makeTimer("", 0, []);
        }
        rootTimer.children.push(createAdditionalTimers(data));

        var method = data.method;
        methods = methods.filter(item -> item.method != method);
        var item = new MethodTreeItem(context, null, rootTimer, data.method);
        methods.push(item);
        methods.sort((item1, item2) -> Reflect.compare(item1.method, item2.method));
        _onDidChangeTreeData.fire();
        // this is awkward... https://github.com/Microsoft/vscode/issues/47153
        // haxe.Timer.delay(() -> treeView.reveal(item, {select: false}), 250);
    }

    function createAdditionalTimers(data:HaxeMethodResult):Timer {
        var transmissionTime = data.arrivalDate - (data.response.timestamp * 1000.0);
        var processingTime = data.processedDate - data.arrivalDate;
        var totalTime = transmissionTime + processingTime;
        return makeTimer("vshaxe", totalTime, [
            makeTimer("transmission", transmissionTime),
            makeTimer("processing", processingTime)
        ]);
    }

    function makeTimer(name:String, time:Float, ?children:Array<Timer>):Timer {
        var date = new Date(time);
        return {
            name: name,
            time: date.getSeconds() + (date.getMilliseconds() / 1000.0),
            children: children
        };
    }

    function update() {
        enabled = workspace.getConfiguration("haxe").get("enableMethodsView");
        commands.executeCommand("setContext", "enableHaxeMethodsView", enabled);
    }

    public function getTreeItem(element:MethodTreeItem):MethodTreeItem {
        return element;
    }

    public function getChildren(?element:MethodTreeItem):Array<MethodTreeItem> {
        return if (element == null) methods else element.children;
    }
{'fraction_non_alphanumeric': 0.1112540192926045, 'fraction_numerical': 0.006591639871382637, 'mean_word_length': 3.1144179894179893, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3213279', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1714, 'n_words': 319}