DoWhatIMeanSupport.st
changeset 4391 903ec83fb9cd
parent 4390 8302e1520ab1
child 4392 9570ef5f05c3
--- a/DoWhatIMeanSupport.st	Mon Sep 16 12:41:11 2013 +0200
+++ b/DoWhatIMeanSupport.st	Wed Sep 18 15:22:08 2013 +0200
@@ -64,17 +64,50 @@
 
 !DoWhatIMeanSupport class methodsFor:'code completion'!
 
-codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
+codeCompletionForLanguage: languageOrNil class: classOrNil context:contextOrNil codeView:codeView
     "contextOrNil is the current context, if this is called from the debugger;
      nil, if called from the browser.
      If nonNil, we can make better guesses, because we actually know what a variable's type is.
      This is not yet done, sigh"
 
     ^ self new 
-        codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
+        codeCompletionForLanguage: languageOrNil class:classOrNil context:contextOrNil codeView:codeView
+
+    "Created: / 18-09-2013 / 13:34:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+codeCompletionForLanguage: languageOrNil method:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
+    "contextOrNil is the current context, if this is called from the debugger;
+     nil, if called from the browser.
+     If nonNil, we can make better guesses, because we actually know what a variable's type is.
+     This is not yet done, sigh"
+
+    ^ self new
+        codeCompletionForLanguage: languageOrNil 
+        method:methodOrNil orClass:classOrNil 
+        context:contextOrNil 
+        codeView:codeView into:actionBlock
+
+    "Created: / 18-09-2013 / 13:35:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!DoWhatIMeanSupport class methodsFor:'code completion - obsolete'!
+
+codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
+    <resource: #obsolete>
+    "contextOrNil is the current context, if this is called from the debugger;
+     nil, if called from the browser.
+     If nonNil, we can make better guesses, because we actually know what a variable's type is.
+     This is not yet done, sigh"
+
+    ^ self  
+        codeCompletionForLanguage: nil class:classOrNil context:contextOrNil codeView:codeView
+
+    "Modified: / 18-09-2013 / 13:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 codeCompletionForMethod:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
+    <resource: #obsolete>
     "contextOrNil is the current context, if this is called from the debugger;
      nil, if called from the browser.
      If nonNil, we can make better guesses, because we actually know what a variable's type is.
@@ -1095,7 +1128,8 @@
 
 !DoWhatIMeanSupport methodsFor:'code completion'!
 
-codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
+codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNil codeView:codeViewArg
+
     "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
      contextOrNil is the current context, if this is called from the debugger;
      nil, if called from the browser.
@@ -1276,11 +1310,100 @@
 
     self information:'Node is neither variable nor message.'.
 
+    "Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+codeCompletionForLanguage: languageOrNil method:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
+    "provide code completion information by analyzing what the editing state is in codeViewArg
+     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
+     the info as argument. Te interface has been defined in that way (and tight coupling with internals
+     of the editor) because
+        1) the completer needs to know about the text around the cursor position
+        2) the edit operation for completion may be non-trivial
+           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
+     For example, in many situations, both a completion of a unary selector before the cursor,
+     or adding another keyword part after the cursor is posisble.
+     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
+     perform the completion.
+     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
+     An additional array containing a textual description for each suggestion is also provided, which could
+     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
+
+     ContextOrNil is the current context, if this is called from the debugger;
+     or nil, if called from the browser.
+     If nonNil, we can make better guesses, because we actually know what a variable's type is"
+
+    |crsrPos char interval source partialSource suggestions1 suggestions2 actions1 actions2 title1 title2|
+
+    methodOrNil := methodOrNilArg.
+    classOrNil := classOrNilArg.
+    codeView := codeViewArg.
+    contextOrNil := contextOrNilArg.
+
+"/    classOrNil isNil ifTrue:[
+"/        self information:'No class'.
+"/        ^ self.
+"/    ].
+
+    crsrPos := codeView characterPositionOfCursor"-1".
+    char := codeView characterAtCharacterPosition:crsrPos.
+    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
+        crsrPos := crsrPos - 1.
+        char := codeView characterAtCharacterPosition:crsrPos.
+    ].
+
+    interval := crsrPos-1 to:crsrPos.
+
+    source := codeView contentsAsString string.
+    partialSource := source copyTo:crsrPos.
+
+    self 
+        tryCodeCompletionWithSource:partialSource nodeInterval:interval 
+        into:[:listOfSuggestions :listOfActions :titleWhenAsking |
+            suggestions1 := listOfSuggestions.
+            actions1 := listOfActions.
+            title1 := titleWhenAsking.
+            "/ suggestions1 size>100 ifTrue:[ self halt].
+        ].
+
+    suggestions1 notEmptyOrNil ifTrue:[
+        actionBlock value:suggestions1 value:actions1 value:title1.
+    ] ifFalse:[
+        self 
+            tryCodeCompletionWithSource:source nodeInterval:interval 
+            into:[:listOfSuggestions :listOfActions :titleWhenAsking |  
+                suggestions2 := listOfSuggestions.
+                actions2 := listOfActions.
+                title2 := titleWhenAsking.
+            ].
+
+        suggestions2 notEmptyOrNil ifTrue:[
+            actionBlock value:suggestions2 value:actions2 value:title2.
+        ]
+    ].
+
+    "Created: / 18-09-2013 / 13:54:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!DoWhatIMeanSupport methodsFor:'code completion - obsolete'!
+
+codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
+    <resource: #obsolete>
+    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
+     contextOrNil is the current context, if this is called from the debugger;
+     nil, if called from the browser.
+     If nonNil, we can make better guesses, because we actually know what a variable's type is.
+     This is not yet done, sigh"
+
+    ^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg
+
     "Modified: / 04-07-2006 / 18:48:26 / fm"
     "Modified: / 28-08-2013 / 17:15:25 / cg"
+    "Modified: / 18-09-2013 / 14:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
+    <resource: #obsolete>
     "provide code completion information by analyzing what the editing state is in codeViewArg
      (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
      the info as argument. Te interface has been defined in that way (and tight coupling with internals
@@ -4044,10 +4167,10 @@
 !DoWhatIMeanSupport class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.159 2013-09-16 10:41:11 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.160 2013-09-18 13:22:08 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.159 2013-09-16 10:41:11 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.160 2013-09-18 13:22:08 vrany Exp $'
 ! !