Skip to content

Enable formatOnType feature #370

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

Merged
merged 18 commits into from
Feb 15, 2017
Merged

Enable formatOnType feature #370

merged 18 commits into from
Feb 15, 2017

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Feb 14, 2017

No description provided.

@kapilmb kapilmb changed the title [WIP] Enable formatOnType feature Enable formatOnType feature Feb 14, 2017
Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

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

Shared some tips, but only one actual change needed I think. Nice work!

/// <summary>
/// Path of the file for which the formatting region is requested.
/// </summary>
public string fileUri;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a FYI, C# class properties should be capitalized like FileUri. The JSON serializer takes care of switching them to/from the correct case when sent through the language server protocol. Not a big deal to change right now, though

return true;
}, true);

if (asts == null || asts.Count() == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

IEnumerable.Any() is way faster than IEnumerable.Count() because it checks if there's at least one item rather than iterating over the whole collection to get the full count. Doesn't matter at all in this case, just a helpful tip to pass along :)

return null;
}

Func<IScriptExtent, int> getExtentWitdh = extent => extent.EndOffset - extent.StartOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is such a simple calculation that is used on 2 lines I'd just inline it instead of trying to make a reusable func, faster that way. Also not important to change for this PR

Func<IScriptExtent, int> getExtentWitdh = extent => extent.EndOffset - extent.StartOffset;
var minDiff = getExtentWitdh(scriptFile.ScriptAst.Extent);
Ast minAst = scriptFile.ScriptAst;
foreach (var ast in asts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment explaining what this loop is doing? Isn't perfectly clear why it's necessary.

@kapilmb kapilmb changed the title Enable formatOnType feature [WIP] Enable formatOnType feature Feb 15, 2017
@daviwil
Copy link
Contributor

daviwil commented Feb 15, 2017

👍

@kapilmb
Copy link
Author

kapilmb commented Feb 15, 2017

@daviwil Thanks for the tips. I have updated the code to take into account all your suggestions.

@kapilmb kapilmb changed the title [WIP] Enable formatOnType feature Enable formatOnType feature Feb 15, 2017
@daviwil
Copy link
Contributor

daviwil commented Feb 15, 2017

If it's ready to merge, go for it!

@kapilmb
Copy link
Author

kapilmb commented Feb 15, 2017

Thanks @daviwil!

@kapilmb kapilmb merged commit 6807e9d into develop Feb 15, 2017
@kapilmb kapilmb deleted the kapilmb/format-on-type branch February 15, 2017 17:03
TylerLeonhardt pushed a commit to TylerLeonhardt/PowerShellEditorServices that referenced this pull request Feb 26, 2019
Added instructions to install Homebrew
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.

3 participants