Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement hover and go to definition providers for citations #29

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

Dominic-DallOsto
Copy link
Contributor

@Dominic-DallOsto Dominic-DallOsto commented Dec 11, 2021

Addresses #28

Hover provider:
image

Go to definition provider (Ctrl + hover):
image

This is mostly a simplified version from LaTeX workshop's hover provider and go to definition provider.

  • For the hover provider, I had to replace newlines in the text with two spaces then a newline, otherwise everything rendered on one line. LaTeX Workshop does this when parsing the documentation initially here - I'm not sure if it's worth doing the same
  • I'm not convinced my regexp to select the citation key is robust - do you have any advice? And since it's reused twice, would it be worth spinning out to a separate function/file?

Replace newline with double space then a newline to actually get a newline. Double newline is a paragraph break, which we don't want.
Show raw bibtex on Ctrl+hover, and go to item's location in bibtex file on click. Same with F12.
@Dominic-DallOsto Dominic-DallOsto changed the title Show citation details on hover Implement hover and go to definition providers for citations Dec 11, 2021
@Dominic-DallOsto Dominic-DallOsto marked this pull request as ready for review December 11, 2021 15:27
Was only working with the first citation key on a line
@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to help with the regex, but first I need to make sure I understand how the matching should happen. Based on lines 14 and 15 I deduce that you need two positions:

  • startResult: match words that follow after @ until a space or line end
  • endResult: what should it match?

One final question, can we use a positive lookbehind assertion? Based on this page, it seems to be possible from ECMAScript 2018.

Would the following work (i.e., see demo here)?

  • startResult: (?<=@)\w+, or to allow for - in the citation key (?<=@)[\w|-]+

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But personally, I find your option already very good (i.e., demo here).

VSCode has an inbuilt function to make this a lot easier
@Dominic-DallOsto
Copy link
Contributor Author

Dominic-DallOsto commented Dec 12, 2021

Sorry, I based that method on how it was done in LaTeX Workshop so it was probably a bit confusing. I just found a nice inbuilt VSCode function to make getting a word at the current cursor position much easier. It should be clearer now.

Should dashes be allowed in the citation keys in general?

@mihaiconstantin
Copy link

Sorry, I based that method on how it was done in LaTeX Workshop so it was probably a bit confusing. I just found a nice inbuilt VSCode function to make getting a word at the current cursor position much easier. It should be clearer now.

No worries! I am happy to hear VSCode has a built-in function for that!

Should dashes be allowed in the citation keys in general?

According to this answer on TeX there a range of characters that can be used as delimiters for BibTeX keys. However, I propose to keep it simple and ignore this for now. I can imagine that these are not very common use cases.

@notZaki
Copy link
Owner

notZaki commented Dec 15, 2021

Wow! Thanks for the excellent contribution @Dominic-DallOsto and for suggesting this in the first place @mihaiconstantin !
I'll merge this and publish a new release.

@notZaki notZaki merged commit 6e1e79c into notZaki:master Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants