Skip to content

Format hash directives inside other hash directives of complex trivia#654

Merged
basoundr merged 4 commits intodotnet:masterfrom
basoundr:fix285
Feb 20, 2015
Merged

Format hash directives inside other hash directives of complex trivia#654
basoundr merged 4 commits intodotnet:masterfrom
basoundr:fix285

Conversation

@basoundr
Copy link
Contributor

Fix #285 : Analyze DisabledTextTrivia appropriately, so that when it is followed by a hash directive, we will be able to determine if we need to format the hash directive.

Fix dotnet#285 : Analyze DisabledTextTrivia appropriately, so that when it is followed by a hash directive, we will be able to determine if we need to format the hash directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

this function always returns false. So the condition OnDisabledTextTrivia() in ShouldFormat() is never true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OnDisabledTextTrivia() like the other methods in ShouldFormat() is a method which introduces side effects. This is the intended behavior of the method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. So, it adjusts position of something and says don't format this again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CodeShapeAnalyzer is a StateMachine and OnDisabledTextTrivia() just modifies the state.

@balajikris
Copy link
Contributor

👍

@basoundr
Copy link
Contributor Author

@heejaechang , a sign off from you and I will merge the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

is last access last char directly? or enumerate through all chars to the end?

Copy link
Contributor

Choose a reason for hiding this comment

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

it is really unfortunate that only way to check last char of a trivia is ToString.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Last() is an extension method which gets the last char. I should introduce a NullEmpty check.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t what it does, what I mean is, is it internally do string[string.length -1] or is it do

Foreach(var c in string)
{
… get to the last one.
Return ch;
}

  •      Heejae
    

From: Balaji [mailto:[email protected]]
Sent: Thursday, February 19, 2015 3:49 PM
To: dotnet/roslyn
Cc: HeeJae Chang
Subject: Re: [roslyn] Format hash directives inside other hash directives of complex trivia (#654)

In src/Workspaces/CSharp/Portable/Formatting/Engine/Trivia/TriviaDataFactory.CodeShapeAnalyzer.cshttps://github.com//pull/654#discussion_r25038276:

@@ -300,6 +297,17 @@ private bool ShouldFormat()

             return false;

         }
  •        private bool OnDisabledTextTrivia(SyntaxTrivia trivia, int index)
    
  •        {
    
  •            if (trivia.IsKind(SyntaxKind.DisabledTextTrivia) &&
    
  •                SyntaxFacts.IsNewLine(trivia.ToString().Last()))
    

Last() is an extension method which gets the last char. I should introduce a NullEmpty check.


Reply to this email directly or view it on GitHubhttps://github.com//pull/654/files#r25038276.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does string[string.length -1]. Hence I added IsNullOrEmpty check.

@heejaechang
Copy link
Contributor

👍

basoundr added a commit that referenced this pull request Feb 20, 2015
Format hash directives inside other hash directives of complex trivia
@basoundr basoundr merged commit 5ac384f into dotnet:master Feb 20, 2015
@basoundr basoundr deleted the fix285 branch February 20, 2015 01:42
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.

#else not formatted in #if'd out code

4 participants