-
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
Open
csessh
wants to merge
7
commits into
knqyf263:main
Choose a base branch
from
csessh:feat-syspath
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58ecbb3
doc: missing code block wrappers
csessh 0c724d4
feat: support relative paths for snippet's filename attribute
csessh 48941bc
bug: fix pet new causing panic when SnippetFile attribute is missing
csessh 67985aa
fixed a typo
csessh 8c6671d
fixed another typo
csessh e87166e
Rewrite ExpandPath to utilise builtin os.UserHomeDir()
csessh 78f9832
Resolve merge conflicts
csessh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andSnippetFile
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:
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.