Skip to content
Open
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
90 changes: 61 additions & 29 deletions src/Group-Entries-Tests/CoCompletionContextTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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' }
Expand Down Expand Up @@ -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' }
Expand All @@ -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'
]
2 changes: 1 addition & 1 deletion src/Group-Entries/CoCompletionContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
90 changes: 89 additions & 1 deletion src/Group-Entries/CoEntry.extension.st
Original file line number Diff line number Diff line change
@@ -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'
]
95 changes: 0 additions & 95 deletions src/Group-Entries/NECPrefixGroupEntry.class.st

This file was deleted.

Loading