Skip to content

Commit

Permalink
Fix regex for getting citation keys
Browse files Browse the repository at this point in the history
Was only working with the first citation key on a line
  • Loading branch information
Dominic-DallOsto committed Dec 11, 2021
1 parent 09b9f1e commit a3cb2a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/providers/definition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { Extension } from '../extension';
import * as fs from 'fs';

export class DefinitionProvider implements vscode.DefinitionProvider {
extension: Extension;
Expand All @@ -10,15 +11,15 @@ export class DefinitionProvider implements vscode.DefinitionProvider {

provideDefinition(document: vscode.TextDocument, position: vscode.Position): vscode.Location | undefined {
// look for an @ at the start of the current word (start) and the end of the current word or line (end)
const startResult = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position)).match(/[\b@]/);
const startResult = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position)).match(/[\b@]\w*$/);
const endResult = document.getText(new vscode.Range(position, new vscode.Position(position.line, 65535))).match(/$|\s/);
if (startResult === null || endResult === null ||
startResult.index === undefined || endResult.index === undefined ||
startResult.index < 0 || endResult.index < 0) {
return undefined;
}

const invoker = startResult[0];
const invoker = startResult[0][0];
if (invoker !== '@') { return; }

const line = document.getText(new vscode.Range(
Expand All @@ -27,7 +28,10 @@ export class DefinitionProvider implements vscode.DefinitionProvider {
)).trim()
const cite = this.extension.completer.citation.getEntry(line);
if (cite) {
// return new vscode.Location(vscode.Uri.parse(`zotero://select/items/bbt:{cite.key}`), new vscode.Position(0,0));
// vscode.env.openExternal(vscode.Uri.parse(`zotero://select/items/bbt:${cite.key}`));
return new vscode.Location( vscode.Uri.file(cite.file), cite.position )
// zotero://select/items/bbt:turingComputableNumbersApplication1937
}
}
}
4 changes: 2 additions & 2 deletions src/providers/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export class HoverProvider implements vscode.HoverProvider {
public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | undefined> {

// look for an @ at the start of the current word (start) and the end of the current word or line (end)
const startResult = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position)).match(/[\b@]/);
const startResult = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position)).match(/[\b@]\w*$/);
const endResult = document.getText(new vscode.Range(position, new vscode.Position(position.line, 65535))).match(/$|\s/);
if (startResult === null || endResult === null ||
startResult.index === undefined || endResult.index === undefined ||
startResult.index < 0 || endResult.index < 0) {
return undefined;
}

const invoker = startResult[0];
const invoker = startResult[0][0];
if (invoker !== '@') { return; }

const line = document.getText(new vscode.Range(
Expand Down

0 comments on commit a3cb2a0

Please sign in to comment.