Skip to content

Move To Roslyn #35 WIP#45

Open
codeFather2 wants to merge 13 commits into
KvanTTT:masterfrom
codeFather2:master
Open

Move To Roslyn #35 WIP#45
codeFather2 wants to merge 13 commits into
KvanTTT:masterfrom
codeFather2:master

Conversation

@codeFather2

Copy link
Copy Markdown
Collaborator

No description provided.

@codeFather2 codeFather2 changed the title Mpve To Roslyn #35 WIP Move To Roslyn #35 WIP Feb 19, 2018

@KvanTTT KvanTTT left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  • Let's completely remove the dependency on NRefactory.
  • Let's introduce continuous integration system (CI) appveyor.com.

Comment thread CSharpMinifier/IdentifierGenerator.cs Outdated

private List<string> _existingNames = new List<string>();

private const int FirstSymbolCode = 97;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Use getting code from string literals. I mean int FirstSymbolCode = (int)'a';

Is it possible to use char instead of int everywhere?

_options = options ?? new MinifierOptions();
_identifierGenerator = new IdentifierGenerator();
//Add cause MSBuild does not work without it
var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you add a link where such behaviour explained?

@codeFather2 codeFather2 Feb 21, 2018

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this decision is possible to avoid the exception of the type "The language 'C#' is not supported". Reason in the latest version of MSBuild, which does not load the required library, since it believes that it is not used in this program, although in fact it is applied.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I mean add a website link with description to comment in the code.

var document = _workspace.AddDocument(project.Id, "Doc", source);
_semanticModel = document.GetSemanticModelAsync().Result;
var newNode = _semanticModel.SyntaxTree.GetRoot();
foreach (KeyValuePair<VariableDeclaratorSyntax, string> variable in _identifierGenerator.RenamedVariables)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Use more line breaks. At least insert line breaks before statements (if, foreach, while etc.).

}

return newNode;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Move initialization stage to the separated method. Maybe Init.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sure


namespace CSharpMinifier.Rewriters
{
class CSharpRewriter : CSharpSyntaxRewriter

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Specify the more specialized name for this class. This is not just a rewriter, but an identifier magnifier.

So, the better name is TokensMinifier or NamesMinifier.

Options = options ?? new MinifierOptions();
IgnoredIdentifiers = ignoredIdentifiers?.ToList() ?? new List<string>();
IgnoredComments = ignoredComments?.ToList() ?? new List<string>();
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In this case, the method should take not only arrays but enumerables too.

After that use the following code:

IgnoredIdentifiers = ignoredIdentifiers as List<string> ?? ignoredIdentifiers?.ToList() ?? new List<string>();

Comment thread CSharpMinifier/RoslynMinifier.cs Outdated
{
public class RoslynMinifier : IMinifier
{
public SyntaxTree SyntaxTree { get; private set; }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It makes sense to remove this property and pass SyntaxTree to the method via arguments instead. Advantage: getting rid of yet another side effect.

Comment thread CSharpMinifier/IdentifierGenerator.cs Outdated
continue;
return fragment + lastChar;
}
return IncrementName(fragment) + Char.ConvertFromUtf32(FirstSymbolCode);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Try to rewrite this method in a more clear way:

  • Get rid of recursion.
  • Remove Char.ConvertFromUtf32. It's possible to use ToString method here.


public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
{
if(_options.LocalVarsCompressing && node.Modifiers.Any(m => m.Value.Equals("private")))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Missed space after if.

var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions);
}

public SyntaxNode VisitAndRename(SyntaxNode node)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think the Visitor functionality doesn't matter in this case. Rename method to MinifyNames or MinifyNamesRecursive.

# Conflicts:
#	CSharpMinifier/IdentifierGenerator.cs
#	CSharpMinifier/Rewriters/TokensMinifier.cs
<<<<<<< HEAD:CSharpMinifier/Rewriters/TokensMinifier.cs

=======
>>>>>>> 5abeb53995ac7760de4ef050808dc751ceb38a2d:CSharpMinifier/Rewriters/CSharpRewriter.cs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What is it? Please resolve merge conflicts and fix build.

_options = options ?? new MinifierOptions();
_identifierGenerator = new IdentifierGenerator();
//Add cause MSBuild does not work without it
var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I mean add a website link with description to comment in the code.

{
node = Visit(node);
return RenameAll(node);
foreach(var project in _workspace.CurrentSolution.Projects)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please use whitespace before the parenthesis.

(newNode, document) = Rename(nodeToSearch, document, variable.Value);
}

foreach(var method in _identifierGenerator.RenamedMethods)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Type name for a not obvious code.

@KvanTTT

KvanTTT commented Feb 14, 2019

Copy link
Copy Markdown
Owner

Hi! What status of this request? 😄 How much work to fix?

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.

2 participants