<commit_before>﻿namespace MonoDevelop.FSharp

open System
open MonoDevelop.Ide.Gui
open MonoDevelop.Ide.Gui.Content
open Mono.TextEditor

type FSharpIndentationTracker(doc:Document) = 
    let textDoc = doc.Editor.Document
    let indentSize = doc.Editor.Options.IndentationSize

    // Lines ending in these strings will be indented
    let indenters = ["=";"do";"{";"[";"[|"]

    let (|AddIndent|_|) (x:string) = 
        let trimmed = x.TrimEnd() 
        if indenters |> List.exists(trimmed.EndsWith) then Some indentSize
        else None
        
    let rec getIndentation (line: DocumentLine) = 
         if line = null then "" else
         match textDoc.GetLineText(line.LineNumber) with
         | x when String.IsNullOrWhiteSpace(x) -> getIndentation line.PreviousLine
         | AddIndent i -> String(' ', line.GetIndentation(textDoc).Length + i)
         | _ -> line.GetIndentation textDoc

    let getIndentString lineNumber column =  
         let line = textDoc.GetLine (lineNumber);
         getIndentation line

    interface IIndentationTracker with
        member x.GetIndentationString (lineNumber, column) = getIndentString lineNumber column
        member x.GetIndentationString (offset) = 
            let loc = textDoc.OffsetToLocation (offset)
            if doc.Editor.Caret.Column = 0 then "" else
            getIndentString loc.Line loc.Column
        member x.GetVirtualIndentationColumn (offset) = 
            let loc = textDoc.OffsetToLocation (offset)
            (getIndentString loc.Line loc.Column).Length
        member x.GetVirtualIndentationColumn (lineNumber, column) = (getIndentString lineNumber column).Length<commit_msg>Indent to 'match' when a match statement is encountered<commit_after>﻿namespace MonoDevelop.FSharp

open System
open MonoDevelop.Ide.Gui
open MonoDevelop.Ide.Gui.Content
open Mono.TextEditor

type FSharpIndentationTracker(doc:Document) = 
    let textDoc = doc.Editor.Document
    let indentSize = doc.Editor.Options.IndentationSize

    // Lines ending in these strings will be indented
    let indenters = ["=";"do";"{";"[";"[|"]

    let (|AddIndent|_|) (x:string) = 
        if indenters |> List.exists(x.EndsWith) then Some ()
        else None
    let (|Match|_|) (x:string) = 
        if x.EndsWith "with" && x.Contains("match ") then Some (x.LastIndexOf "match ")
        else None
        
    let rec getIndentation lineDistance (line: DocumentLine) = 
        if line = null then "" else
        match textDoc.GetLineText(line.LineNumber).TrimEnd() with
        | x when String.IsNullOrWhiteSpace(x) -> getIndentation (lineDistance + 1)line.PreviousLine
        | Match i when lineDistance < 2 -> String(' ', i)
        | AddIndent -> String(' ', line.GetIndentation(textDoc).Length + indentSize)
        | _ -> line.GetIndentation textDoc

    let getIndentString lineNumber column =  
        let line = textDoc.GetLine (lineNumber);
        getIndentation 0 line

    interface IIndentationTracker with
        member x.GetIndentationString (lineNumber, column) = getIndentString lineNumber column
        member x.GetIndentationString (offset) = 
            let loc = textDoc.OffsetToLocation (offset)
            if doc.Editor.Caret.Column = 0 then "" else
            getIndentString loc.Line loc.Column
        member x.GetVirtualIndentationColumn (offset) = 
            let loc = textDoc.OffsetToLocation (offset)
            (getIndentString loc.Line loc.Column).Length
        member x.GetVirtualIndentationColumn (lineNumber, column) = (getIndentString lineNumber column).Length
{'fraction_non_alphanumeric': 0.0938375350140056, 'fraction_numerical': 0.0014005602240896359, 'mean_word_length': 2.9458563535911604, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, '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': '5453800', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1009, 'n_words': 265}