Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Gt4CSS/GtCSSCoderModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Class {
#category : #'Gt4CSS-Model'
}

{ #category : #addons }
GtCSSCoderModel class >> contextHeaderMenuAddOnsPragma [
^#gtCoderHeaderContextMenuAddOns
]

{ #category : #'instance creation' }
GtCSSCoderModel class >> forMethod: aCompiledMethod [
^ self new forMethod: aCompiledMethod
Expand Down Expand Up @@ -116,6 +121,54 @@ GtCSSCoderModel >> addContextMenuAddOns: anAst to: coderAddOns from: aCoderViewM
ifNotNil: [ :anAction | anAction priority: 10.5 ] ] ] ]
]

{ #category : #'add-ons' }
GtCSSCoderModel >> addFormatMethodAst: anAst to: coderAddOns [
<gtCoderContextMenuAddOns>
(self
addContextMenuItemFrom: GtSourceCoderFormatShortcut new
group: BrMenuItemGroupConfiguration refactoring
withId: nil
to: coderAddOns) ifNotNil: [:anAction | anAction priority: 250]
]

{ #category : #'add-ons - header' }
GtCSSCoderModel >> addHeaderFormatMethodSelector: aSelector ast: anAst to: coderAddOns [
<gtCoderHeaderContextMenuAddOns>
(self
addContextMenuItemFrom: GtSourceCoderFormatShortcut new
group: BrMenuItemGroupConfiguration refactoring
withId: nil
to: coderAddOns) ifNotNil: [:anAction | anAction priority: 250]
]

{ #category : #'add-ons - header' }
GtCSSCoderModel >> addImplementorsHeaderContextMenuAddOnsSelector: aSelector ast: anAst to: coderAddOns [
<gtCoderHeaderContextMenuAddOns>
^coderAddOns
addContextMenuItem: GtSourceCoderBrowseImplementorsShortcut new name
group: BrMenuItemGroupConfiguration navigation
action:
[:aCoderViewModel :anEditorElement |
anEditorElement phlow
spawnObject: aCoderViewModel coder selector gtImplementors]
id: nil
shortcutKey: nil
]

{ #category : #'add-ons - header' }
GtCSSCoderModel >> addReferencesHeaderContextMenuAddOnsSelector: aSelector ast: anAst to: coderAddOns [
<gtCoderHeaderContextMenuAddOns>
^coderAddOns
addContextMenuItem: GtSourceCoderBrowseReferencesShortcut new name
group: BrMenuItemGroupConfiguration navigation
action:
[:aCoderViewModel :anEditorElement |
anEditorElement phlow
spawnObject: aCoderViewModel coder selector gtReferences]
id: nil
shortcutKey: nil
]

{ #category : #converting }
GtCSSCoderModel >> asCoderViewModel [
^ GtCSSCoderViewModel new
Expand Down
40 changes: 38 additions & 2 deletions src/Gt4CSS/GtCSSCoderViewModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,43 @@ GtCSSCoderViewModel >> compiledMethod [
^self coderModel compiledMethod
]

{ #category : #'as yet unclassified' }
{ #category : #'private - addons' }
GtCSSCoderViewModel >> computeHeaderContextMenuAstAddOns [
<return: #GtCoderAddOns>
| aCoderModel newAddOns pragmas theAst |
aCoderModel := self coderModel.
theAst := aCoderModel astSync.
pragmas := aCoderModel
pragmasNamed: aCoderModel class contextHeaderMenuAddOnsPragma
inHierarchy: aCoderModel class.
newAddOns := aCoderModel newAddOns.
theAst
ifNotNil:
[pragmas do:
[:eachPragma |

[aCoderModel perform: eachPragma methodSelector
withEnoughArguments:
{aCoderModel selector.
theAst.
newAddOns.
self}]
on: Error
do:
[:anError |
"emit as a beacon signal"
anError emit.
(NonInteractiveTranscript stderr)
nextPut: $[;
print: eachPragma method printString;
nextPut: $];
space;
print: anError;
cr]]].
^newAddOns
]

{ #category : #'api - accessing' }
GtCSSCoderViewModel >> currentSelectorPromise [
^ self coderModel currentSelectorPromise
]
Expand All @@ -54,7 +90,7 @@ GtCSSCoderViewModel >> highlighter: aStyler [
self coder highlighter: aStyler
]

{ #category : #'as yet unclassified' }
{ #category : #testing }
GtCSSCoderViewModel >> isMeta [
"Return true if the method is implemented in a pharo metaclass (~ class side)"

Expand Down
24 changes: 24 additions & 0 deletions src/Gt4CSS/GtCSSSourceCoderEditorElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ Class {
#category : #'Gt4CSS-UI'
}

{ #category : #'as yet unclassified' }
GtCSSSourceCoderEditorElement >> createHeaderContextMenu [
"wait for the addons to be computed"
<return: #BrMenuItems>
| aMenu aMenuItemsPromise |
aMenu := BrMenuItems new.
aMenu beGroupedElementType.
aMenuItemsPromise := self textualCoderViewModel addOns asyncThen:
[:theAddOns |
"extra context menu items that depend on ast and view model state such as selection"
| theItems theContextMenuAstAddons theMenuItems |
theContextMenuAstAddons := self textualCoderViewModel
computeHeaderContextMenuAstAddOns.
theItems := theAddOns contextMenuActions
, theContextMenuAstAddons contextMenuActions.
theItems := theItems reject: [:e | e title isNil].
theMenuItems := theItems
collect: [:eachAction | eachAction asBrMenuItemForCoderElement: self]
thenReject: #isNil.
self enqueueTask: (BlTaskAction new action: [aMenu items: theMenuItems])].
self enqueueTask: (BlPromiseTask new promise: aMenuItemsPromise).
^aMenu
]

{ #category : #initialization }
GtCSSSourceCoderEditorElement >> defaultTextEditorModel [
^ GtLSPEditorModel withEditorMode: self defaultTextEditorMode
Expand Down
14 changes: 8 additions & 6 deletions src/Gt4CSS/GtCSSSourceCoderExpandedContentElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ GtCSSSourceCoderExpandedContentElement >> updateAptitude: editor [
| aptitude |
aptitude := GtLSPEditorAptitude new.
aptitude lspFile: self lspFile.
textualCoderViewModel ifNotNil: [
aptitude styler: textualCoderViewModel compositeStyler ].
textualCoderViewModel
ifNotNil: [aptitude styler: textualCoderViewModel compositeStyler].
editor aptitude: aptitude.
textualCoderViewModel ifNotNil: [self updateHeaderLabel].
editor
addAptitude: (BrGlamorousWithExplicitContextMenuAptitude menu: [ editor createContextMenu ])
textualCoderViewModel ifNotNil: [self updateHeaderLabel: editor].
editor addAptitude: (BrGlamorousWithExplicitContextMenuAptitude
menu: [editor createContextMenu])
]

{ #category : #updating }
GtCSSSourceCoderExpandedContentElement >> updateHeaderLabel [
GtCSSSourceCoderExpandedContentElement >> updateHeaderLabel: editor [
label text: textualCoderViewModel coder selector asRopedText.
label addAptitude: (BrGlamorousWithExplicitContextMenuAptitude
menu: [editor createHeaderContextMenu])
]