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

(finally) Improve formatting of InvocationExpressions #7

Closed
belav opened this issue Feb 26, 2021 · 17 comments · Fixed by #444
Closed

(finally) Improve formatting of InvocationExpressions #7

belav opened this issue Feb 26, 2021 · 17 comments · Fixed by #444
Assignees
Labels
Milestone

Comments

@belav
Copy link
Owner

belav commented Feb 26, 2021

Some examples

                var extension = GetExtensionForLanguageType(
                    (FrontEndResourceLanguage)Enum.Parse(
                        typeof(FrontEndResourceLanguage),
                        this.Language));

            this.Address1 = addressFields.FirstOrDefault(
                field => field.FieldName == "Address1");

// Invocation inside IfStatement
            if (customerOrder == null || !customerOrder.FulfillmentMethod.EqualsIgnoreCase(
                FulfillmentMethod.PickUp.ToString()))
@belav belav added this to the Beta milestone Feb 26, 2021
@belav
Copy link
Owner Author

belav commented Mar 7, 2021

Printing InvocationExpressions well for all the variations looks like it will be a lot of work. See https://github.com/prettier/prettier/blob/main/src/language-js/print/member-chain.js for how complex it could get.

@belav
Copy link
Owner Author

belav commented Mar 8, 2021

I made some progress on formatting simpler cases than the ones above.

Here is another one that needs some work

        this.Address1 = addressFields.Where(
                field => field.FieldName == "Address1")
            .Where(field => yeah)
            .Where(field => yeah);

@belav belav added the type:bug Something isn't working label Mar 14, 2021
@belav
Copy link
Owner Author

belav commented Mar 14, 2021

More examples

    roleNames
        .ToList()
        .ForEach((role) =>
            this.adminContextMock
                .Setup((ctx) => ctx.IsUserInRole(role))
                .Returns(false)
        );

@belav
Copy link
Owner Author

belav commented May 29, 2021

This will require conditionalGroup, run it in prettier to see how they do it.

        var superLongMethodNameForceLine = someFactoryName
            .SuperLongMethodNameForceLine()
            .SomeOtherReallyLongMethodName();

@belav
Copy link
Owner Author

belav commented Jun 7, 2021

Another edge case

    var linePosition________________________ = diagnostics[
            i
        ].Location.GetLineSpan().StartLinePosition;

@belav
Copy link
Owner Author

belav commented Jun 12, 2021

this seems like extra indentation

            var compilation = await project.WithCompilationOptions(compilationOptions)
                    .GetCompilationAsync();

@belav
Copy link
Owner Author

belav commented Jun 12, 2021

Possibly already covered above with the diagnostics[ edge case

                AttributeCollection attributes = TypeDescriptor.GetProperties(modelType)[
                        propertyName
                    ].Attributes;

                JsonIgnoreAttribute jsonIgnoreAttribute = (JsonIgnoreAttribute)attributes[
                        typeof(JsonIgnoreAttribute)
                    ];

@belav
Copy link
Owner Author

belav commented Jun 12, 2021

And

            string signedRequest = htmlHelper.ViewContext.HttpContext.Request.Params[
                "signed_request"
            ];

@belav belav removed this from the Beta milestone Jun 14, 2021
@belav
Copy link
Owner Author

belav commented Jun 17, 2021

This is related, but I think it's actually an ImplicitObjectCreationExpression

public static readonly HardLine HardLineIfNoPreviousLineSkipBreakIfFirstInGroup = new(
    true,
    true);

@belav
Copy link
Owner Author

belav commented Jun 20, 2021

Another edge case

result[i / ReferenceFrameSize] = RenderTreeFrame.ComponentReferenceCapture(
    0,
    null,
    0
);
// should be
result[i / ReferenceFrameSize] = 
    RenderTreeFrame.ComponentReferenceCapture(0, null, 0);

@belav
Copy link
Owner Author

belav commented Jul 17, 2021

Another example

        Diagnostic.Create(
            _descriptor,
            symbolForDiagnostic.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax()
                .GetLocation()
                ?? Location.None,
            symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat)
        );

@belav
Copy link
Owner Author

belav commented Jul 17, 2021

Another example

                if (
                    endpoints[
                        i
                    ].Metadata.GetMetadata<DynamicControllerRouteValueTransformerMetadata>() != null
                ) {

@belav
Copy link
Owner Author

belav commented Jul 19, 2021

This appears to have extra indentation because of the Invocation

            return value == null
                ? CallMethod(
                          value.ToString(),
                          "([a-z])([A-Z])",
                          "$1-$2",
                          RegexOptions.None,
                          TimeSpan.FromMilliseconds(100)
                      )
                      .ToLowerInvariant()
                : Regex.Replace(
                          value.ToString(),
                          "([a-z])([A-Z])",
                          "$1-$2",
                          RegexOptions.None,
                          TimeSpan.FromMilliseconds(100)
                      )
                      .ToLowerInvariant();

@belav
Copy link
Owner Author

belav commented Jul 27, 2021

            FacebookGroupConnection<TStatus> statuses = await GetFacebookObjectAsync<
                FacebookGroupConnection<TStatus>
            >(client, "me/statuses");
// should maybe be
            FacebookGroupConnection<TStatus> statuses = 
                await GetFacebookObjectAsync<FacebookGroupConnection<TStatus>>(
                    client,
                    "me/statuses"
                );

@belav
Copy link
Owner Author

belav commented Jul 27, 2021

This used to be more lines, but more readable, maybe it should go back.

            var proxy1 =
                generator.CreateInterfaceProxyWithTargetInterface<IEventHandler<EventArgs1>>(
                    null,
                    new[] { lazyInterceptor1 }
                );
// is now
            var proxy1 = generator.CreateInterfaceProxyWithTargetInterface<
                IEventHandler<EventArgs1>
            >(null, new[] { lazyInterceptor1 });

@belav
Copy link
Owner Author

belav commented Jul 27, 2021

This may be related

// used to be
            var ex = Assert.Throws<ArgumentException>(
                () =>
                    generator.CreateInterfaceProxyWithTargetInterface<IList<IList<PrivateInterface>>>(
                        new List<IList<PrivateInterface>>(),
                        new IInterceptor[0]
                    )
            );
// is now
            var ex = Assert.Throws<ArgumentException>(
                () =>
                    generator.CreateInterfaceProxyWithTargetInterface<
                        IList<IList<PrivateInterface>>
                    >(new List<IList<PrivateInterface>>(), new IInterceptor[0])
            );

@belav
Copy link
Owner Author

belav commented Aug 8, 2021

These are a bunch of edge cases that are probably related

 // these used to not break so weird
            ref var parentFrame = ref diffContext.NewTree[
                newFrame.ComponentReferenceCaptureParentFrameIndexField
            ];

            var newComponentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[
                0
            ].Component;

            parent = (ContainerNode)parent.Children[
                childIndexAtCurrentDepth + siblingIndex
            ];

            configuration.EncryptionAlgorithmKeySize = (int)encryptionElement.Attribute(
                "keyLength"
            )!;

// used to break onto the next line
            var cbTempSubkeys = checked(
                _symmetricAlgorithmSubkeyLengthInBytes + _hmacAlgorithmSubkeyLengthInBytes
            );
// but then this looks better with checked next to =
            var cbEncryptedData = checked(
                cbCiphertext
                - (
                    KEY_MODIFIER_SIZE_IN_BYTES
                    + _symmetricAlgorithmBlockSizeInBytes
                    + _hmacAlgorithmDigestLengthInBytes
                )
            );
            
// used to be 2 lines
            var cacheKey = (
                ModelType: fieldIdentifier.Model.GetType(),
                fieldIdentifier.FieldName
            );

// this is better, but still looks weird
        public AccessTokenNotAvailableException(
            NavigationManager navigation,
            AccessTokenResult tokenResult,
            IEnumerable<string> scopes
        ) : base(
            message: "Unable to provision an access token for the requested scopes: " + scopes
            != null
                ? $"'{string.Join(", ", scopes ?? Array.Empty<string>())}'"
                : "(default scopes)"
        ) {

// this is just gross, it used to break parameters instead of generic types
            var count = (int)await _invoker.InvokeUnmarshalled<
                string[],
                object?,
                object?,
                Task<object>
            >(GetSatelliteAssemblies, culturesToLoad.ToArray(), null, null);

// not sure what to do with this
                storedArguments[i] = localVariables[i] = Expression.Parameter(
                    parameters[i].ParameterType
                );

@belav belav added this to the Beta milestone Sep 18, 2021
@belav belav self-assigned this Sep 20, 2021
@belav belav modified the milestones: Beta, 0.9.10 Sep 20, 2021
@belav belav changed the title InvocationExpressions need some work (finally) Improve formatting of InvocationExpressions Sep 20, 2021
belav added a commit that referenced this issue Sep 20, 2021
belav added a commit that referenced this issue Sep 26, 2021
belav added a commit that referenced this issue Sep 27, 2021
belav added a commit that referenced this issue Oct 11, 2021
belav added a commit that referenced this issue Oct 18, 2021
* Cleaning up the doc tree

* Code review changes. Adding way to hide nulls on doc tree. Some minor performance tweaks

* Formatting files

* Moving away from SpaceBrace

closes #423

* A little cleanup

* Fixing extra indent in conditionals

Closes #7

* Cleaning up the doc tree

* Making some progress on chained invocations

Fixing bug with ConditionalGroup

* Switch back to printedNode

* A little progress, possibly backwards

* Possibly forwards this time

* Testing notes

* Merge predefinedTypes

* Changing my mind again

* Baby step forward

* Another baby step

* Fixing issues with ConditionalAccessExpression

* Fix case where chain contains a hardline

* Fixing comment edge case

* Another edge case

* more notes

* Merge when identifier is short

* Handling more edge cases

* Some cleanup

* Fixing edge case + some cleanup

* Review changes + more efficient DocSerializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant