-
Notifications
You must be signed in to change notification settings - Fork 322
#6370 Add line numbers to sections and text-blocks #6371
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
#6370 Add line numbers to sections and text-blocks #6371
Conversation
Add line numbers to text blocks and sections. Create removeAll() method to remove all the instances of an item regardless of the line number
Add new section items with dummy line number
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.
If we're using -1 to mark "uninitialized", could we make it a constant somewhere? I have a short memory, I'm sure I'll forget what -1 means 6months from now when I come back to this code.
base/src/com/google/idea/blaze/base/projectview/section/ListSection.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/section/sections/TextBlock.java
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/ProjectView.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/ProjectView.java
Outdated
Show resolved
Hide resolved
Additionally, I'm a bit scared of printing having side effects on the data structure.
|
And, because I forgot to start with this: Thank you for your contributions! Most maintainers here have limited time to implement cool features in the plugin, and it's delightful to see the plugin improving. |
…ay/section_line_number
Remove redundant method Add constant for temporary line numbers
I was about to do that and somehow forgot about it! Done. |
Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
What you are mentioning is the ideal solution beyond any doubt. The problem is that each print statement decides on its own how many new lines to add. Moving the logic to the builder means consolidating all that "new-line logic" into the ProjectView class. Can we guarantee that future printers would be compatible with ProjectView? I mean we can at least add a comment to the |
I really appreciate your support and patience you and especially @tpasternak . I assure you that there will be much bigger changes to come. |
…ay/section_line_number
…ay/section_line_number
… ay/section_line_number
…ay/section_line_number
…ay/section_line_number
Do not add line numbers on printing sections
OK so I removed line number calculation from all the print() methods and then tested the plugin behavior thoroughly. I found that all the code-paths call the parseProjectView() after writing to the file multiple times so there is no need to calculate the line numbers when the file is being created or edited. |
…ay/section_line_number
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 making the changes!
Given the flow you've proposed, I'm not sure we need TEMPORARY_LINE_NUMBER
anymore. In fact, I'm not sure we need to pass line numbers to the individual methods of the Builder
s of different sections.
If I understand correctly, every creation and update to a ProjectView
goes through a Builder
. If we pass the initial line index to a Builder
, it should have enough information to assign line numbers based on the operation and the sections it contains.
So, instead of having Builder.add(T element, int lineIdx)
, we'd have Builder.add(T element)
and the Builder
would take care of calculating which line numbers T
should occupy.
I think this encapsulates the behaviour of adding line numbers neatly into the Builders, so that the calling code doesn't have to keep that state.
What do you think?
aswb/src/com/google/idea/blaze/android/projectview/AndroidSdkPlatformSection.java
Outdated
Show resolved
Hide resolved
aswb/src/com/google/idea/blaze/android/projectview/AndroidSdkPlatformSection.java
Outdated
Show resolved
Hide resolved
aswb/src/com/google/idea/blaze/android/projectview/AndroidSdkPlatformSection.java
Outdated
Show resolved
Hide resolved
aswb/src/com/google/idea/blaze/android/projectview/AndroidSdkPlatformSection.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/ProjectView.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/section/sections/DirectorySection.java
Outdated
Show resolved
Hide resolved
...m/google/idea/blaze/base/projectview/section/sections/AutomaticallyDeriveTargetsSection.java
Outdated
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/section/ListSection.java
Show resolved
Hide resolved
base/src/com/google/idea/blaze/base/projectview/section/ListSection.java
Outdated
Show resolved
Hide resolved
.../src/com/google/idea/blaze/base/projectview/section/sections/AdditionalLanguagesSection.java
Outdated
Show resolved
Hide resolved
…latformSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
…latformSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
…latformSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
…latformSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
…ns/DirectorySection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
…ns/AutomaticallyDeriveTargetsSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
Remove line calculation from print() methods
… ay/section_line_number
Remove redundant method
Update comment
I tried doing that but found multiple instances where the builder is instantiated and used without having known line numbers. The line numbers are mostly defined when the print() method is called, and that's why we are depending on reparsing to replace the temporary line numbers with real one. I can't think of a way for example to make that change to AddDirectoryToProjectAction.doOKAction() and GenerateFromBuildFileSelectProjectViewOption.guessProjectViewFromLocation(). How do you suggest doing these changes in these methods? |
@tpasternak @blorente is there anything else that I need to do here? |
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 finally got a little bit of time to re-review this.
It seems we can't get more invariants from the codebase as it is, so I think it's fine to merge this and iterate later on how we can remove TEMPORARY_LINE_NUMBER
.
Approving with the caveat that I'd love to see more tests, I'll be happy to merge once the tests are there.
aswb/src/com/google/idea/blaze/android/projectview/AndroidSdkPlatformSection.java
Outdated
Show resolved
Hide resolved
base/tests/unittests/com/google/idea/blaze/base/projectview/parser/ProjectViewParserTest.java
Show resolved
Hide resolved
…latformSection.java Co-authored-by: Borja Lorente <blorente@users.noreply.github.com>
@blorente is there any other requirement for merging? |
Not as far as I can tell, thanks for the contribution, and apologies for the slow review turnarounds! |
Checklist
Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.
Discussion thread for this change
Issue number:
6370
Description of this change
Add line numbers to the text blocks and sections so that we can identify them from a PsiElement. It is obvious that not in all cases we know the line number: when we are generating a new file, the line numbers are only known when the file is actually generated. In these cases I set the line number to -1 knowing that before the object is used it will go through the print() command. There, I would update the line number of the element.
If at the moment of the change (ex in my target management feature I already know the line number of the directory entry to change), then there is no need to assign a dummy value first.