<commit_before>[<ReflectedDefinition>]
module FSharpIDE

open FunScript
open FunScript.TypeScript
open FunScript.TypeScript.fs
open FunScript.TypeScript.child_process
open FunScript.TypeScript.AtomCore
open FunScript.TypeScript.text_buffer
open FunScript.TypeScript.path

open Atom
open FSharp.Atom  

type FSharpIDE() =
    let mutable panel : IPanel option = None
    let mutable statusbar : IStatusBar option = None
    let mutable notification : ITile option = None
    let subscriptions = ResizeArray()

    let addStatusNotification status = 
        notification |> Option.iter (fun n -> n.destroy())
        statusbar |> Option.iter(fun s -> 
            let el = sprintf "<span class='fsharp-status'>F# Status - %s</span>" status |> jq
            notification <- s.addLeftTile({item =el ; priority = 100}) |> Some

        )

    let parseProjectForEditor (editor: IEditor) = 
        let parseProj p = 
            let proj (ex : NodeJS.ErrnoException) (arr : string array) =
                let projExist = arr |> Array.tryFind(fun a -> a.Split('.') |> fun n -> n.[n.Length - 1]  = "fsproj")
                match projExist with
                | Some a -> let path = p + "/" + a
                            LanguageService.project path (fun _ -> addStatusNotification "Ready")
                | None -> addStatusNotification "Ready (.fsproj not found)"
            if JS.isDefined p then Globals.readdir(p, System.Func<NodeJS.ErrnoException, string array, unit>(proj))

        if JS.isDefined editor && JS.isPropertyDefined editor "buffer" then
            addStatusNotification "Loading"
            let p = editor.buffer.file.path
            if (p.Split('.') |> fun n -> n.[n.Length - 1]  = "fsproj") || ( JS.isPropertyDefined editor "getGrammar" && editor.getGrammar().name = "F#") then
                if JS.isDefined p then
                    p |> Globals.dirname
                      |> parseProj 

    let register panel =
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> LanguageService.parseEditor ed (fun _ -> ())) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> ErrorPanel.handleEditorChange panel ed) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> Globals.setTimeout((fun _ -> TooltipHandler.initialize ed), 500.) |> ignore) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> ed |> parseProjectForEditor) |> subscriptions.Add        
        Globals.atom.on'("FSharp:Highlight", unbox<Function>(HighlighterHandler.handle)) |> subscriptions.Add
        Globals.atom.on'("FSharp:Highlight", unbox<Function>(ErrorPanel.handle)) |> subscriptions.Add
    

    let initialize panel =
        let editor = Globals.atom.workspace.getActiveTextEditor()
        editor |> parseProjectForEditor
        LanguageService.parseEditor editor (fun _ -> ())
        editor |> ErrorPanel.handleEditorChange panel 
        editor |> TooltipHandler.initialize
        FAKE.register ()

    member x.provide ()=
        AutocompleteProvider.create () 

    member x.consumeStatusBar (sb : IStatusBar) = 
        statusbar <- Some sb<commit_msg>Fix #44<commit_after>[<ReflectedDefinition>]
module FSharpIDE

open FunScript
open FunScript.TypeScript
open FunScript.TypeScript.fs
open FunScript.TypeScript.child_process
open FunScript.TypeScript.AtomCore
open FunScript.TypeScript.text_buffer
open FunScript.TypeScript.path

open Atom
open FSharp.Atom  

type FSharpIDE() =
    let mutable panel : IPanel option = None
    let mutable statusbar : IStatusBar option = None
    let mutable notification : ITile option = None
    let subscriptions = ResizeArray()

    let addStatusNotification status = 
        notification |> Option.iter (fun n -> n.destroy())
        statusbar |> Option.iter(fun s -> 
            let el = sprintf "<span class='fsharp-status'>F# Status - %s</span>" status |> jq
            notification <- s.addLeftTile({item =el ; priority = 100}) |> Some

        )

    let parseProjectForEditor (editor: IEditor) = 
        let parseProj p = 
            let proj (ex : NodeJS.ErrnoException) (arr : string array) =
                let projExist = arr |> Array.tryFind(fun a -> a.Split('.') |> fun n -> n.[n.Length - 1]  = "fsproj")
                match projExist with
                | Some a -> let path = p + "/" + a
                            LanguageService.project path (fun _ -> addStatusNotification "Ready")
                | None -> addStatusNotification "Ready (.fsproj not found)"
            if JS.isDefined p then Globals.readdir(p, System.Func<NodeJS.ErrnoException, string array, unit>(proj))
            else addStatusNotification "Ready (.fsproj not found)"

        if JS.isDefined editor && JS.isPropertyDefined editor "buffer" && unbox<obj>(editor.buffer) <> null then
            let p = editor.buffer.file.path
            if (p.Split('.') |> fun n -> n.[n.Length - 1]  = "fsproj") || ( JS.isPropertyDefined editor "getGrammar" && editor.getGrammar().name = "F#") then
                if JS.isDefined p then
                    p |> Globals.dirname
                      |> parseProj 

    let register panel =
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> LanguageService.parseEditor ed (fun _ -> ())) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> ErrorPanel.handleEditorChange panel ed) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> Globals.setTimeout((fun _ -> TooltipHandler.initialize ed), 500.) |> ignore) |> subscriptions.Add
        Globals.atom.workspace.onDidChangeActivePaneItem (fun ed -> ed |> parseProjectForEditor) |> subscriptions.Add        
        Globals.atom.on'("FSharp:Highlight", unbox<Function>(HighlighterHandler.handle)) |> subscriptions.Add
        Globals.atom.on'("FSharp:Highlight", unbox<Function>(ErrorPanel.handle)) |> subscriptions.Add
    

    let initialize panel =
        let editor = Globals.atom.workspace.getActiveTextEditor()
        editor |> parseProjectForEditor
        LanguageService.parseEditor editor (fun _ -> ())
        editor |> ErrorPanel.handleEditorChange panel 
        editor |> TooltipHandler.initialize
        FAKE.register ()

    member x.provide ()=
        AutocompleteProvider.create () 

    member x.consumeStatusBar (sb : IStatusBar) = 
        statusbar <- Some sb
{'fraction_non_alphanumeric': 0.10916149068322982, 'fraction_numerical': 0.0027950310559006213, 'mean_word_length': 2.66382252559727, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 87, 'https://': 0, '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': '5279029', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1820, 'n_words': 448}