<commit_before>import * as vscode from 'vscode';
import { Index } from './index';
import { AstList, findValue, getStringValue, getValue } from './index/ast';

export class HoverProvider implements vscode.HoverProvider {
  constructor(private index: Index) { }

  provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Hover> {
    let reference = this.index.queryReferences(document.uri, { position: position })[0];
    if (!reference)
      return null;

    let section = this.index.query("ALL_FILES", reference.getQuery())[0];
    if (!section)
      return new vscode.Hover(new vscode.MarkdownString(`Unknown target \`${reference.targetId}\``), reference.location.range);

    let valuePath = reference.valuePath();
    let label = valuePath[0];
    if (section.sectionType === "variable") {
      valuePath = ["default"];
      label = valuePath[0];
    } else if (section.sectionType === "local") {
      valuePath = [null];
      label = section.name;
    } else {
      // we need an attribute to read and it cannot be a splat
      if (valuePath.length === 0 || valuePath[0] === "*") {
        return null;
      }
    }<commit_msg>HoverProvider: Use IndexLocator instead of Index<commit_after>import * as vscode from 'vscode';
import { Index } from './index';
import { AstList, findValue, getStringValue, getValue } from './index/ast';
import { IndexLocator } from './index/index-locator';

export class HoverProvider implements vscode.HoverProvider {
  constructor(private indexLocator: IndexLocator) { }

  provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Hover> {
    let index = this.indexLocator.getIndexForDoc(document);
    let reference = index.queryReferences(document.uri, { position: position })[0];
    if (!reference)
      return null;

    let section = index.query("ALL_FILES", reference.getQuery())[0];
    if (!section)
      return new vscode.Hover(new vscode.MarkdownString(`Unknown target \`${reference.targetId}\``), reference.location.range);

    let valuePath = reference.valuePath();
    let label = valuePath[0];
    if (section.sectionType === "variable") {
      valuePath = ["default"];
      label = valuePath[0];
    } else if (section.sectionType === "local") {
      valuePath = [null];
      label = section.name;
    } else {
      // we need an attribute to read and it cannot be a splat
      if (valuePath.length === 0 || valuePath[0] === "*") {
        return null;
      }
    }
{'fraction_non_alphanumeric': 0.13729271114539143, 'fraction_numerical': 0.004627844195912071, 'mean_word_length': 3.6487455197132617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6220604', 'n_tokens_mistral': 779, 'n_tokens_neox': 769, 'n_words': 202}