Skip to content

Commit

Permalink
dc: fix off-by-one in stmt insert, add create-new-method
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Oct 4, 2023
1 parent 79f35fd commit a20b62e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/DomainCode-Diff/DCMatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ DCMatcher >> fineGrainedMatchFrom: src to: dest in: aMapping [

self halt.
topSrc ifNotNil: [
self assert: (aMapping destForSrc: topSrc owner) = topDest parent.
self assert: (aMapping destForSrc: topSrc parent) = topDest parent.
DCGreedyBottomUpMatcher new
sizeThreshold: 900000000;
lastChanceMatchFrom: topSrc to: topDest in: aMapping]
Expand Down
62 changes: 46 additions & 16 deletions packages/DomainCode-Parser/DCBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ DCBlock class >> smalltalkCheckbox [
toSource: [:source :repl | source contents: (repl checked ifTrue: ['true'] ifFalse: ['false'])])]}
]
{ #category : #smalltalk }
DCBlock class >> smalltalkCreateNewMethod [
<query: #shortcut>
^ {
[:x | x language = SBTSSmalltalk].
[:x |
x registerShortcut: #createNewEmptyModule do: [
{
[:e | | method |
method := DCSmalltalkMethod emptyIn: e containingArtefact methodClass.
e sandblockEditor openMorphInView: method.
method firstDeepChild startInputAtEnd]}]]}
]
{ #category : #smalltalk }
DCBlock class >> smalltalkDeclaration [
Expand Down Expand Up @@ -303,20 +318,20 @@ DCBlock class >> smalltalkInsertArg [
id := DCQuery
script: {self smalltalkMethodArguments. [:args | (args at: index) contents]}
with: block.
block type ~= #identifier
ifTrue: [block insert: id]
ifFalse: [block replaceWith: id]]}]]]}
(block type = #identifier or: [block sandblockEditor mode = #command])
ifTrue: [block replaceWith: id]
ifFalse: [block insert: id]]}]]]}
]
{ #category : #smalltalk }
DCBlock class >> smalltalkJumpPlaceholder [
<query: #change>
<query: #type>
^ {
[:x | x language = SBTSSmalltalk].
[:x | x type = #identifier].
[:x | #(#identifier #'unary_identifier') includes: x type].
[:x | x contents = '__sb'].
[:x | x installReplacement: DCJumpPlaceholder new]}
[:x | x ensureReplacement: DCJumpPlaceholder initDo: [:b | ]]}
]
{ #category : #smalltalk }
Expand Down Expand Up @@ -519,8 +534,9 @@ DCBlock >> allParentsUpTo: aBlock [
{ #category : #'as yet unclassified' }
DCBlock >> allTextMorphsDo: aBlock [
"iterate over morphs, not children, as we're looking for visible text morphs"
self allChildrenDo: [:m | m isTextMorph ifTrue: [aBlock value: m]]
self allMorphsDo: [:m | m isTextMorph ifTrue: [aBlock value: m]]
]
{ #category : #'as yet unclassified' }
Expand Down Expand Up @@ -646,6 +662,12 @@ DCBlock >> encompasses: aRange [
^ self range encompasses: aRange
]
{ #category : #'query actions' }
DCBlock >> ensureReplacement: aClass initDo: aBlock [
self queryState ensureReplacement: aClass for: self initDo: aBlock
]
{ #category : #'as yet unclassified' }
DCBlock >> field [
Expand Down Expand Up @@ -861,13 +883,16 @@ DCBlock >> insertStatementAboveOrBelow: anAboveBoolean [
in: self
morph: (DCEmptyStatement new language: self language))].
(self orOwnerSuchThat: [:morph | morph isTSBlock and: [morph isStatement]]) ifNotNil: [:statement | | target |
(self orOwnerSuchThat: [:morph | morph isTSBlock and: [morph isStatement]]) ifNotNil: [:statement | | target after |
target := (anAboveBoolean not and: [(statement submorphAfter ifNotNil: #treeLabel) = self language statementTerminator])
ifTrue: [statement submorphAfter]
ifFalse: [statement].
ifFalse: [
"if we do not have a trailing dot, we need to insert the dot before the element"
after := anAboveBoolean not.
statement].
self sandblockEditor do: (SBRelInsertCommand new near: target before: anAboveBoolean in: statement owner morph: (DCEmptyStatement new
language: self language;
after: anAboveBoolean not;
after: after;
contents: (SBToggledCode comment: '' active: 1 do: {['']. [self language statementTerminator]})))]
]
Expand Down Expand Up @@ -970,7 +995,7 @@ DCBlock >> keyStroke: anEvent [
insert: text
in: source
at: cursorIndex + 1
do: [:new :edit | apply value: new value: edit value: cursorIndex + 1]]]].
do: [:new :edit | apply value: new value: edit value: (cursorIndex + (text indexOf: anEvent keyCharacter))]]]].
self batchedChangeStep
]
Expand Down Expand Up @@ -1012,13 +1037,13 @@ DCBlock >> layoutCommands [
{ #category : #'as yet unclassified' }
DCBlock >> layoutInset [
self isBlockBody ifTrue: [^ 2 @ 2].
self isBlockBody ifTrue: [^ 4 @ 3].
true ifTrue: [^ super layoutInset].
SBToggledCode comment: '' active: 0 do: {[true ifTrue: [^ super layoutInset]]}.
^ (self type = 'ERROR' and: [self childSandblocks notEmpty])
ifTrue: [0]
ifFalse: [2 @ (self submorphCount > 3 ifTrue: [1] ifFalse: [0])]
ifFalse: [2 @ (self submorphCount > 3 ifTrue: [2] ifFalse: [0])]
]
{ #category : #hierarchy }
Expand Down Expand Up @@ -1236,10 +1261,15 @@ DCBlock >> registerShortcut: aSymbol do: aBlock [
DCBlock >> reloadArtefact [
<action>
self sandblockEditor do: (SBReplaceCommand new target: self containingArtefact replacer: ((DCSmalltalkMethod for: self containingArtefact object)
| method |
method := (DCSmalltalkMethod for: self containingArtefact object)
hResizing: self containingArtefact hResizing;
width: self containingArtefact width;
yourself))
yourself.
self sandblockEditor do: (SBReplaceCommand new target: self containingArtefact replacer: method).
method firstDeepChild startInputAtEnd
]
{ #category : #'text modify' }
Expand Down
1 change: 0 additions & 1 deletion packages/DomainCode-Parser/DCJumpPlaceholder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Class {
{ #category : #'as yet unclassified' }
DCJumpPlaceholder >> adaptInput: input in: source at: cursorIndex textMorph: textMorph event: anEvent [

self halt.
(super adaptInput: input in: source at: cursorIndex textMorph: textMorph event: anEvent) ifNotEmpty: [:newInput |
self
replace: self range
Expand Down
73 changes: 60 additions & 13 deletions packages/DomainCode-Parser/DCQueryState.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Class {
'rootBlock',
'currentShortcut',
'updateQueued',
'suggestions'
'suggestions',
'transientReplacements',
'currentTrigger'
],
#category : #'DomainCode-Parser'
}
Expand All @@ -23,6 +25,24 @@ DCQueryState >> addSuggestions: aCollection for: aBlock [
aBlock updateSuggestions
]

{ #category : #'as yet unclassified' }
DCQueryState >> ensureReplacement: aClass for: aBlock initDo: aClosure [

| replacement |
replacement := aBlock class = aClass
ifFalse: [ | r hadFocus |
hadFocus := aBlock sandblockEditor textFocus ifNotNil: [:t | t hasAnyParent: aBlock] ifNil: [false].
r := aClass new.
aBlock replacedParent: r.
aClosure value: r.
r source: aBlock.
aBlock replaceBy: r.
hadFocus ifTrue: [r startInputAtEnd].
r]
ifTrue: [aBlock].
(transientReplacements at: currentTrigger) add: replacement
]

{ #category : #'as yet unclassified' }
DCQueryState >> errors [

Expand All @@ -40,11 +60,11 @@ DCQueryState >> initialize [

super initialize.

currentDecorators := Dictionary new
at: #selection put: WeakKeyDictionary new;
at: #change put: WeakKeyDictionary new;
at: #type put: WeakKeyDictionary new;
yourself.
currentDecorators := Dictionary new.
transientReplacements := Dictionary new.
self triggers do: [:t |
currentDecorators at: t put: WeakKeyDictionary new.
transientReplacements at: t put: WeakSet new].
updateQueued := Dictionary new
]

Expand Down Expand Up @@ -76,15 +96,11 @@ DCQueryState >> reportError: aDecorator for: aBlock [
{ #category : #'as yet unclassified' }
DCQueryState >> rerunQueriesFor: aSymbol do: aBlock [

| oldDecorators |
newDecorators := WeakKeyDictionary new.
currentTrigger := aSymbol.

aBlock value.
self updateTransientReplacementsDuring: [self updateDecoratorsDuring: [aBlock value]].

oldDecorators := currentDecorators at: aSymbol.
oldDecorators do: [:list | list do: [:d | d detach]].
newDecorators keysAndValuesDo: [:block :list | list do: [:d | block attachDecorator: d]].
currentDecorators at: aSymbol put: newDecorators
currentTrigger := nil
]

{ #category : #accessing }
Expand All @@ -105,6 +121,12 @@ DCQueryState >> suggestionsFor: aBlock [
^ suggestions key = aBlock ifTrue: [suggestions value] ifFalse: [{}]
]

{ #category : #'as yet unclassified' }
DCQueryState >> triggers [

^ #(#shortcut #change #type #selection)
]

{ #category : #shortcuts }
DCQueryState >> tryShortcut: aSymbol do: aBlock [

Expand All @@ -120,6 +142,20 @@ DCQueryState >> updateChangeQueries [
self updateTypeQueries
]

{ #category : #'as yet unclassified' }
DCQueryState >> updateDecoratorsDuring: aBlock [

| oldDecorators |
newDecorators := WeakKeyDictionary new.

aBlock value.

oldDecorators := currentDecorators at: currentTrigger.
oldDecorators do: [:list | list do: [:d | d detach]].
newDecorators keysAndValuesDo: [:block :list | list do: [:d | block attachDecorator: d]].
currentDecorators at: currentTrigger put: newDecorators
]

{ #category : #'as yet unclassified' }
DCQueryState >> updateQueriesFor: aSymbol [

Expand All @@ -139,6 +175,17 @@ DCQueryState >> updateSelectionQueries [
self updateQueriesFor: #selection
]

{ #category : #'as yet unclassified' }
DCQueryState >> updateTransientReplacementsDuring: aBlock [

| old new |
old := transientReplacements at: currentTrigger.
new := WeakSet new.
transientReplacements at: currentTrigger put: new.
aBlock value.
old do: [:r | (new includes: r) ifFalse: [r uninstall]]
]

{ #category : #'as yet unclassified' }
DCQueryState >> updateTypeQueries [

Expand Down
15 changes: 15 additions & 0 deletions packages/DomainCode-Parser/DCReplacement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ DCReplacement >> type [
^ self source type
]

{ #category : #'as yet unclassified' }
DCReplacement >> uninstall [

| hadFocus |
self parent ifNil: [^ self].
hadFocus := self sandblockEditor textFocus
ifNotNil: [:t | t hasAnyParent: self]
ifNil: [false].

self source replacedParent: nil.
self replaceBy: self source.

hadFocus ifTrue: [self source startInputAtEnd]
]

{ #category : #'as yet unclassified' }
DCReplacement >> updateSourceDuring: aBlock [

Expand Down
15 changes: 14 additions & 1 deletion packages/DomainCode-Parser/DCSmalltalkMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ Class {
#category : #'DomainCode-Parser'
}

{ #category : #'as yet unclassified' }
DCSmalltalkMethod class >> emptyIn: aClass [

^ self new emptyIn: aClass
]

{ #category : #'as yet unclassified' }
DCSmalltalkMethod class >> for: aCompiledMethod [

^ self new for: aCompiledMethod
^ aCompiledMethod isSandblock ifFalse: [self new for: aCompiledMethod] ifTrue: [self new emptyIn: aCompiledMethod methodClass]
]

{ #category : #'as yet unclassified' }
Expand All @@ -20,6 +26,13 @@ DCSmalltalkMethod >> browse [
Browser newOnClass: self methodClass selector: self selector
]

{ #category : #'as yet unclassified' }
DCSmalltalkMethod >> emptyIn: aClass [

methodClass := aClass.
self addMorphBack: (DCBlock parseBlock: '__sb' language: SBTSSmalltalk)
]

{ #category : #'as yet unclassified' }
DCSmalltalkMethod >> for: aCompiledMethod [

Expand Down
4 changes: 4 additions & 0 deletions packages/Sandblocks-TSSmalltalk/SBTSSmalltalk.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,8 @@ SBTSSmalltalk class >> highlightQuery [
(string) @string
(symbol) @string
(character) @string
(comment) @comment
(block "|" @punctuation)

(identifier) @variable
(block_argument) @variable
Expand All @@ -1195,6 +1197,8 @@ SBTSSmalltalk class >> highlightQuery [
(binary_selector (binary_operator) @major_declaration.part) @structure.part
(unary_selector (unary_identifier) @major_declaration.part) @structure.part

[(pragma_keyword_selector) (pragma_unary_selector) (pragma_binary_selector)] @structure.part

(temporaries) @punctuation.part
(temporaries (identifier) @punctuation)'
]
Expand Down

0 comments on commit a20b62e

Please sign in to comment.