<commit_before>namespace Ionide.VSCode.FSharp

open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
open Fable.Import.vscode
open Fable.Import.Node
open Fable.Core.JsInterop
open DTO
open Ionide.VSCode
open Ionide.VSCode.Helpers

module Symbols =

    let private createProvider () =
        let convertToKind code =
            match code with
            | "C" -> SymbolKind.Class     (*  CompletionItemKind.Class      *)
            | "E" -> SymbolKind.Enum      (*  CompletionItemKind.Enum       *)
            | "S" -> SymbolKind.Property      (*  CompletionItemKind.Value      *)
            | "I" -> SymbolKind.Interface     (*  CompletionItemKind.Interface  *)
            | "N" -> SymbolKind.Module      (*  CompletionItemKind.Module     *)
            | "M" -> SymbolKind.Method     (*  CompletionItemKind.Method     *)
            | "P" -> SymbolKind.Property      (*  CompletionItemKind.Property   *)
            | "F" -> SymbolKind.Variable     (*  CompletionItemKind.Field      *)
            | "T" -> SymbolKind.Class      (*  CompletionItemKind.Class      *)
            | "Fc" -> SymbolKind.Function
            | _   -> 0 |> unbox

        let mapRes (doc : TextDocument) o =
            let data =
                if isNotNull o then
                    o.Data |> Array.map (fun syms ->
                        let range = CodeRange.fromDTO syms.Declaration.BodyRange
                        let oc = DocumentSymbol(syms.Declaration.Name, "", syms.Declaration.GlyphChar |> convertToKind, range, range) //TODO: Add signature
                        let ocs =
                            syms.Nested |> Array.map (fun sym ->
                                let range = CodeRange.fromDTO sym.BodyRange
                                let oc = DocumentSymbol(sym.Name, "", sym.GlyphChar |> convertToKind, range, range) //TODO: Add signature

                                oc )
                            |> Array.sortBy (fun n -> n.range.start.line)
                            |> ResizeArray
                        oc.children <- ocs
                        oc)
                    else
                        [||]
            let data = data |> Array.sortBy (fun n -> n.range.start.line)
            let head,xs = data.[0], ResizeArray (data.[1..])

            let relations =
                data.[1..]
                |> Seq.mapi (fun id n ->
                    let parent = xs |> Seq.tryFindIndexBack (fun p -> p.range.contains (!^n.range) && not (p.range.isEqual n.range))
                    parent |> Option.map (fun p -> id, p)
                )
                |> Seq.choose id

            relations
            |> Seq.iter (fun (i,p) ->
                let i = xs.[i]
                let p = xs.[p]
                p.children.Add i
            )
            let toRemove = relations |> Seq.map (fun (i,p) -> xs.[i] )
            let xs = xs |> Seq.filter (fun n -> not (toRemove |> Seq.contains n)) |> ResizeArray

            head.children <- xs
            [head]

        { new DocumentSymbolProvider
          with
            member this.provideDocumentSymbols(doc, ct) =
                promise {
                    let text = doc.getText()<commit_msg>Fix document symbol not displaying childs of top module/namespace<commit_after>namespace Ionide.VSCode.FSharp

open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
open Fable.Import.vscode
open Fable.Import.Node
open Fable.Core.JsInterop
open DTO
open Ionide.VSCode
open Ionide.VSCode.Helpers

module Symbols =

    let private createProvider () =
        let convertToKind code =
            match code with
            | "C" -> SymbolKind.Class     (*  CompletionItemKind.Class      *)
            | "E" -> SymbolKind.Enum      (*  CompletionItemKind.Enum       *)
            | "S" -> SymbolKind.Property      (*  CompletionItemKind.Value      *)
            | "I" -> SymbolKind.Interface     (*  CompletionItemKind.Interface  *)
            | "N" -> SymbolKind.Module      (*  CompletionItemKind.Module     *)
            | "M" -> SymbolKind.Method     (*  CompletionItemKind.Method     *)
            | "P" -> SymbolKind.Property      (*  CompletionItemKind.Property   *)
            | "F" -> SymbolKind.Variable     (*  CompletionItemKind.Field      *)
            | "T" -> SymbolKind.Class      (*  CompletionItemKind.Class      *)
            | "Fc" -> SymbolKind.Function
            | _   -> 0 |> unbox

        let mapRes (doc : TextDocument) o =
            let data =
                if isNotNull o then
                    o.Data |> Array.map (fun syms ->
                        let range = CodeRange.fromDTO syms.Declaration.BodyRange
                        let oc = DocumentSymbol(syms.Declaration.Name, "", syms.Declaration.GlyphChar |> convertToKind, range, range) //TODO: Add signature
                        let ocs =
                            syms.Nested |> Array.map (fun sym ->
                                let range = CodeRange.fromDTO sym.BodyRange
                                let oc = DocumentSymbol(sym.Name, "", sym.GlyphChar |> convertToKind, range, range) //TODO: Add signature

                                oc )
                            |> Array.sortBy (fun n -> n.range.start.line)
                            |> ResizeArray
                        oc.children <- ocs
                        oc)
                    else
                        [||]
            let data = data |> Array.sortBy (fun n -> n.range.start.line)
            let head,xs = data.[0], ResizeArray (data.[1..])

            let relations =
                data.[1..]
                |> Seq.mapi (fun id n ->
                    let parent = xs |> Seq.tryFindIndexBack (fun p -> p.range.contains (!^n.range) && not (p.range.isEqual n.range))
                    parent |> Option.map (fun p -> id, p)
                )
                |> Seq.choose id

            relations
            |> Seq.iter (fun (i,p) ->
                let i = xs.[i]
                let p = xs.[p]
                p.children.Add i
            )
            let toRemove = relations |> Seq.map (fun (i,p) -> xs.[i] )
            let xs = xs |> Seq.filter (fun n -> not (toRemove |> Seq.contains n)) |> ResizeArray
            head.children.AddRange xs
            [head]

        { new DocumentSymbolProvider
          with
            member this.provideDocumentSymbols(doc, ct) =
                promise {
                    let text = doc.getText()
{'fraction_non_alphanumeric': 0.1080080234531708, 'fraction_numerical': 0.0012343774108933806, 'mean_word_length': 1.2904593639575972, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254531', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1719, 'n_words': 415}