DoWhatIMeanSupport.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 12:36:45 +0200
changeset 4136 d2d772832f99
parent 4130 9ee47cc0138c
child 4141 08e3afdffc2b
permissions -rw-r--r--
changed: #codeCompletionForMessage:inClass:codeView: #old_askUserForCompletion:for:from:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Object subclass:#DoWhatIMeanSupport
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
    16
	classVariableNames:'LastSource LastParseTree LastChoices'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'System-Support'
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    21
Array variableSubclass:#InputCompletionResult
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    22
	instanceVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    23
	classVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    24
	poolDictionaries:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    25
	privateIn:DoWhatIMeanSupport
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    26
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    27
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
copyright
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 COPYRIGHT (c) 2002 by eXept Software AG
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
              All Rights Reserved
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
documentation
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    misc collected UI support (functional)
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    47
    These used to be in the Smalltalk and SystemBrowser class; 
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    48
    however, they are only needed for programmers, and some of the stuff is useful in multiple
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    49
    places. 
3667
acb358ca4b0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3660
diff changeset
    50
    Therefore it is:
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    51
        1) not needed for standalone executables
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    52
        2) published here to avoid multiple implementations
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    [author:]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        Claus Gittinger (cg@exept.de)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    57
"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    58
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    59
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    60
!DoWhatIMeanSupport class methodsFor:'code completion'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    61
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    62
codeCompletionForClass:classOrNil codeView:codeView
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    63
    self codeCompletionForClass:classOrNil context:nil codeView:codeView
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    64
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    65
    "Modified (format): / 03-07-2011 / 15:49:49 / cg"
3557
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    66
!
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    67
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    68
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    69
    "contextOrNil is the current context, if this is called from the debugger;
3557
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    70
     nil, if called from the browser.
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    71
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    72
     This is not yet done, sigh"
3557
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    73
    
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    74
    |crsrPos char interval source node checkedNode|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    75
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    76
"/    classOrNil isNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    77
"/        self information:'No class'.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    78
"/        ^ self.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    79
"/    ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    80
4070
175d50cdef4c changed: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
    81
    crsrPos := codeView characterPositionOfCursor"-1".
3731
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    82
    char := codeView characterAtCharacterPosition:crsrPos.
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    83
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    84
        crsrPos := crsrPos - 1.
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    85
        char := codeView characterAtCharacterPosition:crsrPos.
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    86
    ].
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    87
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    88
    interval := codeView selectedInterval.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    89
    interval isEmpty ifTrue:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
    90
        interval := crsrPos-1 to:crsrPos.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    91
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    92
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    93
    source := codeView contentsAsString string.
3731
eb92d54a47ac fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
    94
    source := source copyTo:crsrPos.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    95
3720
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
    96
    "/ this is too naive and stupid; if there is a syntactic error,
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
    97
    "/ we will not find a node for a long time (stepping back more and more,
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
    98
    "/ until reaching the beginning). This leads to a thousand and more times reparsing
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
    99
    "/ without any progress.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   100
    "/ TODO: do it vice-versa, in that the parser does a callOut for every node generated
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   101
    "/ as it parses the code. Stop, when the interval is hit.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   102
    "/ that will also work for syntactic incorrect source code.
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   103
    classOrNil notNil ifTrue:[
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   104
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.   
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   105
    ].
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   106
    node isNil ifTrue:[
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   107
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.   
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   108
    ].
3720
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   109
"/    [node isNil] whileTrue:[
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   110
"/        "/ expand to the left ...
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   111
"/        interval start > 1 ifFalse:[
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   112
"/            self information:'No parseNode found'.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   113
"/            ^ self.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   114
"/        ].
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   115
"/        interval start:(interval start - 1).
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   116
"/        node := self findNodeForInterval:interval in:source allowErrors:true.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   117
"/    ].
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   118
    node isNil ifTrue:[
3895
79124f2311a1 comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
   119
        Transcript showCR:'No parseNode found'.
79124f2311a1 comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
   120
        self breakPoint:#cg.
3720
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   121
        self information:'No parseNode found'.
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   122
        ^ self.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   123
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   124
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   125
    (node isVariable
3366
67d627de3bc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3362
diff changeset
   126
    and:[ node parent notNil
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   127
    and:[ node parent isMessage
3366
67d627de3bc7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3362
diff changeset
   128
    and:[ node stop < (codeView characterPositionOfCursor-1) ]]]) ifTrue:[
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   129
        node := node parent.
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   130
    ].
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
   131
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   132
    node isVariable ifTrue:[
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   133
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   134
        ^ self.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   135
    ].
3552
e631f2f7bb2a code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   136
    node isLiteral ifTrue:[
e631f2f7bb2a code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   137
        node value isSymbol ifTrue:[
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   138
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
3552
e631f2f7bb2a code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   139
            ^ self.
e631f2f7bb2a code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   140
        ].
e631f2f7bb2a code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   141
    ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   142
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   143
    checkedNode := node.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   144
    [checkedNode notNil] whileTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   145
        checkedNode isMessage ifTrue:[
3306
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   146
            "/ completion in a message-send
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   147
            self codeCompletionForMessage:checkedNode inClass:classOrNil codeView:codeView.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   148
            ^ self
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   149
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   150
        checkedNode isMethod ifTrue:[
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
   151
            "/ completion in a method's selector pattern
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   152
            self codeCompletionForMethod:checkedNode inClass:classOrNil codeView:codeView.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   153
            ^ self.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   154
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   155
        checkedNode := checkedNode parent.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   156
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   157
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   158
    self information:'Node is neither variable nor message.'.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   159
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   160
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   161
    "Modified: / 16-09-2011 / 14:54:47 / cg"
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   162
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   163
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   164
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   165
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   166
askUserForCompletion:what for:codeView at:position from:allTheBest 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   167
    |list choice lastChoice|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   168
4054
f6bdf516b10b changed: #askUserForCompletion:for:at:from:
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   169
    "/ cg: until the new stuff works,...
f6bdf516b10b changed: #askUserForCompletion:for:at:from:
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   170
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
f6bdf516b10b changed: #askUserForCompletion:for:at:from:
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   171
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   172
    allTheBest isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   173
        ^ nil
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   174
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   175
    allTheBest size == 1 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   176
        ^ allTheBest first
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   177
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   178
    list := allTheBest.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   179
    LastChoices notNil ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   180
        lastChoice := LastChoices at:what ifAbsent:nil.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   181
        lastChoice notNil ifTrue:[
4054
f6bdf516b10b changed: #askUserForCompletion:for:at:from:
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   182
            list := { lastChoice. nil } , (list copyWithout:lastChoice).
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   183
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   184
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   185
    choice := Tools::CodeCompletionMenu 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   186
                openFor:codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   187
                at:position
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   188
                with:allTheBest.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   189
    LastChoices isNil ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   190
        LastChoices := Dictionary new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   191
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   192
    LastChoices at:what put:choice.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   193
    ^ choice
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   194
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   195
    "Created: / 16-02-2010 / 10:09:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4054
f6bdf516b10b changed: #askUserForCompletion:for:at:from:
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   196
    "Modified (format): / 08-07-2011 / 08:49:35 / cg"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   197
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   198
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   199
askUserForCompletion:what for:codeView from:allTheBest
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   200
    |list resources choice lastChoice|
3598
f7556388601b resources
Claus Gittinger <cg@exept.de>
parents: 3586
diff changeset
   201
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   202
    allTheBest isEmpty ifTrue:[ ^ nil ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   203
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   204
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   205
    list := allTheBest.
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   206
    LastChoices notNil ifTrue:[
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   207
        lastChoice := LastChoices at:what ifAbsent:nil.
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   208
        lastChoice notNil ifTrue:[
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   209
            list := {lastChoice. nil. } , (list copyWithout:lastChoice).
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   210
        ].
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   211
    ].
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   212
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   213
    list size < 30 ifTrue:[
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   214
        |menu idx exitKey|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   215
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   216
        menu := PopUpMenu labels:list.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   217
        menu hideOnKeyFilter:[:key | |hide|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   218
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   219
                hide ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   220
                    exitKey := key.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   221
                ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   222
                hide].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   223
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   224
        idx := menu startUp.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   225
        idx == 0 ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   226
            exitKey notNil ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   227
                codeView keyPress:exitKey x:0 y:0.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   228
            ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   229
            ^ nil
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   230
        ].
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   231
        choice := list at:idx.
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   232
    ] ifFalse:[
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   233
        resources := codeView application isNil 
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   234
                        ifTrue:[ codeView resources]
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   235
                        ifFalse:[ codeView application resources ].
3598
f7556388601b resources
Claus Gittinger <cg@exept.de>
parents: 3586
diff changeset
   236
                    
3853
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   237
        choice := Dialog
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   238
           choose:(resources string:'Choose ',what)
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   239
           fromList:list
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   240
           lines:20
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   241
           title:(resources string:'Code completion').
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   242
        choice isNil ifTrue:[^ nil].
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   243
    ].
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   244
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   245
    LastChoices isNil ifTrue:[
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   246
        LastChoices := Dictionary new.
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   247
    ].
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   248
    LastChoices at:what put:choice.
72343b2ef436 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   249
    ^ choice
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   250
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   251
    "Created: / 10-11-2006 / 14:00:53 / cg"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   252
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   253
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   254
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   255
    |sym possibleCompletions best start stop oldLen newLen oldVar|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   256
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   257
    sym := node value.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   258
    possibleCompletions := OrderedCollection new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   259
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   260
    Symbol allInstancesDo:[:existingSym |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   261
        (existingSym startsWith:sym) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   262
            (existingSym = sym) ifFalse:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   263
                possibleCompletions add:existingSym
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   264
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   265
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   266
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   267
    possibleCompletions sort.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   268
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   269
    best := possibleCompletions longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   270
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   271
        best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   272
        best isNil ifTrue:[^ self].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   273
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   274
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   275
"/ self showInfo:best.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   276
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   277
    start := node start.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   278
    stop := node stop.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   279
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   280
        start := start + 1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   281
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   282
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   283
        start := start + 1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   284
        stop := stop - 1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   285
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   286
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   287
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   288
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   289
    codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   290
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   291
        info:'Completion'.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   292
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   293
    (best startsWith:oldVar) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   294
        oldLen := stop - start + 1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   295
        newLen := best size.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   296
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   297
        codeView dontReplaceSelectionOnInput
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   298
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   299
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   300
    "Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   301
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   302
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   303
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   304
codeCompletionForMessage:node inClass:classOrNil codeView:codeView
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   305
    |selector srchClass implClass 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   306
     bestSelectors selector2 bestSelectors2 allBest best info numArgs
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   307
     newParts nSelParts oldLen newLen selectorParts 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   308
     findBest parentNode selectorInBest selector2InBest2
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   309
     parser selectorsSentInCode split|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   310
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   311
    classOrNil notNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   312
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   313
        selectorsSentInCode := parser messagesSent.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   314
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   315
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   316
    findBest := [:node :selector |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   317
        |srchClass bestSelectors bestPrefixes|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   318
4058
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
   319
        codeView topView withCursor:(Cursor questionMark) do:[
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
   320
            srchClass := self lookupClassForMessage:node inClass:classOrNil.
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
   321
            srchClass notNil ifTrue:[
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
   322
                bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true.
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
   323
            ] ifFalse:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   324
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   325
            ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   326
        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   327
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   328
        (bestSelectors includes:selector) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   329
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   330
        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   331
        bestSelectors
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   332
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   333
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   334
    selector := node selector.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   335
    bestSelectors := findBest value:node value:selector.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   336
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   337
    parentNode := node parent.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   338
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   339
    "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   340
    (node selector isUnarySelector 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   341
    and:[ parentNode notNil 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   342
    and:[ parentNode isMessage 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   343
    and:[ (selector2 := parentNode selector) isKeywordSelector ]]]) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   344
        "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   345
        selector2 := selector2,selector.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   346
        bestSelectors2 := findBest value:parentNode value:selector2.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   347
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   348
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   349
    bestSelectors2 isEmptyOrNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   350
        allBest := bestSelectors.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   351
    ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   352
        bestSelectors isEmptyOrNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   353
            allBest := bestSelectors2
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   354
        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   355
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   356
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   357
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   358
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   359
                "/ selector2 is more likely
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   360
                allBest := bestSelectors2
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   361
            ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   362
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   363
                    "/ selector more likely
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   364
                    allBest := bestSelectors
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   365
                ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   366
                    "/ assume same likelyness
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   367
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   368
                    allBest := bestSelectors isEmpty 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   369
                                ifTrue:[ bestSelectors2 ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   370
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   371
                ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   372
            ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   373
        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   374
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   375
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   376
    allBest isEmptyOrNil ifTrue:[ ^ self ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   377
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   378
    split := [:list :splitHow |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   379
        |part1 part2 all|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   380
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   381
        part1 := list select:splitHow.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   382
        part2 := list reject:splitHow.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   383
        part1 isEmpty ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   384
            all := part2.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   385
        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   386
            part2 isEmpty ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   387
                all := part1.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   388
            ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   389
                all := part1 , part2.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   390
            ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   391
        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   392
        all
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   393
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   394
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   395
    selectorsSentInCode notNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   396
        "/ the ones already sent in the code are moved to the top of the list.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   397
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   398
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   399
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   400
    "/ the ones which are a prefix are moved towards the top of the list
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   401
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   402
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   403
    best := allBest first.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   404
    allBest size > 1 ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   405
        "allBest size < 20 ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   406
            |idx|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   407
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   408
            idx := (PopUpMenu labels:allBest) startUp.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   409
            idx == 0 ifTrue:[ ^ self].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   410
            best := allBest at:idx.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   411
        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   412
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   413
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   414
        ]."
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   415
        best := self askUserForCompletion:'selector' for:codeView at: node selectorParts first start from:allBest.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   416
        best isEmptyOrNil ifTrue:[^ self].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   417
        best = '-' ifTrue:[^ self].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   418
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   419
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   420
false ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   421
    srchClass notNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   422
        implClass := srchClass whichClassIncludesSelector:best.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   423
    ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   424
        implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   425
        implClass size == 1 ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   426
            implClass := implClass first.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   427
        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   428
            implClass := nil
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   429
        ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   430
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   431
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   432
    info := best storeString.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   433
    implClass notNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   434
        info := implClass name , ' >> ' , info.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   435
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   436
    self information:info.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   437
].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   438
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   439
    best ~= selector ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   440
        numArgs := best numArgs.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   441
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   442
            selectorParts := parentNode selectorParts , node selectorParts.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   443
        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   444
            selectorParts := node selectorParts.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   445
        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   446
        nSelParts := selectorParts size.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   447
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   448
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   449
        newParts := newParts select:[:part | part size > 0].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   450
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   451
        codeView
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   452
            undoableDo:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   453
                |newCursorPosition stop|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   454
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   455
                numArgs > nSelParts ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   456
                    stop := selectorParts last stop.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   457
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   458
                    "/ append the rest ...
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   459
                    numArgs downTo:nSelParts+1 do:[:idx |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   460
                        |newPart|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   461
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   462
                        newPart := newParts at:idx.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   463
                        (best endsWith:$:) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   464
                            newPart := newPart , ':'
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   465
                        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   466
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   467
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   468
                            newPart := ':' , newPart.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   469
                        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   470
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   471
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   472
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   473
                        newCursorPosition := stop + newPart size.
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   474
                    ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   475
                ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   476
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   477
                (nSelParts min:newParts size) downTo:1 do:[:idx |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   478
                    |newPart oldPartialToken start stop|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   479
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   480
                    newPart := newParts at:idx.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   481
                    oldPartialToken := selectorParts at:idx.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   482
                    start := oldPartialToken start.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   483
                    stop := oldPartialToken stop.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   484
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   485
                    (best endsWith:$:) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   486
                        (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   487
                            newPart := newPart , ':'
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   488
                        ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   489
                    ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   490
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   491
                            newPart := newPart , ':'
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   492
                        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   493
                            (codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   494
                                newPart := newPart , ' '
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   495
                            ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   496
                        ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   497
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   498
"/                        ] ifFalse:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   499
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   500
                    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   501
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   502
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   503
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   504
                    oldLen := stop - start + 1.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   505
                    newLen := newPart size.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   506
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   507
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   508
                    newCursorPosition := stop + (newLen-oldLen).
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   509
                ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   510
                codeView cursorToCharacterPosition:newCursorPosition.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   511
                codeView cursorRight.  "/ avoid going to the next line !!
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   512
                codeView dontReplaceSelectionOnInput.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   513
            ]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   514
        info:'Completion'.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   515
    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   516
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   517
    "Created: / 10-11-2006 / 13:18:27 / cg"
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   518
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   519
    "Modified: / 21-07-2012 / 12:24:06 / cg"
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   520
!
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   521
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   522
codeCompletionForMethod:node inClass:classOrNil codeView:codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   523
    "completion in a methods selector pattern"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   524
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   525
    |crsrPos
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   526
     selectorSoFar matchingSelectors
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   527
     selectors distances best rest 
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   528
     allExistingMethods nameBag namesByCount selectors1 selectors2|  
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   529
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   530
    crsrPos := codeView characterPositionOfCursor - 1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   531
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   532
    selectorSoFar := ''.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   533
    node selectorParts doWithIndex:[:partToken :argNr|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   534
        |part|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   535
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   536
        part := partToken value.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   537
        selectorSoFar := selectorSoFar , part.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   538
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   539
        (crsrPos >= partToken start
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   540
        and:[crsrPos <= partToken stop]) ifTrue:[
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   541
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   542
                matchingSelectors := Smalltalk allClasses
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   543
                                    inject:(Set new)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   544
                                    into:[:theSet :eachClass |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   545
                                        |md|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   546
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   547
                                        md := eachClass theMetaclass methodDictionary.
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   548
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   549
                                        theSet.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   550
                                    ].
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   551
                "/ dont forget the stuff in the class-line
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   552
                Metaclass withAllSuperclassesDo:[:cls |
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   553
                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   554
                ].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   555
            ] ifFalse:[
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   556
                matchingSelectors := Smalltalk allClasses
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   557
                                    inject:(Set new)
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   558
                                    into:[:theSet :eachClass |
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   559
                                        |md|
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   560
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   561
                                        md := eachClass theNonMetaclass methodDictionary.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   562
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   563
                                        theSet.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   564
                                    ].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   565
            ].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   566
            selectors := matchingSelectors asOrderedCollection.
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   567
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   568
            "/ if there is only one, and user has already entered it, he might want to complete the argument-name    
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   569
            (selectors size == 1 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   570
            and:[selectors first = selectorSoFar]) ifTrue:[
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   571
                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   572
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   573
                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   574
                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   575
                nameBag := Bag new.
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   576
                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   577
                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   578
                "/ take the one which occurs most often     
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   579
                best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   580
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   581
                codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   582
                    undoableDo:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   583
                        (crsrPos+1) >= codeView contents size ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   584
                            codeView paste:best.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   585
                        ] ifFalse:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   586
                            codeView insertString:best atCharacterPosition:crsrPos+1.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   587
                        ]
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   588
                    ]
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   589
                    info:'completion'.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   590
                codeView cursorToCharacterPosition:(crsrPos + best size - 1).    
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   591
            ] ifFalse:[
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   592
                "the ones implemented in superclasses are shown first"
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   593
                classOrNil notNil ifTrue:[
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   594
                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   595
                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   596
                ] ifFalse:[
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   597
                    selectors1 := selectors
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   598
                ].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   599
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   600
                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   601
                distances sortWith:selectors1.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   602
                selectors1 reverse.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   603
                selectors := selectors1.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   604
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   605
                selectors2 notEmptyOrNil ifTrue:[
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   606
                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   607
                    distances sortWith:selectors2.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   608
                    selectors2 reverse.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   609
                    selectors1 := selectors1 collect:[:sel | sel allBold].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   610
                    selectors := selectors1,selectors2.
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   611
                ].
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   612
                
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   613
                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   614
                best isNil ifTrue:[^ self].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   615
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   616
                rest := best copyFrom:selectorSoFar size.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   617
                codeView
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   618
                    undoableDo:[ 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   619
                        codeView 
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   620
                            replaceFromCharacterPosition:crsrPos+1 
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   621
                            to:crsrPos+1 
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   622
                            with:rest 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   623
                    ]
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   624
                    info:'Completion'.
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   625
                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   626
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   627
            codeView cursorRight. "/ kludge to make it visible   
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   628
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   629
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   630
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   631
    "Modified: / 04-07-2006 / 18:48:26 / fm"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   632
    "Created: / 10-11-2006 / 13:46:44 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   633
    "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
   634
    "Modified: / 01-06-2012 / 20:31:36 / cg"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   635
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   636
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   637
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   638
    |nonMetaClass crsrPos nm
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   639
     allVariables allDistances best nodeVal
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   640
     char start stop oldLen newLen oldVar
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   641
     getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   642
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   643
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   644
    classOrNil notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   645
        nonMetaClass := classOrNil theNonMetaclass.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   646
    ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   647
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   648
    nm := node name.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   649
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   650
    "/ if we are behind the variable and a space has already been entered,
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   651
    "/ the user is probably looking for a message selector.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   652
    "/ If the variable represents a global, present its instance creation messages
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   653
    crsrPos := codeView characterPositionOfCursor.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   654
    char := codeView characterAtCharacterPosition:crsrPos-1.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   655
    char isSeparator ifTrue:[
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   656
        classOrNil isNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   657
            nodeVal := Smalltalk at:nm asSymbol.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   658
        ] ifFalse:[ 
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   659
            nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   660
        ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   661
        nodeVal isBehavior ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   662
            |methods menu exitKey idx|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   663
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   664
            methods := nodeVal class methodDictionary values
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   665
                            select:[:m | |cat|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   666
                                cat := m category asLowercase.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   667
                                cat = 'instance creation'
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   668
                            ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   669
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   670
            menu := PopUpMenu labels:(methods collect:[:each | each selector]).
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   671
            menu hideOnKeyFilter:[:key | |hide|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   672
                    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   673
                    hide ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   674
                        exitKey := key.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   675
                    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   676
                    hide].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   677
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   678
            idx := menu startUp.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   679
            idx == 0 ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   680
                exitKey notNil ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   681
                    codeView keyPress:exitKey x:0 y:0.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   682
                ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   683
                ^ self
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   684
            ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   685
            best := (methods at:idx) selector.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   686
            codeView
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   687
                undoableDo:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   688
                    codeView insertString:best atCharacterPosition:crsrPos.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   689
                    codeView cursorToCharacterPosition:crsrPos+best size.
3362
9b92a39d5ca8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
   690
                ]
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   691
                info:'completion'.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   692
            ^ self.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   693
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   694
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   695
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   696
    (node parent notNil and:[node parent isMessage]) ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   697
        node == node parent receiver ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   698
            selectorOfMessageToNode := node parent selector
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   699
        ]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   700
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   701
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   702
    getDistanceComputeBlockWithWeight :=
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   703
        [:weight |
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   704
            [:each |
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   705
                |dist factor|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   706
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   707
                dist := each spellAgainst:nm.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   708
                factor := 1.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   709
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   710
                (each startsWith:nm) ifTrue:[
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   711
                    factor := 6 * nm size.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   712
                ] ifFalse:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   713
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   714
                        factor := 4 * nm size.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   715
                    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   716
                ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   717
                dist := dist + (weight*factor).
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   718
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   719
                each -> (dist * weight)
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   720
             ]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   721
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   722
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   723
    addWithFactorBlock :=
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   724
        [:names :factor | |namesToAdd|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   725
            namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   726
            namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   727
            allVariables addAll:namesToAdd.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   728
            allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   729
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   730
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   731
    nm isUppercaseFirst ifTrue:[
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   732
        globalFactor := 2.    "/ favour globals
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   733
        localFactor := 1.
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   734
    ] ifFalse:[
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   735
        globalFactor := 1.    "/ favour locals
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   736
        localFactor := 2.
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   737
    ].
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   738
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   739
    allVariables := OrderedCollection new.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   740
    allDistances := OrderedCollection new.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   741
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   742
    "/ are we in the methods selector spec ?
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   743
    (node parent notNil 
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   744
    and:[node parent isMethod
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   745
    and:[node parent arguments includes:node]]) ifTrue:[
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   746
        "/ now thats cool: look how the naem of this argument is in other implementations
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   747
        "/ of this method, and take that as a basis of the selection
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   748
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   749
        implementors := SystemBrowser 
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   750
                            findImplementorsOf:(node parent selector) 
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   751
                            in:(Smalltalk allClasses)
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   752
                            ignoreCase:false.
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   753
        "/ which argument is it
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   754
        argIdx := node parent arguments indexOf:node.
3554
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   755
        implementors size > 50 ifTrue:[
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   756
            implementors := implementors asOrderedCollection copyTo:50.
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   757
        ].
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   758
        namesUsed := (implementors 
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   759
                        collect:[:eachImplementor |
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   760
                            |parseTree|
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   761
                            parseTree := eachImplementor parseTree.
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   762
                            (parseTree notNil and:[parseTree arguments size > 0]) 
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   763
                                ifFalse:nil
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   764
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   765
                        thenSelect:[:a | a notNil]) asSet.  
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   766
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   767
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   768
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   769
        classOrNil notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   770
            "/ also, look for the keyword before the argument, 
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   771
            "/ and see if there is such an instVar
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   772
            "/ if so, add it with -Arg
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   773
            node parent selector isKeyword ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   774
                kwPart := node parent selector keywords at:argIdx.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   775
                (classOrNil allInstVarNames includes:(kwPart copyWithoutLast:1)) ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   776
                    addWithFactorBlock 
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   777
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   778
                        value:(1 * localFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   779
                ].
3551
0c83710ae45e much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3550
diff changeset
   780
            ].
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   781
        ]
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   782
    ] ifFalse:[
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   783
        classOrNil notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   784
            "/ locals in the block/method
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   785
            names := node allVariablesOnScope.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   786
            "/ if there were no variables (due to a parse error)
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   787
            "/ do another parse and see what we have
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   788
            names isEmpty ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   789
                tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   790
                "/ better if we already have a body (include locals then)
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   791
                "/ otherwise, only the arguments are considered
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   792
                tree notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   793
                    names := (tree body ? tree) allVariablesOnScope.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   794
                ]
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   795
            ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   796
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   797
            addWithFactorBlock value:names value:(4 * localFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   798
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   799
            "/ instance variables
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   800
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
3470
5cbf651bb214 name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents: 3366
diff changeset
   801
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   802
            "/ inherited instance variables
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   803
            classOrNil superclass notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   804
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   805
            ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   806
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   807
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   808
        selectorOfMessageToNode notNil ifTrue:[
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   809
            |names responders nonResponders|
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   810
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   811
            "/ responding to that messsage
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   812
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   813
            classOrNil notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   814
                "/ private classes
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   815
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   816
                                   value:(1.75 * globalFactor).
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   817
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   818
                "/ class variables
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   819
                names := nonMetaClass classVarNames.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   820
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   821
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   822
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   823
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   824
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   825
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   826
                "/ superclass var names
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   827
                nonMetaClass allSuperclassesDo:[:superClass |
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   828
                    names := superClass classVarNames.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   829
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   830
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   831
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   832
                    addWithFactorBlock value:responders value:(1 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   833
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   834
                ].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   835
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   836
                "/ namespace vars
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   837
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   838
                    names := classOrNil topNameSpace keys.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   839
                    names := names reject:[:nm | nm includes:$:].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   840
                    names := names select:[:nm | nm isUppercaseFirst ].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   841
                    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   842
                    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   843
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   844
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   845
                ].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   846
            ].
3470
5cbf651bb214 name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents: 3366
diff changeset
   847
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   848
            "/ globals
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   849
            names := Smalltalk keys.
3718
a720a0edb5c7 namespace globals
Claus Gittinger <cg@exept.de>
parents: 3693
diff changeset
   850
            "/ names := names reject:[:nm | nm includes:$:].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   851
            names := names select:[:nm | nm isUppercaseFirst ].
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   852
            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   853
            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   854
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   855
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
4087
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   856
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   857
            "/ pool variables
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   858
            classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   859
                |pool names|
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   860
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   861
                pool := Smalltalk at:poolName.
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   862
                names := pool classVarNames.
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   863
                names := names select:[:nm | nm isUppercaseFirst ].
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   864
                responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   865
                nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   866
                addWithFactorBlock value:responders value:(2.5 * globalFactor).
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   867
                addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   868
            ].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   869
        ] ifFalse:[
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   870
            classOrNil notNil ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   871
                "/ private classes
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   872
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   873
                                   value:(1.75 * globalFactor).
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   874
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   875
                "/ class variables
4087
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   876
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   877
                classOrNil superclass notNil ifTrue:[
4087
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   878
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   879
                ].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   880
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   881
                "/ namespace vars
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   882
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   883
                    names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   884
                    names := names select:[:nm | nm isUppercaseFirst ].
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   885
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   886
                ].
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
   887
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   888
                "/ pool variables
4083
2b9e1ccc172c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4080
diff changeset
   889
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   890
                    |pool names|
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
   891
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   892
                    pool := Smalltalk at:poolName.
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   893
                    names := pool classVarNames.
4087
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   894
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   895
                ].
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
   896
            ].
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
   897
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   898
            "/ globals
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   899
            names := Smalltalk keys.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   900
            names := names select:[:nm | nm isUppercaseFirst ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   901
            addWithFactorBlock value:names value:(1.5 * globalFactor).
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   902
        ].
3550
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   903
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   904
        "/ pseudos - assuming that thisContext is seldom used.
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   905
        "/ also assuming, that nil is short so its usually typed in.
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   906
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   907
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   908
        addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
34c8ab9f403f much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents: 3549
diff changeset
   909
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   910
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   911
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   912
    bestAssoc := allDistances at:1.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   913
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   914
                                                           ifTrue:[el]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   915
                                                           ifFalse:[best]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   916
                                                    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   917
3660
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   918
    allDistances sort:[:a :b | 
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   919
                                a value > b value ifTrue:[
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   920
                                    true
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   921
                                ] ifFalse:[
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   922
                                    a value = b value ifTrue:[
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   923
                                        a key < b key
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   924
                                    ] ifFalse:[
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   925
                                        false
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   926
                                    ]
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   927
                                ]
5b165ed81191 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   928
                      ].
3554
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   929
    allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   930
    allTheBest size > 15 ifTrue:[
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   931
        allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
96238651bc4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   932
    ].
4047
bd93629fe049 changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4045
diff changeset
   933
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   934
    best := self askUserForCompletion:'variable' for:codeView at: node start from:(allTheBest collect:[:assoc | assoc key]).
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   935
    best isNil ifTrue:[^ self].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   936
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   937
"/ self showInfo:best.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   938
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   939
    start := node start.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   940
    stop := node stop.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   941
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   942
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   943
    codeView
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   944
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
3600
7398a06f6904 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3598
diff changeset
   945
        info:'Completion'.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   946
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   947
    (best startsWith:oldVar) ifTrue:[
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   948
        oldLen := stop - start + 1.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   949
        newLen := best size.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   950
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   951
        codeView dontReplaceSelectionOnInput
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   952
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   953
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   954
    "Created: / 10-11-2006 / 13:16:33 / cg"
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   955
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4087
974ab4810f3c changed: #codeCompletionForVariable:inClass:codeView:
Claus Gittinger <cg@exept.de>
parents: 4083
diff changeset
   956
    "Modified: / 30-10-2011 / 10:59:44 / cg"
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   957
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   958
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   959
findNodeForInterval:interval in:source
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   960
    |tree node|
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   961
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   962
    interval isEmpty ifTrue: [^ nil].
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   963
    RBParser isNil ifTrue: [^ nil].
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   964
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   965
    source = LastSource ifTrue:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   966
        tree := LastParseTree.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   967
    ] ifFalse:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   968
        tree := RBParser
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   969
                parseMethod:source
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   970
                onError: 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   971
                    [:str :err ":nodesSoFar" | 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   972
                        "Transcript showCR:'Parse-Error: ',str." 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   973
                        nil
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   974
                    ].
3905
ad2810a7e3de comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents: 3901
diff changeset
   975
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   976
        tree isNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   977
            "/ try to parse as an expression
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   978
            tree := RBParser
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   979
                    parseExpression:source
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   980
                    onError: 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   981
                        [:str :err ":nodesSoFar" | 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   982
                            "Transcript showCR:'Parse-Error: ',str." 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   983
                            nil
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   984
                        ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   985
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   986
            tree isNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   987
                ^ nil
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   988
            ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
   989
        ].
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   990
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   991
        LastSource := source.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   992
        LastParseTree := tree.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   993
    ].
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   994
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   995
    node := tree whichNodeIsContainedBy:interval.
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   996
    node isNil ifTrue: [
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   997
        node := tree bestNodeFor: interval.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
   998
        node isNil ifTrue: [
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
   999
            node := self findNodeIn:tree forInterval:interval
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1000
        ].
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  1001
    ].
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  1002
    ^ node
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  1003
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1004
    "Modified: / 06-07-2011 / 12:42:53 / cg"
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  1005
!
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  1006
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1007
findNodeForInterval:interval in:source allowErrors:allowErrors
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1008
    ^ self
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1009
        findNodeForInterval:interval in:source allowErrors:allowErrors  
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1010
        mustBeMethod:false
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1011
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1012
    "Modified: / 16-09-2011 / 14:52:28 / cg"
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1013
!
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1014
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1015
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1016
    "if mustBeMethod is true, do not try a regular expression (as in a workspace)."
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1017
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1018
    |tree "errCount" firstIntersectingNode onErrorBlock nodeGenerationHook|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1019
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1020
    interval isEmpty ifTrue: [^ nil].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1021
    RBParser isNil ifTrue: [^ nil].
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
  1022
    LastSource := nil.
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1023
    source = LastSource ifTrue:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1024
        tree := LastParseTree.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1025
    ] ifFalse:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1026
        onErrorBlock := 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1027
            [:str :err :nodesSoFar |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1028
                |nodes|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1029
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1030
                allowErrors ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1031
                    firstIntersectingNode notNil ifTrue:[^ firstIntersectingNode].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1032
                    nodes := nodesSoFar asOrderedCollection
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1033
                                collect:[:nd | nd whichNodeIntersects:interval]
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1034
                                thenSelect:[:nd | nd notNil ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1035
                    nodes size == 1 ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1036
                        ^ nodes first
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1037
                    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1038
                ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1039
                nil
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1040
            ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1041
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1042
        nodeGenerationHook := 
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1043
            [:node |
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1044
                "/ we would like to return here as soon as the node has been created by the parser;
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1045
                "/ however, at that time, its parent(chain) is not yet created and so we might not know
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1046
                "/ what the semantic intepretation (especially: scope of variable) will be.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1047
                "/ therefore, we parse all, and return the found node at the end.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1048
                "//// ^ node.
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1049
                firstIntersectingNode isNil ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1050
                    (node intersectsInterval:interval) ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1051
                        firstIntersectingNode := node
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1052
                    ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1053
                ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1054
            ].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1055
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1056
        tree := RBParser
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1057
                parseMethod:source
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1058
                onError: onErrorBlock
3720
f37c0d1757e3 use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  1059
                rememberNodes:true
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1060
                nodeGenerationCallback:nodeGenerationHook.   
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1061
"/                onError: [:str :err | errCount := (errCount?0) + 1. self halt.]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1062
"/                proceedAfterError:true.
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1063
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1064
        mustBeMethod ifTrue:[
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1065
            "/ only cache parsed methods
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1066
            tree notNil ifTrue:[
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1067
                LastSource := source.
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1068
                LastParseTree := tree.
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1069
            ].
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1070
        ] ifFalse:[    
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1071
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1072
                "/ try as an expression
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1073
                tree := RBParser
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1074
                        parseExpression:source
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1075
                        onError: onErrorBlock
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1076
                        rememberNodes:true
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1077
                        nodeGenerationCallback:nodeGenerationHook.   
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1078
            ].
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1079
        ].
4130
9ee47cc0138c changed:
Claus Gittinger <cg@exept.de>
parents: 4097
diff changeset
  1080
        firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1081
    ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1082
3306
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1083
    ^ self findNodeForInterval:interval inParseTree:tree.
3896
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1084
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
  1085
    "Created: / 16-09-2011 / 14:52:08 / cg"
3306
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1086
!
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1087
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1088
findNodeForInterval:interval inParseTree:parseTree
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1089
    |node|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1090
3306
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1091
    interval isEmpty ifTrue: [^ nil].
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1092
    parseTree isNil ifTrue:[^ nil].
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1093
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
  1094
    node := parseTree whichNodeIsContainedBy:interval.
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1095
    node isNil ifTrue:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1096
        node := parseTree whichNodeIntersects:interval.
3680
1e79e8081859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3667
diff changeset
  1097
        node isNil ifTrue: [
1e79e8081859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3667
diff changeset
  1098
            node := self findNodeIn:parseTree forInterval:interval
1e79e8081859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3667
diff changeset
  1099
        ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1100
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1101
    ^ node
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1102
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1103
    "Modified: / 10-11-2006 / 13:13:58 / cg"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1104
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1105
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1106
findNodeIn:tree forInterval:interval
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1107
    |nodeFound wouldReturn|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1108
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1109
    nodeFound := nil.
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1110
    tree nodesDo:[:eachNode |
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1111
        (eachNode intersectsInterval:interval) ifTrue:[
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1112
            (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1113
                nodeFound := eachNode
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1114
            ] ifFalse:[
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1115
                (nodeFound parent == eachNode parent
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1116
                and:[ eachNode start >= nodeFound start
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1117
                      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1118
                ] ifFalse:[
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1119
                    (nodeFound parent notNil
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1120
                    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1121
                ]
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1122
            ]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1123
        ] ifFalse:[
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1124
            nodeFound notNil ifTrue:[
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1125
                "/ already found one - beyond that one; leave
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1126
                wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1127
            ]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1128
        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1129
    ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1130
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1131
    ^ nodeFound
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1132
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1133
    "Modified: / 20-11-2006 / 12:31:12 / cg"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1134
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1135
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1136
lookupClassForMessage:node inClass:classProvidingNamespaceOrNil
3681
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1137
    |receiver nm nodeVal receiverClass|
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1138
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1139
    receiver := node receiver.
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1140
    receiver isLiteral ifTrue:[
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1141
        ^ receiver value class
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1142
    ].
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1143
    receiver isVariable ifTrue:[
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1144
        nm := receiver name.
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1145
        nm = 'self' ifTrue:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1146
            classProvidingNamespaceOrNil isNil ifTrue:[^ UndefinedObject].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1147
            ^ classProvidingNamespaceOrNil
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1148
        ].
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1149
        nm = 'super' ifTrue:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1150
            classProvidingNamespaceOrNil isNil ifTrue:[^ Object].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1151
            ^ classProvidingNamespaceOrNil superclass
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1152
        ].
3734
0e36383745e0 impreved node finding
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
  1153
        nm isUppercaseFirst ifTrue:[
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1154
            "/ wouldn't it be better to simply 'evaluate' the variable ?
3929
bf3f10bb97c7 changed: #lookupClassForMessage:inClass:
sr
parents: 3905
diff changeset
  1155
            Error handle:[:ex |
bf3f10bb97c7 changed: #lookupClassForMessage:inClass:
sr
parents: 3905
diff changeset
  1156
            ] do:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1157
                |dummyReceiver|
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1158
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1159
                dummyReceiver := classProvidingNamespaceOrNil notNil ifTrue:[classProvidingNamespaceOrNil basicNew] ifFalse:[nil].
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1160
                nodeVal := Parser new evaluate:nm in:nil receiver:dummyReceiver.
3929
bf3f10bb97c7 changed: #lookupClassForMessage:inClass:
sr
parents: 3905
diff changeset
  1161
            ].
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1162
"/            (Smalltalk includesKey:nm asSymbol) ifTrue:[
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1163
"/                nodeVal := Smalltalk at:nm asSymbol.
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1164
"/            ].
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1165
            nodeVal notNil ifTrue:[
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1166
                ^ nodeVal class
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1167
            ]
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1168
        ]
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1169
    ].
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1170
3681
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1171
    receiver isMessage ifTrue:[
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1172
        (receiver selector = 'new'
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1173
        or:[ receiver selector = 'new:' ]) ifTrue:[
4050
df578fc47076 changed:6 methods
Claus Gittinger <cg@exept.de>
parents: 4049
diff changeset
  1174
            receiverClass := self lookupClassForMessage:receiver inClass:classProvidingNamespaceOrNil.
3681
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1175
            receiverClass notNil ifTrue:[
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1176
                receiverClass isBehavior ifTrue:[
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1177
                    receiverClass isMeta ifTrue:[
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1178
                        ^ receiverClass theNonMetaclass
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1179
                    ]
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1180
                ]
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1181
            ].
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1182
        ].
4058
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1183
        classProvidingNamespaceOrNil notNil ifTrue:[
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1184
            (receiver receiver isSelf and:[receiver selector = 'class']) ifTrue:[
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1185
                ^ classProvidingNamespaceOrNil class
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1186
            ].
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1187
        ].
3681
6dca6308d156 better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents: 3680
diff changeset
  1188
    ].
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1189
    ^ nil
3929
bf3f10bb97c7 changed: #lookupClassForMessage:inClass:
sr
parents: 3905
diff changeset
  1190
bf3f10bb97c7 changed: #lookupClassForMessage:inClass:
sr
parents: 3905
diff changeset
  1191
    "Modified: / 24-08-2010 / 15:05:49 / sr"
4058
8221d2e915df changed:
Claus Gittinger <cg@exept.de>
parents: 4054
diff changeset
  1192
    "Modified: / 17-07-2011 / 10:28:19 / cg"
3356
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1193
!
b1e3ccd1bcf2 better messageSelector completion
Claus Gittinger <cg@exept.de>
parents: 3331
diff changeset
  1194
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1195
old_askUserForCompletion:what for:codeView from:allTheBest
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1196
    |list resources choice lastChoice|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1197
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1198
    allTheBest isEmpty ifTrue:[ ^ nil ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1199
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1200
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1201
    list := allTheBest.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1202
    LastChoices notNil ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1203
        lastChoice := LastChoices at:what ifAbsent:nil.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1204
        lastChoice notNil ifTrue:[
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
  1205
            (list includes: lastChoice) ifTrue:[
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
  1206
                list := {lastChoice. nil. } , (list copyWithout:lastChoice).
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
  1207
            ]
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1208
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1209
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1210
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1211
    list size < 30 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1212
        |menu idx exitKey|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1213
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1214
        menu := PopUpMenu labels:list.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1215
        menu hideOnKeyFilter:[:key | |hide|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1216
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1217
                hide ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1218
                    exitKey := key.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1219
                ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1220
                hide].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1221
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1222
        idx := menu startUp.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1223
        idx == 0 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1224
            exitKey notNil ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1225
                codeView keyPress:exitKey x:0 y:0.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1226
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1227
            ^ nil
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1228
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1229
        choice := list at:idx.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1230
    ] ifFalse:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1231
        resources := codeView application isNil 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1232
                        ifTrue:[ codeView resources]
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1233
                        ifFalse:[ codeView application resources ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1234
                    
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1235
        choice := Dialog
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1236
           choose:(resources string:'Choose ',what)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1237
           fromList:list
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1238
           lines:20
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1239
           title:(resources string:'Code completion').
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1240
        choice isNil ifTrue:[^ nil].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1241
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1242
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1243
    LastChoices isNil ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1244
        LastChoices := Dictionary new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1245
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1246
    LastChoices at:what put:choice.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1247
    ^ choice
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1248
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1249
    "Created: / 16-02-2010 / 09:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
  1250
    "Modified: / 21-07-2012 / 12:21:10 / cg"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1251
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1252
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1253
treeForCode:source allowErrors:allowErrors
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1254
    |tree|
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1255
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1256
    source = LastSource ifTrue:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1257
        tree := LastParseTree.
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1258
    ] ifFalse:[
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1259
        tree := RBParser
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1260
                parseMethod:source
4097
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1261
                onError: [:str :err :nodesSoFar :parserOrNil|
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1262
                        allowErrors ifTrue:[
4097
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1263
                            "/ parserOrNil isNil if raised by the scanner
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1264
                            parserOrNil notNil ifTrue:[
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1265
                                ^ parserOrNil currentMethodNode
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1266
                            ]
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1267
                        ].
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1268
                        ^ nil
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1269
                    ]
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1270
                proceedAfterError:false
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1271
                rememberNodes:true.
3896
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1272
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1273
        tree notNil ifTrue:[
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1274
            LastSource := source.
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1275
            LastParseTree := tree.
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1276
        ]
3475
8ed28a1e4e37 cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
  1277
    ].
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1278
    ^ tree
3896
9a5437a71fdb comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1279
4097
e339cf5b41f6 changed: #treeForCode:allowErrors:
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
  1280
    "Modified: / 13-01-2012 / 11:54:30 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1282
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1283
!DoWhatIMeanSupport class methodsFor:'input completion support'!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1284
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1285
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1286
    "given a partial class category name, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1287
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1288
                2nd: collection consisting of matching categories"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1289
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1290
    |matches best lcName|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1291
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1292
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1293
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1294
    "/ search for exact match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1295
    anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1296
        |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1297
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1298
        category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1299
        (category notNil and:[category startsWith:aPartialCategory]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1300
            matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1301
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1302
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1303
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1304
        "/ search for case-ignoring match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1305
        lcName := aPartialCategory asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1306
        anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1307
            |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1308
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1309
            category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1310
            (category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1311
                matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1312
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1313
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1314
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1315
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1316
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1317
        ^ Array with:aPartialCategory with:(Array with:aPartialCategory)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1318
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1319
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1320
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1321
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1322
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1323
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1324
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1325
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1326
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1327
     Smalltalk classCategoryCompletion:'Sys'    
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1328
     Smalltalk classCategoryCompletion:'System'              
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1329
     Smalltalk classCategoryCompletion:'System-BinaryStorage' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1330
    "
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1331
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1332
    "Created: / 10-08-2006 / 13:06:45 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1333
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1334
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1335
classNameEntryCompletionBlock
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1336
    "this block can be used in a dialog to perform className completion"
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1337
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1338
    ^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:'
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1339
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1340
    "Modified: / 10-08-2006 / 13:22:02 / cg"
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1341
!
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1342
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1343
classnameCompletion:aPartialClassName filter:filterBlock inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1344
    "given a partial classname, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1345
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1346
                2nd: collection consisting of matching names"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1347
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1348
    |searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix 
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1349
     others lcSearchName tryToMatch idx words w1 w2 rslt bestMatch matchesForLongestPrefix|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1350
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1351
    aPartialClassName isEmpty ifTrue:[
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1352
        matches := Smalltalk allClassesForWhich:filterBlock.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1353
        ^ InputCompletionResult bestName:aPartialClassName matchingNames:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1354
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1355
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1356
    (words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1357
        w1 := words first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1358
        w2 := words second.
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1359
        rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1360
        bestMatch := rslt first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1361
        matches := rslt second.
3549
c7c19ab7e225 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3547
diff changeset
  1362
        ('class' copyTo:(w2 size min:5)) = w2 ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1363
            matches := matches collect:[:m | m , ' class'].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1364
            bestMatch := bestMatch , ' class'.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1365
        ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1366
        ^ InputCompletionResult bestName:bestMatch matchingNames:matches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1367
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1368
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1369
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1370
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1371
        nsPrefix := 'Smalltalk::'.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1372
        searchName := aPartialClassName copyFrom:'Smalltalk::' size + 1
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1373
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1374
        nsPrefix := ''.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1375
        searchName := aPartialClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1376
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1377
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1378
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1379
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1380
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1381
    isMatchString := searchName includesMatchCharacters.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1382
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1383
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1384
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1385
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1386
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1387
    tryToMatch := 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1388
        [:className :fullClassName|
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1389
            |addIt|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1390
"/ (className startsWith:'JavaScript') ifTrue:[self halt].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1391
            isMatchString ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1392
                addIt := searchName match:className
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1393
            ] ifFalse:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1394
                addIt := className startsWith:searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1395
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1396
            addIt ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1397
                matches add:(nsPrefix , fullClassName).
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1398
                matchedNamesWithoutPrefix add:className.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1399
            ] ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1400
                "/ try ignoring case
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1401
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1402
                isMatchString ifTrue:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1403
                    addIt := searchName match:className ignoreCase:true
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1404
                ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1405
                    addIt := className asLowercase startsWith:lcSearchName.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1406
                    addIt ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1407
                        others add:className 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1408
                    ]
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1409
                ].
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1410
                addIt ifTrue:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1411
                    ignCaseMatches add:(nsPrefix , fullClassName).
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1412
                    matchedNamesWithoutPrefix add:className.
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1413
                ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1414
            ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1415
            addIt
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1416
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1417
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1418
    anEnvironment allClassesForWhich:filterBlock do:[:aClass |
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1419
        |addIt fullClassName classNameWithoutPrefix|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1420
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1421
        aClass isMeta ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1422
            fullClassName := aClass name.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1423
            classNameWithoutPrefix := aClass nameWithoutPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1424
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1425
            addIt := tryToMatch value:fullClassName value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1426
            addIt ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1427
                classNameWithoutPrefix ~~ fullClassName ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1428
                    tryToMatch value:classNameWithoutPrefix value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1429
                ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1430
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1431
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1432
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1433
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1434
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1435
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1436
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1437
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1438
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1439
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1440
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1441
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1442
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1443
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1444
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1445
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1446
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1447
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1448
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1449
"/"/            dist := lcClassName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1450
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1451
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1452
"/"/            dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1453
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1454
"/"/            dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1455
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1456
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1457
"/"/            ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1458
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1459
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1460
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1461
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1462
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1463
    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1464
        ^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1465
    ].                           
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1466
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1467
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1468
        best := matches first.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1469
        ^ InputCompletionResult bestName:best matchingNames:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1470
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1471
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1472
    matches 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1473
        sort:[:name1 :name2 |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1474
            "name1 comes before:name2 iff"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1475
            ((name2 includes:$:) and:[(name1 includes:$:) not])
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1476
            or:[ ((name1 includes:$:) == (name2 includes:$:))
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1477
                  and:[ (name1 size < name2 size) 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1478
                        or: [ name1 < name2 ]]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1479
               ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1480
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1481
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1482
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1483
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1484
    ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1485
        matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1486
        best := ignCaseMatches isEmpty
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1487
                    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1488
                    ifFalse:[ matchesForLongestPrefix longestCommonPrefixIgnoreCase:true ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1489
3198
fea29ae859c9 classnamecompletion fixed when namespace is involved
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1490
        best size < aPartialClassName size "best size == 0" ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1491
            best := matchedNamesWithoutPrefix longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1492
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1493
        best size == 0 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1494
            "if tried again, return next match"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1495
            idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1496
            idx ~~ 1 ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1497
                ^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1498
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1499
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1500
        best size < aPartialClassName size ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1501
            best := aPartialClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1502
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1503
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1504
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1505
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1506
    (cls isBehavior and:[cls isNameSpace]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1507
        (matches conform:[:each | each = best
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1508
                                 or:[each startsWith:(best , '::')]])
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1509
        ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1510
            best := best , '::'
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1511
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1512
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1513
    ^ InputCompletionResult bestName:best matchingNames:matches asArray
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1514
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1515
    "
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1516
     Smalltalk classnameCompletion:'Arr'    
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1517
     Smalltalk classnameCompletion:'Arra' 
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  1518
     Smalltalk classnameCompletion:'arra'  
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1519
     Smalltalk classnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1520
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1521
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1522
    "Created: / 10-08-2006 / 13:01:08 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1523
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1524
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1525
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1526
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1527
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1528
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1529
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1530
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1531
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1532
        filter:[:cls | true] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1533
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1534
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1535
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1536
     Smalltalk classnameCompletion:'Arr' 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1537
     Smalltalk classnameCompletion:'Arra' 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1538
     Smalltalk classnameCompletion:'arra' 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1539
     Smalltalk classnameCompletion:'*rray' 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1540
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1541
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1542
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1543
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1544
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1545
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1546
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1547
    "this block can be used in a dialog to perform className completion"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1548
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1549
    ^ [:contents :field  |
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1550
          |s what m|
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1551
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1552
          s := contents withoutSpaces.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1553
          field topView withCursor:(Cursor questionMark) do:[  
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1554
              what := self perform:completionSelector with:s with:Smalltalk.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1555
          ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1556
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1557
          field contents:(what first).
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1558
          (what at:2) size ~~ 1 ifTrue:[
3693
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
  1559
              UserPreferences current beepInEditor ifTrue:[                
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
  1560
                field device beep
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
  1561
              ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1562
          ]
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1563
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1564
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1565
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1566
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1567
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1568
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1569
    "given a partial globalName, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1570
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1571
                2nd: collection consisting of matching names"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1572
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1573
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1574
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1575
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1576
     Smalltalk globalnameCompletion:'Arr' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1577
     Smalltalk globalnameCompletion:'Arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1578
     Smalltalk globalnameCompletion:'arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1579
     Smalltalk globalnameCompletion:'*rray' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1580
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1581
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1582
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1583
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1584
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1585
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1586
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1587
     2 entries: 1st: the best (longest) match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1588
                2nd: collection consisting of matching names"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1589
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1590
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1591
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1592
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1593
    searchName isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1594
        ^ Array with:searchName with:#()
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1595
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1596
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1597
    (searchName at:1) isLowercase ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1598
        searchName := searchName copy asUppercaseFirst
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1599
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1600
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1601
    isMatchString := doMatch and:[ searchName includesMatchCharacters ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1602
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1603
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1604
    anEnvironment keysDo:[:aGlobalName |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1605
        | addIt|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1606
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1607
        isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1608
            addIt := searchName match:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1609
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1610
            addIt := aGlobalName startsWith:searchName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1611
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1612
        addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1613
            matches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1614
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1615
            "/ try ignoring case
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1616
            isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1617
                addIt := searchName match:aGlobalName ignoreCase:true
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1618
            ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1619
                addIt := aGlobalName asLowercase startsWith:searchName asLowercase
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1620
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1621
            addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1622
                ignCaseMatches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1623
            ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1624
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1625
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1626
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1627
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1628
        matches := ignCaseMatches
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1629
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1630
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1631
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1632
        ^ Array with:searchName with:(Array with:searchName)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1633
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1634
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1635
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1636
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1637
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1638
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1639
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1640
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1641
        best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1642
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1643
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1644
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1645
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1646
     Smalltalk globalnameCompletion:'Arr' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1647
     Smalltalk globalnameCompletion:'Arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1648
     Smalltalk globalnameCompletion:'arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1649
     Smalltalk globalnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1650
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1651
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1652
    "Created: / 10-08-2006 / 13:06:23 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1653
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1654
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1655
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1656
    "given a partial method protocol name, return an array consisting of
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1657
     2 entries: 1st: the best (longest) match 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1658
                2nd: collection consisting of matching protocols"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1659
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1660
    |matches best lcName|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1661
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1662
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1663
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1664
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1665
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1666
        |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1667
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1668
        protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1669
        (protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1670
            matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1671
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1672
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1673
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1674
        "/ search for case-ignoring match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1675
        lcName := aPartialProtocolName asLowercase.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1676
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1677
            |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1678
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1679
            protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1680
            (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1681
                matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1682
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1683
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1684
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1685
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1686
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1687
        ^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1688
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1689
    matches size == 1 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1690
        ^ Array with:matches first with:(matches asArray)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1691
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1692
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1693
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1694
    ^ Array with:best with:matches asArray
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1695
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1696
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1697
     Smalltalk methodProtocolCompletion:'doc'
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1698
     Smalltalk methodProtocolCompletion:'docu' 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1699
     Smalltalk methodProtocolCompletion:'documenta' 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1700
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1701
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1702
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1703
    "Modified: / 16-03-2011 / 12:30:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1704
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
  1705
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1706
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1707
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1708
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1709
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1710
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1711
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1712
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1713
        filter:[:cls | cls isNameSpace] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1714
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1715
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1716
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1717
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk  
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1718
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1719
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1720
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1721
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1722
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1723
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1724
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1725
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1726
                2nd: collection consisting of matching packages"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1727
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1728
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1729
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1730
    matches := IdentitySet new.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1731
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1732
    "/ search for exact match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1733
    anEnvironment allClassesDo:[:aClass |
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1734
        |package|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1735
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1736
        package := aClass package.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1737
        (package notNil and:[package startsWith:aPartialPackage]) ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1738
            matches add:package
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1739
        ]
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1740
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1741
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1742
        "/ search for case-ignoring match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1743
        lcName := aPartialPackage asLowercase.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1744
        anEnvironment allClassesDo:[:aClass |
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1745
            |package|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1746
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1747
            package := aClass package.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1748
            (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1749
                matches add:package
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1750
            ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1751
        ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1752
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1753
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1754
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1755
        ^ Array with:aPartialPackage with:(Array with:aPartialPackage)
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1756
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1757
    matches size == 1 ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1758
        ^ Array with:matches first with:(matches asArray)
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1759
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1760
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1761
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1762
    ^ Array with:best with:matches asArray
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1763
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1764
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1765
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk   
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1766
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk                
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1767
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1768
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  1769
    "Created: / 10-08-2006 / 13:05:07 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1770
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1771
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1772
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1773
    "this block can be used in a dialog to perform className completion"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1774
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1775
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1776
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1777
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1778
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
  1779
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1780
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1781
    "given a partial resource name, return an array consisting of
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1782
     2 entries: 1st: the longest match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1783
                2nd: collection consisting of matching defined resources"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1784
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1785
    |matches best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1786
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1787
    matches := IdentitySet new.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1788
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1789
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1790
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1791
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1792
        eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1793
            eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1794
                (isMatch 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1795
                    ifTrue:[ (aPartialResourceName match:eachResourceName ignoreCase:ignoreCase) ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1796
                    ifFalse:[ ignoreCase 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1797
                                ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ]  
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1798
                                ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1799
                ) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1800
                    matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1801
                ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1802
            ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1803
        ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1804
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1805
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1806
        "/ search for case-ignoring match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1807
        lcSym := aPartialResourceName asLowercase.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1808
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1809
            eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1810
                eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1811
                    (isMatch 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1812
                        ifTrue:[ (aPartialResourceName match:eachResourceName ignoreCase:true) ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1813
                        ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ])
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1814
                     ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1815
                        matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1816
                    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1817
                ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1818
            ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1819
        ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1820
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1821
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1822
    matches isEmpty ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1823
        ^ Array with:aPartialResourceName with:#() 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1824
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1825
    matches size == 1 ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1826
        ^ Array with:matches first with:(matches asArray)
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1827
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1828
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1829
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1830
    ^ Array with:best with:matches asArray
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1831
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1832
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1833
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1834
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1835
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1836
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1837
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1838
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1839
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1840
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
  1841
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1842
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1843
    "given a partial selector, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1844
     2 entries: 1st: the longest match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1845
                2nd: collection consisting of matching implemented selectors"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1846
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1847
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1848
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1849
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1850
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1851
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1852
     2 entries: 1st: the longest match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1853
                2nd: collection consisting of matching implemented selectors"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1854
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1855
    ^ self 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1856
        selectorCompletion:aPartialSymbolName 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1857
        inEnvironment:anEnvironment 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1858
        match:doMatch 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1859
        ignoreCase:false
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1860
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1861
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1862
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1863
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1864
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1865
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1866
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1867
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1868
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1869
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1870
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1871
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1872
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1873
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1874
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1875
     2 entries: 1st: the longest match
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1876
                2nd: collection consisting of matching implemented selectors"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1877
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1878
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1879
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1880
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1881
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1882
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1883
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1884
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1885
        (isMatch 
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1886
            ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:ignoreCase) ]
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1887
            ifFalse:[ ignoreCase 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1888
                        ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ]  
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1889
                        ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ])
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1890
         ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1891
            matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1892
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1893
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1894
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1895
        "/ search for case-ignoring match
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1896
        lcSym := aPartialSymbolName asLowercase.
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1897
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1898
            (isMatch 
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1899
                ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:true) ]
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1900
                ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ])
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  1901
             ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
  1902
                matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1903
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1904
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1905
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1906
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1907
    matches isEmpty ifTrue:[
3864
10c7db09a580 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1908
        ^ Array with:aPartialSymbolName with:#() "/ (Array with:aPartialSymbolName)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1909
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1910
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1911
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1912
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1913
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1914
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1915
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1916
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1917
    "
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1918
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1919
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1920
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1921
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  1922
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1923
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1924
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1925
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
  1926
    "Created: / 26-10-2010 / 20:30:06 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1927
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  1928
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1929
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1930
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1931
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1932
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1933
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
  1934
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1935
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1936
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1937
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1938
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1939
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1940
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1941
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1942
    (lastNewName endsWith:lastOldName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1943
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1944
            'foo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1945
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1946
            'bar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1947
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1948
        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1949
        ^ (prefix , oldName).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1950
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1951
    (lastOldName endsWith:lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1952
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1953
            'Xfoo' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1954
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1955
            'Xbar' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1956
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1957
        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1958
        (oldName startsWith:prefix) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1959
            ^ (oldName copyFrom:prefix size+1).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1960
        ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1961
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1962
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1963
        (lastOldName first ~= lastNewName first) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1964
            (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1965
                "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1966
                    'xfoo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1967
                 then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1968
                    'xbar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1969
                "
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1970
                lastOldName first isLowercase ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1971
                    ^ oldName first asUppercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1972
                ] ifFalse:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1973
                    ^ oldName first asLowercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1974
                ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1975
            ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1976
        ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1977
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1978
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1979
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1980
            '  foo   ' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1981
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1982
            '  bar   ' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
  1983
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1984
        ^ oldName withoutSeparators.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1985
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1986
    (lastNewName startsWith:lastOldName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1987
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1988
            'foo' -> 'fooX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1989
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1990
            'bar' would be 'barX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1991
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1992
        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1993
        ^ (oldName , suffix).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1994
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1995
    (lastOldName startsWith:lastNewName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1996
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1997
            'fooX' -> 'foo'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1998
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1999
            'barX' would be 'bar'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2000
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2001
        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2002
        (oldName endsWith:suffix) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2003
            ^ (oldName copyWithoutLast:suffix size).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2004
        ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2005
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2006
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2007
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2008
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2009
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2010
    (prefix size > 0) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2011
        (suffix size > 0) ifTrue:[
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2012
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2013
            prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2014
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2015
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2016
                'fooR' -> 'fooXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2017
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2018
                'barR' would be 'barXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2019
            "
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2020
            left := lastOldName copyTo:prefix size.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2021
            right := lastOldName copyLast:suffix size.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2022
            lastNewSize > lastOldSize ifTrue:[
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2023
                inserted := (lastNewName copyFrom:(left size + 1)) copyWithoutLast:(right size).
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2024
                inserted size > 0 ifTrue:[
3532
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2025
                    (oldName startsWith:prefix) ifTrue:[
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2026
                        ^ (oldName copyTo:prefix size) , inserted , (oldName copyFrom:prefix size + 1) 
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2027
                    ].
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2028
                ].
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2029
            ].
3585
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2030
            (oldName string endsWith:suffix string) ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2031
                deleted := (lastOldName string copyFrom:(prefix size + 1)) copyWithoutLast:(suffix size).
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2032
                (oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2033
                    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2034
                        "last rename was 
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2035
                            'fooXR' -> 'fooR'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2036
                         then, a good default for
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2037
                            'barXS' would be 'barS'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2038
                        "
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2039
                        ^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
  2040
                    ]
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2041
                ]
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2042
            ]
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2043
        ].
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2044
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2045
        (oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2046
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2047
                'fooX' -> 'fooY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2048
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2049
                'barX' would be 'barY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2050
            "
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2051
            left := oldName copyWithoutLast:(lastOldName copyFrom:prefix size+1) size.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2052
            right := lastNewName copyFrom:prefix size+1.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2053
            ^ left , right
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2054
        ] 
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2055
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2056
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2057
    suffix size > 0 ifTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2058
        |prefix2|
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2059
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2060
        "last rename was:
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2061
            'fooSUFF1' -> 'barSUFF1'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2062
         then, a good default for
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2063
            'fooSUFF2' -> 'barSUFF2'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2064
        "
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2065
        prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2066
        (oldName startsWith:prefix) ifTrue:[    
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2067
            prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2068
            ^ prefix2,(oldName copyFrom:(prefix size+1)).
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2069
        ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2070
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2071
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2072
    "/ was there something stripped at the end?
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2073
    suffix := oldName commonSuffixWith:lastOldName. 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2074
    [suffix size > 0] whileTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2075
        tryAgain := self
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2076
                    goodRenameDefaultFor:(oldName copyWithoutLast:suffix size)
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2077
                    lastOld:(lastOldName copyWithoutLast:suffix size)
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2078
                    lastNew:lastNewName.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2079
        tryAgain notNil ifTrue:[^ tryAgain].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2080
        suffix := suffix copyFrom:2.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2081
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2082
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2083
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2084
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2085
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2086
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2087
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2088
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2089
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2090
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2091
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2092
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'  
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  2093
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2094
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2095
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
  2096
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'            
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
  2097
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'          
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2098
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2099
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  2100
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'  
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
  2101
     self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'  
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2102
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2103
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2104
                       lastOld:'mti.odt2.level1HeadlineMatchPattern' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2105
                       lastNew:'Key_odt2_level1HeadlineMatchPattern'  
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  2106
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2107
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  2108
    "Modified: / 24-07-2011 / 11:06:03 / cg"
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2109
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2110
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2111
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  2112
    "generate a reasonable default for a file rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  2113
     (Try to rename multiple files in the new fileBrowser, 
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  2114
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
  2115
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2116
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2117
     lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2118
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2119
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2120
    default := self goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName.
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2121
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  2122
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  2123
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  2124
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  2125
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2126
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2127
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2128
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2129
        lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2130
            ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2131
        ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2132
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  2133
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2134
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2135
    default notNil ifTrue:[ 
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2136
        lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2137
        lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2138
        oldRest := oldName copyFrom:oldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2139
        
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2140
        ^ default , lastNewRest
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2141
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  2142
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2143
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2144
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2145
        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2146
        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2147
        oldRest := oldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2148
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2149
        (lastNewRest endsWith:lastOldRest) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2150
            t := lastNewRest copyWithoutLast:lastOldRest size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2151
            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2152
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2153
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2154
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2155
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2156
    suffix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2157
        "/ last change changed something at the beginning
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2158
        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2159
        prefix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2160
            "/ this name starts with the same characters
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2161
            lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2162
            lastInserted := lastNewWOSuffix copyWithoutLast:suffix size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2163
            (lastRemoved startsWith:lastInserted) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2164
                oldWOSuffix size >= lastInserted size ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2165
                    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2166
                ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2167
            ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2168
            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2169
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2170
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2171
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2172
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  2173
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  2174
    "Modified: / 07-11-2006 / 13:58:39 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2175
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2176
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2177
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2178
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2179
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2180
    "return true, if k1 and k2 are adjacent keys on the keyboard.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2181
     This is used to specially priorize plausible typing errors of adjacent keys.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2182
     CAVEAT: hard coded us- and german keyboards here."
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2183
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2184
    ^ self isKey:k1 nextTo:k2 onKeyboard:(self keyboard)
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2185
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2186
    "
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2187
     self isKey:$a nextTo:$a   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2188
     self isKey:$a nextTo:$s   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2189
     self isKey:$a nextTo:$q   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2190
     self isKey:$a nextTo:$w   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  2191
     self isKey:$a nextTo:$z   
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  2192
     self isKey:$a nextTo:$x 
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2193
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2194
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2195
    "Modified: / 16-01-2008 / 17:17:31 / cg"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2196
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2197
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2198
isKey:k1 nextTo:k2 onKeyboard:keys
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2199
    "return true, if k1 and k2 are adjacent keys on the keyboard defined by keys"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2200
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2201
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2202
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2203
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  2204
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2205
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  2206
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2207
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2208
    ^ (row1-row2) abs <= 1 and:[(col1-col2) abs <= 1]
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2209
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2210
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  2211
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  2212
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2213
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2214
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2215
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2216
keyboard
4093
f98873e4d965 comment in: #keyboard
Claus Gittinger <cg@exept.de>
parents: 4087
diff changeset
  2217
    "the keyboard layout (useful to figure out which keys are nearby a key,
f98873e4d965 comment in: #keyboard
Claus Gittinger <cg@exept.de>
parents: 4087
diff changeset
  2218
     to find possible typing errors)"
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2219
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2220
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2221
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2222
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2223
    lang == #de ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2224
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2225
               '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2226
               '*qwertzuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2227
               '**asdfghjkl:'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2228
               '***yxcvbnm' ).
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2229
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2230
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2231
    lang == #fr ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2232
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2233
               '1234567890'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2234
               '*azertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2235
               '**qsdfghjklm'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2236
               '***wxcvbn,' ).
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2237
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2238
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2239
    ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2240
           '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2241
           '*qwertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2242
           '**asdfghjkl:'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2243
           '***zxcvbnm' ).
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2244
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2245
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2246
     self keyboard 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2247
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2248
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  2249
    "Created: / 16-01-2008 / 17:17:13 / cg"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2250
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  2251
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2252
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2253
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2254
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2255
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2256
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2257
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2258
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2259
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2260
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2261
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2262
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2263
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2264
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2265
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2266
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2267
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2268
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2269
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2270
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  2271
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2272
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2273
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  2274
version_CVS
4136
d2d772832f99 changed:
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
  2275
    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.93 2012-07-21 10:36:45 cg Exp $'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2276
! !