author | Claus Gittinger <cg@exept.de> |
Sun, 03 Jul 2011 16:27:01 +0200 | |
changeset 4045 | b2d1e9bb8c37 |
parent 4044 | 1ad77f8196e3 |
child 4047 | bd93629fe049 |
permissions | -rw-r--r-- |
2376 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libwidg2' }" |
|
13 |
||
14 |
Object subclass:#DoWhatIMeanSupport |
|
15 |
instanceVariableNames:'' |
|
3853 | 16 |
classVariableNames:'LastSource LastParseTree LastChoices' |
2376 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
19 |
! |
|
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 | 28 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
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 | 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 | 53 |
|
54 |
[author:] |
|
55 |
Claus Gittinger (cg@exept.de) |
|
56 |
||
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
57 |
" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
58 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
59 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
60 |
!DoWhatIMeanSupport class methodsFor:'code completion'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
61 |
|
4044 | 62 |
codeCompletionForClass:classOrNil codeView:codeView |
63 |
self codeCompletionForClass:classOrNil context:nil codeView:codeView |
|
64 |
||
65 |
"Modified (format): / 03-07-2011 / 15:49:49 / cg" |
|
3557 | 66 |
! |
67 |
||
4044 | 68 |
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView |
3900
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
69 |
"contextOrNil is the current context, if this is called from the debugger; |
3557 | 70 |
nil, if called from the browser. |
3900
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
71 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
72 |
This is not yet done, sigh" |
3557 | 73 |
|
3900
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
74 |
|crsrPos char interval source node checkedNode| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
75 |
|
4044 | 76 |
"/ classOrNil isNil ifTrue:[ |
77 |
"/ self information:'No class'. |
|
78 |
"/ ^ self. |
|
79 |
"/ ]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
80 |
|
3731
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
81 |
crsrPos := codeView characterPositionOfCursor-1. |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
82 |
char := codeView characterAtCharacterPosition:crsrPos. |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
83 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
84 |
crsrPos := crsrPos - 1. |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
85 |
char := codeView characterAtCharacterPosition:crsrPos. |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
86 |
]. |
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
87 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
88 |
interval := codeView selectedInterval. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
89 |
interval isEmpty ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
90 |
interval := crsrPos to:crsrPos. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
91 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
92 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
93 |
source := codeView contentsAsString string. |
3731
eb92d54a47ac
fixed code completion for selector
Claus Gittinger <cg@exept.de>
parents:
3720
diff
changeset
|
94 |
source := source copyTo:crsrPos. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
95 |
|
3720
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
96 |
"/ this is too naive and stupid; if there is a syntactic error, |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
97 |
"/ we will not find a node for a long time (stepping back more and more, |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
98 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
99 |
"/ without any progress. |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
100 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
101 |
"/ as it parses the code. Stop, when the interval is hit. |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
102 |
"/ that will also work for syntactic incorrect source code. |
3895
79124f2311a1
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
103 |
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
|
104 |
"/ [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
|
105 |
"/ "/ 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
|
106 |
"/ 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
|
107 |
"/ 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
|
108 |
"/ ^ self. |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
109 |
"/ ]. |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
110 |
"/ 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
|
111 |
"/ 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
|
112 |
"/ ]. |
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
113 |
node isNil ifTrue:[ |
3895
79124f2311a1
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
114 |
Transcript showCR:'No parseNode found'. |
79124f2311a1
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
^ self. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
118 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
119 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
120 |
(node isVariable |
3366 | 121 |
and:[ node parent notNil |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
122 |
and:[ node parent isMessage |
3366 | 123 |
and:[ node stop < (codeView characterPositionOfCursor-1) ]]]) ifTrue:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
124 |
node := node parent. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
125 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
126 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
127 |
node isVariable ifTrue:[ |
4044 | 128 |
self codeCompletionForVariable:node inClass:classOrNil codeView:codeView. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
129 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
130 |
]. |
3552
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
131 |
node isLiteral ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
132 |
node value isSymbol ifTrue:[ |
4044 | 133 |
self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView. |
3552
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
134 |
^ self. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
135 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
136 |
]. |
4044 | 137 |
classOrNil isNil ifTrue:[ |
138 |
^ self. |
|
139 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
140 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
141 |
checkedNode := node. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
142 |
[checkedNode notNil] whileTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
143 |
checkedNode isMessage ifTrue:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
144 |
"/ completion in a message-send |
4044 | 145 |
self codeCompletionForMessage:checkedNode inClass:classOrNil codeView:codeView. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
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 isMethod ifTrue:[ |
3900
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
149 |
"/ completion in a method's selector pattern |
4044 | 150 |
self codeCompletionForMethod:checkedNode inClass:classOrNil codeView:codeView. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
151 |
^ self. |
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 |
checkedNode := checkedNode parent. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
154 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
155 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
156 |
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
|
157 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
158 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
4044 | 159 |
"Modified: / 03-07-2011 / 15:59:25 / cg" |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
160 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
161 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
162 |
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
163 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
164 |
askUserForCompletion:what for:codeView from:allTheBest |
3853 | 165 |
|list resources choice lastChoice| |
3598 | 166 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
167 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
168 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
169 |
|
3853 | 170 |
list := allTheBest. |
171 |
LastChoices notNil ifTrue:[ |
|
172 |
lastChoice := LastChoices at:what ifAbsent:nil. |
|
173 |
lastChoice notNil ifTrue:[ |
|
174 |
list := {lastChoice. nil. } , (list copyWithout:lastChoice). |
|
175 |
]. |
|
176 |
]. |
|
177 |
||
178 |
list size < 30 ifTrue:[ |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
179 |
|menu idx exitKey| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
180 |
|
3853 | 181 |
menu := PopUpMenu labels:list. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
182 |
menu hideOnKeyFilter:[:key | |hide| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
183 |
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
|
184 |
hide ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
185 |
exitKey := key. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
186 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
187 |
hide]. |
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 |
idx := menu startUp. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
190 |
idx == 0 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
191 |
exitKey notNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
192 |
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
|
193 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
194 |
^ nil |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
195 |
]. |
3853 | 196 |
choice := list at:idx. |
197 |
] ifFalse:[ |
|
198 |
resources := codeView application isNil |
|
199 |
ifTrue:[ codeView resources] |
|
200 |
ifFalse:[ codeView application resources ]. |
|
3598 | 201 |
|
3853 | 202 |
choice := Dialog |
203 |
choose:(resources string:'Choose ',what) |
|
204 |
fromList:list |
|
205 |
lines:20 |
|
206 |
title:(resources string:'Code completion'). |
|
207 |
choice isNil ifTrue:[^ nil]. |
|
208 |
]. |
|
209 |
||
210 |
LastChoices isNil ifTrue:[ |
|
211 |
LastChoices := Dictionary new. |
|
212 |
]. |
|
213 |
LastChoices at:what put:choice. |
|
214 |
^ choice |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
215 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
216 |
"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
|
217 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
218 |
|
4044 | 219 |
codeCompletionForVariable:node inClass:classOrNil codeView:codeView |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
220 |
|nonMetaClass crsrPos nm |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
221 |
allVariables allDistances best nodeVal |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
222 |
char start stop oldLen newLen oldVar |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
223 |
getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
224 |
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
|
225 |
|
4044 | 226 |
classOrNil notNil ifTrue:[ |
227 |
nonMetaClass := classOrNil theNonMetaclass. |
|
228 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
229 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
230 |
nm := node name. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
231 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
232 |
"/ 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
|
233 |
"/ 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
|
234 |
"/ 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
|
235 |
crsrPos := codeView characterPositionOfCursor. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
236 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
237 |
char isSeparator ifTrue:[ |
4044 | 238 |
classOrNil isNil ifTrue:[ |
239 |
nodeVal := Smalltalk at:nm asSymbol. |
|
240 |
] ifFalse:[ |
|
241 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
242 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
243 |
nodeVal isBehavior ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
244 |
|methods menu exitKey idx| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
245 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
246 |
methods := nodeVal class methodDictionary values |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
247 |
select:[:m | |cat| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
248 |
cat := m category asLowercase. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
249 |
cat = 'instance creation' |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
250 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
251 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
252 |
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
|
253 |
menu hideOnKeyFilter:[:key | |hide| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
254 |
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
|
255 |
hide ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
256 |
exitKey := key. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
257 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
258 |
hide]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
259 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
260 |
idx := menu startUp. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
261 |
idx == 0 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
262 |
exitKey notNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
263 |
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
|
264 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
265 |
^ self |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
266 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
267 |
best := (methods at:idx) selector. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
268 |
codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
269 |
undoableDo:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
270 |
codeView insertString:best atCharacterPosition:crsrPos. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
271 |
codeView cursorToCharacterPosition:crsrPos+best size. |
3362 | 272 |
] |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
273 |
info:'completion'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
274 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
275 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
276 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
277 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
278 |
(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
|
279 |
node == node parent receiver ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
280 |
selectorOfMessageToNode := node parent selector |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
281 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
282 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
283 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
284 |
getDistanceComputeBlockWithWeight := |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
285 |
[:weight | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
286 |
[:each | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
287 |
|dist factor| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
288 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
289 |
dist := each spellAgainst:nm. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
290 |
factor := 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
291 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
292 |
(each startsWith:nm) ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
293 |
factor := 6 * nm size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
294 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
295 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
296 |
factor := 4 * nm size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
297 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
298 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
299 |
dist := dist + (weight*factor). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
300 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
301 |
each -> (dist * weight) |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
302 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
303 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
304 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
305 |
addWithFactorBlock := |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
306 |
[:names :factor | |namesToAdd| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
307 |
namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
308 |
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
|
309 |
allVariables addAll:namesToAdd. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
310 |
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
|
311 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
312 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
313 |
nm isUppercaseFirst ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
314 |
globalFactor := 2. "/ favour globals |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
315 |
localFactor := 1. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
316 |
] ifFalse:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
317 |
globalFactor := 1. "/ favour locals |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
318 |
localFactor := 2. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
319 |
]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
320 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
321 |
allVariables := OrderedCollection new. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
322 |
allDistances := OrderedCollection new. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
323 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
324 |
"/ are we in the methods selector spec ? |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
325 |
(node parent notNil |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
326 |
and:[node parent isMethod |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
327 |
and:[node parent arguments includes:node]]) ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
328 |
"/ 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
|
329 |
"/ 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
|
330 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
331 |
implementors := SystemBrowser |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
332 |
findImplementorsOf:(node parent selector) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
333 |
in:(Smalltalk allClasses) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
334 |
ignoreCase:false. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
335 |
"/ which argument is it |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
336 |
argIdx := node parent arguments indexOf:node. |
3554 | 337 |
implementors size > 50 ifTrue:[ |
338 |
implementors := implementors asOrderedCollection copyTo:50. |
|
339 |
]. |
|
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
340 |
namesUsed := (implementors |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
341 |
collect:[:eachImplementor | |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
342 |
|parseTree| |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
343 |
parseTree := eachImplementor parseTree. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
344 |
(parseTree notNil and:[parseTree arguments size > 0]) |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
345 |
ifFalse:nil |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
346 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
347 |
thenSelect:[:a | a notNil]) asSet. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
348 |
|
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
349 |
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
|
350 |
|
4044 | 351 |
classOrNil notNil ifTrue:[ |
352 |
"/ also, look for the keyword before the argument, |
|
353 |
"/ and see if there is such an instVar |
|
354 |
"/ if so, add it with -Arg |
|
355 |
node parent selector isKeyword ifTrue:[ |
|
356 |
kwPart := node parent selector keywords at:argIdx. |
|
357 |
(classOrNil allInstVarNames includes:(kwPart copyWithoutLast:1)) ifTrue:[ |
|
358 |
addWithFactorBlock |
|
359 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
360 |
value:(1 * localFactor). |
|
361 |
]. |
|
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
362 |
]. |
4044 | 363 |
] |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
364 |
] ifFalse:[ |
4044 | 365 |
classOrNil notNil ifTrue:[ |
366 |
"/ locals in the block/method |
|
367 |
names := node allVariablesOnScope. |
|
368 |
"/ if there were no variables (due to a parse error) |
|
369 |
"/ do another parse and see what we have |
|
370 |
names isEmpty ifTrue:[ |
|
371 |
tree := self treeForCode:(codeView contentsAsString string) allowErrors:true. |
|
372 |
"/ better if we already have a body (include locals then) |
|
373 |
"/ otherwise, only the arguments are considered |
|
374 |
tree notNil ifTrue:[ |
|
375 |
names := (tree body ? tree) allVariablesOnScope. |
|
376 |
] |
|
377 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
378 |
|
4044 | 379 |
addWithFactorBlock value:names value:(4 * localFactor). |
380 |
||
381 |
"/ instance variables |
|
382 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
3470
5cbf651bb214
name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents:
3366
diff
changeset
|
383 |
|
4044 | 384 |
"/ inherited instance variables |
385 |
classOrNil superclass notNil ifTrue:[ |
|
386 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
387 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
388 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
389 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
390 |
selectorOfMessageToNode notNil ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
391 |
|names responders nonResponders| |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
392 |
|
4044 | 393 |
"/ responding to that messsage |
394 |
||
395 |
classOrNil notNil ifTrue:[ |
|
396 |
"/ private classes |
|
397 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
398 |
value:(1.75 * globalFactor). |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
399 |
|
4044 | 400 |
"/ class variables |
401 |
names := nonMetaClass classVarNames. |
|
402 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
403 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
404 |
|
4044 | 405 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
406 |
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
|
407 |
|
4044 | 408 |
"/ superclass var names |
409 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
410 |
names := superClass classVarNames. |
|
411 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
412 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
413 |
||
414 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
|
415 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
416 |
]. |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
417 |
|
4044 | 418 |
"/ namespace vars |
419 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
420 |
names := classOrNil topNameSpace keys. |
|
421 |
names := names reject:[:nm | nm includes:$:]. |
|
422 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
423 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
424 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
425 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
426 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
427 |
]. |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
428 |
]. |
3470
5cbf651bb214
name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents:
3366
diff
changeset
|
429 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
430 |
"/ globals |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
431 |
names := Smalltalk keys. |
3718 | 432 |
"/ names := names reject:[:nm | nm includes:$:]. |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
433 |
names := names select:[:nm | nm isUppercaseFirst ]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
434 |
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
|
435 |
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
|
436 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
437 |
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
|
438 |
] ifFalse:[ |
4044 | 439 |
classOrNil notNil ifTrue:[ |
440 |
"/ private classes |
|
441 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
442 |
value:(1.75 * globalFactor). |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
443 |
|
4044 | 444 |
"/ class variables |
445 |
addWithFactorBlock value:nonMetaClass classVarNames value:(1.5 * globalFactor). |
|
446 |
classOrNil superclass notNil ifTrue:[ |
|
447 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(1 * globalFactor). |
|
448 |
]. |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
449 |
|
4044 | 450 |
"/ namespace vars |
451 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
452 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
453 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
454 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
455 |
]. |
|
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
456 |
|
4044 | 457 |
"/ pool variables |
458 |
classOrNil theNonMetaclass sharedPools do:[:poolName | |
|
459 |
|pool names| |
|
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
460 |
|
4044 | 461 |
pool := Smalltalk at:poolName. |
462 |
names := pool classVarNames. |
|
463 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
464 |
]. |
|
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
465 |
]. |
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
466 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
467 |
"/ globals |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
468 |
names := Smalltalk keys. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
469 |
names := names select:[:nm | nm isUppercaseFirst ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
470 |
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
|
471 |
]. |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
472 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
473 |
"/ pseudos - assuming that thisContext is seldom used. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
474 |
"/ 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
|
475 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
476 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
477 |
addWithFactorBlock value:#('super' 'false') value:(2 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
478 |
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
|
479 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
480 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
481 |
bestAssoc := allDistances at:1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
482 |
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
|
483 |
ifTrue:[el] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
484 |
ifFalse:[best] |
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 |
|
3660 | 487 |
allDistances sort:[:a :b | |
488 |
a value > b value ifTrue:[ |
|
489 |
true |
|
490 |
] ifFalse:[ |
|
491 |
a value = b value ifTrue:[ |
|
492 |
a key < b key |
|
493 |
] ifFalse:[ |
|
494 |
false |
|
495 |
] |
|
496 |
] |
|
497 |
]. |
|
3554 | 498 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)]. |
499 |
allTheBest size > 15 ifTrue:[ |
|
500 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)]. |
|
501 |
]. |
|
4044 | 502 |
self halt. |
503 |
best := self askUserForCompletion:'variable' for:codeView at: node start from:(allTheBest collect:[:assoc | assoc key]). |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
504 |
best isNil ifTrue:[^ self]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
505 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
506 |
"/ self showInfo:best. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
507 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
508 |
start := node start. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
509 |
stop := node stop. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
510 |
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
|
511 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
512 |
codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
513 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
3600 | 514 |
info:'Completion'. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
515 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
516 |
(best startsWith:oldVar) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
517 |
oldLen := stop - start + 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
518 |
newLen := best size. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
519 |
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
|
520 |
codeView dontReplaceSelectionOnInput |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
521 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
522 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
523 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
4044 | 524 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
525 |
"Modified: / 03-07-2011 / 16:17:05 / cg" |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
526 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
527 |
|
3300 | 528 |
findNodeForInterval:interval in:source |
529 |
|tree node| |
|
530 |
||
531 |
interval isEmpty ifTrue: [^ nil]. |
|
532 |
RBParser isNil ifTrue: [^ nil]. |
|
533 |
||
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
534 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
535 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
536 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
537 |
tree := RBParser |
3300 | 538 |
parseMethod:source |
3905
ad2810a7e3de
comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents:
3901
diff
changeset
|
539 |
onError: [:str :err ":nodesSoFar" | |
ad2810a7e3de
comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents:
3901
diff
changeset
|
540 |
"Transcript showCR:'Parse-Error: ',str." |
ad2810a7e3de
comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents:
3901
diff
changeset
|
541 |
^ nil]. |
ad2810a7e3de
comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents:
3901
diff
changeset
|
542 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
543 |
tree isNil ifTrue:[^ nil]. |
3300 | 544 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
545 |
LastSource := source. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
546 |
LastParseTree := tree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
547 |
]. |
3300 | 548 |
|
549 |
node := tree whichNodeIsContainedBy:interval. |
|
550 |
node isNil ifTrue: [ |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
551 |
node := tree bestNodeFor: interval. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
552 |
node isNil ifTrue: [ |
3734 | 553 |
node := self findNodeIn:tree forInterval:interval |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
554 |
]. |
3300 | 555 |
]. |
556 |
^ node |
|
557 |
||
3905
ad2810a7e3de
comment/format in: #findNodeForInterval:in:
Claus Gittinger <cg@exept.de>
parents:
3901
diff
changeset
|
558 |
"Modified: / 08-06-2010 / 13:20:30 / cg" |
3300 | 559 |
! |
560 |
||
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
561 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3751 | 562 |
|tree "errCount" firstIntersectingNode| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
563 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
564 |
interval isEmpty ifTrue: [^ nil]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
565 |
RBParser isNil ifTrue: [^ nil]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
566 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
567 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
568 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
569 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
570 |
tree := RBParser |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
571 |
parseMethod:source |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
572 |
onError: [:str :err :nodesSoFar | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
573 |
|nodes| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
574 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
575 |
allowErrors ifTrue:[ |
3751 | 576 |
firstIntersectingNode notNil ifTrue:[^ firstIntersectingNode]. |
3586 | 577 |
nodes := nodesSoFar asOrderedCollection |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
578 |
collect:[:nd | nd whichNodeIntersects:interval] |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
579 |
thenSelect:[:nd | nd notNil ]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
580 |
nodes size == 1 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
581 |
^ nodes first |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
582 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
583 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
584 |
^ nil] |
3720
f37c0d1757e3
use new rbparser callback-as-nodes-are-generated to find a node
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
585 |
rememberNodes:true |
3751 | 586 |
nodeGenerationCallback:[:node | |
587 |
"/ we would like to return here as soon as the node has been created by the parser; |
|
588 |
"/ however, at that time, its parent(chain) is not yet created and so we might not know |
|
589 |
"/ what the semantic intepretation (especially: scope of variable) will be. |
|
590 |
"/ therefore, we parse all, and return the found node at the end. |
|
591 |
"//// ^ node. |
|
592 |
firstIntersectingNode isNil ifTrue:[ |
|
593 |
(node intersectsInterval:interval) ifTrue:[ |
|
594 |
firstIntersectingNode := node |
|
595 |
]. |
|
596 |
]. |
|
3895
79124f2311a1
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
597 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
598 |
"/ 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
|
599 |
"/ proceedAfterError:true. |
3751 | 600 |
|
601 |
tree notNil ifTrue:[ |
|
602 |
LastSource := source. |
|
603 |
LastParseTree := tree. |
|
604 |
]. |
|
605 |
^ firstIntersectingNode |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
606 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
607 |
|
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
608 |
^ self findNodeForInterval:interval inParseTree:tree. |
3896
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
609 |
|
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
610 |
"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
|
611 |
! |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
612 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
613 |
findNodeForInterval:interval inParseTree:parseTree |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
614 |
|node| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
615 |
|
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
616 |
interval isEmpty ifTrue: [^ nil]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
617 |
parseTree isNil ifTrue:[^ nil]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
618 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
619 |
node := parseTree whichNodeIsContainedBy:interval. |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
620 |
node isNil ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
621 |
node := parseTree whichNodeIntersects:interval. |
3680 | 622 |
node isNil ifTrue: [ |
623 |
node := self findNodeIn:parseTree forInterval:interval |
|
624 |
]. |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
625 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
626 |
^ node |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
627 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
628 |
"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
|
629 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
630 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
631 |
findNodeIn:tree forInterval:interval |
3734 | 632 |
|nodeFound wouldReturn| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
633 |
|
3734 | 634 |
nodeFound := nil. |
635 |
tree nodesDo:[:eachNode | |
|
636 |
(eachNode intersectsInterval:interval) ifTrue:[ |
|
637 |
(nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[ |
|
638 |
nodeFound := eachNode |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
639 |
] ifFalse:[ |
3734 | 640 |
(nodeFound parent == eachNode parent |
641 |
and:[ eachNode start >= nodeFound start |
|
642 |
and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[ |
|
643 |
] ifFalse:[ |
|
644 |
(nodeFound parent notNil |
|
645 |
and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil] |
|
646 |
] |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
647 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
648 |
] ifFalse:[ |
3734 | 649 |
nodeFound notNil ifTrue:[ |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
650 |
"/ already found one - beyond that one; leave |
3734 | 651 |
wouldReturn notNil ifTrue:[wouldReturn := nodeFound]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
652 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
653 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
654 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
655 |
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt]. |
3734 | 656 |
^ nodeFound |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
657 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
658 |
"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
|
659 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
660 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
661 |
lookupClassForMessage:node inClass:classProvidingNamespace |
3681
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
662 |
|receiver nm nodeVal receiverClass| |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
663 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
664 |
receiver := node receiver. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
665 |
receiver isVariable ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
666 |
nm := receiver name. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
667 |
nm = 'self' ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
668 |
^ classProvidingNamespace |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
669 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
670 |
nm = 'super' ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
671 |
^ classProvidingNamespace superclass |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
672 |
]. |
3734 | 673 |
nm isUppercaseFirst ifTrue:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
674 |
"/ wouldn't it be better to simply 'evaluate' the variable ? |
3929 | 675 |
Error handle:[:ex | |
676 |
] do:[ |
|
677 |
nodeVal := Parser new evaluate:nm in:nil receiver:(classProvidingNamespace basicNew). |
|
678 |
]. |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
679 |
"/ (Smalltalk includesKey:nm asSymbol) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
680 |
"/ nodeVal := Smalltalk at:nm asSymbol. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
681 |
"/ ]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
682 |
nodeVal notNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
683 |
^ nodeVal class |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
684 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
685 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
686 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
687 |
receiver isLiteral ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
688 |
^ receiver value class |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
689 |
]. |
3681
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
690 |
receiver isMessage ifTrue:[ |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
691 |
(receiver selector = 'new' |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
692 |
or:[ receiver selector = 'new:' ]) ifTrue:[ |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
693 |
receiverClass := self lookupClassForMessage:receiver inClass:classProvidingNamespace. |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
694 |
receiverClass notNil ifTrue:[ |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
695 |
receiverClass isBehavior ifTrue:[ |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
696 |
receiverClass isMeta ifTrue:[ |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
697 |
^ receiverClass theNonMetaclass |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
698 |
] |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
699 |
] |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
700 |
]. |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
701 |
]. |
6dca6308d156
better selector completion for (class new) receivers
Claus Gittinger <cg@exept.de>
parents:
3680
diff
changeset
|
702 |
]. |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
703 |
^ nil |
3929 | 704 |
|
705 |
"Modified: / 24-08-2010 / 15:05:49 / sr" |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
706 |
! |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
707 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
708 |
treeForCode:source allowErrors:allowErrors |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
709 |
|tree| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
710 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
711 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
712 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
713 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
714 |
tree := RBParser |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
715 |
parseMethod:source |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
716 |
onError: [:str :err :nodesSoFar :parser| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
717 |
allowErrors ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
718 |
^ parser currentMethodNode |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
719 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
720 |
^ nil |
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 |
proceedAfterError:false |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
723 |
rememberNodes:true. |
3896
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
724 |
|
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
725 |
tree notNil ifTrue:[ |
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
726 |
LastSource := source. |
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
727 |
LastParseTree := tree. |
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
728 |
] |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
729 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
730 |
^ tree |
3896
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
731 |
|
9a5437a71fdb
comment/format in: #findNodeForInterval:in:allowErrors:
Claus Gittinger <cg@exept.de>
parents:
3895
diff
changeset
|
732 |
"Modified: / 27-04-2010 / 17:57:37 / cg" |
2376 | 733 |
! ! |
734 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
735 |
!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
|
736 |
|
2975 | 737 |
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
738 |
"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
|
739 |
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
|
740 |
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
|
741 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
742 |
|matches best lcName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
743 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
744 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
745 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
746 |
"/ search for exact match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
747 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
748 |
|category| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
749 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
750 |
category := aClass category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
751 |
(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
|
752 |
matches add:category |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
753 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
754 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
755 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
756 |
"/ search for case-ignoring match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
757 |
lcName := aPartialCategory asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
758 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
759 |
|category| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
760 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
761 |
category := aClass category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
762 |
(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
|
763 |
matches add:category |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
764 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
765 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
766 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
767 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
768 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
769 |
^ 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
|
770 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
771 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
772 |
^ 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
|
773 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
774 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
775 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
776 |
^ 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
|
777 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
778 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
779 |
Smalltalk classCategoryCompletion:'Sys' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
780 |
Smalltalk classCategoryCompletion:'System' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
781 |
Smalltalk classCategoryCompletion:'System-BinaryStorage' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
782 |
" |
2975 | 783 |
|
784 |
"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
|
785 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
786 |
|
2830 | 787 |
classNameEntryCompletionBlock |
788 |
"this block can be used in a dialog to perform className completion" |
|
789 |
||
2977 | 790 |
^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:' |
2830 | 791 |
|
2977 | 792 |
"Modified: / 10-08-2006 / 13:22:02 / cg" |
2830 | 793 |
! |
794 |
||
2975 | 795 |
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
|
796 |
"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
|
797 |
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
|
798 |
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
|
799 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
800 |
|searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
801 |
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
|
802 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
803 |
aPartialClassName isEmpty ifTrue:[ |
2975 | 804 |
matches := Smalltalk allClassesForWhich:filterBlock. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
805 |
^ InputCompletionResult bestName:aPartialClassName matchingNames:#() |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
806 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
807 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
808 |
(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
|
809 |
w1 := words first. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
810 |
w2 := words second. |
2975 | 811 |
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
|
812 |
bestMatch := rslt first. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
813 |
matches := rslt second. |
3549 | 814 |
('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
|
815 |
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
|
816 |
bestMatch := bestMatch , ' class'. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
817 |
]. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
818 |
^ 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
|
819 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
820 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
821 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
822 |
(aPartialClassName startsWith:'Smalltalk::') ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
823 |
nsPrefix := 'Smalltalk::'. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
824 |
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
|
825 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
826 |
nsPrefix := ''. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
827 |
searchName := aPartialClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
828 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
829 |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
830 |
searchName := searchName asUppercaseFirst. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
831 |
lcSearchName := searchName asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
832 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
833 |
isMatchString := searchName includesMatchCharacters. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
834 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
835 |
matchedNamesWithoutPrefix := Set new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
836 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
837 |
others := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
838 |
|
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
839 |
tryToMatch := |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
840 |
[:className :fullClassName| |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
841 |
|addIt| |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
842 |
"/ (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
|
843 |
isMatchString ifTrue:[ |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
844 |
addIt := searchName match:className |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
845 |
] ifFalse:[ |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
846 |
addIt := className startsWith:searchName. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
847 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
848 |
addIt ifTrue:[ |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
849 |
matches add:(nsPrefix , fullClassName). |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
850 |
matchedNamesWithoutPrefix add:className. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
851 |
] ifFalse:[ |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
852 |
"/ try ignoring case |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
853 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
854 |
isMatchString ifTrue:[ |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
855 |
addIt := searchName match:className ignoreCase:true |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
856 |
] ifFalse:[ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
857 |
addIt := className asLowercase startsWith:lcSearchName. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
858 |
addIt ifFalse:[ |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
859 |
others add:className |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
860 |
] |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
861 |
]. |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
862 |
addIt ifTrue:[ |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
863 |
ignCaseMatches add:(nsPrefix , fullClassName). |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
864 |
matchedNamesWithoutPrefix add:className. |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
865 |
]. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
866 |
]. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
867 |
addIt |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
868 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
869 |
|
2975 | 870 |
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
|
871 |
|addIt fullClassName classNameWithoutPrefix| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
872 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
873 |
aClass isMeta ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
874 |
fullClassName := aClass name. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
875 |
classNameWithoutPrefix := aClass nameWithoutPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
876 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
877 |
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
|
878 |
addIt ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
879 |
classNameWithoutPrefix ~~ fullClassName ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
880 |
tryToMatch value:classNameWithoutPrefix value:fullClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
881 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
882 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
883 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
884 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
885 |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
886 |
"/ matches isEmpty ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
887 |
"/ matches := ignCaseMatches. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
888 |
"/ ]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
889 |
matches := matches , ignCaseMatches. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
890 |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
891 |
"/ matches isEmpty ifTrue:[ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
892 |
"/ matches := ignCaseMatches. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
893 |
"/ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
894 |
"/"/ matches isEmpty ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
895 |
"/"/ | nearBy | |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
896 |
"/"/ nearBy := SortedCollection new sortBlock:[:a :b | a key < b key]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
897 |
"/"/ others do:[:className | |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
898 |
"/"/ |lcClassName dist cmpName| |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
899 |
"/"/ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
900 |
"/"/ lcClassName := className asLowercase. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
901 |
"/"/ 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
|
902 |
"/"/ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
903 |
"/"/ cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
904 |
"/"/ 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
|
905 |
"/"/ cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
906 |
"/"/ 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
|
907 |
"/"/ dist < 4 ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
908 |
"/"/ nearBy add:( dist -> (nsPrefix , className) ). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
909 |
"/"/ ] |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
910 |
"/"/ ]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
911 |
"/"/ matches := nearBy collect:[:eachPair | eachPair value]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
912 |
"/"/ ]. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
913 |
"/ ]. |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
914 |
|
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
915 |
matches isEmpty ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
916 |
^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName) |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
917 |
]. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
918 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
919 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
920 |
best := matches first. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
921 |
^ 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
|
922 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
923 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
924 |
matches |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
925 |
sort:[:name1 :name2 | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
926 |
"name1 comes before:name2 iff" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
927 |
((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
|
928 |
or:[ ((name1 includes:$:) == (name2 includes:$:)) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
929 |
and:[ (name1 size < name2 size) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
930 |
or: [ name1 < name2 ]] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
931 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
932 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
933 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
934 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
935 |
best := searchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
936 |
] ifFalse:[ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
937 |
matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
938 |
best := ignCaseMatches isEmpty |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
939 |
ifTrue:[ matchesForLongestPrefix longestCommonPrefix ] |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
940 |
ifFalse:[ matchesForLongestPrefix longestCommonPrefixIgnoreCase:true ]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
941 |
|
3198
fea29ae859c9
classnamecompletion fixed when namespace is involved
Claus Gittinger <cg@exept.de>
parents:
3135
diff
changeset
|
942 |
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
|
943 |
best := matchedNamesWithoutPrefix longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
944 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
945 |
best size == 0 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
946 |
"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
|
947 |
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
|
948 |
idx ~~ 1 ifTrue:[ |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
949 |
^ 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
|
950 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
951 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
952 |
best size < aPartialClassName size ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
953 |
best := aPartialClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
954 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
955 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
956 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
957 |
cls := anEnvironment classNamed:best. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
958 |
(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
|
959 |
(matches conform:[:each | each = best |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
960 |
or:[each startsWith:(best , '::')]]) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
961 |
ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
962 |
best := best , '::' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
963 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
964 |
]. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
965 |
^ 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
|
966 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
967 |
" |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
968 |
Smalltalk classnameCompletion:'Arr' |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
969 |
Smalltalk classnameCompletion:'Arra' |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
970 |
Smalltalk classnameCompletion:'arra' |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
971 |
Smalltalk classnameCompletion:'*rray' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
972 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
973 |
|
2975 | 974 |
"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
|
975 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
976 |
|
2975 | 977 |
classnameCompletion:aPartialClassName inEnvironment:anEnvironment |
978 |
"given a partial classname, return an array consisting of |
|
979 |
2 entries: 1st: the best (longest) match |
|
980 |
2nd: collection consisting of matching names" |
|
981 |
||
982 |
^ self |
|
983 |
classnameCompletion:aPartialClassName |
|
984 |
filter:[:cls | true] |
|
985 |
inEnvironment:anEnvironment |
|
986 |
||
987 |
" |
|
988 |
Smalltalk classnameCompletion:'Arr' |
|
989 |
Smalltalk classnameCompletion:'Arra' |
|
990 |
Smalltalk classnameCompletion:'arra' |
|
991 |
Smalltalk classnameCompletion:'*rray' |
|
992 |
" |
|
993 |
||
994 |
"Created: / 24-11-1995 / 17:24:45 / cg" |
|
995 |
"Modified: / 10-08-2006 / 13:01:30 / cg" |
|
996 |
! |
|
997 |
||
2977 | 998 |
entryCompletionBlockFor:completionSelector |
999 |
"this block can be used in a dialog to perform className completion" |
|
1000 |
||
1001 |
^ [:contents :field | |
|
1002 |
|s what m| |
|
1003 |
||
1004 |
s := contents withoutSpaces. |
|
1005 |
field topView withCursor:(Cursor questionMark) do:[ |
|
1006 |
what := self perform:completionSelector with:s with:Smalltalk. |
|
1007 |
]. |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
1008 |
|
2977 | 1009 |
field contents:(what first). |
1010 |
(what at:2) size ~~ 1 ifTrue:[ |
|
3693 | 1011 |
UserPreferences current beepInEditor ifTrue:[ |
1012 |
field device beep |
|
1013 |
] |
|
2977 | 1014 |
] |
1015 |
]. |
|
1016 |
||
1017 |
"Created: / 10-08-2006 / 13:21:37 / cg" |
|
1018 |
! |
|
1019 |
||
2975 | 1020 |
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1021 |
"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
|
1022 |
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
|
1023 |
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
|
1024 |
|
3863 | 1025 |
^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true |
1026 |
||
1027 |
" |
|
1028 |
Smalltalk globalnameCompletion:'Arr' |
|
1029 |
Smalltalk globalnameCompletion:'Arra' |
|
1030 |
Smalltalk globalnameCompletion:'arra' |
|
1031 |
Smalltalk globalnameCompletion:'*rray' |
|
1032 |
" |
|
1033 |
||
1034 |
"Created: / 10-08-2006 / 13:06:23 / cg" |
|
1035 |
! |
|
1036 |
||
1037 |
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch |
|
1038 |
"given a partial globalName, return an array consisting of |
|
1039 |
2 entries: 1st: the best (longest) match |
|
1040 |
2nd: collection consisting of matching names" |
|
1041 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1042 |
|searchName matches ignCaseMatches best isMatchString| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1043 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1044 |
searchName := aPartialGlobalName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1045 |
searchName isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1046 |
^ Array with:searchName with:#() |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1047 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1048 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1049 |
(searchName at:1) isLowercase ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1050 |
searchName := searchName copy asUppercaseFirst |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1051 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1052 |
|
3863 | 1053 |
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
|
1054 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1055 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1056 |
anEnvironment keysDo:[:aGlobalName | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1057 |
| addIt| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1058 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1059 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1060 |
addIt := searchName match:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1061 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1062 |
addIt := aGlobalName startsWith:searchName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1063 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1064 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1065 |
matches add:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1066 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1067 |
"/ try ignoring case |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1068 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1069 |
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
|
1070 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1071 |
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
|
1072 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1073 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1074 |
ignCaseMatches add:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1075 |
] |
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 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1078 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1079 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1080 |
matches := ignCaseMatches |
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 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1083 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1084 |
^ 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
|
1085 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1086 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1087 |
^ 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
|
1088 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1089 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1090 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1091 |
best := searchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1092 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1093 |
best := matches longestCommonPrefix. |
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 |
^ 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
|
1096 |
|
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 |
Smalltalk globalnameCompletion:'Arr' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1099 |
Smalltalk globalnameCompletion:'Arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1100 |
Smalltalk globalnameCompletion:'arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1101 |
Smalltalk globalnameCompletion:'*rray' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1102 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1103 |
|
2975 | 1104 |
"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
|
1105 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1106 |
|
2975 | 1107 |
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment |
1108 |
"given a partial name, return an array consisting of |
|
1109 |
2 entries: 1st: the best (longest) match |
|
1110 |
2nd: collection consisting of matching names" |
|
1111 |
||
1112 |
^ self |
|
1113 |
classnameCompletion:aPartialClassName |
|
1114 |
filter:[:cls | cls isNameSpace] |
|
1115 |
inEnvironment:anEnvironment |
|
1116 |
||
1117 |
" |
|
1118 |
DoWhatIMeanSupport nameSpaceCompletion:'To' inEnvironment:Smalltalk |
|
1119 |
" |
|
1120 |
||
1121 |
"Created: / 10-08-2006 / 13:02:16 / cg" |
|
1122 |
! |
|
1123 |
||
1124 |
packageCompletion:aPartialPackage inEnvironment:anEnvironment |
|
1125 |
"given a partial package name, return an array consisting of |
|
1126 |
2 entries: 1st: the best (longest) match |
|
1127 |
2nd: collection consisting of matching packages" |
|
1128 |
||
1129 |
|matches best lcName| |
|
1130 |
||
1131 |
matches := IdentitySet new. |
|
1132 |
||
1133 |
"/ search for exact match |
|
1134 |
anEnvironment allClassesDo:[:aClass | |
|
1135 |
|package| |
|
1136 |
||
1137 |
package := aClass package. |
|
1138 |
(package notNil and:[package startsWith:aPartialPackage]) ifTrue:[ |
|
1139 |
matches add:package |
|
1140 |
] |
|
1141 |
]. |
|
1142 |
matches isEmpty ifTrue:[ |
|
1143 |
"/ search for case-ignoring match |
|
1144 |
lcName := aPartialPackage asLowercase. |
|
1145 |
anEnvironment allClassesDo:[:aClass | |
|
1146 |
|package| |
|
1147 |
||
1148 |
package := aClass package. |
|
1149 |
(package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[ |
|
1150 |
matches add:package |
|
1151 |
]. |
|
1152 |
]. |
|
1153 |
]. |
|
1154 |
||
1155 |
matches isEmpty ifTrue:[ |
|
1156 |
^ Array with:aPartialPackage with:(Array with:aPartialPackage) |
|
1157 |
]. |
|
1158 |
matches size == 1 ifTrue:[ |
|
1159 |
^ Array with:matches first with:(matches asArray) |
|
1160 |
]. |
|
1161 |
matches := matches asSortedCollection. |
|
1162 |
best := matches longestCommonPrefix. |
|
1163 |
^ Array with:best with:matches asArray |
|
1164 |
||
1165 |
" |
|
1166 |
DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk |
|
1167 |
DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk |
|
1168 |
" |
|
1169 |
||
1170 |
"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
|
1171 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1172 |
|
2977 | 1173 |
packageNameEntryCompletionBlock |
1174 |
"this block can be used in a dialog to perform className completion" |
|
1175 |
||
1176 |
^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:' |
|
1177 |
||
1178 |
"Created: / 10-08-2006 / 13:22:31 / cg" |
|
1179 |
! |
|
1180 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1181 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1182 |
"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
|
1183 |
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
|
1184 |
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
|
1185 |
|
3863 | 1186 |
^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false |
1187 |
! |
|
1188 |
||
1189 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch |
|
1190 |
"given a partial selector, return an array consisting of |
|
1191 |
2 entries: 1st: the longest match |
|
1192 |
2nd: collection consisting of matching implemented selectors" |
|
1193 |
||
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1194 |
^ self |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1195 |
selectorCompletion:aPartialSymbolName |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1196 |
inEnvironment:anEnvironment |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1197 |
match:doMatch |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1198 |
ignoreCase:false |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1199 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1200 |
" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1201 |
DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1202 |
DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1203 |
DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1204 |
DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1205 |
DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1206 |
" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1207 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1208 |
"Modified: / 07-06-1996 / 08:44:33 / stefan" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1209 |
"Modified: / 26-10-2010 / 20:30:27 / cg" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1210 |
! |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1211 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1212 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1213 |
"given a partial selector, return an array consisting of |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1214 |
2 entries: 1st: the longest match |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1215 |
2nd: collection consisting of matching implemented selectors" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1216 |
|
3863 | 1217 |
|matches best lcSym isMatch| |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1218 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1219 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1220 |
|
3863 | 1221 |
isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters]. |
1222 |
||
3751 | 1223 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
3863 | 1224 |
(isMatch |
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1225 |
ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:ignoreCase) ] |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1226 |
ifFalse:[ ignoreCase |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1227 |
ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ] |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1228 |
ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ]) |
3863 | 1229 |
ifTrue:[ |
3751 | 1230 |
matches add:eachSelector |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1231 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1232 |
]. |
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1233 |
(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
|
1234 |
"/ search for case-ignoring match |
3867
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1235 |
lcSym := aPartialSymbolName asLowercase. |
3751 | 1236 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
3863 | 1237 |
(isMatch |
3867
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1238 |
ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:true) ] |
3863 | 1239 |
ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ]) |
1240 |
ifTrue:[ |
|
3751 | 1241 |
matches add:eachSelector |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1242 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1243 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1244 |
]. |
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 isEmpty ifTrue:[ |
3864
10c7db09a580
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1247 |
^ 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
|
1248 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1249 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1250 |
^ 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
|
1251 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1252 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1253 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1254 |
^ 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
|
1255 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1256 |
" |
3867
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1257 |
DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true |
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1258 |
DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true |
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1259 |
DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true |
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1260 |
DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true |
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
1261 |
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
|
1262 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1263 |
|
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1264 |
"Modified: / 07-06-1996 / 08:44:33 / stefan" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
1265 |
"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
|
1266 |
! ! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1267 |
|
2376 | 1268 |
!DoWhatIMeanSupport class methodsFor:'rename support'! |
1269 |
||
1270 |
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName |
|
2513 | 1271 |
"generate a reasonable default for a rename operation. |
1272 |
(used for rename category etc.)" |
|
2468 | 1273 |
|
2559 | 1274 |
|prefix suffix lastNewSize lastOldSize left right inserted deleted| |
2376 | 1275 |
|
1276 |
lastNewName isNil ifTrue:[ ^ nil]. |
|
1277 |
||
1278 |
lastNewSize := lastNewName size. |
|
1279 |
lastOldSize := lastOldName size. |
|
1280 |
||
1281 |
(lastNewName endsWith:lastOldName) ifTrue:[ |
|
2514 | 1282 |
"last rename was |
1283 |
'foo' -> 'Xfoo' |
|
1284 |
then, a good default for |
|
1285 |
'bar' would be 'Xbar' |
|
1286 |
" |
|
2376 | 1287 |
prefix := lastNewName copyTo:(lastNewSize - lastOldSize). |
1288 |
^ (prefix , oldName). |
|
1289 |
]. |
|
1290 |
(lastOldName endsWith:lastNewName) ifTrue:[ |
|
2514 | 1291 |
"last rename was |
1292 |
'Xfoo' -> 'foo' |
|
1293 |
then, a good default for |
|
1294 |
'Xbar' would be 'bar' |
|
1295 |
" |
|
2376 | 1296 |
prefix := lastOldName copyTo:(lastOldSize - lastNewSize). |
2514 | 1297 |
(oldName startsWith:prefix) ifTrue:[ |
1298 |
^ (oldName copyFrom:prefix size+1). |
|
1299 |
] |
|
1300 |
]. |
|
1301 |
(lastOldName asLowercase = lastNewName asLowercase) ifTrue:[ |
|
1302 |
(lastOldName first ~= lastNewName first) ifTrue:[ |
|
1303 |
(lastOldName first isLowercase = oldName first isLowercase) ifTrue:[ |
|
1304 |
"last rename was |
|
1305 |
'xfoo' -> 'Xfoo' |
|
1306 |
then, a good default for |
|
1307 |
'xbar' would be 'Xbar' |
|
1308 |
" |
|
1309 |
lastOldName first isLowercase ifTrue:[ |
|
1310 |
^ oldName first asUppercase asString , (oldName copyFrom:2). |
|
1311 |
] ifFalse:[ |
|
1312 |
^ oldName first asLowercase asString , (oldName copyFrom:2). |
|
1313 |
] |
|
1314 |
] |
|
1315 |
]. |
|
2376 | 1316 |
]. |
1317 |
(lastOldName withoutSeparators = lastNewName) ifTrue:[ |
|
2514 | 1318 |
"last rename was |
1319 |
' foo ' -> 'foo' |
|
1320 |
then, a good default for |
|
1321 |
' bar ' would be 'bar' |
|
1322 |
" |
|
2376 | 1323 |
^ oldName withoutSeparators. |
1324 |
]. |
|
1325 |
(lastNewName startsWith:lastOldName) ifTrue:[ |
|
2557 | 1326 |
"last rename was |
1327 |
'foo' -> 'fooX' |
|
1328 |
then, a good default for |
|
1329 |
'bar' would be 'barX' |
|
1330 |
" |
|
2376 | 1331 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize). |
1332 |
^ (oldName , suffix). |
|
1333 |
]. |
|
1334 |
(lastOldName startsWith:lastNewName) ifTrue:[ |
|
2557 | 1335 |
"last rename was |
1336 |
'fooX' -> 'foo' |
|
1337 |
then, a good default for |
|
1338 |
'barX' would be 'bar' |
|
1339 |
" |
|
2376 | 1340 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize). |
1341 |
(oldName endsWith:suffix) ifTrue:[ |
|
1342 |
^ (oldName copyWithoutLast:suffix size). |
|
1343 |
] |
|
1344 |
]. |
|
2558 | 1345 |
|
2557 | 1346 |
prefix := lastOldName commonPrefixWith:lastNewName. |
1347 |
suffix := lastOldName commonSuffixWith:lastNewName. |
|
2559 | 1348 |
|
2558 | 1349 |
(prefix size > 0) ifTrue:[ |
1350 |
(suffix size > 0) ifTrue:[ |
|
2559 | 1351 |
|
1352 |
prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size). |
|
1353 |
||
2558 | 1354 |
"last rename was |
1355 |
'fooR' -> 'fooXR' |
|
1356 |
then, a good default for |
|
1357 |
'barR' would be 'barXR' |
|
1358 |
" |
|
1359 |
left := lastOldName copyTo:prefix size. |
|
1360 |
right := lastOldName copyLast:suffix size. |
|
2559 | 1361 |
lastNewSize > lastOldSize ifTrue:[ |
1362 |
inserted := (lastNewName copyFrom:(left size + 1)) copyWithoutLast:(right size). |
|
1363 |
inserted size > 0 ifTrue:[ |
|
3532 | 1364 |
(oldName startsWith:prefix) ifTrue:[ |
1365 |
^ (oldName copyTo:prefix size) , inserted , (oldName copyFrom:prefix size + 1) |
|
1366 |
]. |
|
2559 | 1367 |
]. |
1368 |
]. |
|
3585 | 1369 |
(oldName string endsWith:suffix string) ifTrue:[ |
1370 |
deleted := (lastOldName string copyFrom:(prefix size + 1)) copyWithoutLast:(suffix size). |
|
1371 |
(oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[ |
|
1372 |
((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[ |
|
1373 |
"last rename was |
|
1374 |
'fooXR' -> 'fooR' |
|
1375 |
then, a good default for |
|
1376 |
'barXS' would be 'barS' |
|
1377 |
" |
|
1378 |
^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix |
|
1379 |
] |
|
2559 | 1380 |
] |
1381 |
] |
|
2558 | 1382 |
]. |
1383 |
||
1384 |
(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[ |
|
1385 |
"last rename was |
|
1386 |
'fooX' -> 'fooY' |
|
1387 |
then, a good default for |
|
1388 |
'barX' would be 'barY' |
|
1389 |
" |
|
1390 |
left := oldName copyWithoutLast:(lastOldName copyFrom:prefix size+1) size. |
|
1391 |
right := lastNewName copyFrom:prefix size+1. |
|
1392 |
^ left , right |
|
1393 |
] |
|
2557 | 1394 |
]. |
2376 | 1395 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1396 |
^ nil |
2557 | 1397 |
|
1398 |
" |
|
2558 | 1399 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX' |
1400 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo' |
|
1401 |
||
1402 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' |
|
1403 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
1404 |
||
1405 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' |
|
1406 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
1407 |
||
2559 | 1408 |
self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01' |
1409 |
self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY' |
|
2560 | 1410 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo' |
1411 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo' |
|
2559 | 1412 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo' |
1413 |
||
1414 |
self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001' |
|
2560 | 1415 |
self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar' |
2557 | 1416 |
" |
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1417 |
! |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1418 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1419 |
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
2513 | 1420 |
"generate a reasonable default for a file rename operation. |
1421 |
(Try to rename multiple files in the new fileBrowser, |
|
1422 |
to see what this is doing)" |
|
2468 | 1423 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1424 |
|prefix suffix t |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1425 |
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
|
1426 |
lastRemoved lastInserted default| |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1427 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1428 |
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
|
1429 |
default notNil ifTrue:[ ^ default]. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1430 |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1431 |
lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1432 |
lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1433 |
oldWOSuffix := oldName asFilename nameWithoutSuffix. |
2376 | 1434 |
|
2434 | 1435 |
"/ suffix change ? |
1436 |
lastOldWOSuffix = lastNewWOSuffix ifTrue:[ |
|
1437 |
lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[ |
|
1438 |
^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName |
|
1439 |
]. |
|
1440 |
]. |
|
1441 |
||
2553 | 1442 |
default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix. |
1443 |
default notNil ifTrue:[ |
|
1444 |
lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1. |
|
1445 |
lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1. |
|
1446 |
oldRest := oldName copyFrom:oldWOSuffix size + 1. |
|
1447 |
||
1448 |
^ default , lastNewRest |
|
1449 |
]. |
|
1450 |
||
2376 | 1451 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix. |
1452 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[ |
|
1453 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1. |
|
1454 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1. |
|
1455 |
oldRest := oldWOSuffix copyFrom:prefix size + 1. |
|
1456 |
||
1457 |
(lastNewRest endsWith:lastOldRest) ifTrue:[ |
|
1458 |
t := lastNewRest copyWithoutLast:lastOldRest size. |
|
1459 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name |
|
1460 |
]. |
|
1461 |
]. |
|
1462 |
||
1463 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix. |
|
1464 |
suffix size > 0 ifTrue:[ |
|
1465 |
"/ last change changed something at the beginning |
|
1466 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix. |
|
1467 |
prefix size > 0 ifTrue:[ |
|
1468 |
"/ this name starts with the same characters |
|
1469 |
lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size. |
|
1470 |
lastInserted := lastNewWOSuffix copyWithoutLast:suffix size. |
|
1471 |
(lastRemoved startsWith:lastInserted) ifTrue:[ |
|
1472 |
oldWOSuffix size >= lastInserted size ifTrue:[ |
|
1473 |
^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1) |
|
1474 |
] |
|
1475 |
]. |
|
1476 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1) |
|
1477 |
]. |
|
1478 |
]. |
|
1479 |
||
1480 |
^ nil |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1481 |
|
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1482 |
"Modified: / 07-11-2006 / 13:58:39 / cg" |
2376 | 1483 |
! ! |
1484 |
||
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1485 |
!DoWhatIMeanSupport class methodsFor:'typing distance'! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1486 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1487 |
isKey:k1 nextTo:k2 |
2774 | 1488 |
"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
|
1489 |
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
|
1490 |
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
|
1491 |
|
3316 | 1492 |
^ 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
|
1493 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1494 |
" |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1495 |
self isKey:$a nextTo:$a |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1496 |
self isKey:$a nextTo:$s |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1497 |
self isKey:$a nextTo:$q |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1498 |
self isKey:$a nextTo:$w |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1499 |
self isKey:$a nextTo:$z |
2517 | 1500 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1501 |
" |
3316 | 1502 |
|
1503 |
"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
|
1504 |
! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1505 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1506 |
isKey:k1 nextTo:k2 onKeyboard:keys |
2774 | 1507 |
"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
|
1508 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1509 |
|row1 row2 col1 col2| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1510 |
|
2774 | 1511 |
row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0]. |
2517 | 1512 |
row1 == 0 ifTrue:[^ false]. |
2774 | 1513 |
row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0]. |
2517 | 1514 |
row2 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1515 |
|
2774 | 1516 |
^ (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
|
1517 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1518 |
" |
2774 | 1519 |
self isKey:$a nextTo:$q |
2517 | 1520 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1521 |
" |
3316 | 1522 |
! |
1523 |
||
1524 |
keyboard |
|
1525 |
"the keyboard layout (to find possible typing errors)" |
|
1526 |
||
1527 |
|lang| |
|
1528 |
||
1529 |
lang := UserPreferences current language. |
|
1530 |
lang == #de ifTrue:[ |
|
1531 |
^ #( |
|
1532 |
'1234567890-' |
|
1533 |
'*qwertzuiop' |
|
1534 |
'**asdfghjkl:' |
|
1535 |
'***yxcvbnm' ). |
|
1536 |
]. |
|
1537 |
||
1538 |
lang == #fr ifTrue:[ |
|
1539 |
^ #( |
|
1540 |
'1234567890' |
|
1541 |
'*azertyuiop' |
|
1542 |
'**qsdfghjklm' |
|
1543 |
'***wxcvbn,' ). |
|
1544 |
]. |
|
1545 |
||
1546 |
^ #( |
|
1547 |
'1234567890-' |
|
1548 |
'*qwertyuiop' |
|
1549 |
'**asdfghjkl:' |
|
1550 |
'***zxcvbnm' ). |
|
1551 |
||
1552 |
" |
|
1553 |
self keyboard |
|
1554 |
" |
|
1555 |
||
1556 |
"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
|
1557 |
! ! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1558 |
|
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1559 |
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1560 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1561 |
bestName:bestNameArg matchingNames:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1562 |
^ self with:bestNameArg with:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1563 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1564 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1565 |
self bestName:123 matchingNames:345 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1566 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1567 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1568 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1569 |
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1570 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1571 |
bestName |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1572 |
^ self at:1 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1573 |
! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1574 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1575 |
matchingNames |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1576 |
^ self at:2 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1577 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
1578 |
|
2376 | 1579 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
1580 |
||
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1581 |
version_CVS |
4045
b2d1e9bb8c37
support non-class based code completion
Claus Gittinger <cg@exept.de>
parents:
4044
diff
changeset
|
1582 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.78 2011-07-03 14:27:01 cg Exp $' |
2376 | 1583 |
! ! |