<b>=============== Summary ===============</b><br>
<br>
Change Set: selectUnusedVariable<br>
Date: 30 December 2022<br>
Author: Christoph Thiede<br>
<br>
During interactive parsing, while asking the user about a unused temporary variable, select the variable declaration in question. This aligns the notification behavior with the notifications for ambiguous selectors, unknown selectors, undeclared variables, and undefined variables.<br>
<br>
<b>=============== Diff ===============</b><br>
<br>
<b>BlockLocalTemporariesRemovalTest>>selectIntervalInvisibly: {requesting} · ct 12/30/2022 20:57</b><br>
<font color="#FF0000">+ selectIntervalInvisibly: anInterval</font><br>
<br>
<b>CompilerExceptionsTest>>testUnusedVariable {tests} · ct 12/30/2022 20:53 (changed)</b><br>
testUnusedVariable<br>
<br>
self <br>
compiling: 'griffle | goo | ^nil'<br>
shouldRaise: UnusedVariable<br>
<s><font color="#0000FF">- andSelect: [self text]<br>
</font></s><font color="#FF0000">+ andSelect: 'goo'<br>
</font> testing: {<br>
[:ex | ex resume] -> [self assertCanceled].<br>
false -> [self assertSucceeded].<br>
true -> [self assertSucceeded: 'griffle\s*\^nil' asRegex] }.<br>
self <br>
compiling: [self compileNoPattern: '| goo|^ nil' "note there is no space between the variable and the bar"]<br>
shouldRaise: UnusedVariable<br>
<s><font color="#0000FF">- andSelect: [self text]<br>
</font></s><font color="#FF0000">+ andSelect: 'goo'<br>
</font> testing: { true -> [self assertSucceeded: '\s*\^ nil' asRegex] }.<br>
<font color="#FF0000">+ self <br>
+ compiling: 'griffle | goo1 goo | ^ (goo1 := nil)'<br>
+ shouldRaise: UnusedVariable<br>
+ andSelect: [(text allRangesOfRegexMatches: 'goo(?!1)') first]<br>
+ testing: {<br>
+ [:ex | ex resume] -> [self assertCanceled].<br>
+ false -> [self assertSucceeded].<br>
+ true -> [self assertSucceeded: 'griffle \| goo1 \| \^ \(goo1 \:= nil\)' asRegex] }.<br>
</font> self<br>
compiling: 'griffle ^[ | goo | ]'<br>
shouldRaise: UnusedVariable<br>
<s><font color="#0000FF">- andSelect: [self text]<br>
</font></s><font color="#FF0000">+ andSelect: 'goo'<br>
</font> testing: {<br>
[:ex | ex resume] -> [self assertCanceled].<br>
false -> [self assertSucceeded].<br>
true -> [self assertSucceeded: 'griffle \^\[\s*\]' asRegex] }.<br>
<br>
<b>Parser>>removeUnusedTemps: {error correction} · ct 12/30/2022 20:54 (changed)</b><br>
removeUnusedTemps: methodNode<br>
"Scan for unused temp names, and prompt the user about the prospect of removing each one found"<br>
<br>
| madeChanges tempsMarkHolder unusedTempNames tempMarkHoldersToChange |<br>
madeChanges := false.<br>
tempMarkHoldersToChange := OrderedCollection new.<br>
tempsMarkHolder := self collectTemporaryDeclarationsFrom: methodNode.<br>
unusedTempNames := encoder unusedTempNames select: <br>
[ :temp | (encoder lookupVariable: temp ifAbsent: [ ]) isUndefTemp <br>
and: [ self queriedUnusedTemporaries at: temp ifAbsentPut: [<br>
<s><font color="#0000FF">- (UnusedVariable name: temp) ifNil: [ ^ self fail ]] ]].<br>
</font></s><font color="#FF0000">+ | str declStart declStop |<br>
+ str := cue requestor text asString.<br>
+ declStop := (str indexOf: $|) - 1.<br>
+ [declStart := str findString: temp startingAt: declStop + 2.<br>
+ declStop := declStart + temp size - 1]<br>
+ doWhileFalse: "don't select other declaration with same prefix"<br>
+ [#(xDelimiter verticalBar) includes:<br>
+ (self typeTableAt: (str at: declStop + 1))].<br>
+ self selectFrom: declStart to: declStop during:<br>
+ [(UnusedVariable name: temp) ifNil: [ ^ self fail ]] ] ]].<br>
</font> tempsMarkHolder do: [ :currentBlock | <br>
tempMarkHoldersToChange add: currentBlock.<br>
unusedTempNames do: <br>
[ :temp |<br>
(self <br>
removeUnusedTemporaryNamed: temp <br>
from: cue requestor text asString <br>
lookingAt: currentBlock<br>
movingTempMarksOf: tempMarkHoldersToChange) ifTrue: [ madeChanges := true ]]].<br>
madeChanges<br>
ifTrue: [ self removeEmptyTempDeclarationsFrom: methodNode.<br>
ReparseAfterSourceEditing signal ]<br>
<br>
<b>Parser>>selectFrom:to:during: {error correction} · ct 12/30/2022 20:47 (changed)</b><br>
selectFrom: start to: stop during: aBlock<br>
"Temporarily focus user attention on a zone of error thru text section.<br>
Then restore original user selection.<br>
Note: the original selection is restored invisibly (not displayed).<br>
This will avoid flickering when chaining multiple corrections."<br>
<br>
<s><font color="#0000FF">- | userSelection |<br>
</font></s><font color="#FF0000">+ | userSelection result |<br>
</font> userSelection := cue requestor selectionInterval.<br>
cue requestor selectFrom: start to: stop.<br>
<s><font color="#0000FF">- aBlock value.<br>
- cue requestor selectIntervalInvisibly: userSelection<br>
</font></s><font color="#FF0000">+ result := aBlock value.<br>
+ cue requestor selectIntervalInvisibly: userSelection.<br>
+ ^ result</font><br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
["selectUnusedVariable.1.cs"]