public async provideDefinition()

in src/definition/bazel_goto_definition_provider.ts [33:66]


  public async provideDefinition(
    document: TextDocument,
    position: Position,
    token: CancellationToken,
  ): Promise<Definition | DefinitionLink[]> {
    const workspaceInfo = BazelWorkspaceInfo.fromDocument(document);
    if (workspaceInfo === undefined) {
      // Not in a Bazel Workspace.
      return null;
    }

    const range = document.getWordRangeAtPosition(position, LABEL_REGEX);
    const targetText = document.getText(range);
    const match = LABEL_REGEX.exec(targetText);

    const targetName = match[1];
    // don't try to process visibility targets.
    if (targetName.startsWith("//visibility")) {
      return null;
    }

    const queryResult = await new BazelQuery(
      getDefaultBazelExecutablePath(),
      Utils.dirname(document.uri).fsPath,
      `kind(rule, "${targetName}")`,
      [],
    ).queryTargets();

    if (!queryResult.target.length) {
      return null;
    }
    const location = new QueryLocation(queryResult.target[0].rule.location);
    return new Location(Uri.file(location.path), location.range);
  }