scry
scry copied to clipboard
Recommend better alternatives for a piece of code?
For example, in RubyMine, there's a feature where something such as:
for a in [*0...10]
RubyMine will automatically recommend you to change the for
statement to a each do
statement. This also applies to something like when you use if
with a negative statement (in which case unless
is recommended), etcetera.
This requires a centralised style guide or linter, however.
Yeah, that functionality is called Code Action, and is in our Roadmap :)
I'm thinking in taking information from error messages like this:
require "http"
server = HTTP::Server.new("0.0.0.0", 8080) do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world!"
end
serve.listen
So the error looks like:
$ crystal u.cr
Error in u.cr:8: undefined local variable or method 'serve' (did you mean 'server'?)
serve.listen
So we should use a light bulb or some mechanism to suggest server
instead of serve
allowing to the user to fix or even improve the code as you said.
Also We can follow best practices for crystal:
- https://crystal-lang.org/docs/guides/performance.html
- https://crystal-lang.org/docs/conventions/
Hi, I already implementing basic Code Actions (including support for RubyMine :tada: ) although I think scry doesn't support code style suggestions yet, I guess we can include ameba tool for this, @veelenga WDYT?
That's right. For example, ameba right now suggests the use of if
instead the else
block with the unless
.
https://github.com/veelenga/ameba/blob/master/src/ameba/rule/unless_else.cr
However, ameba is able to find such piece of code, not to change it. To automatically correct (while clicking a light bulb in RubyMine), we need to implement the autocorrect feature https://github.com/veelenga/ameba/issues/34