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

Golang: Display Go external libraries based on importpath structure #2973

Closed
wants to merge 1 commit into from

Conversation

blico
Copy link
Member

@blico blico commented Sep 30, 2021

Checklist

  • I have filed an issue about this change and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Discussion thread for this change

Issue number: #1744 #2365

Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

This is essentially achieved by extending Go's additionalLibraryRootsProvider to carry external dependency importpath mappings and then using that information from a new Go treeStructureProvider to create the importpath based directory structure.

Due to my unfamiliarity with this project and the lack of pre-existing tests I struggled to write tests for this feature. If anyone more familiar with the codebase could provide some guidance that would be very helpful.

@AlexeyGy
Copy link
Collaborator

Thank you very much for this PR and sorry that it took me a while to review!

Unfortunately, I don't think that we can upstream the changes as-is. In particular, it worries me to let state leak out out of ExternalLibraryManager in the form of a importpathToFilesMap. We heavily rely on controlling the state of libraries and sources in our plugin. For example, this state controls what libraries are attached after the sync (this is why "Go external libraries" will initially disappear when you reopen a project). I fear that changing this may cause unforeseeable problems like libraries not disappearing after removing them from BUILD files.

TreeStructureprovider is the right way to go since changes there will only be cosmetic for the user. We can get the current project state via BlazeProjectDataManager.getInstance(project).getProjectData or even via using the SyncCache.

Then, we only need to use the DFS that you've already drafted up to create the right structure.

Testing

In terms of tests, I think, the ideal point would be a unit test which checks if the tree structure is properly generated (i.e., a test for different scenarios ofcreateSyntheticDirectoryStructure) and that covers several bad scenarios (e.g., what if we don't have all entries in importPath->Files map).

How to move ahead

Let me move ahead with drafting up a PR based on this and then you can tell me if it would work for you (let's flip the script). I'd make it so you are co-author of the change on GitHub when it gets submitted. I'd probably also want to have this change behind a feature flag, just to be sure that users who don't want this can fall back on something.

@blico
Copy link
Member Author

blico commented Nov 10, 2021

That makes sense about not wanting to leak state and sounds like a good plan forward. Thank you @AlexeyGy !

@blico
Copy link
Member Author

blico commented Mar 22, 2022

@AlexeyGy @alice-ks friendly ping. Do you have any plans on taking this PR?

@AlexeyGy
Copy link
Collaborator

@AlexeyGy @alice-ks friendly ping. Do you have any plans on taking this PR?

Still on it and have a WIP PR but did not yet get to push it out mainly because I want this functionality to be well covered by unit tests.

@loeffel-io
Copy link

Any update?

@loeffel-io
Copy link

Can someone please merge this thing - it's so annoying

@linzhp
Copy link

linzhp commented Jul 21, 2022

@jastice FYI

@jastice jastice requested review from jastice, mai93 and tpasternak and removed request for vsiva and alice-ks July 21, 2022 15:26
@jastice
Copy link
Collaborator

jastice commented Aug 2, 2022

@AlexeyGy maybe you could publish your draft PR so that somoebody could pick it up?

@loeffel-io
Copy link

Never wanted a PR so bad ❤️ @linzhp

copybara-service bot pushed a commit that referenced this pull request Aug 9, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
copybara-service bot pushed a commit that referenced this pull request Aug 9, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
copybara-service bot pushed a commit that referenced this pull request Aug 9, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
@AlexeyGy
Copy link
Collaborator

AlexeyGy commented Aug 9, 2022

New PR is finally out: #3833. Under internal review.

@loeffel-io
Copy link

🎉

copybara-service bot pushed a commit that referenced this pull request Aug 10, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 401216309
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

## Design choices:
 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

## Discussion thread for this change

Issue number: #1744 #2365

## Description of this change

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

## Tests
Unit tests added.

PiperOrigin-RevId: 467145600
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
See #2365 and #2973 for context.

PiperOrigin-RevId: 467146104
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
See #2365 and #2973 for context.

PiperOrigin-RevId: 467146104
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
See #2365 and #2973 for context.

PiperOrigin-RevId: 467146104
copybara-service bot pushed a commit that referenced this pull request Aug 12, 2022
See #2365 and #2973 for context.

PiperOrigin-RevId: 467183336
@tpasternak
Copy link
Collaborator

@blico once the change is merged, can we close this PR?

@blico
Copy link
Member Author

blico commented Aug 12, 2022

Done!

@blico blico closed this Aug 12, 2022
@linzhp
Copy link

linzhp commented Aug 12, 2022

@AlexeyGy In the future, it's a better to separate your change from @blico's in different commits, so the original author get some credits in the list of commits

mai93 pushed a commit that referenced this pull request Aug 12, 2022
…bazelbuild/intellij PR import #2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

Issue number: #1744 #2365

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within #2365 for an example of how the new structure looks.

Closes #2973

Unit tests added.

(cherry picked from commit 4d0f56b)
mai93 pushed a commit that referenced this pull request Aug 13, 2022
cpsauer pushed a commit to hedronvision/bazelbuild-intellij that referenced this pull request Aug 13, 2022
…bazelbuild/intellij PR import bazelbuild#2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

Issue number: bazelbuild#1744 bazelbuild#2365

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within bazelbuild#2365 for an example of how the new structure looks.

Closes bazelbuild#2973

Unit tests added.

(cherry picked from commit 4d0f56b)
cpsauer pushed a commit to hedronvision/bazelbuild-intellij that referenced this pull request Aug 13, 2022
AlexeyGy added a commit that referenced this pull request Aug 16, 2022
See #2365  and #2973 for context.

Co-authored-by: Brandon Lico <[email protected]>
ittaiz pushed a commit to wix-playground/intellij that referenced this pull request Oct 24, 2022
…bazelbuild/intellij PR import bazelbuild#2973)

This is a modified version of the original change by Brandon Lico with a few modifications:
 * read from the fileToImportPathMap directly when modifying the structure
 * add unit tests.

 * We don't inherit from BlazeExternalSyntheticLibrary since that contains irrelevant logic. Also we can't logically fulfill the "Only supports one instance per value of presentableText." condition that's outlined in the class javadoc since we could have nodes with identical presentableText properties in the tree in different positions.

Issue number: bazelbuild#1744 bazelbuild#2365

Modifies the structure of the external "Go Libraries" project view to be based on importpath rather than a flat list of files. See my comment within bazelbuild#2365 for an example of how the new structure looks.

Closes bazelbuild#2973

Unit tests added.

(cherry picked from commit 4d0f56b)
ittaiz pushed a commit to wix-playground/intellij that referenced this pull request Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants