-
Notifications
You must be signed in to change notification settings - Fork 238
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
Conversation
Using FilePosition file type causes JSON serializer to crash. Hence we use line and column numbers.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
👍 |
@daviwil Thanks for the tips. I have updated the code to take into account all your suggestions. |
If it's ready to merge, go for it! |
Thanks @daviwil! |
Added instructions to install Homebrew
No description provided.