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

Add Imports Formatter #693

Merged
merged 12 commits into from Jun 1, 2020
Merged

Add Imports Formatter #693

merged 12 commits into from Jun 1, 2020

Conversation

JoeRobich
Copy link
Member

Builds on the work from #685. Thanks @wojciechcibor!

  • Adds AnalyzerConfigDocument to test workspace, so that AnalyzerConfigOptions are flowing into DocumentOptionSet properly.
  • Adds resource string for ImportsFormatter fix message
  • Adds ImportsFormatterTests from features/analyzers

@JoeRobich
Copy link
Member Author

Opened dotnet/roslyn#44710 for the Roslyn formatting error

try
{
var organizedDocument = await Formatter.OrganizeImportsAsync(document, cancellationToken);
if (organizedDocument == document)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think equality for documents was implemented. Did we add that? I would normally compare the document ids.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I just want to know if the document was changed, so I thought a ref equals would be fine. Could use HasTextChanged instead tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, HasTextChanged seems the most efficient implementation since it looks at the text version

Copy link
Member Author

Choose a reason for hiding this comment

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

And it is internal. =) I could run GetTextChangesAsync and check to see if it is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I've verified the ref check is doing exactly what I want it to do. The call to Organize is returning the same document instance when there are no changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, that's why I always recommend customers compare DocumentIds, I forgot. DocumentId implements equitable so you can do (organizedDocument.Id == document.Id)

Copy link
Contributor

Choose a reason for hiding this comment

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

The call to Organize is returning the same document instance when there are no changes.

Good to know. Feel free to ignore this then. My only nit is that I think this behavior is an implementation detail and not part of the public API contract.

catch (InsufficientExecutionStackException)
{
// This case is normally not hit when running against a handwritten code file.
// https://github.com/dotnet/roslyn/issues/44710#issuecomment-636253053
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably tell the user that the file was too large to format.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, although is it a size issue or an expression complexity issue. Perhaps can just be vague and say "Unable to organize file {filename}"

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the message the compiler gives here is expression is too complex


protected virtual string DefaultTestProjectPath => "." + Path.DirectorySeparatorChar + DefaultTestProjectName + "." + DefaultFileExt + "proj";
protected virtual string DefaultFolderPath => Path.DirectorySeparatorChar + DefaultTestProjectName + Path.DirectorySeparatorChar;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we Path.Combine for all of these cases? Why append the slashes manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

The beginning separator is important because I need the path to appear rooted. Using Path.Combine elsewhere is a thing i can do tho.

Copy link
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

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

:shipit:

@JoeRobich JoeRobich merged commit 15d4777 into master Jun 1, 2020
@JoeRobich JoeRobich deleted the pull/685/head branch June 3, 2020 23:32
vdurante pushed a commit to vdurante/format that referenced this pull request Feb 29, 2024
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

3 participants