Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

goImports: avoid collapsing new imports into pseudo import line #3045

Merged
merged 2 commits into from
Apr 27, 2020

Conversation

hyangah
Copy link
Contributor

@hyangah hyangah commented Feb 13, 2020

getTextEditForAddImport tries to insert a newly added package
into an existing import group. If no import group exists, it
tries to merge single line import statements and create a group.

In this process, import statements like

import "C"

are pseudo imports and shouldn't be grouped with other imports.
This CL changes parseFilePrelude to detect such pseudo imports
and excludes such imports from the grouping logic.

Fixes #1701

@hyangah
Copy link
Contributor Author

hyangah commented Feb 13, 2020

the test failures on platforms other than mac are real - I messed up with file name (case sensitivity). Will fix it when I can access my linux tomorrow.

getTextEditForAddImport tries to insert a newly added package
into an existing import group. If no import group exists, it
tries to merge single line import statements and create a group.

In this process, import statements like

  import "C"

are pseudo imports and shouldn't be grouped with other imports.
This CL changes parseFilePrelude to detect such pseudo imports
and excludes such imports from the grouping logic.

Fixes microsoft#1701
mac and vsccode ignored casing, but linux and git were unhappy.
@@ -156,11 +156,12 @@ export function parseFilePrelude(text: string): Prelude {
}
if (line.match(/^(\s)*import(\s)+\(/)) {
ret.imports.push({ kind: 'multi', start: i, end: -1, pkgs: [] });
}
if (line.match(/^(\s)*import(\s)+[^\(]/)) {
} else if (line.match(/^\s*import\s+"C"/)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is C the only import that falls under this pseudo category?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. "C" is the only one in this category (psuedo import whose placement in the import affects the correctness/functionality)

@ramya-rao-a ramya-rao-a merged commit c565b21 into microsoft:master Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automatic import adder should not separate first import from its comment
2 participants