Skip to content

Add get_grammar_names method to registry struct - #74

Merged
Keats merged 4 commits into
getzola:masterfrom
blucardin:master
Sep 5, 2026
Merged

Keats merged 4 commits into
getzola:masterfrom
blucardin:master

Conversation

@blucardin

Copy link
Copy Markdown
Contributor

A small PR that adds a getter function to the registry struct to output all contained grammar names and their aliases.

Purpose:
I am working on integrating giallo into typst to replace syntect. In order to allow for auto completion of the available grammars, the default grammar name/alias list need to be generated. Since it can change for every new version of the builtin registry, a consistent getter is required.

I believe this functionality does not exist in the current version of giallo.

Tests:
A testcase has been added to ensures this method works.

Improvements could be made to allow for more read assess to the internal registry data.

No AI was used in the writing of this code.

Comment thread src/registry.rs Outdated

/// Gets the name and aliases of all grammars in the registry
/// Outputs a vector of tuples of the form (Name, Aliases)
pub fn get_grammar_names(&self) -> Vec<(String, Vec<String>)> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need owned values? I would rather borrow and let the user clone if they need to. Maybe use a struct rather than a tuple as well?

@blucardin

Copy link
Copy Markdown
Contributor Author

#74 (comment) The requested changes have been added.

I am unfamiliar with lifetimes, can you ensure that I implemented this correctly?

#[derive(Debug, PartialEq)]
pub struct GrammarNameAndAliases<'a> {
    pub name: &'a String,
    pub aliases: &'a Vec<String>,
}

Comment thread src/registry.rs Outdated
#[derive(Debug, PartialEq)]
pub struct GrammarNameAndAliases<'a> {
pub name: &'a String,
pub aliases: &'a Vec<String>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should use &'a [String]

Comment thread src/registry.rs Outdated

#[derive(Debug, PartialEq)]
pub struct GrammarNameAndAliases<'a> {
pub name: &'a String,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should use &'a str

@blucardin

Copy link
Copy Markdown
Contributor Author

The requested changes have been added.

Thank you for assisting me with this - I appreciate it.

Let me know if there is anything else.

@Keats
Keats merged commit 148fec0 into getzola:master Sep 5, 2026
3 of 5 checks passed
@Keats

Keats commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Thanks!

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.

2 participants