<commit_before>[<ReflectedDefinition>]
module Ionide.Fake

open System
open System.Text.RegularExpressions
open FunScript
open FunScript.TypeScript
open FunScript.TypeScript.fs
open FunScript.TypeScript.child_process
open FunScript.TypeScript.AtomCore
open FunScript.TypeScript.text_buffer
open Atom
open Atom.FSharp

[<ReflectedDefinition>]
module FakeService =
    type BuildData = {Name : string; Start : DateTime; mutable End : DateTime option; mutable Output : string; mutable TextEditor : IEditor option}

    let mutable linuxPrefix = ""
    let mutable command = ""
    let mutable script = ""
    let mutable parameters : string[]= [||]

    //let mutable private File : (string * string) option = None
    let mutable private taskListView : (atom.SelectListView * IPanel) option = None
    let mutable private buildListView : (atom.SelectListView * IPanel) option = None
    let mutable private BuildList = ResizeArray()


    let private viewForItem (desc : ListView.ItemDescription) =
        if JS.isDefined desc then
            sprintf "<li>%s</li>" desc.data |> jq
        else
            "<li></li>" |> jq

    let private startBuild (packageDescription :  ListView.ItemDescription) =
        let data = {Name = packageDescription.data; Start = DateTime.Now; End = None; Output = ""; TextEditor = None}
        BuildList.Add data
        let fakeProcess = Process.spawnWithNotifications command linuxPrefix packageDescription.data
        fakeProcess.on("exit",unbox<Function>(fun _ -> data.End <- Some DateTime.Now)) |> ignore
        fakeProcess.stdout.on("data", unbox<Function>(fun e ->
            data.Output <- data.Output + e.ToString()
            data.TextEditor |> Option.iter (fun te ->
                let b = te.getBuffer()
                e.ToString() |> b.append |> ignore
                )
            )) |> ignore
        fakeProcess.stderr.on("data", unbox<Function>(fun e ->
            data.Output <- data.Output + e.ToString()
            data.TextEditor |> Option.iter (fun te ->
                let b = te.getBuffer()
                e.ToString() |> b.append |> ignore
            )
        )) |> ignore
 
        ()

    let private registerTaskList () =
        let stopChangingCallback (ev : IEditor) (lv : atom.SelectListView) = fun () -> ()
        let cancelledCallback = Func<_>(fun _ -> taskListView |> Option.iter(fun (model, view) ->  view.hide()) :> obj)
        let confirmedCallback = unbox<Func<_, _>> (fun (packageDescription : ListView.ItemDescription) ->
            taskListView |> Option.iter (fun (model, view) -> view.hide())
            startBuild packageDescription
        )
        ListView.regiterListView stopChangingCallback cancelledCallback confirmedCallback viewForItem false

    let private registerBuildList () =
        let stopChangingCallback (ev : IEditor) (lv : atom.SelectListView) = fun () -> ()
        let cancelledCallback = Func<_>(fun _ -> buildListView |> Option.iter(fun (model, view) ->  view.hide()) :> obj)
        let confirmedCallback = unbox<Func<_, _>> (fun (buildDescription : ListView.ItemDescription) ->
            buildListView |> Option.iter (fun (model, view) -> view.hide())
            let build = BuildList |> Seq.find(fun n ->
                let dateString = n.Start.ToShortDateString().Replace("\\",".").Replace("/",".")
                let timeString = n.Start.ToShortTimeString().Replace("\\",".").Replace("/", ".")
                let desc = sprintf "%s - %s %s" n.Name dateString timeString
                desc = buildDescription.data)

            Globals.atom.workspace._open(buildDescription.data, {split = "right"})._done((fun ed ->
                build.TextEditor <- Some ed
                ed.insertText build.Output |> ignore
                ed.onDidDestroy((fun _ -> build.TextEditor <- None) |> unbox<Function>) |> ignore
                let view = Globals.atom.views.getView ed
                setComponentEnabled(view, false)) |> unbox<Function>)
            ()
        )
        ListView.regiterListView stopChangingCallback cancelledCallback confirmedCallback viewForItem false

    let loadParameters () =
        let p = Globals.atom.project.getPaths().[0]
        linuxPrefix <- Settings.loadOrDefault (fun s -> s.Fake.linuxPrefix ) "sh"
        command <- Settings.loadOrDefault (fun s -> p + "/" + s.Fake.command ) (if Process.isWin () then p + "/" + "build.cmd" else p + "/" + "build.sh")
        script <- Settings.loadOrDefault (fun s -> p + "/" + s.Fake.build )  (p + "/" + "build.fsx")
        ()

    let private FAKENotFound () =
        Process.notice (ref None) true "FAKE error" "FAKE script not found"

    let private BuildTask () =
        loadParameters ()
        if Globals.existsSync script |> not || Globals.existsSync command |> not then
            FAKENotFound ()
        else
            taskListView |> Option.iter(fun (model, view) ->
            view.show()
            model.focusFilterEditor() |> ignore
            let script = script |> Globals.readFileSync
                                |> fun n -> n.toString()
            let matches = Regex.Matches(script, "Target \"([\\w.]+)\"") |> Seq.cast<Match> |> Seq.toArray<commit_msg>proofreading<commit_after>[<ReflectedDefinition>]
module Ionide.Fake

open System
open System.Text.RegularExpressions
open FunScript
open FunScript.TypeScript
open FunScript.TypeScript.fs
open FunScript.TypeScript.child_process
open FunScript.TypeScript.AtomCore
open FunScript.TypeScript.text_buffer
open Atom
open Atom.FSharp

[<ReflectedDefinition>]
module FakeService =
    type BuildData = {Name : string; Start : DateTime; mutable End : DateTime option; mutable Output : string; mutable TextEditor : IEditor option}

    let mutable linuxPrefix = ""
    let mutable command = ""
    let mutable script = ""
    let mutable parameters : string[]= [||]

    //let mutable private File : (string * string) option = None
    let mutable private taskListView : (atom.SelectListView * IPanel) option = None
    let mutable private buildListView : (atom.SelectListView * IPanel) option = None
    let mutable private BuildList = ResizeArray()


    let private viewForItem (desc : ListView.ItemDescription) =
        if JS.isDefined desc then
            sprintf "<li>%s</li>" desc.data |> jq
        else
            "<li></li>" |> jq

    let private startBuild (packageDescription :  ListView.ItemDescription) =
        let data = {Name = packageDescription.data; Start = DateTime.Now; End = None; Output = ""; TextEditor = None}
        BuildList.Add data
        let fakeProcess = Process.spawnWithNotifications command linuxPrefix packageDescription.data
        fakeProcess.on("exit",unbox<Function>(fun _ -> data.End <- Some DateTime.Now)) |> ignore
        fakeProcess.stdout.on("data", unbox<Function>(fun e ->
            data.Output <- data.Output + e.ToString()
            data.TextEditor |> Option.iter (fun te ->
                let b = te.getBuffer()
                e.ToString() |> b.append |> ignore
                )
            )) |> ignore
        fakeProcess.stderr.on("data", unbox<Function>(fun e ->
            data.Output <- data.Output + e.ToString()
            data.TextEditor |> Option.iter (fun te ->
                let b = te.getBuffer()
                e.ToString() |> b.append |> ignore
            )
        )) |> ignore

        ()

    let private registerTaskList () =
        let stopChangingCallback (ev : IEditor) (lv : atom.SelectListView) = fun () -> ()
        let cancelledCallback = Func<_>(fun _ -> taskListView |> Option.iter(fun (model, view) ->  view.hide()) :> obj)
        let confirmedCallback = unbox<Func<_, _>> (fun (packageDescription : ListView.ItemDescription) ->
            taskListView |> Option.iter (fun (model, view) -> view.hide())
            startBuild packageDescription
        )
        ListView.registerListView stopChangingCallback cancelledCallback confirmedCallback viewForItem false

    let private registerBuildList () =
        let stopChangingCallback (ev : IEditor) (lv : atom.SelectListView) = fun () -> ()
        let cancelledCallback = Func<_>(fun _ -> buildListView |> Option.iter(fun (model, view) ->  view.hide()) :> obj)
        let confirmedCallback = unbox<Func<_, _>> (fun (buildDescription : ListView.ItemDescription) ->
            buildListView |> Option.iter (fun (model, view) -> view.hide())
            let build = BuildList |> Seq.find(fun n ->
                let dateString = n.Start.ToShortDateString().Replace("\\",".").Replace("/",".")
                let timeString = n.Start.ToShortTimeString().Replace("\\",".").Replace("/", ".")
                let desc = sprintf "%s - %s %s" n.Name dateString timeString
                desc = buildDescription.data)

            Globals.atom.workspace._open(buildDescription.data, {split = "right"})._done((fun ed ->
                build.TextEditor <- Some ed
                ed.insertText build.Output |> ignore
                ed.onDidDestroy((fun _ -> build.TextEditor <- None) |> unbox<Function>) |> ignore
                let view = Globals.atom.views.getView ed
                setComponentEnabled(view, false)) |> unbox<Function>)
            ()
        )
        ListView.registerListView stopChangingCallback cancelledCallback confirmedCallback viewForItem false

    let loadParameters () =
        let p = Globals.atom.project.getPaths().[0]
        linuxPrefix <- Settings.loadOrDefault (fun s -> s.Fake.linuxPrefix ) "sh"
        command <- Settings.loadOrDefault (fun s -> p + "/" + s.Fake.command ) (if Process.isWin () then p + "/" + "build.cmd" else p + "/" + "build.sh")
        script <- Settings.loadOrDefault (fun s -> p + "/" + s.Fake.build )  (p + "/" + "build.fsx")
        ()

    let private FAKENotFound () =
        Process.notice (ref None) true "FAKE error" "FAKE script not found"

    let private BuildTask () =
        loadParameters ()
        if Globals.existsSync script |> not || Globals.existsSync command |> not then
            FAKENotFound ()
        else
            taskListView |> Option.iter(fun (model, view) ->
            view.show()
            model.focusFilterEditor() |> ignore
            let script = script |> Globals.readFileSync
                                |> fun n -> n.toString()
            let matches = Regex.Matches(script, "Target \"([\\w.]+)\"") |> Seq.cast<Match> |> Seq.toArray
{'fraction_non_alphanumeric': 0.12627526467757458, 'fraction_numerical': 0.00019249278152069297, 'mean_word_length': 2.415844838921762, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7406674', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2829, 'n_words': 729}