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