Update simple console implementation to use updated -complete command
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 12 Jun 2019 20:04:33 +0100
changeset 170 cd9615ebe6a9
parent 169 807f5f62c910
child 171 39774c491dbf
Update simple console implementation to use updated -complete command ...merged into GDB in commit 26648588294d03.
VDBSimpleConsoleView.st
VDBSimpleDebuggerConsoleApplication.st
tests/VDBSimpleConsoleViewTest.st
--- a/VDBSimpleConsoleView.st	Wed Jun 12 15:16:33 2019 +0100
+++ b/VDBSimpleConsoleView.st	Wed Jun 12 20:04:33 2019 +0100
@@ -73,28 +73,32 @@
     "Created: / 26-01-2019 / 22:16:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-completions: anArray"of Strings"
-    "Should be called by application when completions are computed."
+completion: completion matches: matches
 
-    | completion |
-
-    lastCompletions := anArray.
+    lastCompletions := matches.
     lastCompletions isEmptyOrNil ifTrue:[
         lastCompletions := nil.
         self flash: (resources string:'Nothing to complete').
         ^self.
     ].
-    completion := lastCompletions longestCommonPrefix copyFrom: bufferPosition.
 
-    completion isEmpty ifTrue:[ 
+    completion isEmptyOrNil ifTrue:[ 
         self flash: (resources string:'Ambiguous')
     ] ifFalse:[
-        buffer := (buffer copyTo: bufferPosition - 1) , completion , (buffer copyFrom: bufferPosition).
-        self insertStringAtCursor: completion.
-        bufferPosition := bufferPosition + completion size.
+        (completion startsWith: (buffer copyTo: bufferPosition - 1)) ifTrue:[
+            | insertion |
+
+            insertion := completion copyFrom: bufferPosition.
+            buffer := (buffer copyTo: bufferPosition - 1) , insertion , (buffer copyFrom: bufferPosition).
+            self insertStringAtCursor: insertion.
+            bufferPosition := bufferPosition + insertion size.
+        ] ifFalse:[
+            self breakpoint: #jv
+        ]
     ]
 
-    "Created: / 25-01-2019 / 21:50:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 12-06-2019 / 18:28:09 / jv"
+    "Modified: / 12-06-2019 / 19:54:15 / jv"
 !
 
 completionsShow
--- a/VDBSimpleDebuggerConsoleApplication.st	Wed Jun 12 15:16:33 2019 +0100
+++ b/VDBSimpleDebuggerConsoleApplication.st	Wed Jun 12 20:04:33 2019 +0100
@@ -68,12 +68,13 @@
     command := GDBMI_complete arguments: (Array with: line).
     debugger send: command andWithResultDo: [ :result |
         result isDone ifTrue:[ 
-            consoleView completions: (result propertyAt: #completions)
+            consoleView completion: (result propertyAt: #completion) matches: (result propertyAt: #matches)
         ].
     ].
 
     "Created: / 30-12-2018 / 22:01:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 25-01-2019 / 22:03:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2019 / 18:27:04 / jv"
 !
 
 doFire: aString
--- a/tests/VDBSimpleConsoleViewTest.st	Wed Jun 12 15:16:33 2019 +0100
+++ b/tests/VDBSimpleConsoleViewTest.st	Wed Jun 12 20:04:33 2019 +0100
@@ -124,20 +124,24 @@
 
 test_completion_01
     console completeAction:[ :partial | 
-        console completions: #('finish')
+        console completion: 'finish' matches: #('finish')
     ].
     consoleI type: 'fi'.
     consoleI type: #Tab.
     self assert: console list first asString = 'finish'.
 
     "Created: / 25-01-2019 / 22:47:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2019 / 19:56:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_completion_02
 
     console completeAction:[ :partial | 
-        console completions:     
-            (#('file' 'finish') select: [ :each | each startsWith: partial ]).
+        | completion matches |
+
+        matches := #('file' 'finish') select: [ :each | each startsWith: partial ].
+        completion := matches longestCommonPrefix.
+        console completion: completion matches: matches
     ].
     consoleI type: 'f'.
     consoleI type: #Tab.
@@ -148,14 +152,18 @@
     self assert: console list first asString = 'file'.
 
     "Created: / 25-01-2019 / 22:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2019 / 19:58:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_completion_03
     console show: '-> '.
 
     console completeAction:[ :partial | 
-        console completions:     
-            (#('file' 'finish') select: [ :each | each startsWith: partial ]).
+        | completion matches |
+
+        matches := #('file' 'finish') select: [ :each | each startsWith: partial ].
+        completion := matches longestCommonPrefix.
+        console completion: completion matches: matches
     ].
     consoleI type: 'f'.
     consoleI type: #Tab.
@@ -170,6 +178,7 @@
     self assert: (console list at: 4) asString = '-> finish'.
 
     "Created: / 25-01-2019 / 22:48:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 12-06-2019 / 19:59:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBSimpleConsoleViewTest class methodsFor:'documentation'!