-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Tree-sitter rolling fixes: 1.121 edition #1085
Changes from 1 commit
4a701e2
338f688
74ef36a
6eee25f
c5f87a6
3834c3f
50dbbd1
738536f
02f1563
9db65c0
26be874
87a9322
f64b44f
d433753
4d696a7
72b1a6e
c674d8f
265d7e0
fbdf18a
03ba902
44ad31f
cdad4ff
44d7734
0f0050f
99521c7
986c697
74479ba
c1d3a8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4176,17 +4176,7 @@ class IndentResolver { | |
|
||
let originalControllingLayer = options.controllingLayer; | ||
|
||
let comparisonRow = options.comparisonRow; | ||
if (comparisonRow === undefined) { | ||
comparisonRow = row - 1; | ||
if (options.skipBlankLines) { | ||
// It usually makes no sense to compare to a blank row, so we'll move | ||
// upward until we find a line with text on it. | ||
while (this.buffer.isRowBlank(comparisonRow) && comparisonRow > 0) { | ||
comparisonRow--; | ||
} | ||
} | ||
} | ||
let comparisonRow = options.comparisonRow ?? this.getComparisonRow(row, options); | ||
|
||
let existingIndent = 0; | ||
if (options.preserveLeadingWhitespace) { | ||
|
@@ -4817,6 +4807,7 @@ class IndentResolver { | |
let { languageMode } = this; | ||
const line = this.buffer.lineForRow(row); | ||
const currentRowIndent = this.indentLevelForLine(line, tabLength); | ||
let comparisonRow = options.comparisonRow ?? this.getComparisonRow(row, options); | ||
|
||
// If the row is not indented at all, we have nothing to do, because we can | ||
// only dedent a line at this phase. | ||
|
@@ -4912,6 +4903,12 @@ class IndentResolver { | |
if (node.startPosition.row !== row) { continue; } | ||
// Ignore captures that fail their scope tests. | ||
if (!scopeResolver.store(indent)) { continue; } | ||
let passed = this.applyTests(indent, { | ||
currentRow: row, | ||
comparisonRow, | ||
tabLength | ||
}); | ||
if (!passed) return; | ||
|
||
let force = this.getProperty(indent, 'force', 'boolean', false); | ||
|
||
|
@@ -4962,6 +4959,18 @@ class IndentResolver { | |
return currentRowIndent; | ||
} | ||
|
||
getComparisonRow(row, { skipBlankLines = true } = {}) { | ||
let comparisonRow = row - 1; | ||
if (skipBlankLines) { | ||
// It usually makes no sense to compare to a blank row, so we'll move | ||
// upward until we find a line with text on it. | ||
while (this.buffer.isRowBlank(comparisonRow) && comparisonRow > 0) { | ||
comparisonRow--; | ||
} | ||
} | ||
return comparisonRow; | ||
} | ||
|
||
indentLevelForLine(line, tabLength) { | ||
let indentLength = 0; | ||
for (let i = 0, { length } = line; i < length; i++) { | ||
|
@@ -4990,7 +4999,9 @@ class IndentResolver { | |
return undefined; | ||
} | ||
|
||
// `indent.match` used to be called `indent.matchIndentOf`. | ||
let matchIndentOf = this.getProperty(capture, ['match', 'matchIndentOf'], 'string', null); | ||
// `indent.offset` used to be called `indent.offsetIndent`. | ||
let offsetIndent = this.getProperty(capture, ['offset', 'offsetIndent'], 'number', 0); | ||
|
||
if (!matchIndentOf) return undefined; | ||
|
@@ -5012,31 +5023,39 @@ class IndentResolver { | |
return Math.max(result, 0); | ||
} | ||
|
||
// Look up an `indent.` capture property applied with a `#set!` directive, | ||
// optionally coercing to a specified type or falling back to a default | ||
// value. | ||
// | ||
// `names` can be an array in cases where the property may have several | ||
// aliases. The first one that exists will be returned. (Omit the leading | ||
// `indent.` when passing property names.) | ||
Comment on lines
+5202
to
+5208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this a verb "capture" or a noun "capture"? If a verb: Who captures the property? And dare I ask: why? Or if it's a noun "capture": is this telling us a capture property was applied with a https://i.kym-cdn.com/photos/images/newsfeed/002/029/841/a26.png Sorry, just surfacing some of my specific confusion areas around this subject, as I see it was requested in the PR body to ask clarifying questions if I don't understand something. And joking around a bit, I hope you don't mind the humor. (See PNG above.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the following line adds quite a bit of context, just from the function name and argument names alone, but still. I'm not sure I totally understand.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's a noun capture! Capture properties are things like the ((foo) @bar
(#set! indent.offset 1)) Despite the fact that it doesn't require quotes, the We also have
STOP DOING HUMOR
“Why did the chicken cross the road???“ they have played us for absolute fools |
||
getProperty(capture, names, coercion = null, fallback = null) { | ||
if (typeof names === 'string') { | ||
names = [names]; | ||
} | ||
for (let name of names) { | ||
let fullName = `indent.${name}`; | ||
let { setProperties: props = {} } = capture; | ||
if (!(fullName in props)) { | ||
continue; | ||
} | ||
if (!(fullName in props)) { continue; } | ||
return this.coerce(props[fullName], coercion) ?? fallback; | ||
} | ||
return fallback; | ||
} | ||
|
||
coerce(value, coercion) { | ||
switch (coercion) { | ||
case String: | ||
case 'string': | ||
if (value == null) return ""; | ||
return value; | ||
case Number: | ||
case 'number': { | ||
let number = Number(value); | ||
if (isNaN(number)) return null; | ||
return number; | ||
} | ||
case Boolean: | ||
case 'boolean': | ||
if (value == null) return null; | ||
return true; | ||
|
@@ -5065,6 +5084,7 @@ class IndentResolver { | |
} | ||
} | ||
|
||
|
||
IndentResolver.TESTS = { | ||
// Returns `true` if the position descriptor's row equals that of the current | ||
// row (the row whose indentation level is being suggested). | ||
|
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.
I'm tapping out reading all of this refactor line by line before review.
I can appreciate the motivation given in the PR body as for why this is being done. So, I will take some of the content on trust, it is simply too large to review closely in a timely manner, IMO. But hopefully this brings benefits as laid out in the PR body.
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.
I'm angry at the diff; it really does overstate the change. I took three or four methods' worth of logic and put them in a new class at the bottom. The diff makes it seem like I changed this entire file!