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

Port trivia line by line C# -> VB #512

Merged
merged 66 commits into from
Feb 3, 2020
Merged

Conversation

GrahamTheCoder
Copy link
Member

@GrahamTheCoder GrahamTheCoder commented Jan 26, 2020

  • A rewrite of comment conversion code which could handle VB -> C# and C# -> VB, but not very reliably, so was never activated for C# -> VB in production.
  • This PR will focus on implementing a conversion for C# -> VB - fixes C# -> VB code comments are not converted #8
  • A later PR will replace the VB -> C# comment conversion with the same mechanism used here

The focus here is not losing any comments - getting all of them into the result in roughly the order, and within a line or so of where they were in the source. To understand why this is a bit vague, take the example of a for loop in C#, which sometimes needs to turn into a while loop in VB:

Some source code:

for(double y = 0d; y < height; y += 10d) // 10 is the same amount we used earlier
    Draw(y);

for(double y = 0d; y < height; y += 10d) // don't go past height
    Draw(y);

The conversion we might hope for:

While y < height
    Draw(y)
    y += 10R ' 10 is the same amount we used earlier
End While

While y < height ' don't go past height
    Draw(y)
    y += 10R
End While

Obviously we can't know whether the comment was regarding the condition or the increment expression. This PR keeps the comment with the closest expression wherever possible. (i.e. the first case will work, the second will look a bit wrong)

To do

  • Handle method body comments
  • Source mapping markers for identifiers
  • Implement new test helper (add a line comment on every line, assert the output contains all the line comments on their own line and in order)
  • Source mapping markers for statements (to get ends of blocks working)
  • Source mapping for imports
  • Deal with multiple source lines mapping to the same target line
  • Tidy up any obvious edge cases, put others out of scope

@GrahamTheCoder GrahamTheCoder added the C# -> VB Specific to C# -> VB conversion label Jan 26, 2020
@GrahamTheCoder GrahamTheCoder marked this pull request as ready for review February 3, 2020 13:39
# Conflicts:
#	ICSharpCode.CodeConverter/VB/CommonConversions.cs
#	ICSharpCode.CodeConverter/VB/NodesVisitor.cs
#	Tests/VB/ExpressionTests.cs
#	Tests/VB/NamespaceLevelTests.cs
#	Tests/VB/StandaloneStatementTests.cs
#	Tests/VB/TypeCastTests.cs
@GrahamTheCoder GrahamTheCoder changed the title WIP Port trivia line by line Port trivia line by line C# -> VB Feb 3, 2020
@GrahamTheCoder GrahamTheCoder merged commit 2d88c58 into master Feb 3, 2020
@GrahamTheCoder GrahamTheCoder deleted the rewrite-method-trivia branch February 3, 2020 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# -> VB Specific to C# -> VB conversion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C# -> VB code comments are not converted
2 participants