[squeak-dev] Review Request: selectUnusedVariable.1.cs
christoph.thiede at student.hpi.uni-potsdam.de
christoph.thiede at student.hpi.uni-potsdam.de
Fri Dec 30 20:04:50 UTC 2022
=============== Summary ===============
Change Set: selectUnusedVariable
Date: 30 December 2022
Author: Christoph Thiede
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.
=============== Diff ===============
BlockLocalTemporariesRemovalTest>>selectIntervalInvisibly: {requesting} · ct 12/30/2022 20:57
+ selectIntervalInvisibly: anInterval
CompilerExceptionsTest>>testUnusedVariable {tests} · ct 12/30/2022 20:53 (changed)
testUnusedVariable
self
compiling: 'griffle | goo | ^nil'
shouldRaise: UnusedVariable
- andSelect: [self text]
+ andSelect: 'goo'
testing: {
[:ex | ex resume] -> [self assertCanceled].
false -> [self assertSucceeded].
true -> [self assertSucceeded: 'griffle\s*\^nil' asRegex] }.
self
compiling: [self compileNoPattern: '| goo|^ nil' "note there is no space between the variable and the bar"]
shouldRaise: UnusedVariable
- andSelect: [self text]
+ andSelect: 'goo'
testing: { true -> [self assertSucceeded: '\s*\^ nil' asRegex] }.
+ self
+ compiling: 'griffle | goo1 goo | ^ (goo1 := nil)'
+ shouldRaise: UnusedVariable
+ andSelect: [(text allRangesOfRegexMatches: 'goo(?!1)') first]
+ testing: {
+ [:ex | ex resume] -> [self assertCanceled].
+ false -> [self assertSucceeded].
+ true -> [self assertSucceeded: 'griffle \| goo1 \| \^ \(goo1 \:= nil\)' asRegex] }.
self
compiling: 'griffle ^[ | goo | ]'
shouldRaise: UnusedVariable
- andSelect: [self text]
+ andSelect: 'goo'
testing: {
[:ex | ex resume] -> [self assertCanceled].
false -> [self assertSucceeded].
true -> [self assertSucceeded: 'griffle \^\[\s*\]' asRegex] }.
Parser>>removeUnusedTemps: {error correction} · ct 12/30/2022 20:54 (changed)
removeUnusedTemps: methodNode
"Scan for unused temp names, and prompt the user about the prospect of removing each one found"
| madeChanges tempsMarkHolder unusedTempNames tempMarkHoldersToChange |
madeChanges := false.
tempMarkHoldersToChange := OrderedCollection new.
tempsMarkHolder := self collectTemporaryDeclarationsFrom: methodNode.
unusedTempNames := encoder unusedTempNames select:
[ :temp | (encoder lookupVariable: temp ifAbsent: [ ]) isUndefTemp
and: [ self queriedUnusedTemporaries at: temp ifAbsentPut: [
- (UnusedVariable name: temp) ifNil: [ ^ self fail ]] ]].
+ | str declStart declStop |
+ str := cue requestor text asString.
+ declStop := (str indexOf: $|) - 1.
+ [declStart := str findString: temp startingAt: declStop + 2.
+ declStop := declStart + temp size - 1]
+ doWhileFalse: "don't select other declaration with same prefix"
+ [#(xDelimiter verticalBar) includes:
+ (self typeTableAt: (str at: declStop + 1))].
+ self selectFrom: declStart to: declStop during:
+ [(UnusedVariable name: temp) ifNil: [ ^ self fail ]] ] ]].
tempsMarkHolder do: [ :currentBlock |
tempMarkHoldersToChange add: currentBlock.
unusedTempNames do:
[ :temp |
(self
removeUnusedTemporaryNamed: temp
from: cue requestor text asString
lookingAt: currentBlock
movingTempMarksOf: tempMarkHoldersToChange) ifTrue: [ madeChanges := true ]]].
madeChanges
ifTrue: [ self removeEmptyTempDeclarationsFrom: methodNode.
ReparseAfterSourceEditing signal ]
Parser>>selectFrom:to:during: {error correction} · ct 12/30/2022 20:47 (changed)
selectFrom: start to: stop during: aBlock
"Temporarily focus user attention on a zone of error thru text section.
Then restore original user selection.
Note: the original selection is restored invisibly (not displayed).
This will avoid flickering when chaining multiple corrections."
- | userSelection |
+ | userSelection result |
userSelection := cue requestor selectionInterval.
cue requestor selectFrom: start to: stop.
- aBlock value.
- cue requestor selectIntervalInvisibly: userSelection
+ result := aBlock value.
+ cue requestor selectIntervalInvisibly: userSelection.
+ ^ result
---
Sent from Squeak Inbox Talk
["selectUnusedVariable.1.cs"]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221230/ccaa7b4c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: selectUnusedVariable.1.cs
Type: application/octet-stream
Size: 3888 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221230/ccaa7b4c/attachment.obj>
More information about the Squeak-dev
mailing list
|