Conversation
ad22e90 to
1062e3b
Compare
|
@atscott @ayazhafiz As mentioned in the meeting just now, I've refactored the adapter into a standalone class, and added more comments to explain why we need to manage resource (templates) separately. PTAL. |
1062e3b to
66e03b2
Compare
66e03b2 to
a4aad45
Compare
There was a problem hiding this comment.
For example, could we clear the modifiedTemplates here and return the previous contents? (If the compiler only needs the same changes once)
There was a problem hiding this comment.
I think it's not a good idea to clear the modified templates here, because
- we are relying on the compiler to only call this method once
This assumption is fragile. Within the compiler it's perfectly fine for it to call this method multiple times, and it'd be surprising to them if the results of the first call is different from the second call - the behavior would not be consistent within the same compiler run
This is a method defined by the compiler, and we need to adhere to the behavior they expect, not the behavior we provide.
angular/packages/compiler-cli/src/ngtsc/core/api/src/interfaces.ts
Lines 47 to 51 in bc69182
I gave this some more thought, and realize that we could clear the modified template after the compiler has read the updated version. The pro is that it'll always be consistent, i.e. once the compiler reads the template, it's no longer marked as modified. The con is that there's no explicit way for language service to make sure the template update is cleared after every request. I think pro > con in this case, because it's very unlikely that the compiler would not read a template that's been marked as modified.
With this, I deleted theclearTemplateUpdates()method.
There was a problem hiding this comment.
One more note: let's say the compiler asks for all the modified resources (getModifiedResourceFiles), then reads one modified resource, then asks for the modified resources again. In this case, with what you have described, the second set of modified resources would be one less than the first, so the expectation that first call = second call in the same run is lost. Is this something we need to be concerned about?
There was a problem hiding this comment.
I think the behavior is still consistent in this case, because once the compiler reads a template, it already has the latest state of the file, so the file is no longer considered "modified".
That said, I agree this is not the best design. I think the initial design with clearTemplateUpdates() is the most straightforward solution with no surprise. Would you prefer that over the current solution?
There was a problem hiding this comment.
Why don't we just recreate the program adapter each time we create a compiler?
There was a problem hiding this comment.
The adapter is stateful because it needs to keep track of the template versions.
We could make it stateless, but in that case, the language service class itself will have to keep track of the template versions. I think the responsibility of tracking versions should fall under the adapter, not the language service.
There was a problem hiding this comment.
Oh youre right I forgot about the versioning. Okay I am fine either way, sorry this was such a long discussion. Maybe later on we can figure out some nicer abstractions, even on the compiler side.
There was a problem hiding this comment.
It's good, your comments make me think more about the architecture, and I agree there's an opportunity here to reuse some of TS logic to keep track of changed files, instead of us doing our custom checking.
Could you please approve this PR?
b29925a to
a66ac03
Compare
7789bac to
5163226
Compare
…plates
This PR enables `getSemanticDiagnostics()` to be called on external templates.
Several changes are needed to land this feature:
1. The adapter needs to implement two additional methods:
a. `readResource()`
Load the template from snapshot instead of reading from disk
b. `getModifiedResourceFiles()`
Inform the compiler that external templates have changed so that the
loader could invalidate its internal cache.
2. Create `ScriptInfo` for external templates in MockHost.
Prior to this, MockHost only track changes in TypeScript files. Now it
needs to create `ScriptInfo` for external templates as well.
For (1), in order to make sure we don't reload the template if it hasn't
changed, we need to keep track of its version. Since the complexity has
increased, the adapter is refactored into its own class.
5163226 to
680a368
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR enables
getSemanticDiagnostics()to be called on external templates.Several changes are needed to land this feature:
a.
readResource()Load the template from snapshot instead of reading from disk
b.
getModifiedResourceFiles()Inform the compiler that external templates have changed so that the
loader could invalidate its internal cache.
ScriptInfofor external templates in MockHost.Prior to this, MockHost only track changes in TypeScript files. Now it
needs to create
ScriptInfofor external templates as well.For (1), in order to make sure we don't reload the template if it hasn't
changed, we need to keep track of its version. Since the complexity has
increased, the adapter is refactored into its own class.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information