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

Add rudimentary BibTeX outline #53

Merged
merged 1 commit into from
Jan 9, 2025
Merged

Add rudimentary BibTeX outline #53

merged 1 commit into from
Jan 9, 2025

Conversation

jansol
Copy link
Contributor

@jansol jansol commented Jan 9, 2025

Closes #52

Somewhat inspired by how the LaTeX outline keeps the \command as context, see breadcrumb bar at the top:
image

On one hand it would be nice to strip out the outer braces or quotes but I don't see any good way to do that with the current layout of the syntax tree and I don't want to get into modifying the grammar atm.

@lnay lnay merged commit 32070a8 into rzukic:main Jan 9, 2025
@jansol jansol deleted the outline branch January 9, 2025 23:36
@lnay
Copy link
Collaborator

lnay commented Jan 9, 2025

Great! The people behind the grammar may not be keen to take changes anyway because the thing you noticed isn't an issue for neovim (and changes would require them to rewrite some query files elsewhere).

On a basic level, the treesitter queries only allow matching to single nodes, but neovim introduced directives to get around this limitation.

In this case the directive (#offset! x y z w) (link) would be a good fit and hopefully could be introduced to Zed in the future.

@jansol
Copy link
Contributor Author

jansol commented Jan 10, 2025

The problem is that often double braces are used to quote the whole string (like title={{A lengthy introduction to \latex}}) and that needs to be distinguished from cases like {{THiS} deliberate use of "incorrect" casing}. So to handle it properly one would have to

  1. count the number of braces/quotes to strip and
  2. make sure that the number matches both before and after the string

Or alternatively change the grammar to turn a brace/quote delimited string into its own node type (which I imagine would still get hairy since there can be LaTeX commands at any point in it, such as \url{foo://bar}). Might be possible to treat it as a node that injects the LaTeX grammar.

@lnay
Copy link
Collaborator

lnay commented Jan 10, 2025

I see, the first suggestion could be approximated with something like the gsub directive in neovim but I don't think there are any directives supported by Zed which do any kind of processing of the captured text. For the second suggestion, I'm assuming you would then have a query that matches multiple nodes in the title value which "cuts out" the parts we don't want, however this will end up creating multiple outline entries (or at least it used to).

If any of this changes in the future it would be good to revisit this, as well as the outline in latex, for example \texorpdfstring{x}{y} ought to only show "y" in the outline.

@lnay
Copy link
Collaborator

lnay commented Jan 10, 2025

Something relevant I just noticed now: #20 (comment)

@jansol
Copy link
Contributor Author

jansol commented Jan 10, 2025

I did consider doing something like that but that is not enough for properly handling the corner cases I mentioned.

@lnay
Copy link
Collaborator

lnay commented Jan 12, 2025

@jansol I'm going to publish a release, do you want to be included as an author? If so, what name+email do you want?

@jansol
Copy link
Contributor Author

jansol commented Jan 12, 2025

The ones I used in the commit should be good. Although I'm not sure how much I'll be keeping an eye on this repo (and by extension how useful being listed would be).

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.

List entry names in BibTeX outline
2 participants