import * as vscode from 'vscode';
import { Index } from './index';
import { IndexLocator } from './index/index-locator';

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

  provideDefinition(document: vscode.TextDocument, position: vscode.Position): vscode.Location {
    let reference = this.indexLocator.getIndexForDoc(document).queryReferences(document.uri, { position: position })[0];
    if (!reference)
      return null;

    let section = this.indexLocator.getIndexForDoc(document).query("ALL_FILES", reference.getQuery())[0];
    if (!section)
      return null;
    return section.location;
  }
}

import * as vscode from 'vscode';
import { Index } from './index';

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

  provideDefinition(document: vscode.TextDocument, position: vscode.Position): vscode.Location {
    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 null;
    return section.location;
  }
}

--- 
+++ 
@@ -1,15 +1,16 @@
 import * as vscode from 'vscode';
 import { Index } from './index';
+import { IndexLocator } from './index/index-locator';
 
 export class DefinitionProvider implements vscode.DefinitionProvider {
-  constructor(private index: Index) { }
+  constructor(private indexLocator: IndexLocator) { }
 
   provideDefinition(document: vscode.TextDocument, position: vscode.Position): vscode.Location {
-    let reference = this.index.queryReferences(document.uri, { position: position })[0];
+    let reference = this.indexLocator.getIndexForDoc(document).queryReferences(document.uri, { position: position })[0];
     if (!reference)
       return null;
 
-    let section = this.index.query("ALL_FILES", reference.getQuery())[0];
+    let section = this.indexLocator.getIndexForDoc(document).query("ALL_FILES", reference.getQuery())[0];
     if (!section)
       return null;
     return section.location;
DefinitionProvider: Use IndexLocator instead of Index
