Skip to content
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

Better member annotation scoping #4648

Merged

Conversation

MDoerner
Copy link
Contributor

This PR simplifies the annotation scoping.

After this PR, the rules will be as follows, where annotations and comments are considered to be whitespace.

  • Annotations on non-whitespace logical lines are illegal and do not annotate anything.
  • Annotations annotate the next physical non-whitespace line below them.
  • Whether an annotation annotates a construct on the annotated line depends on its AnnotationType.
  • Module annotations annotate the module, provided the annotated line is at most the first line of the first module body element, if there is any.

In addition, this PR changes the GetDescendent<TContext>() extension to a depth first search approach from traversing the entire tree collecting all candidates, then sorting them and finally taking the first.

This also deems all annotations on non-whitespace lines illegal.

The reasoning behind this change is that the previous system was somewhat unintuitive and fragile in that comments and non-member annotations could break a member annotation section. This is inconvenient in particular when removing annotations with a comment on the same line. Moreover, the new scoping is better aligned with VBE's own procedure separators.

As a side-effect, the logic for determining the annotated line has been centralized and simplified. In addition, stacking identifier annotations along a procedure is no longer possible, which could be problematic before.
This switches getting the first endOfLine to a new dedicated extension that takes as much shortcuts as possible.
Previously, it first got all matches by walking the entire subtree, then ordered the results by start index and finally took the first one.

Now, it uses a depth-first search approach to find the first result and bails out as soon as a match is found.
annotations.AddRange(annotationsStartingOnCurrentLine);
}
return annotations;
return _declarationFinder.FindAnnotations(module, line).Where(annotation => annotation.AnnotationType.HasFlag(AnnotationType.IdentifierAnnotation));
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Should this method be inlined at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make sense. Then, the entire class is needed no longer.

The only method does no longer contain a lot of logic; it is just one call to the `DeclarationFinder` followed by a single `Where` on the annotation type.
@retailcoder retailcoder merged commit dda9300 into rubberduck-vba:next Dec 22, 2018
@MDoerner MDoerner deleted the BetterMemberAnnotationScoping branch January 5, 2019 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants