Add export(typed: false) to ParamProxy and rewrite_signature to MethodProxy - #9
Add export(typed: false) to ParamProxy and rewrite_signature to MethodProxy#9obsidiannnn wants to merge 6 commits into
Conversation
| all_params = @params.map do |p| | ||
| p.expression ? p.export(typed: false) : p.name.to_s | ||
| end | ||
| rebuilt = "#{indent}#{scope_prefix}#{@name}(#{all_params.join(', ')})" |
There was a problem hiding this comment.
We could use a method like lines that handles the indentation logic for us. lines will work if we jus pass in an array of one line?
There was a problem hiding this comment.
Makes sense, will look at using lines to handle the indentation instead of building it manually.
There was a problem hiding this comment.
If you use lines=(new_lines) instead of lines[start_index] = ... then it should handle the indent for you? It's doing very similar logic to the indent = original[/^\s*/] bit: https://github.com/low-rb/lowkey/blob/main/lib/models/source.rb#L19
There was a problem hiding this comment.
So you can keep original = lines[start_index] for the original.match?(/def self\./) ? 'def self.' : 'def ' bit but no need for indent = original[/^\s*/] here I believe
| indent = original[/^\s*/] | ||
| lines[start_index] = indent + sig_lines[0].lstrip | ||
| return_suffix = @return_proxy ? " #{@return_proxy.export}" : '' | ||
| self.lines = ["#{scope_prefix}#{@name}(#{all_params.join(', ')})#{return_suffix}\n"] |
There was a problem hiding this comment.
This uses the lines=(new_lines) method I believe, cool
…me plain to untyped
…dle return type in rewrite_signature
d5279d3 to
48c5041
Compare
|
|
||
| def rewrite_signature | ||
| old_line = lines[start_index] | ||
| scope_prefix = old_line.match?(/def self\./) ? 'def self.' : 'def ' |
There was a problem hiding this comment.
It's not a blocker but I wonder if a method proxy already has info on whether it's a class method or not
Summary
Adds two new methods to Lowkey as foundational pieces for the
LowType method rewriting project (low-rb/low_type#38).
Changes
ParamProxy#export(typed: false)
typed: true(default) - existing behavior, returns raw sourcetyped: false- returns plain param string without type annotation,using param name and
expression.default_valueMethodProxy#rewrite_signature
export(typed: false)on each param proxy
linesarray in-placelinesreference,file_proxy.exportreflects the change automaticallyTests
29 examples, 0 failures - all existing specs pass plus
10 new specs covering both methods.