From 1491600b38815946065c1e90b61a6265f2713dc7 Mon Sep 17 00:00:00 2001 From: Omar AbedelKader <113094232+omarabedelkader@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:39:25 +0100 Subject: [PATCH 1/4] Fix 13825. Create a new sorter for the completion engine . --- .../CoResultSet.class.st | 8 +++++--- .../CoCompletionEngineTest.class.st | 16 +++++++++++++++ src/NECompletion/NoSorter.class.st | 20 +++++++++++++++++++ src/NECompletion/SizeSorter.class.st | 20 +++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/NECompletion/NoSorter.class.st create mode 100644 src/NECompletion/SizeSorter.class.st diff --git a/src/HeuristicCompletion-Model/CoResultSet.class.st b/src/HeuristicCompletion-Model/CoResultSet.class.st index 5f4beb45f8b..009a1b35ad3 100644 --- a/src/HeuristicCompletion-Model/CoResultSet.class.st +++ b/src/HeuristicCompletion-Model/CoResultSet.class.st @@ -15,7 +15,8 @@ Class { #instVars : [ 'results', 'fetcher', - 'filter' + 'filter', + 'sorter' ], #category : 'HeuristicCompletion-Model-Core', #package : 'HeuristicCompletion-Model', @@ -56,7 +57,7 @@ CoResultSet >> fetch: anInteger [ | newResults | newResults := fetcher next: anInteger. - results addAll: newResults + results addAll: (sorter sortCompletionList: newResults) ] { #category : 'fetching' } @@ -117,7 +118,8 @@ CoResultSet >> initialize [ super initialize. results := OrderedCollection new. - filter := CoFilter empty + filter := CoFilter empty. + sorter := CompletionContext sorterClass new ] { #category : 'testing' } diff --git a/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st b/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st index 9666ff37419..23b344252c8 100644 --- a/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st +++ b/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st @@ -1,6 +1,9 @@ Class { #name : 'CoCompletionEngineTest', #superclass : 'CompletionEngineTest', + #instVars : [ + 'oldSort' + ], #category : 'HeuristicCompletion-Tests', #package : 'HeuristicCompletion-Tests' } @@ -28,6 +31,19 @@ CoCompletionEngineTest >> newCompletionEngine [ ^ CoCompletionEngine new ] +{ #category : 'accessing' } +CoCompletionEngineTest >> setUp [ + super setUp. + oldSort := CompletionContext sorterClass. + CompletionContext sorterClass: NoSorter. +] + +{ #category : 'accessing' } +CoCompletionEngineTest >> tearDown [ + super tearDown. + CompletionContext sorterClass: oldSort. +] + { #category : 'tests - interaction' } CoCompletionEngineTest >> testCmdCtrlLeft [ diff --git a/src/NECompletion/NoSorter.class.st b/src/NECompletion/NoSorter.class.st new file mode 100644 index 00000000000..252a70322ef --- /dev/null +++ b/src/NECompletion/NoSorter.class.st @@ -0,0 +1,20 @@ +" +I'm a class that do nothing in the suggestion list. + +I return the list created from the compltion engine. + +This class is created to pass the test. +" +Class { + #name : 'NoSorter', + #superclass : 'CompletionSorter', + #category : 'NECompletion-Sorting', + #package : 'NECompletion', + #tag : 'Sorting' +} + +{ #category : 'sorting' } +NoSorter >> sortCompletionList: anOrderedCollection [ + + ^ anOrderedCollection +] diff --git a/src/NECompletion/SizeSorter.class.st b/src/NECompletion/SizeSorter.class.st new file mode 100644 index 00000000000..758ddd251f2 --- /dev/null +++ b/src/NECompletion/SizeSorter.class.st @@ -0,0 +1,20 @@ +" +I'm a class that do sorting based on the size of the context itself. + +I return a list sorted by size. + + +" +Class { + #name : 'SizeSorter', + #superclass : 'CompletionSorter', + #category : 'NECompletion-Sorting', + #package : 'NECompletion', + #tag : 'Sorting' +} + +{ #category : 'sorting' } +SizeSorter >> sortCompletionList: anOrderedCollection [ + + ^ anOrderedCollection sort: [ :a :b | a contents size < b contents size ] +] From 67a907d39c8ca1ff34ffabf9b513674fd0aa3dc6 Mon Sep 17 00:00:00 2001 From: Omar AbedelKader <113094232+omarabedelkader@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:15:42 +0100 Subject: [PATCH 2/4] Change the default sorter of the completion engine results --- src/NECompletion/CompletionSorter.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NECompletion/CompletionSorter.class.st b/src/NECompletion/CompletionSorter.class.st index f633c119b60..568cc78e540 100644 --- a/src/NECompletion/CompletionSorter.class.st +++ b/src/NECompletion/CompletionSorter.class.st @@ -21,7 +21,7 @@ CompletionSorter class >> kind [ { #category : 'tools registry' } CompletionSorter class >> register [ - CompletionContext sorterClass: AlphabeticSorter + CompletionContext sorterClass: SizeSorter ] { #category : 'accessing' } From b542097c7c8fad8e6cb73f73c5c75ab3c703ea2b Mon Sep 17 00:00:00 2001 From: Omar AbedelKader <113094232+omarabedelkader@users.noreply.github.com> Date: Sun, 1 Dec 2024 18:28:48 +0100 Subject: [PATCH 3/4] Fixing writing mistakes. --- src/NECompletion/NoSorter.class.st | 4 ++-- src/NECompletion/SizeSorter.class.st | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NECompletion/NoSorter.class.st b/src/NECompletion/NoSorter.class.st index 252a70322ef..f46a0875200 100644 --- a/src/NECompletion/NoSorter.class.st +++ b/src/NECompletion/NoSorter.class.st @@ -1,7 +1,7 @@ " -I'm a class that do nothing in the suggestion list. +I'm a class that does nothing in the suggestion list. -I return the list created from the compltion engine. +I return the list created from the completion engine. This class is created to pass the test. " diff --git a/src/NECompletion/SizeSorter.class.st b/src/NECompletion/SizeSorter.class.st index 758ddd251f2..94eba489365 100644 --- a/src/NECompletion/SizeSorter.class.st +++ b/src/NECompletion/SizeSorter.class.st @@ -1,5 +1,5 @@ " -I'm a class that do sorting based on the size of the context itself. +I'm a class that does sorting based on the size of the context itself. I return a list sorted by size. From 532184a82587bd2ba28289d08d67ebc66a078504 Mon Sep 17 00:00:00 2001 From: Omar AbedelKader <113094232+omarabedelkader@users.noreply.github.com> Date: Sun, 1 Dec 2024 19:11:07 +0100 Subject: [PATCH 4/4] adding the `tab` in the `Tests` packages of the completion engine. --- src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st b/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st index 23b344252c8..4b73a703a31 100644 --- a/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st +++ b/src/HeuristicCompletion-Tests/CoCompletionEngineTest.class.st @@ -41,7 +41,7 @@ CoCompletionEngineTest >> setUp [ { #category : 'accessing' } CoCompletionEngineTest >> tearDown [ super tearDown. - CompletionContext sorterClass: oldSort. + CompletionContext sorterClass: oldSort. ] { #category : 'tests - interaction' }