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

Relative import and recusive fix #986

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

max-ishere
Copy link

@max-ishere max-ishere commented Nov 30, 2023

Description

  • Added relative imports using ./ to make the location relative to currently loaded file. ../ prefix looks for the source file one layer up. These can stack (../../../) since they use the Path* types to resolve the location.
  • Added a hint to use (include) instead of (import).
  • Return an empty AST when loading a yuck file that was already loaded by FileDatabase. This prevents recursive imports from stack overflowing and crashing eww, as well as multiple variable declaration errors.

Relative imports are quite useful since they allow you to create isolated modules that can be shared among users without having to recreate the same file structure or using separate configuration directories.

Usage

Here's a snippet from the updated (include) documentation:

Using include

A single yuck file may import the contents of any other yuck file. For this, make use of the include directive.

Imports are resolved in a similar way to shell paths. This is explained below:

; These imports are located inside ~/.config/eww/example/example.yuck

;       Prefix            Resolves to

(import "file.yuck")    ; ~/.config/eww/file.yuck
(import "/file.yuck")   ; /file.yuck
(import "./file.yuck") ‌ ; ~/.config/eww/example/file.yuck
(import "../file.yuck") ; ~/.config/eww/file.yuck

As you can see they behave the same way as paths would in the shell. The only rule is that when there is no ‌/‌, ./‌ or ../ the
path is relative to the config directory. You should try to use relative paths as much as possible for better modularity.

Some older yuck imports may break if they used the ./ prefix.

Additional Notes

I would like to hear some feedback from users/maintainers since some of the solutions to the issues might have to be changed.

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes. Um, this folder doesn't exist?..
  • I used cargo fmt to automatically format all code before committing

Bugs

  • The path is not canonicalized before it is sent to be loaded.
  • I think I just uym.,..... deactivated hot reloading in 35725d5

@max-ishere
Copy link
Author

max-ishere commented Nov 30, 2023

Ooopsie, I was looking at my configs and fixing them up and noticed this:

error: Included file `./modules/x-ui/button.yuck` not found
  ┌─ /home/max_ishere/.config/eww/modules/./x-ui/widgets.yuck:1:10
  │
1 │ (include "./modules/x-ui/button.yuck")
  │          ──────────────────────────── Included here
  │
  → Hint: Resolved to `/home/max_ishere/.config/eww/modules/x-ui/./modules/x-ui/button.yuck`

Specifically, the /home/max_ishere/.config/eww/modules/./x-ui/widgets.yuck:1:10 on line 2 contains a .. Should be quite easy to fix.

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.

None yet

1 participant