You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: index.rs
    path of file: ./repos/tabby/crates/tabby-scheduler/src
    
    the code of the file until where you have to start completion: use std::{fs, io::IsTerminal};

use anyhow::Result;
use kdam::BarExt;
use tabby_common::{
    config::RepositoryConfig,
    index::{register_tokenizers, CodeSearchSchema},
    path::index_dir,
    SourceFile,
};
use tantivy::{directory::MmapDirectory, doc, Index};

use crate::utils::tqdm;

// Magic numbers
static MAX_LINE_LENGTH_THRESHOLD: usize = 300;
static AVG_LINE_LENGTH_THRESHOLD: f32 = 150f32;
static MAX_BODY_LINES_THRESHOLD: usize = 15;

pub fn index_repositories(_config: &[RepositoryConfig]) -> Result<()> {
    let code = CodeSearchSchema::new();

    fs::create_dir_all(index_dir())?;
    let directory = MmapDirectory::open(index_dir())?;
    let index = Index::open_or_create(directory, code.schema)?;
    register_tokenizers(&index);

    // Initialize the search index writer with an initial arena size of 150 MB.
    let mut writer = index.writer(150_000_000)?;
    writer.delete_all_documents()?;

    let mut pb = std::io::stdout()
        .is_terminal()
        .then(SourceFile::all)
        .transpose()?
        .map(|iter| tqdm(iter.count()));
    for file in SourceFile::all()? {
        pb.as_mut().map(|b| b.update(1)).transpose()?;

        if file.max_line_length > MAX_LINE_LENGTH_THRESHOLD {
            continue;
        }

        if file.avg_line_length > AVG_LINE_LENGTH_THRESHOLD {
         
    
pub fn index_repositories(_config: &[RepositoryConfig]) -> Result<()> {
    let code = CodeSearchSchema::new();

    fs::create_dir_all(index_dir())?;
    let directory = MmapDirectory::open(index_dir())?;
    let index = Index::open_or_create(directory, code.schema)?;
    register_tokenizers(&index);

    // Initialize the search index writer with an initial arena size of 150 MB.
    let mut writer = index.writer(150_000_000)?;
    writer.delete_all_documents()?;

    let mut pb = std::io::stdout()
        .is_terminal()
        .then(SourceFile::all)
        .transpose()?
        .map(|iter| tqdm(iter.count()));
    for file in SourceFile::all()? {
        pb.as_mut().map(|b| b.update(1)).transpose()?;

        if file.max_line_length > MAX_LINE_LENGTH_THRESHOLD {
            continue;
        }

        if file.avg_line_length > AVG_LINE_LENGTH_THRESHOLD {
            continue;
        }

        for doc in from_source_file(file) {
            writer.add_document(doc!(
                    code.field_git_url => doc.git_url,
                    code.field_filepath => doc.filepath,
                    code.field_language => doc.language,
                    code.field_name => doc.name,
                    code.field_body => doc.body,
                    code.field_kind => doc.kind,
            ))?;
        }
    }

    writer.commit()?;
    writer.wait_merging_threads()?;

    Ok(())
}