Skip to content

Commit

Permalink
multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
cademack committed Jul 16, 2024
1 parent 2b30a31 commit 0b01bd1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/language/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AmalgamDefinitionProvider implements vscode.DefinitionProvider {
word = "!" + word;
}
}
const definitionPattern = new RegExp(`^[^;]+#${word}`);
const definitionPattern = new RegExp(`^[^;]*#${word}`);

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders) {
Expand All @@ -40,6 +40,7 @@ export class AmalgamDefinitionProvider implements vscode.DefinitionProvider {
token
);

const locations: vscode.Location[] = [];
for (const file of files) {
if (token.isCancellationRequested) {
return undefined;
Expand All @@ -48,14 +49,20 @@ export class AmalgamDefinitionProvider implements vscode.DefinitionProvider {
const content = await this.readFile(file.fsPath);
const lines = content.split("\n");
for (let i = 0; i < lines.length; i++) {
if (token.isCancellationRequested) {
return undefined;
}
if (definitionPattern.test(lines[i])) {
const definitionUri = vscode.Uri.file(file.fsPath);
const definitionPosition = new vscode.Position(i, lines[i].indexOf(`#${word}`));
return new vscode.Location(definitionUri, definitionPosition);
locations.push(new vscode.Location(definitionUri, definitionPosition));
}
}
}

if (locations.length > 0){
return locations
}
return undefined;
}

Expand Down

0 comments on commit 0b01bd1

Please sign in to comment.