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

Allow Razor generated documents to respect tabs/spaces settings #31211

Merged
merged 15 commits into from
Mar 30, 2021

Conversation

allisonchou
Copy link
Contributor

Part of dotnet/razor#3317. Enables generated documents to respect the tabs/spaces settings passed in from Razor tooling.

The bulk of this is Ajay's work from dotnet/razor#1606, so major creds to him. 🎉

@allisonchou allisonchou requested a review from a team as a code owner March 24, 2021 22:45
Copy link
Contributor

@TanayParikh TanayParikh left a comment

Choose a reason for hiding this comment

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

LGTM!

@Pilchie Pilchie added the area-razor.compiler This issue is related to the Razor compiler (now external) label Mar 24, 2021

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TanayParikh It looks like Ajay was seeing the same issue in dotnet/razor#1606. It doesn't look too impactful, but just want to check this change is OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, so this wont have any actual impact on the runnability of the code since it's outside of the line pragma; however, it's concerning that this is being touched at all? Definitely need to look into what's happening here. Also, in the other files I wouldn't imagine that generated locations would change unless there was a mashup of tabs in the source files / interesting settings in the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, @pranavkm does this not worry you?

{
if (Length == 0 || this[Length - 1] == '\n')
if (size == 0 || (Length != 0 && this[Length - 1] != '\n'))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unrelated to your PR, but indexing in to StringBuilder (which is what this[..] is doing) is really slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, interesting. Maybe we can keep track of the last character somehow, possibly storing it in a field?
(Don't know if it's in the scope of this PR, but would be a good follow up later on.)

Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

Looking good! One big concern is that the generated files changed. Need to validate that it's expected and that we were doing the wrong thing previously and not doing the wrong thing now. I wouldn't have imagined they'd change is all

@@ -32,7 +32,7 @@ public override RazorCSharpDocument WriteDocument(RazorCodeDocument codeDocument
}

var context = new DefaultCodeRenderingContext(
new CodeWriter(),
new CodeWriter(Environment.NewLine, _options.IndentWithTabs, _options.IndentSize),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm I wonder if it makes more sense for the code writer to take in the code gen options instead. @pranavkm thoughts now that you own this? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right, it would also make it easier in the future if we were to add other code gen option variables to the constructor.


Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, so this wont have any actual impact on the runnability of the code since it's outside of the line pragma; however, it's concerning that this is being touched at all? Definitely need to look into what's happening here. Also, in the other files I wouldn't imagine that generated locations would change unless there was a mashup of tabs in the source files / interesting settings in the tests.

@allisonchou
Copy link
Contributor Author

Okay, so I think I see what's going on here in regards to why the code gen and mappings have changed.
tl;dr I think the current changes are correct.

In the existing code, the indent logic for padding is done here in CodeWriterExtensions. However, I believe this logic is incorrect since it does not properly increment the _currentLineCharacterIndex and _absoluteIndex variables in the backing CodeWriter. The current PR correctly increments the variables, hence the changes.

cc @NTaylorMullen

@NTaylorMullen
Copy link
Contributor

Okay, so I think I see what's going on here in regards to why the code gen and mappings have changed.
tl;dr I think the current changes are correct.

In the existing code, the indent logic for padding is done here in CodeWriterExtensions. However, I believe this logic is incorrect since it does not properly increment the _currentLineCharacterIndex and _absoluteIndex variables in the backing CodeWriter. The current PR correctly increments the variables, hence the changes.

cc @NTaylorMullen

Ahhhh I can totally see that. Thank you for validating @allisonchou !

@ryanbrandenburg
Copy link
Contributor

The failure looks random, will probably pass on retry.

@BrennanConroy
Copy link
Member

The failure looks random, will probably pass on retry.

Or, you could file an issue and mark the test as quarantined.

@allisonchou allisonchou merged commit 2c4444f into main Mar 30, 2021
@allisonchou allisonchou deleted the dev/allichou/TabsSpacesCodeGeneration branch March 30, 2021 20:45
@allisonchou allisonchou restored the dev/allichou/TabsSpacesCodeGeneration branch March 30, 2021 20:45
@allisonchou allisonchou deleted the dev/allichou/TabsSpacesCodeGeneration branch March 30, 2021 20:45
@allisonchou allisonchou restored the dev/allichou/TabsSpacesCodeGeneration branch March 30, 2021 20:45
@allisonchou allisonchou deleted the dev/allichou/TabsSpacesCodeGeneration branch March 30, 2021 20:45
@BrennanConroy
Copy link
Member

#31405
Try not to ignore test failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-razor.compiler This issue is related to the Razor compiler (now external)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants