Skip to content

Commit

Permalink
the locate debugger button is placed in the same place as the embedde…
Browse files Browse the repository at this point in the history
…d debugger [feenkcom/gtoolkit#3735]

- add `GtEmbeddedDebuggerTextAttributePositionCalculator`
  • Loading branch information
JurajKubelka committed May 15, 2024
1 parent 31ec0e1 commit 56b8756
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 33 deletions.
27 changes: 11 additions & 16 deletions src/GToolkit-Debugger/GtEmbeddedDebuggerInSpaceStyler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@ Class {

{ #category : #'api - styling' }
GtEmbeddedDebuggerInSpaceStyler >> extraStyle: aText ast: theAst [
| aStatus anEvaluatedSource anEvaluatedInterval theSourceStartInText theSourceEndInText anAttribute |
| aStatus anAttribute anAttributeIndex |
super extraStyle: aText ast: theAst.

self coderViewModel ifNil: [ ^ self ].
aStatus := self coderViewModel evaluationStatus.
aStatus ifNil: [ ^ self ].
aStatus hasDebugSessionInSpace ifFalse: [ ^ self ].

anEvaluatedSource := aStatus sourceString.
anEvaluatedInterval := aStatus sourceInterval.
theSourceStartInText := aText finder
caseSensitiveSubstring: anEvaluatedSource;
startAtPosition: anEvaluatedInterval first;
searchClosest.

"what did we evaluate?"
theSourceStartInText isZero ifTrue: [ ^ self ].
theSourceEndInText := theSourceStartInText + anEvaluatedSource size - 1
min: aText size.
anAttributeIndex := GtEmbeddedDebuggerTextAttributePositionCalculator new
sourceString: aStatus sourceString;
sourceInterval: aStatus sourceInterval;
evaluatedCodeInterval: [ aStatus evaluatedCodeInterval ];
targetText: aText;
compute.

anAttributeIndex ifNil: [ ^ self ].

aText
clearAttributes: [ :each | {GtEmbeddedDebuggerInSpaceAttribute} anySatisfy: [ :cls | each isKindOf: cls ] ].
anAttribute := GtEmbeddedDebuggerInSpaceAttribute new
evaluationStatus: aStatus;
coderViewModel: self coderViewModel.
aText
attribute: anAttribute
from: theSourceEndInText
to: theSourceEndInText
from: anAttributeIndex
to: anAttributeIndex
]
27 changes: 10 additions & 17 deletions src/GToolkit-Debugger/GtEmbeddedDebuggerStyler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,27 @@ Class {

{ #category : #'api - styling' }
GtEmbeddedDebuggerStyler >> extraStyle: aText ast: theAst [
| aStatus anEvaluatedSource anEvaluatedInterval theSourceStartInText theSourceEndInText anAttribute anAttributeIndex |
| aStatus anAttribute anAttributeIndex |
super extraStyle: aText ast: theAst.

self coderViewModel ifNil: [ ^ self ].
aStatus := self coderViewModel evaluationStatus.
aStatus ifNil: [ ^ self ].
aStatus hasSharedDebugSession ifFalse: [ ^ self ].

anEvaluatedSource := aStatus sourceString.
anEvaluatedInterval := aStatus sourceInterval.
theSourceStartInText := aText finder
caseSensitiveSubstring: anEvaluatedSource;
startAtPosition: anEvaluatedInterval first;
searchClosest.

"what did we evaluate?"
theSourceStartInText isZero ifTrue: [ ^ self ].
theSourceEndInText := theSourceStartInText + anEvaluatedSource size - 1
min: aText size.
anAttributeIndex := GtEmbeddedDebuggerTextAttributePositionCalculator new
sourceString: aStatus sourceString;
sourceInterval: aStatus sourceInterval;
evaluatedCodeInterval: [ aStatus evaluatedCodeInterval ];
targetText: aText;
compute.

anAttributeIndex ifNil: [ ^ self ].

anAttribute := GtEmbeddedDebuggerAttribute new
signaledException: aStatus exception;
debugSession: aStatus sharedDebugSession.

anAttributeIndex := aStatus evaluatedCodeInterval
ifNil: [ theSourceEndInText ]
ifNotNil: [ :aContextInterval | (aContextInterval last + theSourceStartInText - 1) min: aText size ].


aText
attribute: anAttribute
from: anAttributeIndex
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Class {
#name : #GtEmbeddedDebuggerTextAttributePositionCalculator,
#superclass : #Object,
#instVars : [
'sourceString',
'sourceInterval',
'evaluatedCodeInterval',
'targetText',
'sourceEndInText',
'sourceStartInText',
'attributeIndex',
'isSourceFound'
],
#category : #'GToolkit-Debugger-Embedded - Text'
}

{ #category : #'accessing - computed' }
GtEmbeddedDebuggerTextAttributePositionCalculator >> attributeIndex [
<return: #Integer or: nil>
^ attributeIndex
]

{ #category : #computing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> compute [
<return: #Integer or: nil>
isSourceFound := false.
sourceStartInText := targetText finder
caseSensitiveSubstring: sourceString;
startAtPosition: sourceInterval first;
searchClosest.

"what did we evaluate?"
sourceStartInText isZero ifTrue: [ ^ nil ].
isSourceFound := true.
sourceEndInText := sourceStartInText + sourceString size - 1 min: targetText size.

attributeIndex := evaluatedCodeInterval value
ifNil: [ sourceEndInText ]
ifNotNil: [ :aContextInterval | (aContextInterval last + sourceStartInText - 1) min: targetText size ].

^ attributeIndex
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> evaluatedCodeInterval [
<return: #Interval or: #BlockClosure>
^ evaluatedCodeInterval
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> evaluatedCodeInterval: anObject [
evaluatedCodeInterval := anObject
]

{ #category : #'accessing - computed' }
GtEmbeddedDebuggerTextAttributePositionCalculator >> isSourceFound [
^ isSourceFound
]

{ #category : #'accessing - computed' }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceEndInText [
<return: #Integer or: nil>
^ sourceEndInText
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceInterval [
"Return evaluated source interval"

<return: #Interval>
^ sourceInterval
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceInterval: anObject [
sourceInterval := anObject
]

{ #category : #'accessing - computed' }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceStartInText [
<return: #Integer or: nil>
^ sourceStartInText
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceString [
"Return evaluated source string"

<return: #String>
^ sourceString
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> sourceString: anObject [
sourceString := anObject
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> targetText [
<return: #BlRope>
^ targetText
]

{ #category : #accessing }
GtEmbeddedDebuggerTextAttributePositionCalculator >> targetText: anObject [
targetText := anObject
]

0 comments on commit 56b8756

Please sign in to comment.