<commit_before>module FSharpRefactor.Evaluator.CodeRefactorer

open System.Text.RegularExpressions
open Microsoft.FSharp.Compiler.Range
open FSharpRefactor.Engine.Ast
open FSharpRefactor.Refactorings.Rename
open FSharpRefactor.Evaluator.GenerationState

//TODO: multiline code
let posFromIndex code index = mkPos 1 index

let (|Ident|_|) code =
    let m = Regex("[^i]*(ident[0-9]*)(.*)").Match(code)
    if m.Success then
        let identGroup = m.Groups.[1]
        let rest = m.Groups.[2]
        Some (identGroup.Value, identGroup.Index, rest.Value)
    else
        None

let getIdentifiers code =
    let rec getIdentifiersTc remainingCode index identifiers =
        match remainingCode with
            | Ident(ident, indexInRemainingCode, rest) ->
                let identIndex = indexInRemainingCode + index
                let identRange =
                    mkRange "test.fs"
                            (posFromIndex code identIndex)
                            (posFromIndex code (identIndex + ident.Length))
                getIdentifiersTc rest
                                 (identIndex + ident.Length)
                                 ((ident,identRange)::identifiers)
            | _ -> identifiers
    getIdentifiersTc code 0 []

let randomRename code newName identifierIndex =
    let identifier =
        (getIdentifiers code).[identifierIndex]
    let tree = (Ast.Parse code).Value

    code, DoRename code tree identifier newName<commit_msg>Only choose one of the available identifiers<commit_after>module FSharpRefactor.Evaluator.CodeRefactorer

open System.Text.RegularExpressions
open Microsoft.FSharp.Compiler.Range
open FSharpRefactor.Engine.Ast
open FSharpRefactor.Refactorings.Rename
open FSharpRefactor.Evaluator.GenerationState

//TODO: multiline code
let posFromIndex code index = mkPos 1 index

let (|Ident|_|) code =
    let m = Regex("[^i]*(ident[0-9]*)(.*)").Match(code)
    if m.Success then
        let identGroup = m.Groups.[1]
        let rest = m.Groups.[2]
        Some (identGroup.Value, identGroup.Index, rest.Value)
    else
        None

let getIdentifiers code =
    let rec getIdentifiersTc remainingCode index identifiers =
        match remainingCode with
            | Ident(ident, indexInRemainingCode, rest) ->
                let identIndex = indexInRemainingCode + index
                let identRange =
                    mkRange "test.fs"
                            (posFromIndex code identIndex)
                            (posFromIndex code (identIndex + ident.Length))
                getIdentifiersTc rest
                                 (identIndex + ident.Length)
                                 ((ident,identRange)::identifiers)
            | _ -> identifiers
    getIdentifiersTc code 0 []

let randomRename code newName identifierIndex =
    let identifiers = getIdentifiers code
    let identifier = identifiers.[identifierIndex % identifiers.Length]
    let tree = (Ast.Parse code).Value

    code, DoRename code tree identifier newName
{'fraction_non_alphanumeric': 0.07858090185676393, 'fraction_numerical': 0.003978779840848806, 'mean_word_length': 2.2793478260869566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2340176', 'n_tokens_mistral': 837, 'n_tokens_neox': 785, 'n_words': 211}