Skip to content

Commit

Permalink
Add inspector view for closures.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed Sep 2, 2024
1 parent 7ea0129 commit 89a1855
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
54 changes: 52 additions & 2 deletions src/Browsing.ns
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class Browsing usingPlatform: p ide: webIde = (
private TextEditorFragment = p hopscotch fragments TextEditorFragment.
private Color = p graphics Color.
private Gradient = p hopscotch Gradient.
private Closure = p kernel Closure.
private WeakArray = p kernel WeakArray.
private List = p collections List.
private Map = p collections Map.
private Set = p collections Set.
private ClassMirror = p mirrors ClassMirror.
private ClosureMirror = p mirrors ClosureMirror.
private ObjectMirror = p mirrors ObjectMirror.
private ClassDeclarationBuilder = p mirrors ClassDeclarationBuilder.
private JSObject = [p js global at: 'Object'] on: Exception do: [:e | nil].
Expand Down Expand Up @@ -395,6 +397,22 @@ public transientSlotsSubject ^ <TransientSlotGroupSubject> = (
)
) : (
)
class ClosureView onSubject: s = ProgrammingPresenter onSubject: s (
) (
definition = (
^column: {
subject closureMethod presenter
showClassName: true;
highlightSourceRange: subject closureSourceRange.
column: (subject closureSlots collect:
[:slot <SlotSubject> | slot presenter]).
}
)
public title = (
^'Closure'
)
) : (
)
(* DefinitionListPresenter is an abstract superclass of presenters that displays helper ''transient'' presenters that visually appear to belong to the main list of subject presenters. One common example is a method list presenter which can at times include presenters for methods being added or residue presenters of removed methods. *)
public class DefinitionListPresenter onSubject: s = ProgrammingPresenter onSubject: s (
|
Expand Down Expand Up @@ -1030,6 +1048,7 @@ modelMirrorCollection ^ <Collection[MethodMirror]> = (
)
(* A presenter for a single method. *)
class MethodPresenter onSubject: s <MethodSubject> = MemberPresenter onSubject: s (
| public highlightSourceRange |
) (
acceptResponse ^ <[:CodeMirrorFragment :Event]> = (
^[:ed <CodeMirrorFragment> :event <Event> |
Expand All @@ -1040,8 +1059,18 @@ acceptResponse ^ <[:CodeMirrorFragment :Event]> = (
ed leaveEditState.
]
)
colorizeSource: s <String> withEditor: cm <CodeMirrorFragment> = (
ide colorizer colorizeMethod: s fromMixin: subject methodMirror definingMixin in: cm.
colorizeSource: source <String> withEditor: editor <CodeMirrorFragment> = (
| style |

subject methodMirror name = '[evaluate]'
ifTrue: [ide colorizer colorizeDoIt: source fromMixin: subject methodMirror definingMixin in: editor]
ifFalse: [ide colorizer colorizeMethod: source fromMixin: subject methodMirror definingMixin in: editor].

nil = highlightSourceRange ifTrue: [^self].
nil = JSObject ifTrue: [^self].
style:: JSObject new.
style at: 'css' put: 'color:blue; font-weight:bold; text-decoration: underline'.
editor style: style from: highlightSourceRange start to: highlightSourceRange stop.
)
) : (
)
Expand Down Expand Up @@ -1554,6 +1583,9 @@ availableObjectViews = (
subject isModelKindOfSet ifTrue:
[^{DoView title: 'Set' onSubject: subject. BasicView onSubject: subject}].
subject isModelKindOfClosure ifTrue:
[^{ClosureView onSubject: subject. BasicView onSubject: subject}].
^{BasicView onSubject: subject}
)
captionBar: body = (
Expand Down Expand Up @@ -1631,6 +1663,21 @@ public className ^<String> = (
public classSubject = (
^ClassSubject onModel: classMirror mixin declaration
)
public closureMethod ^<MethodSubject> = (
^MethodSubject onModel: closureMirror method
)
public closureMirror ^<ClosureMirror> = (
^ClosureMirror reflecting: model reflectee
)
public closureSlots ^<Collection[SlotSubject]> = (
| result = List new. |
result add: (SlotSubject name: #self value: closureMirror receiver).
closureMirror slots do: [:s | result add: (SlotSubject name: s name value: s value)].
^result
)
public closureSourceRange ^<Interval> = (
^closureMirror sourceRange
)
public createPresenter = (
^ObjectPresenter onSubject: self
)
Expand Down Expand Up @@ -1659,6 +1706,9 @@ public isModelKindOfArray ^<Boolean> = (
classMirror = (ClassMirror reflecting: WeakArray) ifTrue: [^true].
^false
)
public isModelKindOfClosure ^<Boolean> = (
^classMirror = (ClassMirror reflecting: Closure)
)
public isModelKindOfInteger ^<Boolean> = (
(* bogus - should not send message to inspectee *)
^objectMirror reflectee isKindOfInteger
Expand Down

0 comments on commit 89a1855

Please sign in to comment.