Skip to content

Commit 3f85290

Browse files
committed
Improve TSSymbolExplorerPresenter to display number of children by fields
In the TSSymbolExplorerPresenter, next to the field name, I now dispaly the min and max number of children I found in the node. This allows to know easily multiple things: - If the node is optional - If the node always has the same value - If the node has un undefined number of values
1 parent 7024a93 commit 3f85290

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/TreeSitter-Spec/TSFieldExplorerWrapper.class.st

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Class {
99
#instVars : [
1010
'field',
1111
'symbolsAndCode',
12-
'isOptional'
12+
'minSize',
13+
'maxSize'
1314
],
1415
#category : 'TreeSitter-Spec',
1516
#package : 'TreeSitter-Spec'
@@ -26,6 +27,13 @@ TSFieldExplorerWrapper class >> field: aSymbol [
2627
{ #category : 'adding' }
2728
TSFieldExplorerWrapper >> addAll: aColl code: aString [
2829

30+
"I save the min and max number of children I can have to display this info to the user."
31+
minSize := minSize
32+
ifNil: [ aColl size ]
33+
ifNotNil: [ minSize min: aColl size ].
34+
maxSize := maxSize
35+
ifNil: [ aColl size ]
36+
ifNotNil: [ maxSize max: aColl size ].
2937
aColl do: [ :node | (symbolsAndCode keys includes: node type) ifFalse: [ symbolsAndCode at: node type put: (node parent textFromSourceText: aString) ] ]
3038
]
3139

@@ -49,18 +57,29 @@ TSFieldExplorerWrapper >> field: anObject [
4957
TSFieldExplorerWrapper >> initialize [
5058

5159
super initialize.
52-
symbolsAndCode := OrderedDictionary new.
53-
isOptional := false
60+
symbolsAndCode := OrderedDictionary new
5461
]
5562

5663
{ #category : 'accessing' }
5764
TSFieldExplorerWrapper >> isOptional [
58-
^ isOptional
65+
66+
^ minSize isNotNil and: [ minSize = 0 ]
5967
]
6068

6169
{ #category : 'accessing' }
6270
TSFieldExplorerWrapper >> isOptional: anObject [
63-
isOptional := anObject
71+
72+
anObject ifTrue: [ minSize := 0 ]
73+
]
74+
75+
{ #category : 'accessing' }
76+
TSFieldExplorerWrapper >> maxSize [
77+
^ maxSize
78+
]
79+
80+
{ #category : 'accessing' }
81+
TSFieldExplorerWrapper >> minSize [
82+
^ minSize
6483
]
6584

6685
{ #category : 'accessing' }

src/TreeSitter-Spec/TSSymbolExplorerPresenter.class.st

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
I am a presenter used by `TSSymbolExplorerPresenter` to display its result in the inspector.
33
44
I display the list of symbols present in the project. And when one is selected I show two other panes:
5-
- A tree with all the fields that the symbol can have and their possible contents
5+
- A tree with all the fields that the symbol can have and their possible contents. For each fields I display the min and max number of children I found in the code provided.
66
- A list of possible symbols that can be the parents of this symbol
77
"
88
Class {
@@ -148,9 +148,9 @@ TSSymbolExplorerPresenter >> initializePresenters [
148148
display: [ :item |
149149
item class = TSFieldExplorerWrapper
150150
ifTrue: [
151-
'Field: ' , item field , (item isOptional
152-
ifTrue: [ ' (optional)' ]
153-
ifFalse: [ '' ]) ]
151+
'Field: ' , item field , ' (Size: ' , (item minSize = item maxSize
152+
ifTrue: [ item minSize asString ]
153+
ifFalse: [ item minSize asString , '..' , item maxSize asString ]) , ')' ]
154154
ifFalse: [ item ] ];
155155
children: [ :item |
156156
item class = TSFieldExplorerWrapper

src/TreeSitter-Spec/TSSymbolsBuilderVisitor.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ TSSymbolsBuilderVisitor >> visitNode: aTSNode [
101101
"This needs to be done here and not in the bloc for nodes that cannot have a child"
102102
fields := symbolDictionary
103103
at: aTSNode type
104-
ifPresent: [ :flds | "We check if some fields are missing in the current node to mark them as optional"
104+
ifPresent: [ :flds | "We check if some fields are missing in the current node to mark them as optional, meaning the minimal number of nodes for this field can be 0"
105105
flds
106106
reject: [ :field | aTSNode collectFieldNameOfNamedChild keys includes: field field ]
107107
thenDo: [ :field | field isOptional: true ] ]

0 commit comments

Comments
 (0)