-
Notifications
You must be signed in to change notification settings - Fork 650
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
Added support for target date variables in daily note template #781
Conversation
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.
Looks good to me. Only the linter is not entirely happy at all places.
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.
'DAILY_NOTE_YEAR', | ||
'DAILY_NOTE_YEAR_SHORT', | ||
'DAILY_NOTE_MONTH', | ||
'DAILY_NOTE_MONTH_NAME', | ||
'DAILY_NOTE_MONTH_NAME_SHORT', | ||
'DAILY_NOTE_DATE', | ||
'DAILY_NOTE_DAY_NAME', | ||
'DAILY_NOTE_DAY_NAME_SHORT', | ||
'DAILY_NOTE_HOUR', | ||
'DAILY_NOTE_MINUTE', | ||
'DAILY_NOTE_SECOND', | ||
'DAILY_NOTE_SECONDS_UNIX', |
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.
- My intention originally was to have all the Foam-specific variables namespaced with the
FOAM_
prefix.- To keep it clear that this is a Foam variable, and not a VSCode variable.
DAILY_NOTE
is very specific. The name gets awkward when we were to start using these in other places- (i.e., I think that any snippet variables should be
validuseful in all scenarios they can be used in order to justify their inclusion. We shouldn't be adding any special logic/variables for daily notes; they are just notes like any other.)
- (i.e., I think that any snippet variables should be
Perhaps FOAM_DATE_*
?
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.
Thanks for the thorough answer @movermeyer.
Happy to go with FOAM_*
, that's a good point.
More complicated is the topic of FOAM_DAILY_NOTE_*
vs FOAM_DATE_*
, I wonder if you are thinking of those variables as replacing the "date" snippet variables for our other purposes. The description of the PR is not super detailed, I will update it just to be sure.
These variables kinda make sense only in the context of a daily note (it is the date a daily note is referring to) so I think it's ok for these variables being empty in other templates
I think that any snippet variables should be valid in all scenarios they can be used
They would be valid, just empty - the same way FOAM_SELECTED_TEXT is valid and empty if there is no selected text or if we trigger the "New note" command.
Or maybe you are suggesting that in those cases they'd map to the current date? I actually wonder whether that would cause more confusion than just keeping them empty.
Before I address anything else I would like to be sure we are on the same page so far
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.
They would be valid, just empty
I should have used the word "useful", not "valid". Discussed in the "Simplicity" section of my new comment
dateVariables.set('DAILY_NOTE_HOUR', '00'); // The current hour in 24-hour clock format | ||
dateVariables.set('DAILY_NOTE_MINUTE', '00'); // The current minute | ||
dateVariables.set('DAILY_NOTE_SECOND', '00'); // The current second |
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.
These are always returning 00
?
I think the value probably makes sense if you need to have completeness relative to the VSCode snippets (since you only have a date, and it should be the start of the date).
But in what scenarios would you expect a user to use/want these?
In general, is there enough value to justify having a complete set of variables just to match the VSCode variables (which we already know aren't great for user's flexibility)? Every variable is additional tech debt.
Perhaps a better option instead of this PR is introduce a single variable $FOAM_DATE_FORMAT
to solve this issue and this issue.
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 would agree we should just kill the hour/minute/second, they don't really add anything except the "mirroring" but even then it's kinda empty.
I feel the $FOAM_DATE_FORMAT
solves a different issue? this comment is part of the reason why I am not sure we are thinking about the same problem, am I missing something?
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 feel the
$FOAM_DATE_FORMAT
solves a different issue?
Yeah, there are two discussions mixing here. The relationship to is discussed in the "Expressivity" section of my new comment.
export const readFile = async (filepath?: string[] | URI): Promise<string> => { | ||
const rootUri = vscode.workspace.workspaceFolders[0].uri; | ||
filepath = filepath ?? [randomString() + '.md']; |
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 I'm missing something...
Where is this used?
Why is filepath
optional?
Why is there randomness in the filepath
assignment?
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.
oh my, this is my bad copying of the writeFile
function. I wanted them to be mirror of each other, but obviously the optionality of the argument shouldn't fall into that 🤦♂️
This is actually not used anywhere because in the end I just ended up using the editor itself to check the generation of the note, so we can actually get rid of it
@riccardoferretti I think we're actually very similar in our thinking, but I didn't put enough time into writing it all out. 😅 I think there are two separate topics to discuss:
SimplicityMy gut instinct when I saw the issue was to create a Foam-specific variable that could replace the use of In this PR, the daily note variables are Benefits
Detriments
ExpressivityRelation to #564Since this involves customizing date formats in daily notes, and you will also want to use the new variables in filepaths, it is very adjacent to this issue. I think they can be solved at the same time? We were hoping for a solution more flexible than what VSCode snippet variables can offer us (and there are similar issues in the upstream complaining about the limitations of the existing date variables), so I'm not convinced that copying their variables is a good idea. As discussed briefly on that issue, something similar to Example ---
foam_template:
filepath: 'journal/${FOAM_DATE_FORMAT}.md'
---
# ${FOAM_DATE_FORMAT}
## What did I do today? Question: What if a user actually wants the current date in their "relative daily note"?(The current PR also works in this way. I just wanted to comment here since I had asked myself this question.) They might want a "created on" in their notes. Desired note contents: # 2021-12-13 <- Some date in the future
# $FOAM_TITLE
Created on 2021-10-13 <- Today's date Answer: In this case, they can make use of the existing # $FOAM_DATE_FORMAT <- Some date in the future
# $FOAM_TITLE
Created on $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE <- Today's date The current PR also works in this way. I just wanted to comment here since I had asked myself this question. |
I agree with everything you wrote, happy to go in that direction, except on the topic of |
2e22d14
to
fbde5d0
Compare
@movermeyer it took a bit longer because in the end I decided to move the resolution to the resolver itself.. can you take a look and see if it fits with the original design of the resolver? |
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.
@riccardoferretti I still don't understand your changes to packages/foam-vscode/src/test/test-utils-vscode.ts
, and I noticed a few oddities, but things look much better now. 👏
packages/foam-vscode/src/features/create-from-template-variables.spec.ts
Show resolved
Hide resolved
packages/foam-vscode/src/features/create-from-template-variables.spec.ts
Show resolved
Hide resolved
packages/foam-vscode/src/features/create-from-template-variables.spec.ts
Outdated
Show resolved
Hide resolved
I have now implemented the feedback, and ready to merge. |
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.
@riccardoferretti LGTM.
I am curious about the oddities, feel free to share them or not.
The oddities were just the bits I pointed out in the last review, which you have now fixed. 👍
(I could have been clearer 🙃)
I've added two commits to this PR to document the feature, and add a CHANGELOG entry. Take a look.
Yup thanks for the docs! |
fixes #776
We are adding new variables to the Foam daily note template.
These variables reflect the date of the note being created, so that a custom template can use them.