<commit_before>import * as vscode from "vscode";
import { indexLocator } from "../extension";
import { Reference } from "../index/reference";
import { Section } from "../index/section";
import { to_vscode_Range } from "../index/vscode-adapter";
import { Command } from "./command";

class ReferenceQuickPick implements vscode.QuickPickItem {
  readonly reference: Reference;
  readonly label: string;
  readonly description: string;
  readonly detail?: string;

  constructor(reference: Reference) {
    this.reference = reference;

    if (reference.section) {
      this.label = reference.section.id();
      this.description = reference.section.sectionType;
    } else {
      // tfvars
      this.label = "(assignment)";
      this.description = vscode.Uri.parse(reference.location.uri.toString()).path;
    }
  }

  goto() {
    vscode.window.showTextDocument(vscode.Uri.parse(this.reference.location.uri.toString()), {
      preserveFocus: true,
      preview: true,
      selection: to_vscode_Range(this.reference.location.range)
    });
  }
}

export class ShowReferencesCommand extends Command {
  constructor() {
    super("showReferences");
  }

  protected async perform(section: Section): Promise<any> {
    let index = indexLocator.getIndexForSection(section);
    let picks = index.queryReferences("ALL_FILES", { target: section }).map((r) => new ReferenceQuickPick(r));

    return await vscode.window.showQuickPick(picks, {
      onDidSelectItem: (r: ReferenceQuickPick) => r.goto()
    });
  }
}<commit_msg>Adapt show references command after indexing refactoring<commit_after>import * as vscode from "vscode";
import { IndexAdapter } from "../index/index-adapter";
import { Reference } from "../index/reference";
import { Section } from "../index/section";
import { to_vscode_Range } from "../index/vscode-adapter";
import { Command } from "./command";

class ReferenceQuickPick implements vscode.QuickPickItem {
  readonly reference: Reference;
  readonly label: string;
  readonly description: string;
  readonly detail?: string;

  constructor(reference: Reference) {
    this.reference = reference;

    if (reference.section) {
      this.label = reference.section.id();
      this.description = reference.section.sectionType;
    } else {
      // tfvars
      this.label = "(assignment)";
      this.description = vscode.Uri.parse(reference.location.uri.toString()).path;
    }
  }

  goto() {
    vscode.window.showTextDocument(vscode.Uri.parse(this.reference.location.uri.toString()), {
      preserveFocus: true,
      preview: true,
      selection: to_vscode_Range(this.reference.location.range)
    });
  }
}

export class ShowReferencesCommand extends Command {
  constructor(private index: IndexAdapter) {
    super("showReferences");
  }

  protected async perform(section: Section): Promise<any> {
    let group = this.index.index.groupFor(section);
    let picks = group.queryReferences("ALL_FILES", { target: section }).map((r) => new ReferenceQuickPick(r));

    return await vscode.window.showQuickPick(picks, {
      onDidSelectItem: (r: ReferenceQuickPick) => r.goto()
    });
  }
}
{'fraction_non_alphanumeric': 0.132202304737516, 'fraction_numerical': 0.0, 'mean_word_length': 3.8003072196620584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3372966', 'n_tokens_mistral': 922, 'n_tokens_neox': 891, 'n_words': 198}