diff --git a/src/Group-Entries-Tests/CoCompletionContextTest.class.st b/src/Group-Entries-Tests/CoCompletionContextTest.class.st index 17bc6fe..4bf30de 100644 --- a/src/Group-Entries-Tests/CoCompletionContextTest.class.st +++ b/src/Group-Entries-Tests/CoCompletionContextTest.class.st @@ -20,12 +20,19 @@ CoCompletionContextTest >> setUp [ { #category : 'testing' } CoCompletionContextTest >> testBuildGroupedEntriesFromWCheckBoundaries [ - "hello's size is 5 so it has no prefix, helloW's size is 6" + "hello's size is 5 so it has no prefix, helloW's size is 6, Both will not be wrapped, since the 1st one's size is equal to the token's size, and the bucket only has one element " + completionContext completionToken: 'hello'. items - add: (CoGlobalEntry new contents: 'hello'; yourself); - add: (CoGlobalEntry new contents: 'helloW'; yourself) . - self assert: (completionContext buildGroupedEntriesFrom: items ) size equals: 2 + add: (CoGlobalEntry new + contents: 'hello'; + yourself); + add: (CoGlobalEntry new + contents: 'helloW'; + yourself). + self assert: (completionContext buildGroupedEntriesFrom: items) size equals: 2. + self assert: (completionContext buildGroupedEntriesFrom: items)first class equals: CoGlobalEntry. + self assert: (completionContext buildGroupedEntriesFrom: items)second class equals: CoGlobalEntry. ] { #category : 'testing' } @@ -45,34 +52,53 @@ CoCompletionContextTest >> testBuildGroupedEntriesFromWhenEntriesShorterThanPref { #category : 'testing' } CoCompletionContextTest >> testBuildGroupedEntriesFromWithMixedComponents [ - "Two entries sharing the same prefix, one single entry, and a short entry" + "Two entries sharing the same prefix, one single entry, and a short entry, the 2 first entries are wrapped in CoEntry" + completionContext completionToken: 'CoASTHeuristics'. items - add: (CoGlobalEntry new contents: 'CoASTHeuristicsResultSetBuilder'; yourself); - add: (CoGlobalEntry new contents: 'CoASTHeuristicsFetcher'; yourself); - add: (CoGlobalEntry new contents: 'CoEntry'; yourself); - add: (CoGlobalEntry new contents: 'Co'; yourself) . - self assert: (completionContext buildGroupedEntriesFrom: items ) size equals: 3 + add: (CoGlobalEntry new + contents: 'CoASTHeuristicsResultSetBuilder'; + yourself); + add: (CoGlobalEntry new + contents: 'CoASTHeuristicsFetcher'; + yourself); + add: (CoGlobalEntry new + contents: 'CoEntry'; + yourself); + add: (CoGlobalEntry new + contents: 'Co'; + yourself). + self assert: (completionContext buildGroupedEntriesFrom: items) size equals: 3. + self assert: (completionContext buildGroupedEntriesFrom: items) third class equals: CoEntry. ] { #category : 'testing' } CoCompletionContextTest >> testBuildGroupedEntriesFromWithMultipleLongEntries [ - "With multiple entries sharing the same prefix, it should return a NECPrefixGroupEntry" - completionContext completionToken: 'CoASTHeuristics'. - items - add: (CoGlobalEntry new contents: 'CoASTHeuristicsResultSetBuilder'; yourself); - add: (CoGlobalEntry new contents: 'CoASTHeuristicsFetcher'; yourself). - self assert: (completionContext buildGroupedEntriesFrom: items) size equals: 1. - self assert: (completionContext buildGroupedEntriesFrom: items) first class equals: NECPrefixGroupEntry. + "With multiple entries sharing the same prefix, it should return a NECPrefixGroupEntry" + + completionContext completionToken: 'CoASTHeuristics'. + items + add: (CoGlobalEntry new + contents: 'CoASTHeuristicsResultSetBuilder'; + yourself); + add: (CoGlobalEntry new + contents: 'CoASTHeuristicsFetcher'; + yourself). + self assert: (completionContext buildGroupedEntriesFrom: items) size equals: 1. + self assert: (completionContext buildGroupedEntriesFrom: items) first class equals: CoEntry ] { #category : 'testing' } CoCompletionContextTest >> testBuildGroupedEntriesFromWithSingleLongEntry [ - "With One single entry, it shouldn't return a NECPrefixGroupEntry" + "With One single entry, it shouldn't return a CoENtry" + completionContext completionToken: 'CoASTHeuristics'. - items - add: (CoGlobalEntry new contents: 'CoASTHeuristicsResultSetBuilder'; yourself). - self assert: (completionContext buildGroupedEntriesFrom: items ) equals: items + items add: (CoGlobalEntry new + contents: 'CoASTHeuristicsResultSetBuilder'; + yourself). + self assert: (completionContext buildGroupedEntriesFrom: items) equals: items. + self deny: (completionContext buildGroupedEntriesFrom: items) first class equals: CoEntry + ] { #category : 'testing' } @@ -117,14 +143,15 @@ CoCompletionContextTest >> testLeaveGroupWhenGroupStackIsEmpty [ { #category : 'testing' } CoCompletionContextTest >> testLeaveGroupWhenGroupStackIsNotEmpty [ + | group | - group := NECPrefixGroupEntry new - children: { CoGlobalEntry new. CoSelectorEntry new }. + group := CoEntry new children: { + CoGlobalEntry new. + CoSelectorEntry new }. completionContext openGroup: group. - self assert: (completionContext leaveGroup) equals: true. - + self assert: completionContext leaveGroup equals: true ] { #category : 'testing' } @@ -135,12 +162,17 @@ CoCompletionContextTest >> testTitleWhenGroupStackIsEmpty [ { #category : 'testing' } CoCompletionContextTest >> testTitleWhenGroupStackIsNotEmpty [ + | group | - group := NECPrefixGroupEntry new - children: { CoGlobalEntry new contents: 'foo'; yourself. CoSelectorEntry new contents: 'bar'; yourself }. + group := CoEntry new children: { + (CoGlobalEntry new + contents: 'foo'; + yourself). + (CoSelectorEntry new + contents: 'bar'; + yourself) }. completionContext openGroup: group. - self assert: (completionContext title) equals: ('Completions · ', 'foo') - + self assert: completionContext title equals: 'Completions · ' , 'foo' ] diff --git a/src/Group-Entries/CoCompletionContext.class.st b/src/Group-Entries/CoCompletionContext.class.st index f8f46fa..3d2e88a 100644 --- a/src/Group-Entries/CoCompletionContext.class.st +++ b/src/Group-Entries/CoCompletionContext.class.st @@ -68,7 +68,7 @@ CoCompletionContext >> buildGroupedEntriesFrom: aCollection [ bucket := buckets at: prefix. bucket size = 1 ifTrue: [ grouped add: bucket first ] - ifFalse: [ grouped add: (NECPrefixGroupEntry prefix: prefix children: bucket) ] ]. + ifFalse: [ grouped add: (CoEntry prefix: prefix children: bucket) ] ]. ^ grouped ] diff --git a/src/Group-Entries/CoEntry.extension.st b/src/Group-Entries/CoEntry.extension.st index 5940f2b..f7320df 100644 --- a/src/Group-Entries/CoEntry.extension.st +++ b/src/Group-Entries/CoEntry.extension.st @@ -1,7 +1,95 @@ Extension { #name : 'CoEntry' } { #category : '*Group-Entries' } -CoEntry >> isGroupEntry [ +CoEntry >> activateOn: aCompletionContext [ + + | entryContents | + self propertyAt: #children + ifPresent: [ aCompletionContext openGroup: self ] + ifAbsent: [ + "Log the usage" + CoAdHocUsageTracker incrementUsageFor: self contents. + "By default insert the contents of the entry instead of the token in the text editor" + entryContents := self contents asSymbol separateKeywords. + entryContents := self class spaceAfterCompletion + ifTrue: [ entryContents , ' ' ] + ifFalse: [ entryContents ]. + aCompletionContext replaceTokenInEditorWith: entryContents ] +] +{ #category : '*Group-Entries' } +CoEntry >> browse [ ^ false ] + +{ #category : '*Group-Entries' } +CoEntry >> children [ + self propertyAt: #children ifPresent: [ ^self propertyAt: #children ] +] + +{ #category : '*Group-Entries' } +CoEntry >> children: aCollection [ + + self propertyAt: #children put: aCollection +] + +{ #category : '*Group-Entries' } +CoEntry >> createDescription [ + + | preview limit | + limit := (self propertyAt: #children) size min: 10. + + preview := String streamContents: [ :stream | + 1 to: limit do: [ :i | + stream + nextPutAll: ((self propertyAt: #children) at: i) displayedContents; + cr ] ]. + + ^ CoEntryDescription label: 'group' title: (self propertyAt: #prefix) , ' (' , (self propertyAt: #children) size asString , ')' description: preview +] + +{ #category : '*Group-Entries' } +CoEntry >> hightlightSymbol [ + + + ^ self propertyAt: #children + ifPresent: [ (self propertyAt: #children) ifEmpty: [ nil ] ifNotEmpty: [ (self propertyAt: #children) first hightlightSymbol ]] + ifAbsent: [ nil ] +] + +{ #category : '*Group-Entries' } +CoEntry >> isGroupEntry [ + + self propertyAt: #children + ifPresent: [ ^true ] + ifAbsent: [ ^false ] +] + +{ #category : '*Group-Entries' } +CoEntry >> prefix [ + + ^ self propertyAt: #prefix +] + +{ #category : '*Group-Entries' } +CoEntry >> prefix: aString [ + + self propertyAt: #prefix put: aString +] + +{ #category : '*Group-Entries' } +CoEntry class >> prefix: aString children: aCollection [ + + ^ self new + propertyAt: #prefix put: aString; + propertyAt: #children put: aCollection asOrderedCollection ; + contents: aString; + displayedContents: aString , ' ▸'; + yourself +] + +{ #category : '*Group-Entries' } +CoEntry >> rawLabel [ + + ^ 'group' +] diff --git a/src/Group-Entries/NECPrefixGroupEntry.class.st b/src/Group-Entries/NECPrefixGroupEntry.class.st deleted file mode 100644 index c1dcc5b..0000000 --- a/src/Group-Entries/NECPrefixGroupEntry.class.st +++ /dev/null @@ -1,95 +0,0 @@ -Class { - #name : 'NECPrefixGroupEntry', - #superclass : 'CoEntry', - #instVars : [ - 'children', - 'prefix' - ], - #category : 'Group-Entries', - #package : 'Group-Entries' -} - -{ #category : 'as yet unclassified' } -NECPrefixGroupEntry class >> prefix: aString children: aCollection [ - - ^ self new - prefix: aString; - children: aCollection asOrderedCollection; - contents: aString; - displayedContents: aString , ' ▸'; - yourself -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> activateOn: aCompletionContext [ - - aCompletionContext openGroup: self -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> browse [ - - ^ false -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> children [ - - ^ children -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> children: aCollection [ - - children := aCollection -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> createDescription [ - - | preview limit | - limit := children size min: 10. - - preview := String streamContents: [ :stream | - 1 to: limit do: [ :i | - stream - nextPutAll: (children at: i) displayedContents; - cr ] ]. - - ^ CoEntryDescription - label: 'group' - title: prefix , ' (' , children size asString , ')' - description: preview -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> hightlightSymbol [ - - ^ children - ifEmpty: [ nil ] - ifNotEmpty: [ children first hightlightSymbol ] -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> isGroupEntry [ - - ^ true -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> prefix [ - - ^ prefix -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> prefix: aString [ - - prefix := aString -] - -{ #category : 'actions' } -NECPrefixGroupEntry >> rawLabel [ - - ^ 'group' -]