-
Notifications
You must be signed in to change notification settings - Fork 229
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
Support relative path for snippet's filename attribute #322
base: main
Are you sure you want to change the base?
Conversation
@RamiAwar could you review this PR, please? |
How are you handling interaction with snippet directories? |
Directories can also be expressed in relative path format, e.g. |
filepath, err := config.ExpandPath(config.Conf.General.SnippetFile) | ||
if err != nil { | ||
return 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in #321, I made an assumption that if SnippetFile is omitted, it should simply return 0 for line count instead of panicking.
Perhaps whoever understands multiple directories better could correct me here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm yes let me look into this further.
I'm concerned about having a relative snippet file with directories, not sure how that would be handled.
That's even a concern in the current version of pet where you might have an absolute snippet file path as well as directories. Might not be an issue, just have to look into it and possibly document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having both SnippetDirs
and SnippetFile
configurable can be rather confusing due to the lack of signs to indicate which one of those two options should take priority.
I'd propose something like this:
SnippetFiles = ["~/.config/pet/snippet-1.toml", "/var/tmp/pet/snippet-2.toml" ]
This consolidates the option of managing multiple directories under one single configurable item.
If you want to keep everything under a single file, specify a single snippet file.
If you want to manage multiple files, in various directories, specify multiple paths.
When save/edit, a prompt to choose which file to save/edit is simple enough.
Of course, I image it'd be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RamiAwar I could take a jab at this approach later this week if you think it's worth considering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csessh sorry I still didn't look into this more, I was actually typing up a reply at some point but lost the tab 😓
I think it's not a problem and there's no work necessary on your end, but I want to better document this. Will respond in a few days time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to add some more context here - will add it to the docs later as well. You don't have to act on this, just FYI, going through this to review your PR properly.
Having the main snippet file is mandatory.
If snippet directories are also configured, then the snippet Load method will load snippets from the main file + all files inside the snippet directory!
What does this mean for:
1- Edits: How do we edit a snippet if it can be part of any of several files? -> We make the user select the snippet they want to edit first, which tells us which file we should open for editing.
This is still not amazing UX because we send them to the beginning of the file and not the correct snippet line - this should be fixed. (should add a test for this, making sure we jump to the right line + fix it)
2- Search: We just search across all snippets from all files.
More fundamental operations:
3- Load: Loads snippets from the core file (mandatory) + all the files in all directories specified into one big list. Nice, expected.
4- Save: Given a slice of SnippetInfo, this loops over every snippet and checks its filename. This logic doesn't look right to me - we're just overwriting the snippetFile as we loop through? If it's empty, we're setting it to the FIRST snippet directory + a custom file name (???).
I think here it was meant to be snippet.Filename
maybe. This definitely seems like a bug, consistent with what you reported in that issue #321 I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it makes sense for the sync to only sync the main snippet file and ignore files in the directories?
I want to try and avoid having to sync multiple files and keep track of each. Directories are nice, but I want to keep it a 'secondary' feature until I iron out the kinks. There are quite some bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#323 fixes some of these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be fine if it's communicated clearly in the tool's documentation that only main snippet file is sync'd.
I, personally, don't use directories. sync or not.
validate string, raise err and other minor typos
Resolved conflicts |
Awesome, thank you! @csessh Will review this carefully this week. Thanks for waiting 🙏🏼 ✨ |
closes #320
This pull request contains changes to support both relative and absolute path types for snippet file's filename attribute.
Given the test case listed in #320:
The same case presented in the issue
Given this config:
SnippetFile
is a relative path which expands to/home/csessh/.config/test/test.toml
Current Pet version:
As expected,
~/.config/test/test.toml
expands to/home/csessh/.config/test/test.toml
Using feature branch version:
file path stays the same. The same result applies for the following test case:
Full path is rendered for every snippets.
I didn't go too deep into testing filename with the use of multiple directories as I ran into #321 problem. However, I did include the safeguard check for it in this PR too.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.