Summary integration#276
Conversation
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
I think I do see one bug. In lib/tasks.dart, we have a list of errors that turn into a map of codes to types, which is used to deserialize errors from summaries.
We'll likely need a similar pattern for ast errors.
I bet that if you open up green tea, then hit reanalyze, all the syntactic errors will disappear because they will fail to be deserialized without a means to go from string error code to object error code.
Really looking forward to getting this merged. Love the new parser.
| import 'package:html/parser.dart' as html; | ||
| import 'package:source_span/source_span.dart'; | ||
|
|
||
| html.Element firstElement(html.Node node) { |
There was a problem hiding this comment.
Nice we can remove this :)
|
|
||
| // Following Angular2 Logic: | ||
| // https://github.com/dart-lang/angular2/blob/8220ba3a693aff51eed33cd1ec9542bde9017423/lib/src/compiler/schema/dom_element_schema_registry.dart#L199 | ||
| static const attrToPropMap = const { |
There was a problem hiding this comment.
should this be done in angular_ast?
There was a problem hiding this comment.
One problem I see with this is that angular_ast doesn't keep track of two different names, which could make the offset off for 'class':'className' conversion. ExpressionBoundAttribute class keeps track of two different names: origName and propName, which allows us some flexibility in what is being interpreted for value and one for offset.
There was a problem hiding this comment.
From our conversation -- agreed. This is the right place for this!
| return root; | ||
| } | ||
|
|
||
| NodeInfo convert(StandaloneTemplateAst node, {ElementInfo parent}) { |
There was a problem hiding this comment.
parent is no longer optional, really, right?
You could make it just a second parameter, or to keep the parent: naming (kinda nice right?) you can mark it @required which will make it an error if we forget to use parent: even though its a named (as opposed to positional) param.
| } else { | ||
| openingSpan = _toSourceRange( | ||
| node.beginToken.offset, node.endToken.end - node.beginToken.offset); | ||
| openingNameSpan = |
There was a problem hiding this comment.
there's no real opening/closing name span in angular ast? Would be nice to not make it openingNameSpan - '<'.length, but something tracked at parse time.
There was a problem hiding this comment.
I can use the identifierToken actually so it will be similar to how openingSpan is defined.
openingNameSpan = _toSourceRange(identifierToken.offset, identifierToken.length)
| node.beginToken.offset, node.endToken.end - node.beginToken.offset); | ||
| openingNameSpan = | ||
| new SourceRange(openingSpan.offset + '<'.length, localName.length); | ||
| var pnode = node as ParsedEmbeddedContentAst; |
There was a problem hiding this comment.
Why is this cast necessary? Can't the Parsed and Synthetic versions of EmbeddedContentAst both share the same interface?
There was a problem hiding this comment.
Parsed version have access to tokens, synthetic does not and the tokens contain the direct offsets. As a result, the casting is necessary.
There was a problem hiding this comment.
Interesting. Ok, just wanted to ask!
There was a problem hiding this comment.
In fact that's great, as compared to getting null unexpectedly.
| template.view.classElement, dartRequest, | ||
| skipChildClass: false)); | ||
| var memberContributor = new TypeMemberContributor(); | ||
| var inheritedContributor = new InheritedReferenceContributor(); |
There was a problem hiding this comment.
Liking the reduction of types that don't help readability. Very nice! Though I might have preferred final, not everyone does, so it can be a controversy worth avoiding :) So looks great!
| inheritedContributor.computeSuggestionsForClass( | ||
| template.view.classElement, | ||
| dartRequest, | ||
| skipChildClass: false, |
There was a problem hiding this comment.
Ah turns out if you put a dangling comma at the end and call 'dartfmt', it makes long lists very neatly aligned. If it's a long list with nested functions, I think this adds to readability in exchange for some additional lines.
| suggestions, varExtractor.variables, dartRequest.opType); | ||
| suggestions, | ||
| varExtractor.variables, | ||
| dartRequest.opType, |
| suggestTransclusions(target.parent, suggestions); | ||
| } | ||
| } | ||
| // Directly within closing tag; suggest nothing. Ex: '</div^>' |
There was a problem hiding this comment.
Once again, nice comments.
There was a problem hiding this comment.
Can you maybe move this comment inside the else block? Otherwise I read this as the end of the control structure, takes me a moment to realize that the "else" goes here.
| } | ||
| } | ||
| // Directly within closing tag; suggest nothing. Ex: '</div^>' | ||
| else |
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
Nice changes so far, looking great
| valueOffset, dartParser.findMustaches(value, valueOffset))); | ||
| } | ||
| } | ||
| ; |
| property, "[", "]", ExpressionBoundType.input)); | ||
| } | ||
| } | ||
| ; |
| valueOffset, dartParser.findMustaches(value, valueOffset))); | ||
| } | ||
| } | ||
| ; |
| property, "[", "]", ExpressionBoundType.input)); | ||
| } | ||
| } | ||
| ; |
| valueOffset, | ||
| dartParser.findMustaches(value, valueOffset))); | ||
| } | ||
| ; |
| void assertMultipleErrorsExplicit( | ||
| Source source, | ||
| String code, | ||
| List<Tuple4<String, int, ErrorCode, List<Object>>> expectedErrors, |
| * code segment where offset begins, | ||
| * length of the error highlight, | ||
| * errorCode, | ||
| * and optional error args - pass empty list if not needed. |
There was a problem hiding this comment.
only just realized that your new assertion function here checks the args. I've wanted to have tests for them, this is great!
| NgParserWarningCode.EXPECTED_WHITESPACE_BEFORE_NEW_DECORATOR), | ||
| new AnalysisError(htmlSource, 6, 14, NgParserWarningCode.SUFFIX_PROPERTY), | ||
| assertMultipleErrorsExplicit(htmlSource, code, [ | ||
| new Tuple4(']', 0, AngularWarningCode.NONEXIST_INPUT_BOUND, ['']), |
There was a problem hiding this comment.
Hmm, hadn't noticed before that these errors had a length of zero. How does intelliJ handle that?
There was a problem hiding this comment.
When you double click it it puts the cursor right at the spot, but doesn't squiggle anything since it's of length 0. I'm planning sometime later once the ast is merged to do another pass and make the error messages more helpful in terms of length.
| expect(realErrors.length, expectedErrors.length, | ||
| reason: 'Expected error counts do not match.'); | ||
| for (Tuple4 expectedError in expectedErrors) { | ||
| var offset = code.indexOf(expectedError.item1); |
There was a problem hiding this comment.
Might want to assert that this isn't -1, or maybe even assert that the expected code doesn't occur more than once in the test file?
There was a problem hiding this comment.
Looks like you did this, and github didn't realize. Commenting here so we know
| suggestTransclusions(target.parent, suggestions); | ||
| } | ||
| } | ||
| // Directly within closing tag; suggest nothing. Ex: '</div^>' |
There was a problem hiding this comment.
Can you maybe move this comment inside the else block? Otherwise I read this as the end of the control structure, takes me a moment to realize that the "else" goes here.
|
Still need to add change such that conversion does not have three semi-redundant conversions based on check of ElementAst, EmbeddedTemplateAst, and EmbeddedContentAst. Need to add some refactor into angular_ast to create a generic encapsulation interface and want to re-factor EmbeddedContentAst generation to recycle some code instead of creating its own (seemingly wasteful) logic. |
| List<ParsedEventAst> events: const [], | ||
| List<ParsedPropertyAst> properties: const [], | ||
| List<ParsedReferenceAst> references: const [], | ||
| List<ParsedStarAst> stars: const [], |
There was a problem hiding this comment.
I like the use of named params, makes it really clean when called
(there should probably be a lint for having more than x unnamed parameters, don't you think?)
There was a problem hiding this comment.
Agreed, especially when the values have defaults - makes things so much cleaner.
|
|
||
| element.events.forEach((event) { | ||
| attributes.add(_convertStatementsBoundAttribute(event, "(", ")")); | ||
| bananas.forEach((banana) { |
There was a problem hiding this comment.
this could -- depending on preference -- be
bananas.map(_convertExpressionBoundAttribute).forEach(returnAttributes.add)
There was a problem hiding this comment.
I like it, changing it 👍
|
|
||
| value = ast.value; | ||
| ParsedEventAst ast) { | ||
| var origName = |
There was a problem hiding this comment.
nested ternaries...hmm, should probably have at least one if statement I think
| expect(realErrors.length, expectedErrors.length, | ||
| reason: 'Expected error counts do not match.'); | ||
| for (Tuple4 expectedError in expectedErrors) { | ||
| var offset = code.indexOf(expectedError.item1); |
There was a problem hiding this comment.
Looks like you did this, and github didn't realize. Commenting here so we know
| git: | ||
| url: https://github.com/mk13/angular_ast | ||
| ref: master | ||
| ref: on_bind_parsing |
There was a problem hiding this comment.
This can be master again, right?
There was a problem hiding this comment.
Oh yeah, that's true. But I might have to switch this again.
|
I wanted to condense the three element type condensing - but that depends on the condensing of the three types in the angular_ast (dart-archive/angular_ast#34). Seeing as how it needs to be discussed more, it might be a good point to end this PR here and make the condensing of Element types into a separate PR. Ending the refactor of code/code clean-up and moving onto resolving the potential issue of errors not properly deserializing. |
…mplate> causing crash
|
Ping @MichaelRFairhurst for approval. Modified logic that loads the error codes into memory. Think we should add this logic here? or create a separate map within angular_ast? |
|
Definitely worth building and running against greentea as a last check, but it LGTM! |
* Summary integration (#276) * Sync to origin master * checkpoint * Initial ast integration - ranges not behaving properly * Minor bug fix * checkpoint * Tasks tests all passing * Checkpoint before error code fix * Tasks tests set back to 100% after introducing error codes * resolver_test midway checkpoint * Checkpoint * Full test coverage in analyzer. Server still left * All tests passing * Make paths explicit * Remove comments * Attributes now sorted by offset. Improves performance in auto completion * DOCTYPE now acceptable * Created separate Ast for top level document container * Refactored primary function in completion.dart * Minor code clean up * Fuzz tester bug fix * Revert try catch block * Rename exception codes after changes in angular_ast * Bug fix on [class. [style. [attr. bindings; range error * Allow spaces in msutaches * Autocompletion in text attribute value is now empty * Allow for plain [class] binding * Fixed update_deps.sh to work with angular_ast * Clean up deps and remove some unnecessary comments * Changed pubspec to pull from master * Defend against files hidden by generated files (#271) * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * Travis sdk fix (#272) * Sync to origin master * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * First round of quick fixes based on feedback * remove comment * Error codes no longer use hard offsets; uses string instead * Merged attribute generating logic to be agnostic of Element or template type. * Assert for indexOf added into test. Moved comments for clarity * Remove comment-blocked chunk * Changes based on feedback * Error codes added to hashmap so now show up. Fixed issue with <div template> causing crash * Changed pubspec to pull from master in angular_ast * Summary integration sync (#288) * Sync to origin master * checkpoint * Initial ast integration - ranges not behaving properly * Minor bug fix * checkpoint * Tasks tests all passing * Checkpoint before error code fix * Tasks tests set back to 100% after introducing error codes * resolver_test midway checkpoint * Checkpoint * Full test coverage in analyzer. Server still left * All tests passing * Make paths explicit * Remove comments * Attributes now sorted by offset. Improves performance in auto completion * DOCTYPE now acceptable * Created separate Ast for top level document container * Refactored primary function in completion.dart * Minor code clean up * Fuzz tester bug fix * Revert try catch block * Rename exception codes after changes in angular_ast * Bug fix on [class. [style. [attr. bindings; range error * Allow spaces in msutaches * Autocompletion in text attribute value is now empty * Allow for plain [class] binding * Fixed update_deps.sh to work with angular_ast * Clean up deps and remove some unnecessary comments * Changed pubspec to pull from master * Defend against files hidden by generated files (#271) * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * Travis sdk fix (#272) * Sync to origin master * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * First round of quick fixes based on feedback * Tick to 8 (#277) * Sync to origin master * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * Tick to 0.0.8 * remove comment * Error codes no longer use hard offsets; uses string instead * Track @Attribute annotated constructor parameters (#270) * Merged attribute generating logic to be agnostic of Element or template type. * Assert for indexOf added into test. Moved comments for clarity * Remove comment-blocked chunk * Resolve plain attributes -- in ranges, and strchecks for inputs. (#278) * Resolve plain attributes -- in ranges, and strchecks for inputs. Record resolved ranges for `x="y"` where `x` is an input or a constructor `@Attribute`. If its an input, check that strings are assignable to it. If not, give it its own error that hopefully explains the semi magical situation. * Track/typecheck std attrs Eventually we should * report errors for <a href="foo" [href]="bar"> * not suggest href after [href] has been used * not suggest [href] after href has been used * Changes based on feedback * Error codes added to hashmap so now show up. Fixed issue with <div template> causing crash * Changed pubspec to pull from master in angular_ast * Template parsing fix (#279) * Sync to origin master * Fix travis build. Fix sdk related errors (ContextRoot and IdeOptions). Clean up imports to remove unused * Fix issue that caused empty binding on template attribute to crash * Now ready: Priority angular analysis (#273) * Priority dart & html analysis * Starter class, await supplementing errors or they're added too late. * Report has work to analyze for priority requests * Don't await for requesting files, do have a cache busting option * Handle case of files being requested multiple times * Priority html requests, requires serving errors with line infos. * Report all html files for all dart contexts in one method, plus tests I think before we were getting a last-one-wins effect, where the last analyzed dart/html pair would cover up all the errors for every other dart/html pair. As such, I need to carefully test that this change doesn't introduce new false errors (from them being covered up before). But now with this, we can report html errors back for multiple contexts from a single method when that's requested. Next I just have to use that method on getErrors when we have multiple relationships tracked already. * Guess html/dart relationship when none exist, otherwise use what's known using isEmpty rather than == 0 * Get setterType by setter.parameters[0] instead of setter.variable.type (#283) Seems like in the precense of a getter, setter.variable.type is the getter type, not the setter's type. So use the first function argument instead. * Remove contextRoot, won't be required in master soon, and breaks dev (#284) * Disable global attr plaintext typechecking until #280 has a clear solution (#286) * Update test_reflective_loader, fix analyzer warnings&errors (#285) * Update test_reflective_loader, fix analyzer warnings&errors * Fix the single server test too, which prevents build errors * Use var instead of types in angular_driver_test * Add TODOs * Percentage use fix in style.width and style.height. Test cases added (#282) * Percentage use fix in style.width and style.height. Test cases added * Added more property names that use percentage * Tests passing * Sync to master; tests passing
One more try.