Skip to content

Resolve all time-based snippet variables using the same time#128571

Merged
jrieken merged 1 commit intomicrosoft:mainfrom
movermeyer:mo/resolve_time_based_snippet_variables
Jul 15, 2021
Merged

Resolve all time-based snippet variables using the same time#128571
jrieken merged 1 commit intomicrosoft:mainfrom
movermeyer:mo/resolve_time_based_snippet_variables

Conversation

@movermeyer
Copy link
Contributor

@movermeyer movermeyer commented Jul 13, 2021

What are you trying to accomplish?

This PR fixes #128570

What approach did you choose and why?

Since TimeBasedVariableResolver is only used as part of CompositeSnippetVariableResolver and immediately used to resolve all the variables in a snippet, I added the time as a field on TimeBasedVariableResolver without worrying about it getting stale.

The impact of these changes

All the time-based snippet variables in a snippet will resolve using the same time, fixing #128570

Checklist

  • I have manually tested this change.
  • This PR is safe to roll back.

@movermeyer movermeyer changed the title Resolve all time-based snippet variables using the same time [WIP] Resolve all time-based snippet variables using the same time Jul 13, 2021
@movermeyer movermeyer changed the title [WIP] Resolve all time-based snippet variables using the same time Resolve all time-based snippet variables using the same time Jul 13, 2021
@movermeyer movermeyer requested a review from jrieken July 14, 2021 10:31
Copy link
Member

@jrieken jrieken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nit about the test, I leave it up to you. Will merge later today. Thanks so far

const resolver = new TimeBasedVariableResolver;

const firstResolve = new SnippetParser().parse(snippetText).resolveVariables(resolver);
clock.tick((365 * 24 * 3600 * 1000) + (24 * 3600 * 1000) + (3661 * 1000)); // 1 year + 1 day + 1 hour + 1 minute + 1 second
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since _date is a new constructor argument you could simplify this further, e.g. skip clock-magic and just a fixed date when constructing the resolver

Copy link
Contributor Author

@movermeyer movermeyer Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on what behaviour you want to test/express.

The test as it is shows that "the same resolver will return the same values even though time has passed".
Changing the test to just use the constructor would change the test to "the resolver uses the date given".

I agree that the different tests would fail in the same ways, but IMO, the intention is captured better in the current code. 🤷

Happy to make the change if you want it.


(The resolver only has a constructor argument since we don't have "native" private fields. So think I consider it an implementation detail, and not part of the actual interface???)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolver only has a constructor argument since we don't have "native" private fields.

Not sure what that means? You can define a non-native private field anywhere, not just as ctor-argument-field

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the different tests would fail in the same ways, but IMO, the intention is captured better in the current code. 🤷

Yeah, either way is fine for me. I would have done it different or most likely I wouldn't have written a test ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define a non-native private field anywhere, not just as ctor-argument-field

Whoops. Fixed in #128857

@jrieken jrieken added this to the July 2021 milestone Jul 15, 2021
@jrieken jrieken merged commit ecea969 into microsoft:main Jul 15, 2021
movermeyer added a commit to movermeyer/vscode that referenced this pull request Jul 16, 2021
It was incorrectly placed there by me in microsoft#128571
movermeyer added a commit to movermeyer/vscode that referenced this pull request Jul 16, 2021
It was incorrectly placed there by me in microsoft#128571
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All time-based snippets variables should resolve using the same time

2 participants