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
Conversation
Opened dotnet/roslyn#44710 for the Roslyn formatting error |
src/Formatters/ImportsFormatter.cs
Outdated
try | ||
{ | ||
var organizedDocument = await Formatter.OrganizeImportsAsync(document, cancellationToken); | ||
if (organizedDocument == document) |
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 didn't think equality for documents was implemented. Did we add that? I would normally compare the document ids.
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.
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.
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.
yeah, HasTextChanged
seems the most efficient implementation since it looks at the text version
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.
And it is internal. =) I could run GetTextChangesAsync and check to see if it is empty.
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.
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.
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.
ah, that's why I always recommend customers compare DocumentId
s, I forgot. DocumentId
implements equitable so you can do (organizedDocument.Id == document.Id)
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.
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 |
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.
We should probably tell the user that the file was too large to format.
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.
Yeah, although is it a size issue or an expression complexity issue. Perhaps can just be vague and say "Unable to organize file {filename}
"
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 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; |
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.
Can we Path.Combine
for all of these cases? Why append the slashes manually?
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.
The beginning separator is important because I need the path to appear rooted. Using Path.Combine elsewhere is a thing i can do tho.
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.
Add Imports Formatter
Builds on the work from #685. Thanks @wojciechcibor!