Conversation
837f6d1 to
57e2a7d
Compare
tompng
commented
Jun 20, 2023
| end | ||
| end | ||
| when :on_tstring_beg, :on_regexp_beg, :on_symbeg | ||
| when :on_tstring_beg, :on_regexp_beg, :on_symbeg, :on_backtick |
Member
Author
There was a problem hiding this comment.
I forgot to add :on_backtick and the test test_pasted_code_keep_base_indent_spaces failed
]+[["a
b" + `c
d` + /e ← failed here
f/ + :"g
h".tap do
st0012
approved these changes
Jun 29, 2023
| # irb(main):002:1* if b # base_indent is 6, indent calculated from tokens is 2 | ||
| # irb(main):003:0> c # base_indent is 6, indent calculated from tokens is 4 | ||
| if prev_open_token | ||
| base_indent = [0, indent_difference(lines, line_results, prev_open_token.pos[0] - 1)].max |
Member
There was a problem hiding this comment.
Does this imply the result of indent_difference(lines, line_results, prev_open_token.pos[0] - 1) could be negative?
Member
Author
There was a problem hiding this comment.
Yes. It could be negative.
if 1 # diff = 0
if 2 # diff = 0
end
end if 1 # diff = 4
if 2 # diff = 4
end
end if 1 # diff = 4
if 2 # diff = 2
end
endif 1 # diff = 0
if 2 # diff = -2 ← negative
end
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-imlement prev_space feature #605 (temporarily dropped in #500)
Code pasted to irb sometimes have base indent. This pull request make IRB indent correctly with base indent
Example of base indent and heredoc
TODO: wait for #515, #608, write tests for heredocdoneBasic algorithm
I defined
base_indentto satisfyactual_indent == base_indent + 2 * indent_level. base_indent can differ on line.Pasted code
Reference code
Line 5 is just inside token
doon line 4. We need to calculate base_indent of line 4 wheredois located.base_indent of line 4 can be calculated by
12 - 2 * indent_level.12 is the indent of pasted code on line 4 and indent_level is 2
Exceptional case
If the beginning of line 4 is inside string literal, we cannot calculate base_indent of line 4.
In that case, base_indent of line 3 is used instead.
Exceptional case 2
Cannot calculate line 4, fallback to line 3 (beginning of tstring_beg)
Cannot calculate line 3, fallback to line 1 (beginning of symbeg)
base_indent of line 1 is 6