Skip to content

Commit

Permalink
fix: Link the full label / file name instead of linking each componen…
Browse files Browse the repository at this point in the history
…t individually

So far, the `go_to_definition` provider did not provide a
`originSelectionRange`. Hence, VS Code was falling back on its internal
tokenization to decide which part of the text to provide the HyperLink
for.

For the label "my/package:file.txt", we hence linked `my`, `package`,
`file` and `txt` individually, all pointing to the same file.

With this change, we now instead always provide the link on the full
label.
  • Loading branch information
vogelsgesang committed Apr 16, 2024
1 parent fa38d08 commit 1e8c8b5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/definition/bazel_goto_definition_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ export class BazelGotoDefinitionProvider implements DefinitionProvider {
return null;
}
const result = queryResult.target[0];
let location;
if (result.type === blaze_query.Target.Discriminator.RULE) {
const location = new QueryLocation(result.rule.location);
return new Location(Uri.file(location.path), location.range);
location = new QueryLocation(result.rule.location);
} else {
const location = new QueryLocation(result.sourceFile.location);
return new Location(Uri.file(location.path), new Position(0, 0));
location = new QueryLocation(result.sourceFile.location);
}
return [
{
originSelectionRange: range,
targetUri: Uri.file(location.path),
targetRange: location.range,
},
] as DefinitionLink[];
}
}

0 comments on commit 1e8c8b5

Please sign in to comment.