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

Silicon assumes all config directories exist #242

Open
kenielf opened this issue Feb 29, 2024 · 1 comment · May be fixed by #249
Open

Silicon assumes all config directories exist #242

kenielf opened this issue Feb 29, 2024 · 1 comment · May be fixed by #249

Comments

@kenielf
Copy link

kenielf commented Feb 29, 2024

The Issue

If I was adding a custom theme, I would normally not need to also create a syntaxes directory, however, the application crashes with the following when trying to rebuild its cache:

$ silicon --build-cache
[error] error finding all the files in a directory: IO error for operation on /home/kenielf/.config/silicon/syntaxes: No such file or directory (os error 2)

Note: this also happens if I was trying to just add custom syntaxes without creating the theme directory

Workaround

Although this can be easily circumvented by simply creating all necessary directories:

mkdir -p ~/.config/silicon/{themes,syntaxes}

However, it might be better to just check first in the code if the directories exist, and if they don't, just skip them altogether.

Fix

Looking into it, the issue seems to be easily resolved by tweaking the add_from_folder function in the impl HighlightingAssets to first check if the directory exists, in the cases where it does not, just skip the building.

I have tested a simple solution and it is working normally on my end:

    pub fn add_from_folder<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
        let path = path.as_ref();
        let theme_dir = path.join("themes");
        if theme_dir.is_dir() {
            self.theme_set.add_from_folder(theme_dir)?;
        }
        let mut builder = self.syntax_set.clone().into_builder();
        let syntaxes_dir = path.join("syntaxes");
        if syntaxes_dir.is_dir() {
            builder.add_from_folder(syntaxes_dir, true)?;
            self.syntax_set = builder.build();
        }
        Ok(())
    }

I can submit a PR myself if desired.

@uncenter
Copy link

You should definitely submit a PR!

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 a pull request may close this issue.

2 participants