author | HG Automerge |
Wed, 25 Jan 2017 17:42:13 +0000 | |
branch | jv |
changeset 5433 | e02d0b8d3f0e |
parent 5397 | 90fbd6970646 |
parent 5419 | 7ba6ce8016c2 |
child 5814 | 70d07365a2d4 |
permissions | -rw-r--r-- |
2376 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
4548 | 3 |
All Rights Reserved |
2376 | 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 |
||
4710 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
2376 | 16 |
Object subclass:#DoWhatIMeanSupport |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
17 |
instanceVariableNames:'tree tokens languageOrNil classOrNil methodOrNil contextOrNil |
4434 | 18 |
instanceOrNil codeView rememberedScopeNodes rememberedNodes |
19 |
codeAspect' |
|
4933 | 20 |
classVariableNames:'LastSource LastParseTree LastScanTokens LastChoices |
5044 | 21 |
LastCompletedSelectors Verbose' |
2376 | 22 |
poolDictionaries:'' |
23 |
category:'System-Support' |
|
24 |
! |
|
25 |
||
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
26 |
Array variableSubclass:#InputCompletionResult |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
27 |
instanceVariableNames:'' |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
28 |
classVariableNames:'' |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
29 |
poolDictionaries:'' |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
30 |
privateIn:DoWhatIMeanSupport |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
31 |
! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
32 |
|
2376 | 33 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
34 |
||
35 |
copyright |
|
36 |
" |
|
37 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
4548 | 38 |
All Rights Reserved |
2376 | 39 |
|
40 |
This software is furnished under a license and may be used |
|
41 |
only in accordance with the terms of that license and with the |
|
42 |
inclusion of the above copyright notice. This software may not |
|
43 |
be provided or otherwise made available to, or used by, any |
|
44 |
other person. No title to or ownership of the software is |
|
45 |
hereby transferred. |
|
46 |
" |
|
47 |
! |
|
48 |
||
49 |
documentation |
|
50 |
" |
|
4352 | 51 |
Attention: this is currently being rewritten and refactored. |
52 |
Don't get mad at the ugly (and duplicate) code. |
|
53 |
Will cleanup when finished. |
|
54 |
||
2376 | 55 |
misc collected UI support (functional) |
4548 | 56 |
These used to be in the Smalltalk and SystemBrowser class; |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
57 |
however, they are only needed for programmers, and some of the stuff is useful in multiple |
4548 | 58 |
places. |
3667 | 59 |
Therefore it is: |
4548 | 60 |
1) not needed for standalone executables |
61 |
2) published here to avoid multiple implementations |
|
2376 | 62 |
|
63 |
[author:] |
|
4548 | 64 |
Claus Gittinger (cg@exept.de) |
2376 | 65 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
66 |
" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
67 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
68 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
69 |
!DoWhatIMeanSupport class methodsFor:'code completion'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
70 |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
71 |
codeCompletionFor: aspect language: languageOrNil method:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
72 |
"aspect is so-called code-aspect symbol saying what's edited - #method, #expression, #classDefinition... |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
73 |
contextOrNil is the current context, if this is called from the debugger; |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
74 |
nil, if called from the browser. |
4591 | 75 |
If nonNil, we can make better guesses, |
76 |
because we actually know what a variable's type is." |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
77 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
78 |
^ self new |
4591 | 79 |
codeCompletionFor: aspect |
80 |
language: languageOrNil |
|
81 |
method:methodOrNil orClass:classOrNil |
|
82 |
context:contextOrNil |
|
83 |
codeView:codeView into:actionBlock |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
84 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
85 |
"Created: / 27-09-2013 / 10:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
86 |
! |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
87 |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
88 |
codeCompletionForLanguage: languageOrNil class: classOrNil context:contextOrNil codeView:codeView |
3900
82fa031be815
comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents:
3896
diff
changeset
|
89 |
"contextOrNil is the current context, if this is called from the debugger; |
3557 | 90 |
nil, if called from the browser. |
4591 | 91 |
If nonNil, we can make better guesses, |
92 |
because we actually know what a variable's type is." |
|
4238 | 93 |
|
4548 | 94 |
^ self new |
4591 | 95 |
codeCompletionForLanguage: languageOrNil |
96 |
class:classOrNil |
|
97 |
context:contextOrNil |
|
98 |
codeView:codeView |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
99 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
100 |
"Created: / 18-09-2013 / 13:34:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
101 |
! ! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
102 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
103 |
!DoWhatIMeanSupport class methodsFor:'code completion - obsolete'! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
104 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
105 |
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
106 |
<resource: #obsolete> |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
107 |
"contextOrNil is the current context, if this is called from the debugger; |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
108 |
nil, if called from the browser. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
109 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
110 |
This is not yet done, sigh" |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
111 |
|
4548 | 112 |
^ self |
113 |
codeCompletionForLanguage: nil class:classOrNil context:contextOrNil codeView:codeView |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
114 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
115 |
"Modified: / 18-09-2013 / 13:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4238 | 116 |
! |
117 |
||
118 |
codeCompletionForMethod:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
119 |
<resource: #obsolete> |
4238 | 120 |
"contextOrNil is the current context, if this is called from the debugger; |
121 |
nil, if called from the browser. |
|
122 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
|
123 |
This is not yet done, sigh" |
|
124 |
||
125 |
^ self new |
|
4548 | 126 |
codeCompletionForMethod:methodOrNil orClass:classOrNil |
127 |
context:contextOrNil |
|
128 |
codeView:codeView into:actionBlock |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
129 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
130 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
131 |
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
132 |
|
3300 | 133 |
findNodeForInterval:interval in:source |
5272 | 134 |
"utility" |
135 |
||
136 |
|tree node remember| |
|
137 |
||
138 |
interval isEmpty ifTrue: [^ nil]. |
|
139 |
RBParser isNil ifTrue: [^ nil]. |
|
140 |
||
141 |
source = LastSource ifTrue:[ |
|
142 |
tree := LastParseTree. |
|
143 |
] ifFalse:[ |
|
144 |
remember := true. |
|
145 |
LastSource := LastParseTree := nil. |
|
146 |
tree := RBParser |
|
147 |
parseMethod:source |
|
148 |
onError: |
|
149 |
[:str :err ":nodesSoFar" | |
|
150 |
"/ Transcript showCR:'Parse-Error: ',str. |
|
151 |
nil |
|
152 |
]. |
|
153 |
||
154 |
tree isNil ifTrue:[ |
|
155 |
"/ try to parse as an expression |
|
156 |
tree := RBParser |
|
157 |
parseExpression:source |
|
158 |
onError: |
|
159 |
[:str :err ":nodesSoFar" | |
|
160 |
"Transcript showCR:'Parse-Error: ',str." |
|
161 |
nil |
|
162 |
]. |
|
163 |
||
164 |
tree isNil ifTrue:[ |
|
165 |
"/ try to parse the selected text alone as expression |
|
166 |
remember := false. |
|
167 |
tree := RBParser |
|
5274 | 168 |
parseExpression:(source copyFrom:interval start to:(interval stop min:source size)) |
5272 | 169 |
onError: |
170 |
[:str :err ":nodesSoFar" | |
|
171 |
"Transcript showCR:'Parse-Error: ',str." |
|
172 |
nil |
|
173 |
]. |
|
174 |
^ tree |
|
175 |
]. |
|
176 |
]. |
|
177 |
remember ifTrue:[ |
|
178 |
LastSource := source. |
|
179 |
LastParseTree := tree. |
|
180 |
]. |
|
181 |
]. |
|
182 |
||
183 |
Error handle:[:ex | |
|
184 |
] do:[ |
|
185 |
node := tree whichNodeIsContainedBy:interval. |
|
186 |
]. |
|
187 |
node isNil ifTrue: [ |
|
188 |
node := tree bestNodeFor: interval. |
|
189 |
node isNil ifTrue: [ |
|
190 |
node := self findNodeIn:tree forInterval:interval |
|
191 |
]. |
|
192 |
]. |
|
193 |
^ node |
|
194 |
||
195 |
"Modified: / 06-07-2011 / 12:42:53 / cg" |
|
3300 | 196 |
! |
197 |
||
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
198 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
4238 | 199 |
^ self new findNodeForInterval:interval in:source allowErrors:allowErrors |
4080
413b8c8a0161
added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents:
4070
diff
changeset
|
200 |
! |
413b8c8a0161
added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents:
4070
diff
changeset
|
201 |
|
413b8c8a0161
added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents:
4070
diff
changeset
|
202 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod |
413b8c8a0161
added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents:
4070
diff
changeset
|
203 |
"if mustBeMethod is true, do not try a regular expression (as in a workspace)." |
413b8c8a0161
added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents:
4070
diff
changeset
|
204 |
|
4238 | 205 |
^ self new |
4548 | 206 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
207 |
! |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
208 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
209 |
findNodeForInterval:interval inParseTree:parseTree |
4238 | 210 |
^ self new findNodeForInterval:interval inParseTree:parseTree |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
211 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
212 |
|
5272 | 213 |
findNodeIn:aTree forInterval:anInterval |
214 |
"utility" |
|
215 |
||
216 |
|nodeFound wouldReturn| |
|
217 |
||
218 |
anInterval isEmpty ifTrue:[^nil]. |
|
219 |
||
220 |
nodeFound := nil. |
|
221 |
aTree nodesDo:[:eachNode | |
|
222 |
(eachNode intersectsInterval:anInterval) ifTrue:[ |
|
223 |
(nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[ |
|
224 |
nodeFound := eachNode |
|
225 |
] ifFalse:[ |
|
226 |
(nodeFound parent == eachNode parent |
|
227 |
and:[ eachNode start >= nodeFound start |
|
228 |
and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[ |
|
229 |
] ifFalse:[ |
|
230 |
(nodeFound parent notNil |
|
231 |
and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil] |
|
232 |
] |
|
233 |
] |
|
234 |
] ifFalse:[ |
|
235 |
nodeFound notNil ifTrue:[ |
|
236 |
"/ already found one - beyond that one; leave |
|
237 |
wouldReturn notNil ifTrue:[wouldReturn := nodeFound]. |
|
238 |
] |
|
239 |
]. |
|
240 |
]. |
|
241 |
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt]. |
|
242 |
^ nodeFound |
|
243 |
||
244 |
"Modified: / 20-11-2006 / 12:31:12 / cg" |
|
2376 | 245 |
! ! |
246 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
247 |
!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
|
248 |
|
2975 | 249 |
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
250 |
"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
|
251 |
2 entries: 1st: the best (longest) match |
4548 | 252 |
2nd: collection consisting of matching categories" |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
253 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
254 |
|matches best lcName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
255 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
256 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
257 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
258 |
"/ search for exact match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
259 |
anEnvironment allClassesDo:[:aClass | |
4548 | 260 |
|category| |
261 |
||
262 |
category := aClass category. |
|
263 |
(category notNil and:[category startsWith:aPartialCategory]) ifTrue:[ |
|
264 |
matches add:category |
|
265 |
] |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
266 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
267 |
matches isEmpty ifTrue:[ |
4548 | 268 |
"/ search for case-ignoring match |
269 |
lcName := aPartialCategory asLowercase. |
|
270 |
anEnvironment allClassesDo:[:aClass | |
|
271 |
|category| |
|
272 |
||
273 |
category := aClass category. |
|
274 |
(category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[ |
|
275 |
matches add:category |
|
276 |
]. |
|
277 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
278 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
279 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
280 |
matches isEmpty ifTrue:[ |
4548 | 281 |
^ Array with:aPartialCategory with:(Array with:aPartialCategory) |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
282 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
283 |
matches size == 1 ifTrue:[ |
4548 | 284 |
^ Array with:matches first with:(matches asArray) |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
285 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
286 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
287 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
288 |
^ 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
|
289 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
290 |
" |
4548 | 291 |
Smalltalk classCategoryCompletion:'Sys' |
292 |
Smalltalk classCategoryCompletion:'System' |
|
293 |
Smalltalk classCategoryCompletion:'System-BinaryStorage' |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
294 |
" |
2975 | 295 |
|
296 |
"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
|
297 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
298 |
|
2830 | 299 |
classNameEntryCompletionBlock |
300 |
"this block can be used in a dialog to perform className completion" |
|
301 |
||
2977 | 302 |
^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:' |
2830 | 303 |
|
2977 | 304 |
"Modified: / 10-08-2006 / 13:22:02 / cg" |
2830 | 305 |
! |
306 |
||
2975 | 307 |
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
|
308 |
"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
|
309 |
2 entries: 1st: the best (longest) match |
5052 | 310 |
2nd: collection consisting of matching names" |
4548 | 311 |
|
312 |
|searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
313 |
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
|
314 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
315 |
(words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[ |
5052 | 316 |
w1 := words first. |
317 |
w2 := words second. |
|
318 |
rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment. |
|
319 |
bestMatch := rslt first. |
|
320 |
matches := rslt second. |
|
321 |
('class' copyTo:(w2 size min:5)) = w2 ifTrue:[ |
|
322 |
matches := matches collect:[:m | m , ' class']. |
|
323 |
bestMatch := bestMatch , ' class'. |
|
324 |
]. |
|
325 |
^ InputCompletionResult bestName:bestMatch matchingNames:matches |
|
326 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
327 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
328 |
(aPartialClassName startsWith:'Smalltalk::') ifTrue:[ |
5052 | 329 |
nsPrefix := 'Smalltalk::'. |
330 |
searchName := aPartialClassName withoutPrefix:'Smalltalk::' |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
331 |
] ifFalse:[ |
5052 | 332 |
nsPrefix := ''. |
333 |
searchName := aPartialClassName. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
334 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
335 |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
336 |
searchName := searchName asUppercaseFirst. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
337 |
lcSearchName := searchName asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
338 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
339 |
isMatchString := searchName includesMatchCharacters. |
5052 | 340 |
(searchName size > 2 |
341 |
and:[ searchName first = $* |
|
342 |
and:[ searchName last = $* ]] |
|
343 |
) ifTrue:[ |
|
344 |
isMatchString := false. |
|
345 |
searchName := searchName unquote:$*. |
|
346 |
]. |
|
347 |
||
348 |
searchName isEmpty ifTrue:[ |
|
349 |
matches := Smalltalk allClassesForWhich:filterBlock. |
|
350 |
^ InputCompletionResult bestName:searchName matchingNames:#() |
|
351 |
]. |
|
352 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
353 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
354 |
matchedNamesWithoutPrefix := Set new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
355 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
356 |
others := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
357 |
|
4548 | 358 |
tryToMatch := |
5052 | 359 |
[:className :fullClassName| |
360 |
|addIt| |
|
361 |
||
362 |
isMatchString ifTrue:[ |
|
363 |
addIt := searchName match:className |
|
364 |
] ifFalse:[ |
|
365 |
addIt := className includesString:searchName. |
|
366 |
]. |
|
367 |
addIt ifTrue:[ |
|
368 |
matches add:(nsPrefix , fullClassName). |
|
369 |
matchedNamesWithoutPrefix add:className. |
|
370 |
] ifFalse:[ |
|
371 |
"/ try ignoring case |
|
372 |
||
373 |
isMatchString ifTrue:[ |
|
374 |
addIt := searchName match:className caseSensitive:false |
|
375 |
] ifFalse:[ |
|
376 |
addIt := className includesString:lcSearchName caseSensitive:false. |
|
377 |
addIt ifFalse:[ |
|
378 |
others add:className |
|
379 |
] |
|
380 |
]. |
|
381 |
addIt ifTrue:[ |
|
382 |
ignCaseMatches add:(nsPrefix , fullClassName). |
|
383 |
matchedNamesWithoutPrefix add:className. |
|
384 |
]. |
|
385 |
]. |
|
386 |
addIt |
|
387 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
388 |
|
2975 | 389 |
anEnvironment allClassesForWhich:filterBlock do:[:aClass | |
5052 | 390 |
|addIt fullClassName classNameWithoutPrefix| |
391 |
||
392 |
aClass isMeta ifFalse:[ |
|
393 |
fullClassName := aClass name. |
|
394 |
classNameWithoutPrefix := aClass nameWithoutPrefix. |
|
395 |
||
396 |
addIt := tryToMatch value:fullClassName value:fullClassName. |
|
397 |
addIt ifFalse:[ |
|
398 |
classNameWithoutPrefix ~~ fullClassName ifTrue:[ |
|
399 |
tryToMatch value:classNameWithoutPrefix value:fullClassName. |
|
400 |
]. |
|
401 |
]. |
|
402 |
] |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
403 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
404 |
|
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
405 |
"/ matches isEmpty ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
406 |
"/ matches := ignCaseMatches. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
407 |
"/ ]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
408 |
matches := matches , ignCaseMatches. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
409 |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
410 |
"/ matches isEmpty ifTrue:[ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
411 |
"/ matches := ignCaseMatches. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
412 |
"/ |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
413 |
"/"/ matches isEmpty ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
414 |
"/"/ | nearBy | |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
415 |
"/"/ nearBy := SortedCollection new sortBlock:[:a :b | a key < b key]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
416 |
"/"/ others do:[:className | |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
417 |
"/"/ |lcClassName dist cmpName| |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
418 |
"/"/ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
419 |
"/"/ lcClassName := className asLowercase. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
420 |
"/"/ 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
|
421 |
"/"/ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
422 |
"/"/ cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
423 |
"/"/ 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
|
424 |
"/"/ cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
425 |
"/"/ 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
|
426 |
"/"/ dist < 4 ifTrue:[ |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
427 |
"/"/ nearBy add:( dist -> (nsPrefix , className) ). |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
428 |
"/"/ ] |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
429 |
"/"/ ]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
430 |
"/"/ matches := nearBy collect:[:eachPair | eachPair value]. |
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
431 |
"/"/ ]. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
432 |
"/ ]. |
3876
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
433 |
|
6e63fce83590
fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3867
diff
changeset
|
434 |
matches isEmpty ifTrue:[ |
5052 | 435 |
^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName) |
4548 | 436 |
]. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
437 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
438 |
matches size == 1 ifTrue:[ |
5052 | 439 |
best := matches first. |
440 |
^ 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
|
441 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
442 |
|
4548 | 443 |
matches |
5052 | 444 |
sort:[:name1 :name2 | |
445 |
"name1 comes before:name2 iff" |
|
446 |
((name2 includes:$:) and:[(name1 includes:$:) not]) |
|
447 |
or:[ ((name1 includes:$:) == (name2 includes:$:)) |
|
448 |
and:[ (name1 size < name2 size) |
|
449 |
or: [ name1 < name2 ]] |
|
450 |
] |
|
451 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
452 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
453 |
isMatchString ifTrue:[ |
5052 | 454 |
best := searchName. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
455 |
] ifFalse:[ |
5052 | 456 |
matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName]. |
457 |
best := ignCaseMatches isEmpty |
|
458 |
ifTrue:[ matchesForLongestPrefix longestCommonPrefix ] |
|
459 |
ifFalse:[ matchesForLongestPrefix longestCommonPrefixCaseSensitive:false ]. |
|
460 |
||
461 |
best size < aPartialClassName size "best size == 0" ifTrue:[ |
|
462 |
best := matchedNamesWithoutPrefix longestCommonPrefix. |
|
463 |
]. |
|
464 |
best size == 0 ifTrue:[ |
|
465 |
"if tried again, return next match" |
|
466 |
idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size. |
|
467 |
idx ~~ 1 ifTrue:[ |
|
468 |
^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray) |
|
469 |
]. |
|
470 |
]. |
|
471 |
best size < aPartialClassName size ifTrue:[ |
|
472 |
best := aPartialClassName. |
|
473 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
474 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
475 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
476 |
cls := anEnvironment classNamed:best. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
477 |
(cls isBehavior and:[cls isNameSpace]) ifTrue:[ |
5052 | 478 |
(matches conform:[:each | each = best |
479 |
or:[each startsWith:(best , '::')]]) |
|
480 |
ifTrue:[ |
|
481 |
best := best , '::' |
|
482 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
483 |
]. |
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
484 |
^ 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
|
485 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
486 |
" |
4548 | 487 |
Smalltalk classnameCompletion:'Arr' |
488 |
Smalltalk classnameCompletion:'Arra' |
|
489 |
Smalltalk classnameCompletion:'arra' |
|
490 |
Smalltalk classnameCompletion:'*rray' |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
491 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
492 |
|
2975 | 493 |
"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
|
494 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
495 |
|
2975 | 496 |
classnameCompletion:aPartialClassName inEnvironment:anEnvironment |
497 |
"given a partial classname, return an array consisting of |
|
498 |
2 entries: 1st: the best (longest) match |
|
4548 | 499 |
2nd: collection consisting of matching names" |
2975 | 500 |
|
501 |
^ self |
|
4548 | 502 |
classnameCompletion:aPartialClassName |
503 |
filter:[:cls | true] |
|
504 |
inEnvironment:anEnvironment |
|
2975 | 505 |
|
506 |
" |
|
4148
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
507 |
self classnameCompletion:'Arr' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
508 |
self classnameCompletion:'Arra' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
509 |
self classnameCompletion:'arra' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
510 |
self classnameCompletion:'*rray' inEnvironment:Smalltalk |
2975 | 511 |
" |
512 |
||
513 |
"Created: / 24-11-1995 / 17:24:45 / cg" |
|
514 |
"Modified: / 10-08-2006 / 13:01:30 / cg" |
|
515 |
! |
|
516 |
||
2977 | 517 |
entryCompletionBlockFor:completionSelector |
518 |
"this block can be used in a dialog to perform className completion" |
|
519 |
||
520 |
^ [:contents :field | |
|
4548 | 521 |
|s what m| |
522 |
||
523 |
s := contents withoutSpaces. |
|
524 |
field topView withCursor:(Cursor questionMark) do:[ |
|
525 |
what := self perform:completionSelector with:s with:Smalltalk. |
|
526 |
]. |
|
527 |
||
528 |
field contents:(what first). |
|
529 |
(what at:2) size ~~ 1 ifTrue:[ |
|
530 |
UserPreferences current beepInEditor ifTrue:[ |
|
531 |
field device beep |
|
532 |
] |
|
533 |
] |
|
2977 | 534 |
]. |
535 |
||
536 |
"Created: / 10-08-2006 / 13:21:37 / cg" |
|
537 |
! |
|
538 |
||
2975 | 539 |
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
540 |
"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
|
541 |
2 entries: 1st: the best (longest) match |
4548 | 542 |
2nd: collection consisting of matching names" |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
543 |
|
3863 | 544 |
^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true |
545 |
||
546 |
" |
|
4548 | 547 |
Smalltalk globalnameCompletion:'Arr' |
548 |
Smalltalk globalnameCompletion:'Arra' |
|
549 |
Smalltalk globalnameCompletion:'arra' |
|
550 |
Smalltalk globalnameCompletion:'*rray' |
|
3863 | 551 |
" |
552 |
||
553 |
"Created: / 10-08-2006 / 13:06:23 / cg" |
|
554 |
! |
|
555 |
||
556 |
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch |
|
557 |
"given a partial globalName, return an array consisting of |
|
558 |
2 entries: 1st: the best (longest) match |
|
4548 | 559 |
2nd: collection consisting of matching names" |
3863 | 560 |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
561 |
|searchName matches ignCaseMatches best isMatchString| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
562 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
563 |
searchName := aPartialGlobalName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
564 |
searchName isEmpty ifTrue:[ |
4548 | 565 |
^ Array with:searchName with:#() |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
566 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
567 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
568 |
(searchName at:1) isLowercase ifTrue:[ |
4548 | 569 |
searchName := searchName copy asUppercaseFirst |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
570 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
571 |
|
3863 | 572 |
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
|
573 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
574 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
575 |
anEnvironment keysDo:[:aGlobalName | |
4548 | 576 |
| addIt| |
577 |
||
578 |
isMatchString ifTrue:[ |
|
579 |
addIt := searchName match:aGlobalName |
|
580 |
] ifFalse:[ |
|
581 |
addIt := aGlobalName startsWith:searchName |
|
582 |
]. |
|
583 |
addIt ifTrue:[ |
|
584 |
matches add:aGlobalName |
|
585 |
] ifFalse:[ |
|
586 |
"/ try ignoring case |
|
587 |
isMatchString ifTrue:[ |
|
588 |
addIt := searchName match:aGlobalName caseSensitive:false |
|
589 |
] ifFalse:[ |
|
590 |
addIt := aGlobalName asLowercase startsWith:searchName asLowercase |
|
591 |
]. |
|
592 |
addIt ifTrue:[ |
|
593 |
ignCaseMatches add:aGlobalName |
|
594 |
] |
|
595 |
] |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
596 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
597 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
598 |
matches isEmpty ifTrue:[ |
4548 | 599 |
matches := ignCaseMatches |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
600 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
601 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
602 |
matches isEmpty ifTrue:[ |
4548 | 603 |
^ Array with:searchName with:(Array with:searchName) |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
604 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
605 |
matches size == 1 ifTrue:[ |
4548 | 606 |
^ Array with:matches first with:(matches asArray) |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
607 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
608 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
609 |
isMatchString ifTrue:[ |
4548 | 610 |
best := searchName. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
611 |
] ifFalse:[ |
4548 | 612 |
best := matches longestCommonPrefix. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
613 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
614 |
^ 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
|
615 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
616 |
" |
4548 | 617 |
Smalltalk globalnameCompletion:'Arr' |
618 |
Smalltalk globalnameCompletion:'Arra' |
|
619 |
Smalltalk globalnameCompletion:'arra' |
|
620 |
Smalltalk globalnameCompletion:'*rray' |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
621 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
622 |
|
2975 | 623 |
"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
|
624 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
625 |
|
4051 | 626 |
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment |
627 |
"given a partial method protocol name, return an array consisting of |
|
4548 | 628 |
2 entries: 1st: the best (longest) match |
629 |
2nd: collection consisting of matching protocols" |
|
4051 | 630 |
|
631 |
|matches best lcName| |
|
632 |
||
633 |
matches := IdentitySet new. |
|
634 |
||
635 |
"/ search for exact match |
|
636 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
|
4548 | 637 |
|protocol| |
638 |
||
639 |
protocol := eachMethod category. |
|
640 |
(protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[ |
|
641 |
matches add:protocol |
|
642 |
]. |
|
4051 | 643 |
]. |
644 |
matches isEmpty ifTrue:[ |
|
4548 | 645 |
"/ search for case-ignoring match |
646 |
lcName := aPartialProtocolName asLowercase. |
|
647 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
|
648 |
|protocol| |
|
649 |
||
650 |
protocol := eachMethod category. |
|
651 |
(protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[ |
|
652 |
matches add:protocol |
|
653 |
]. |
|
654 |
]. |
|
4051 | 655 |
]. |
656 |
||
657 |
matches isEmpty ifTrue:[ |
|
4548 | 658 |
^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName) |
4051 | 659 |
]. |
660 |
matches size == 1 ifTrue:[ |
|
4548 | 661 |
^ Array with:matches first with:(matches asArray) |
4051 | 662 |
]. |
663 |
matches := matches asSortedCollection. |
|
664 |
best := matches longestCommonPrefix. |
|
665 |
^ Array with:best with:matches asArray |
|
666 |
||
667 |
" |
|
668 |
Smalltalk methodProtocolCompletion:'doc' |
|
4548 | 669 |
Smalltalk methodProtocolCompletion:'docu' |
670 |
Smalltalk methodProtocolCompletion:'documenta' |
|
4051 | 671 |
" |
672 |
||
673 |
"Created: / 10-08-2006 / 13:05:27 / cg" |
|
674 |
"Modified: / 16-03-2011 / 12:30:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
675 |
! |
|
676 |
||
2975 | 677 |
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment |
678 |
"given a partial name, return an array consisting of |
|
679 |
2 entries: 1st: the best (longest) match |
|
4548 | 680 |
2nd: collection consisting of matching names" |
2975 | 681 |
|
682 |
^ self |
|
4548 | 683 |
classnameCompletion:aPartialClassName |
684 |
filter:[:cls | cls isNameSpace] |
|
685 |
inEnvironment:anEnvironment |
|
2975 | 686 |
|
687 |
" |
|
4548 | 688 |
DoWhatIMeanSupport nameSpaceCompletion:'To' inEnvironment:Smalltalk |
2975 | 689 |
" |
690 |
||
691 |
"Created: / 10-08-2006 / 13:02:16 / cg" |
|
692 |
! |
|
693 |
||
694 |
packageCompletion:aPartialPackage inEnvironment:anEnvironment |
|
695 |
"given a partial package name, return an array consisting of |
|
696 |
2 entries: 1st: the best (longest) match |
|
4976 | 697 |
2nd: collection consisting of matching packages" |
2975 | 698 |
|
699 |
|matches best lcName| |
|
700 |
||
4976 | 701 |
matches := Smalltalk allPackageIDs |
702 |
select:[:package | package startsWith:aPartialPackage]. |
|
2975 | 703 |
|
704 |
matches isEmpty ifTrue:[ |
|
4976 | 705 |
"/ search for case-ignoring match |
706 |
lcName := aPartialPackage asLowercase. |
|
707 |
anEnvironment allClassesDo:[:aClass | |
|
708 |
|package| |
|
709 |
||
710 |
package := aClass package. |
|
711 |
(package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[ |
|
712 |
matches add:package |
|
713 |
]. |
|
714 |
]. |
|
2975 | 715 |
]. |
716 |
||
717 |
matches isEmpty ifTrue:[ |
|
4976 | 718 |
^ Array with:aPartialPackage with:(Array with:aPartialPackage) |
2975 | 719 |
]. |
720 |
matches size == 1 ifTrue:[ |
|
4976 | 721 |
^ Array with:matches first with:(matches asArray) |
2975 | 722 |
]. |
723 |
matches := matches asSortedCollection. |
|
724 |
best := matches longestCommonPrefix. |
|
725 |
^ Array with:best with:matches asArray |
|
726 |
||
727 |
" |
|
4548 | 728 |
DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk |
729 |
DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk |
|
2975 | 730 |
" |
731 |
||
732 |
"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
|
733 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
734 |
|
2977 | 735 |
packageNameEntryCompletionBlock |
736 |
"this block can be used in a dialog to perform className completion" |
|
737 |
||
738 |
^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:' |
|
739 |
||
740 |
"Created: / 10-08-2006 / 13:22:31 / cg" |
|
741 |
! |
|
742 |
||
4148
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
743 |
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
744 |
"given a partial poolname, return an array consisting of |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
745 |
2 entries: 1st: the best (longest) match |
4548 | 746 |
2nd: collection consisting of matching names" |
4148
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
747 |
|
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
748 |
^ self |
4548 | 749 |
classnameCompletion:aPartialClassName |
750 |
filter:[:cls | cls isSharedPool] |
|
751 |
inEnvironment:anEnvironment |
|
4148
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
752 |
|
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
753 |
" |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
754 |
self poolnameCompletion:'Win' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
755 |
self poolnameCompletion:'Z' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
756 |
self poolnameCompletion:'a' inEnvironment:Smalltalk |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
757 |
" |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
758 |
! |
b314d59c1654
added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
4146
diff
changeset
|
759 |
|
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
760 |
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
761 |
"given a partial resource name, return an array consisting of |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
762 |
2 entries: 1st: the longest match |
4548 | 763 |
2nd: collection consisting of matching defined resources" |
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
764 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
765 |
|matches best lcSym isMatch| |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
766 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
767 |
matches := IdentitySet new. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
768 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
769 |
isMatch := doMatch and:[aPartialResourceName includesMatchCharacters]. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
770 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
771 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
4548 | 772 |
eachMethod hasResource ifTrue:[ |
773 |
eachMethod resources keysDo:[:eachResourceName | |
|
774 |
(isMatch |
|
775 |
ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:ignoreCase not) ] |
|
776 |
ifFalse:[ ignoreCase |
|
777 |
ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ] |
|
778 |
ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ] |
|
779 |
) ifTrue:[ |
|
780 |
matches add:eachResourceName |
|
781 |
]. |
|
782 |
]. |
|
783 |
]. |
|
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
784 |
]. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
785 |
(matches isEmpty and:[ignoreCase not]) ifTrue:[ |
4548 | 786 |
"/ search for case-ignoring match |
787 |
lcSym := aPartialResourceName asLowercase. |
|
788 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
|
789 |
eachMethod hasResource ifTrue:[ |
|
790 |
eachMethod resources keysDo:[:eachResourceName | |
|
791 |
(isMatch |
|
792 |
ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:false) ] |
|
793 |
ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ]) |
|
794 |
ifTrue:[ |
|
795 |
matches add:eachResourceName |
|
796 |
]. |
|
797 |
]. |
|
798 |
]. |
|
799 |
]. |
|
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
800 |
]. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
801 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
802 |
matches isEmpty ifTrue:[ |
4548 | 803 |
^ Array with:aPartialResourceName with:#() |
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
804 |
]. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
805 |
matches size == 1 ifTrue:[ |
4548 | 806 |
^ Array with:matches first with:(matches asArray) |
4049
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
807 |
]. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
808 |
matches := matches asSortedCollection. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
809 |
best := matches longestCommonPrefix. |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
810 |
^ Array with:best with:matches asArray |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
811 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
812 |
" |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
813 |
DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
814 |
DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
815 |
DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
816 |
DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
817 |
" |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
818 |
|
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
819 |
"Created: / 06-07-2011 / 12:04:41 / cg" |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
820 |
! |
b5540a857436
added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
4047
diff
changeset
|
821 |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
822 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
823 |
"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
|
824 |
2 entries: 1st: the longest match |
4548 | 825 |
2nd: collection consisting of matching implemented selectors" |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
826 |
|
3863 | 827 |
^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false |
828 |
! |
|
829 |
||
830 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch |
|
831 |
"given a partial selector, return an array consisting of |
|
832 |
2 entries: 1st: the longest match |
|
4548 | 833 |
2nd: collection consisting of matching implemented selectors" |
834 |
||
835 |
^ self |
|
836 |
selectorCompletion:aPartialSymbolName |
|
837 |
inEnvironment:anEnvironment |
|
838 |
match:doMatch |
|
839 |
ignoreCase:false |
|
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
840 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
841 |
" |
4548 | 842 |
DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true |
843 |
DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true |
|
844 |
DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true |
|
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
845 |
DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
846 |
DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
847 |
" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
848 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
849 |
"Modified: / 07-06-1996 / 08:44:33 / stefan" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
850 |
"Modified: / 26-10-2010 / 20:30:27 / cg" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
851 |
! |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
852 |
|
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
853 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
854 |
"given a partial selector, return an array consisting of |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
855 |
2 entries: 1st: the longest match |
4548 | 856 |
2nd: collection consisting of matching implemented selectors" |
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
857 |
|
3863 | 858 |
|matches best lcSym isMatch| |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
859 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
860 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
861 |
|
3863 | 862 |
isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters]. |
863 |
||
3751 | 864 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
4548 | 865 |
(isMatch |
866 |
ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:ignoreCase not) ] |
|
867 |
ifFalse:[ ignoreCase |
|
868 |
ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ] |
|
869 |
ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ]) |
|
870 |
ifTrue:[ |
|
871 |
matches add:eachSelector |
|
872 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
873 |
]. |
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
874 |
(matches isEmpty and:[ignoreCase not]) ifTrue:[ |
4548 | 875 |
"/ search for case-ignoring match |
876 |
lcSym := aPartialSymbolName asLowercase. |
|
877 |
anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector | |
|
878 |
(isMatch |
|
879 |
ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:false) ] |
|
880 |
ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ]) |
|
881 |
ifTrue:[ |
|
882 |
matches add:eachSelector |
|
883 |
]. |
|
884 |
]. |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
885 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
886 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
887 |
matches isEmpty ifTrue:[ |
4548 | 888 |
^ 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
|
889 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
890 |
matches size == 1 ifTrue:[ |
4548 | 891 |
^ Array with:matches first with:(matches asArray) |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
892 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
893 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
894 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
895 |
^ 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
|
896 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
897 |
" |
4548 | 898 |
DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true |
899 |
DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true |
|
900 |
DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true |
|
3867
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
901 |
DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true |
03f7ad841731
changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents:
3864
diff
changeset
|
902 |
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
|
903 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
904 |
|
3955
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
905 |
"Modified: / 07-06-1996 / 08:44:33 / stefan" |
94fb4a47d108
added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents:
3929
diff
changeset
|
906 |
"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
|
907 |
! ! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
908 |
|
2376 | 909 |
!DoWhatIMeanSupport class methodsFor:'rename support'! |
910 |
||
911 |
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName |
|
2513 | 912 |
"generate a reasonable default for a rename operation. |
913 |
(used for rename category etc.)" |
|
2468 | 914 |
|
4065
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
915 |
|prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain| |
2376 | 916 |
|
917 |
lastNewName isNil ifTrue:[ ^ nil]. |
|
918 |
||
919 |
lastNewSize := lastNewName size. |
|
920 |
lastOldSize := lastOldName size. |
|
921 |
||
922 |
(lastNewName endsWith:lastOldName) ifTrue:[ |
|
5143 | 923 |
"last rename was |
924 |
'foo' -> 'Xfoo' |
|
925 |
then, a good default for |
|
926 |
'bar' would be 'Xbar' |
|
927 |
" |
|
928 |
prefix := lastNewName copyTo:(lastNewSize - lastOldSize). |
|
929 |
^ (prefix , oldName). |
|
2376 | 930 |
]. |
931 |
(lastOldName endsWith:lastNewName) ifTrue:[ |
|
5143 | 932 |
"last rename was |
933 |
'Xfoo' -> 'foo' |
|
934 |
then, a good default for |
|
935 |
'Xbar' would be 'bar' |
|
936 |
" |
|
937 |
prefix := lastOldName copyTo:(lastOldSize - lastNewSize). |
|
938 |
(oldName startsWith:prefix) ifTrue:[ |
|
939 |
^ (oldName copyFrom:prefix size+1). |
|
940 |
] |
|
2514 | 941 |
]. |
942 |
(lastOldName asLowercase = lastNewName asLowercase) ifTrue:[ |
|
5143 | 943 |
(lastOldName first ~= lastNewName first) ifTrue:[ |
944 |
(lastOldName first isLowercase = oldName first isLowercase) ifTrue:[ |
|
945 |
"last rename was |
|
946 |
'xfoo' -> 'Xfoo' |
|
947 |
then, a good default for |
|
948 |
'xbar' would be 'Xbar' |
|
949 |
" |
|
950 |
lastOldName first isLowercase ifTrue:[ |
|
951 |
^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)". |
|
952 |
] ifFalse:[ |
|
953 |
^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)". |
|
954 |
] |
|
955 |
] |
|
956 |
]. |
|
2376 | 957 |
]. |
958 |
(lastOldName withoutSeparators = lastNewName) ifTrue:[ |
|
5143 | 959 |
"last rename was |
960 |
' foo ' -> 'foo' |
|
961 |
then, a good default for |
|
962 |
' bar ' would be 'bar' |
|
963 |
" |
|
964 |
^ oldName withoutSeparators. |
|
2376 | 965 |
]. |
966 |
(lastNewName startsWith:lastOldName) ifTrue:[ |
|
5143 | 967 |
"last rename was |
968 |
'foo' -> 'fooX' |
|
969 |
then, a good default for |
|
970 |
'bar' would be 'barX' |
|
971 |
" |
|
972 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize). |
|
973 |
^ (oldName , suffix). |
|
2376 | 974 |
]. |
975 |
(lastOldName startsWith:lastNewName) ifTrue:[ |
|
5143 | 976 |
"last rename was |
977 |
'fooX' -> 'foo' |
|
978 |
then, a good default for |
|
979 |
'barX' would be 'bar' |
|
980 |
" |
|
981 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize). |
|
982 |
(oldName endsWith:suffix) ifTrue:[ |
|
983 |
^ (oldName copyButLast:suffix size). |
|
984 |
] |
|
2376 | 985 |
]. |
2558 | 986 |
|
2557 | 987 |
prefix := lastOldName commonPrefixWith:lastNewName. |
988 |
suffix := lastOldName commonSuffixWith:lastNewName. |
|
2559 | 989 |
|
2558 | 990 |
(prefix size > 0) ifTrue:[ |
5143 | 991 |
(suffix size > 0) ifTrue:[ |
992 |
||
993 |
prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size). |
|
994 |
||
995 |
"last rename was |
|
996 |
'fooR' -> 'fooXR' |
|
997 |
then, a good default for |
|
998 |
'barR' would be 'barXR' |
|
999 |
" |
|
1000 |
left := lastOldName copyTo:prefix size. |
|
1001 |
right := lastOldName copyLast:suffix size. |
|
1002 |
lastNewSize > lastOldSize ifTrue:[ |
|
1003 |
inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size). |
|
1004 |
inserted size > 0 ifTrue:[ |
|
1005 |
(oldName startsWith:prefix) ifTrue:[ |
|
1006 |
^ oldName copyWithAll:inserted insertedAfterIndex:prefix size |
|
1007 |
]. |
|
1008 |
]. |
|
1009 |
]. |
|
1010 |
(oldName string endsWith:suffix string) ifTrue:[ |
|
1011 |
deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size). |
|
1012 |
(oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[ |
|
1013 |
((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[ |
|
1014 |
"last rename was |
|
1015 |
'fooXR' -> 'fooR' |
|
1016 |
then, a good default for |
|
1017 |
'barXS' would be 'barS' |
|
1018 |
" |
|
1019 |
^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix |
|
1020 |
] |
|
1021 |
] |
|
1022 |
] |
|
1023 |
]. |
|
1024 |
||
1025 |
(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[ |
|
1026 |
"last rename was |
|
1027 |
'fooX' -> 'fooY' |
|
1028 |
then, a good default for |
|
1029 |
'barX' would be 'barY' |
|
1030 |
" |
|
1031 |
left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size. |
|
1032 |
right := lastNewName copyFrom:prefix size+1. |
|
1033 |
^ left , right |
|
1034 |
] |
|
2557 | 1035 |
]. |
2376 | 1036 |
|
4065
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1037 |
suffix size > 0 ifTrue:[ |
5143 | 1038 |
|prefix2| |
1039 |
||
1040 |
"last rename was: |
|
1041 |
'fooSUFF1' -> 'barSUFF1' |
|
1042 |
then, a good default for |
|
1043 |
'fooSUFF2' -> 'barSUFF2' |
|
1044 |
" |
|
1045 |
prefix := lastOldName copyTo:(lastOldName size - suffix size). "/ the foo |
|
1046 |
(oldName startsWith:prefix) ifTrue:[ |
|
1047 |
prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar |
|
1048 |
^ prefix2,(oldName copyFrom:(prefix size+1)). |
|
1049 |
]. |
|
4065
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1050 |
]. |
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1051 |
|
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1052 |
"/ was there something stripped at the end? |
4548 | 1053 |
suffix := oldName commonSuffixWith:lastOldName. |
5143 | 1054 |
(suffix size > 0) ifTrue:[ |
1055 |
^ self |
|
1056 |
goodRenameDefaultFor:(oldName copyButLast:suffix size) |
|
1057 |
lastOld:(lastOldName copyButLast:suffix size) |
|
1058 |
lastNew:lastNewName. |
|
4065
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1059 |
]. |
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1060 |
^ nil |
2557 | 1061 |
|
1062 |
" |
|
2558 | 1063 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX' |
1064 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo' |
|
1065 |
||
4548 | 1066 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' |
2558 | 1067 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
1068 |
||
4548 | 1069 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' |
1070 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
1071 |
||
1072 |
self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01' |
|
2559 | 1073 |
self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY' |
4548 | 1074 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo' |
1075 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo' |
|
1076 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo' |
|
1077 |
||
1078 |
self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001' |
|
1079 |
self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar' |
|
1080 |
||
1081 |
self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle' |
|
5143 | 1082 |
lastOld:'mti.odt2.level1HeadlineMatchPattern' |
1083 |
lastNew:'Key_odt2_level1HeadlineMatchPattern' |
|
2557 | 1084 |
" |
4065
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1085 |
|
ebea28fa8bab
changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
1086 |
"Modified: / 24-07-2011 / 11:06:03 / cg" |
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1087 |
! |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1088 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1089 |
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
2513 | 1090 |
"generate a reasonable default for a file rename operation. |
4548 | 1091 |
(Try to rename multiple files in the new fileBrowser, |
2513 | 1092 |
to see what this is doing)" |
2468 | 1093 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1094 |
|prefix suffix t |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1095 |
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
|
1096 |
lastRemoved lastInserted default| |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1097 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1098 |
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
|
1099 |
default notNil ifTrue:[ ^ default]. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1100 |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1101 |
lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1102 |
lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1103 |
oldWOSuffix := oldName asFilename nameWithoutSuffix. |
2376 | 1104 |
|
2434 | 1105 |
"/ suffix change ? |
1106 |
lastOldWOSuffix = lastNewWOSuffix ifTrue:[ |
|
4548 | 1107 |
lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[ |
1108 |
^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName |
|
1109 |
]. |
|
2434 | 1110 |
]. |
1111 |
||
2553 | 1112 |
default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix. |
4548 | 1113 |
default notNil ifTrue:[ |
1114 |
lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1. |
|
1115 |
lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1. |
|
1116 |
oldRest := oldName copyFrom:oldWOSuffix size + 1. |
|
1117 |
||
1118 |
^ default , lastNewRest |
|
2553 | 1119 |
]. |
1120 |
||
2376 | 1121 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix. |
1122 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[ |
|
4548 | 1123 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1. |
1124 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1. |
|
1125 |
oldRest := oldWOSuffix copyFrom:prefix size + 1. |
|
1126 |
||
1127 |
(lastNewRest endsWith:lastOldRest) ifTrue:[ |
|
1128 |
t := lastNewRest copyButLast:lastOldRest size. |
|
1129 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name |
|
1130 |
]. |
|
2376 | 1131 |
]. |
1132 |
||
1133 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix. |
|
1134 |
suffix size > 0 ifTrue:[ |
|
4548 | 1135 |
"/ last change changed something at the beginning |
1136 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix. |
|
1137 |
prefix size > 0 ifTrue:[ |
|
1138 |
"/ this name starts with the same characters |
|
1139 |
lastRemoved := lastOldWOSuffix copyButLast:suffix size. |
|
1140 |
lastInserted := lastNewWOSuffix copyButLast:suffix size. |
|
1141 |
(lastRemoved startsWith:lastInserted) ifTrue:[ |
|
1142 |
oldWOSuffix size >= lastInserted size ifTrue:[ |
|
1143 |
^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1) |
|
1144 |
] |
|
1145 |
]. |
|
1146 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1) |
|
1147 |
]. |
|
2376 | 1148 |
]. |
1149 |
||
1150 |
^ nil |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1151 |
|
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1152 |
"Modified: / 07-11-2006 / 13:58:39 / cg" |
2376 | 1153 |
! ! |
1154 |
||
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1155 |
!DoWhatIMeanSupport class methodsFor:'typing distance'! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1156 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1157 |
isKey:k1 nextTo:k2 |
2774 | 1158 |
"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
|
1159 |
This is used to specially priorize plausible typing errors of adjacent keys. |
4386 | 1160 |
CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else." |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1161 |
|
3316 | 1162 |
^ 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
|
1163 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1164 |
" |
4548 | 1165 |
self isKey:$a nextTo:$a |
1166 |
self isKey:$a nextTo:$s |
|
1167 |
self isKey:$a nextTo:$q |
|
1168 |
self isKey:$a nextTo:$w |
|
1169 |
self isKey:$a nextTo:$z |
|
1170 |
self isKey:$a nextTo:$x |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1171 |
" |
3316 | 1172 |
|
1173 |
"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
|
1174 |
! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1175 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1176 |
isKey:k1 nextTo:k2 onKeyboard:keys |
5040 | 1177 |
"return true, if k1 and k2 are adjacent keys on the keyboard defined by keys. |
1178 |
This is used to specially priorize plausible typing errors of adjacent keys. |
|
1179 |
(typo checker uses a modified levenshtein, |
|
1180 |
in which keys next to each other are valued differently)" |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1181 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1182 |
|row1 row2 col1 col2| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1183 |
|
2774 | 1184 |
row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0]. |
2517 | 1185 |
row1 == 0 ifTrue:[^ false]. |
2774 | 1186 |
row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0]. |
2517 | 1187 |
row2 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1188 |
|
2774 | 1189 |
^ (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
|
1190 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1191 |
" |
2774 | 1192 |
self isKey:$a nextTo:$q |
2517 | 1193 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1194 |
" |
5040 | 1195 |
|
1196 |
"Modified (comment): / 01-05-2016 / 12:19:24 / cg" |
|
3316 | 1197 |
! |
1198 |
||
1199 |
keyboard |
|
4548 | 1200 |
"the keyboard layout |
4386 | 1201 |
(useful to figure out which keys are nearby a key, to find possible typing errors) |
1202 |
CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else." |
|
3316 | 1203 |
|
1204 |
|lang| |
|
1205 |
||
1206 |
lang := UserPreferences current language. |
|
1207 |
lang == #de ifTrue:[ |
|
4548 | 1208 |
^ #( |
1209 |
'1234567890-' |
|
1210 |
'*qwertzuiop' |
|
1211 |
'**asdfghjkl:' |
|
1212 |
'***yxcvbnm' |
|
1213 |
). |
|
3316 | 1214 |
]. |
1215 |
||
1216 |
lang == #fr ifTrue:[ |
|
4548 | 1217 |
^ #( |
1218 |
'1234567890' |
|
1219 |
'*azertyuiop' |
|
1220 |
'**qsdfghjklm' |
|
1221 |
'***wxcvbn,' |
|
1222 |
). |
|
3316 | 1223 |
]. |
1224 |
||
4548 | 1225 |
^ #( |
1226 |
'1234567890-' |
|
1227 |
'*qwertyuiop' |
|
1228 |
'**asdfghjkl:' |
|
1229 |
'***zxcvbnm' |
|
4386 | 1230 |
). |
3316 | 1231 |
|
1232 |
" |
|
4548 | 1233 |
self keyboard |
3316 | 1234 |
" |
1235 |
||
1236 |
"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
|
1237 |
! ! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1238 |
|
4238 | 1239 |
!DoWhatIMeanSupport methodsFor:'code completion'! |
1240 |
||
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1241 |
codeCompletionFor: codeAspectArg language: languageOrNilArg method:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1242 |
"provide code completion information by analyzing what the editing state is in codeViewArg |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1243 |
(cursor position, characters around cursor etc.) and calling back into actionBlock, passing |
4591 | 1244 |
the info as argument. |
1245 |
The interface has been defined in that way |
|
1246 |
(and tight coupling with internals of the editor) because |
|
1247 |
1) the completer needs to know about the text around the cursor position |
|
1248 |
2) the edit operation for completion may be non-trivial |
|
1249 |
(although not yet fully implemented, non-local rewrite procedures may and will be added in the future |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1250 |
For example, in many situations, both a completion of a unary selector before the cursor, |
4591 | 1251 |
or adding another keyword part after the cursor is possible. |
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1252 |
Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1253 |
perform the completion. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1254 |
The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1255 |
An additional array containing a textual description for each suggestion is also provided, which could |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1256 |
be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1257 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1258 |
ContextOrNil is the current context, if this is called from the debugger; |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1259 |
or nil, if called from the browser. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1260 |
If nonNil, we can make better guesses, because we actually know what a variable's type is" |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1261 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1262 |
| language | |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1263 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1264 |
codeAspect := codeAspectArg. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1265 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1266 |
languageOrNilArg notNil ifTrue:[ |
4591 | 1267 |
language := languageOrNilArg |
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1268 |
] ifFalse:[ |
4591 | 1269 |
contextOrNilArg notNil ifTrue:[ |
1270 |
| method | |
|
1271 |
||
1272 |
method := contextOrNilArg method. |
|
1273 |
method notNil ifTrue:[ |
|
1274 |
language := method programmingLanguage |
|
1275 |
] ifFalse:[ |
|
1276 |
contextOrNilArg isJavaContext ifTrue:[ |
|
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1277 |
language := (Smalltalk at:#JavaLanguage) instance |
4591 | 1278 |
] ifFalse:[ |
1279 |
language := SmalltalkLanguage instance. |
|
1280 |
]. |
|
1281 |
]. |
|
1282 |
] ifFalse:[ |
|
1283 |
methodOrNilArg notNil ifTrue:[ |
|
1284 |
language := methodOrNilArg programmingLanguage |
|
1285 |
] ifFalse:[ |
|
1286 |
classOrNilArg notNil ifTrue:[ |
|
1287 |
language := classOrNilArg programmingLanguage |
|
1288 |
] |
|
1289 |
] |
|
1290 |
]. |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1291 |
]. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1292 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1293 |
language notNil ifTrue:[ |
4591 | 1294 |
language isSmalltalk ifTrue:[ |
1295 |
^self codeCompletionForSmalltalkMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock |
|
1296 |
]. |
|
1297 |
language isSTXJavaScript ifTrue:[ |
|
1298 |
^self codeCompletionForJavascriptMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock |
|
1299 |
]. |
|
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1300 |
]. |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1301 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1302 |
"/ No completion support for given language |
5051 | 1303 |
"/ self breakPoint: #cg. |
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1304 |
|
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1305 |
"Created: / 27-09-2013 / 10:21:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1306 |
"Modified: / 25-09-2015 / 07:36:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4426
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1307 |
! |
76a0c105e8f4
Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4423
diff
changeset
|
1308 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1309 |
codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNilArg codeView:codeViewArg |
5043 | 1310 |
"going to become OBSOLETE; migrating to use the the new 'xxx: into:' protocol. |
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1311 |
contextOrNil is the current context, if this is called from the debugger; |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1312 |
nil, if called from the browser. |
4591 | 1313 |
If nonNil, we can make better guesses, |
1314 |
because we actually know what a variable's type is." |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1315 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1316 |
| language | |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1317 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1318 |
languageOrNil notNil ifTrue:[ |
4591 | 1319 |
language := languageOrNil |
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1320 |
] ifFalse:[ |
4591 | 1321 |
contextOrNilArg notNil ifTrue:[ |
1322 |
language := contextOrNilArg method programmingLanguage. |
|
1323 |
] ifFalse:[ |
|
1324 |
classOrNilArg notNil ifTrue:[ |
|
1325 |
language := classOrNilArg programmingLanguage. |
|
1326 |
] |
|
1327 |
]. |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1328 |
]. |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1329 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1330 |
language notNil ifTrue:[ |
4591 | 1331 |
language isSmalltalk ifTrue:[ |
4731 | 1332 |
classOrNil := classOrNilArg. |
1333 |
contextOrNil := contextOrNilArg. |
|
4591 | 1334 |
^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg |
1335 |
]. |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1336 |
]. |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1337 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1338 |
"/ No completion support for given language |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1339 |
self breakPoint: #cg. |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1340 |
self breakPoint: #jv. |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1341 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1342 |
"Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5007 | 1343 |
! |
1344 |
||
1345 |
setClass: classOrNilArg andContext:contextOrNilArg |
|
1346 |
classOrNil := classOrNilArg. |
|
1347 |
contextOrNil := contextOrNilArg. |
|
5272 | 1348 |
! |
1349 |
||
1350 |
setSelf: instanceOrNilArg |
|
1351 |
instanceOrNil := instanceOrNilArg. |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1352 |
! ! |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1353 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1354 |
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'! |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1355 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1356 |
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1357 |
"provide code completion information by analyzing what the editing state is in codeViewArg |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1358 |
(cursor position, characters around cursor etc.) and calling back into actionBlock, passing |
4591 | 1359 |
the info as argument. |
1360 |
The interface has been defined in that way |
|
1361 |
(and tight coupling with internals of the editor) because |
|
1362 |
1) the completer needs to know about the text around the cursor position |
|
1363 |
2) the edit operation for completion may be non-trivial |
|
1364 |
(although not yet fully implemented, non-local rewrite procedures may and will be added in the future |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1365 |
For example, in many situations, both a completion of a unary selector before the cursor, |
4591 | 1366 |
or adding another keyword part after the cursor is possible. |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1367 |
Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1368 |
perform the completion. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1369 |
The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1370 |
An additional array containing a textual description for each suggestion is also provided, which could |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1371 |
be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1372 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1373 |
ContextOrNil is the current context, if this is called from the debugger; |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1374 |
or nil, if called from the browser. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1375 |
If nonNil, we can make better guesses, because we actually know what a variable's type is" |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1376 |
|
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1377 |
languageOrNil := (Smalltalk at:#STXJavaScriptLanguage) instance. |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1378 |
methodOrNil := methodOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1379 |
classOrNil := classOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1380 |
codeView := codeViewArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1381 |
contextOrNil := contextOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1382 |
|
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1383 |
(Smalltalk at:#STXJavaScriptLanguage) notNil ifTrue:[ |
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1384 |
(Smalltalk at:#STXJavaScriptLanguage) new |
4591 | 1385 |
completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock. |
4548 | 1386 |
]. |
4423
c21baefab5d0
Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4422
diff
changeset
|
1387 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1388 |
self information:'Not yet supported'. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1389 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1390 |
"Created: / 18-09-2013 / 16:24:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
1391 |
"Modified: / 25-09-2015 / 07:37:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1392 |
! ! |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1393 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1394 |
!DoWhatIMeanSupport methodsFor:'code completion - Smalltalk'! |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1395 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1396 |
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1397 |
|
4379 | 1398 |
"OBSOLETE; migrating to use the the new 'xxx: into:' protocol. |
4352 | 1399 |
contextOrNil is the current context, if this is called from the debugger; |
4238 | 1400 |
nil, if called from the browser. |
1401 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
|
1402 |
This is not yet done, sigh" |
|
4548 | 1403 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1404 |
|crsrPos char interval source node parent checkedNode instanceOrNilArg |
4710 | 1405 |
forceNewMessageSend classOfReceiver prevChar| |
4238 | 1406 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1407 |
languageOrNil := SmalltalkLanguage instance. |
4238 | 1408 |
classOrNil := classOrNilArg. |
1409 |
codeView := codeViewArg. |
|
1410 |
||
1411 |
crsrPos := codeView characterPositionOfCursor"-1". |
|
1412 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
4301 | 1413 |
"/ Transcript show:crsrPos; show:' '; showCR:char. |
4238 | 1414 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
4710 | 1415 |
crsrPos := crsrPos - 1. |
1416 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
4238 | 1417 |
]. |
1418 |
||
1419 |
interval := codeView selectedInterval. |
|
4301 | 1420 |
"/ Transcript show:'iv: '; showCR:interval. |
4238 | 1421 |
interval isEmpty ifTrue:[ |
4710 | 1422 |
interval := crsrPos"-1" to:crsrPos. |
1423 |
"/ Transcript show:'iv2: '; showCR:interval. |
|
4238 | 1424 |
]. |
1425 |
||
1426 |
source := codeView contentsAsString string. |
|
1427 |
source := source copyTo:crsrPos. |
|
1428 |
||
1429 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
1430 |
"/ we will not find a node for a long time (stepping back more and more, |
|
1431 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
1432 |
"/ without any progress. |
|
1433 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
1434 |
"/ as it parses the code. Stop, when the interval is hit. |
|
1435 |
"/ that will also work for syntactic incorrect source code. |
|
1436 |
classOrNil notNil ifTrue:[ |
|
4710 | 1437 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
1438 |
"/ Transcript show:'nd1: '; showCR:node. |
|
4238 | 1439 |
]. |
1440 |
node isNil ifTrue:[ |
|
4710 | 1441 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false. |
1442 |
"/ Transcript show:'nd2 try: '; showCR:node. |
|
1443 |
node isNil ifTrue:[ |
|
1444 |
"/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'. |
|
1445 |
self breakPoint:#cg. |
|
1446 |
"/ self information:'No parseNode found (syntax error before or in comment?)'. |
|
1447 |
^ self. |
|
1448 |
] |
|
4238 | 1449 |
]. |
1450 |
||
4346 | 1451 |
forceNewMessageSend := false. |
1452 |
||
1453 |
"/ if there a separator between the variable's name and the cursor position... |
|
4710 | 1454 |
prevChar := codeView characterBeforeCursor. |
1455 |
(prevChar isSeparator or:[ ')}]''' includes:prevChar ]) ifTrue:[ |
|
1456 |
(node isVariable |
|
1457 |
and:[ (parent := node parent) notNil |
|
1458 |
and:[ parent isMessage ]] |
|
1459 |
) ifTrue:[ |
|
1460 |
"/ completion after a variable node... |
|
1461 |
parent isKeyword ifTrue:[ |
|
1462 |
"/ and it is a keyword message, we complete the keyword message instead |
|
1463 |
node := parent. |
|
1464 |
] ifFalse:[ |
|
1465 |
"/ otherwise, a unary message is probably intended to be sent to the variable. |
|
1466 |
"/ (however, no character is available to determine what is useful) |
|
1467 |
forceNewMessageSend := true. |
|
1468 |
]. |
|
1469 |
] ifFalse:[ |
|
1470 |
(node isMessage and:[node isUnary]) ifTrue:[ |
|
1471 |
"/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo) |
|
1472 |
"/ |
|
1473 |
forceNewMessageSend := true. |
|
4346 | 1474 |
"/ "/ can we see what we get from foo? |
4548 | 1475 |
"/ classOfReceiver := self |
4346 | 1476 |
"/ classOfReceiver:node receiver |
1477 |
"/ inClass:classOrNil instance:instanceOrNil context:contextOrNil. |
|
1478 |
"/ classOfReceiver notNil ifTrue:[ |
|
1479 |
"/ |mthd| |
|
1480 |
"/ |
|
1481 |
"/ mthd := classOfReceiver lookupMethodFor:node selector. |
|
1482 |
"/ mthd notNil ifTrue:[ |
|
1483 |
"/ self halt. |
|
1484 |
"/ (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[ |
|
1485 |
"/ forceNewMessageSend := true. |
|
1486 |
"/ ] |
|
1487 |
"/ ] |
|
1488 |
"/ ]. |
|
4710 | 1489 |
] |
1490 |
] |
|
4346 | 1491 |
]. |
1492 |
||
1493 |
forceNewMessageSend ifTrue:[ |
|
4710 | 1494 |
"/ completion with nothing to start (right after a variable) |
1495 |
"/ see what the variable can understand and present the most useful stuff (very thin ice here) |
|
1496 |
classOfReceiver := self classOfNode:node. |
|
1497 |
classOfReceiver isNil ifTrue:[ |
|
1498 |
"/ it does not make sense to offer anything, if we don't have any idea of what this |
|
1499 |
"/ will be... |
|
1500 |
Screen current beep. |
|
1501 |
] ifFalse:[ |
|
1502 |
|superClass possible choice| |
|
1503 |
||
1504 |
possible := classOfReceiver selectors. |
|
1505 |
superClass := classOfReceiver superclass. |
|
4938 | 1506 |
[superClass notNil "and:[(possible size + superClass selectors size) < 500]"] whileTrue:[ |
4710 | 1507 |
possible := possible,superClass selectors. |
1508 |
superClass := superClass superclass. |
|
1509 |
]. |
|
1510 |
possible := possible copy sort. |
|
4938 | 1511 |
choice := self askUserForCompletion:('Message to "%1"' bindWith:node formattedCode) for:codeView from:possible. |
4710 | 1512 |
choice isNil ifTrue:[ |
1513 |
Screen current beep. |
|
1514 |
^ self |
|
1515 |
]. |
|
1516 |
||
1517 |
codeView |
|
1518 |
undoableDo:[ |
|
1519 |
codeView insertStringAtCursor:choice |
|
1520 |
] |
|
1521 |
info:'Completion'. |
|
1522 |
]. |
|
1523 |
^ self |
|
4238 | 1524 |
]. |
1525 |
||
1526 |
node isVariable ifTrue:[ |
|
4710 | 1527 |
self codeCompletionForVariable:node inClass:classOrNil codeView:codeView. |
1528 |
^ self. |
|
4238 | 1529 |
]. |
1530 |
node isLiteral ifTrue:[ |
|
4710 | 1531 |
node value isSymbol ifTrue:[ |
1532 |
self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView. |
|
1533 |
^ self. |
|
1534 |
]. |
|
1535 |
^ self "/ huh - strings or what? |
|
4238 | 1536 |
]. |
1537 |
||
1538 |
checkedNode := node. |
|
1539 |
[checkedNode notNil] whileTrue:[ |
|
4710 | 1540 |
checkedNode isMessage ifTrue:[ |
1541 |
"/ completion in a message-send |
|
1542 |
contextOrNilArg notNil ifTrue:[ |
|
4329 | 1543 |
"/ |rcvrNode idx rcvr val| |
1544 |
"/ |
|
1545 |
"/ (rcvrNode := checkedNode receiver) isVariable ifTrue:[ |
|
1546 |
"/ rcvrNode isSelf ifTrue:[ |
|
1547 |
"/ classOrNil := contextOrNil receiver class. |
|
1548 |
"/ ] ifFalse:[ |
|
1549 |
"/ (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1550 |
"/ val := contextOrNil argsAndVars at:idx. |
|
1551 |
"/ classOrNil := val class. |
|
1552 |
"/ ] ifFalse:[ |
|
1553 |
"/ (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1554 |
"/ val := contextOrNil receiver instVarNamed:rcvrNode name. |
|
1555 |
"/ classOrNil := val class. |
|
1556 |
"/ ] |
|
1557 |
"/ ] |
|
1558 |
"/ ] |
|
1559 |
"/ ]. |
|
4710 | 1560 |
instanceOrNilArg := contextOrNilArg receiver |
1561 |
]. |
|
1562 |
self |
|
1563 |
codeCompletionForMessage:checkedNode |
|
1564 |
inClass:classOrNil instance:instanceOrNilArg |
|
1565 |
context:contextOrNilArg codeView:codeView. |
|
1566 |
^ self |
|
1567 |
]. |
|
1568 |
checkedNode isMethod ifTrue:[ |
|
1569 |
"/ completion in a method's selector pattern |
|
1570 |
self codeCompletionForMethodSpec:checkedNode. |
|
1571 |
^ self. |
|
1572 |
]. |
|
1573 |
checkedNode := checkedNode parent. |
|
4238 | 1574 |
]. |
1575 |
||
1576 |
self information:'Node is neither variable nor message.'. |
|
1577 |
||
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1578 |
"Created: / 18-09-2013 / 15:25:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1579 |
! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1580 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1581 |
codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1582 |
"provide code completion information by analyzing what the editing state is in codeViewArg |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1583 |
(cursor position, characters around cursor etc.) and calling back into actionBlock, passing |
4591 | 1584 |
the info as argument. |
1585 |
The interface has been defined in that way |
|
1586 |
(and tight coupling with internals of the editor) because |
|
1587 |
1) the completer needs to know about the text around the cursor position |
|
1588 |
2) the edit operation for completion may be non-trivial |
|
1589 |
(although not yet fully implemented, non-local rewrite procedures may and will be added in the future |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1590 |
For example, in many situations, both a completion of a unary selector before the cursor, |
4591 | 1591 |
or adding another keyword part after the cursor is possible. |
4926 | 1592 |
Thus, this provides a list of completions PLUS a list of edit operations (as per completion), |
1593 |
to perform the completion. |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1594 |
The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1595 |
An additional array containing a textual description for each suggestion is also provided, which could |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1596 |
be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1597 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1598 |
ContextOrNil is the current context, if this is called from the debugger; |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1599 |
or nil, if called from the browser. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1600 |
If nonNil, we can make better guesses, because we actually know what a variable's type is" |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1601 |
|
4524 | 1602 |
|crsrPos char interval i source partialSource cursorLineSource |
5080 | 1603 |
suggestions actions title suggestionCollector| |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1604 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1605 |
languageOrNil := SmalltalkLanguage instance. |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1606 |
methodOrNil := methodOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1607 |
classOrNil := classOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1608 |
codeView := codeViewArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1609 |
contextOrNil := contextOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1610 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1611 |
"/ classOrNil isNil ifTrue:[ |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1612 |
"/ self information:'No class'. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1613 |
"/ ^ self. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1614 |
"/ ]. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1615 |
|
4524 | 1616 |
crsrPos := codeView characterPositionOfCursor. |
4592 | 1617 |
char := codeView characterAtCharacterPosition:(crsrPos-1 max:1). |
4591 | 1618 |
[crsrPos > 1 and:[char isSeparator "or:['.' includes:char]"]] whileTrue:[ |
1619 |
crsrPos := crsrPos - 1. |
|
1620 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
1621 |
]. |
|
4711 | 1622 |
char == $. ifTrue:[ |
4591 | 1623 |
"/ either at end of statement or after a character constant |
1624 |
crsrPos == 1 ifTrue:[^ self]. |
|
1625 |
(codeView characterAtCharacterPosition:crsrPos-1) == $$ ifFalse:[^ self]. |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1626 |
]. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1627 |
|
5080 | 1628 |
suggestionCollector := |
1629 |
[:listOfSuggestions :listOfActionsOrBlock :titleWhenAsking | |
|
1630 |
"/ may be called multiple times!! |
|
1631 |
suggestions isNil ifTrue:[ |
|
1632 |
suggestions := listOfSuggestions. |
|
1633 |
actions := listOfActionsOrBlock. |
|
1634 |
title := titleWhenAsking. |
|
1635 |
] ifFalse:[ |
|
1636 |
suggestions := suggestions asOrderedCollection. |
|
1637 |
actions isBlock ifTrue:[ |
|
1638 |
actions := Array new:suggestions size withAll:actions. |
|
1639 |
]. |
|
1640 |
actions := actions asOrderedCollection. |
|
1641 |
||
1642 |
suggestions addAll:listOfSuggestions. |
|
1643 |
listOfActionsOrBlock isBlock ifTrue:[ |
|
1644 |
actions addAll:(Array new:listOfSuggestions size withAll:listOfActionsOrBlock). |
|
1645 |
] ifFalse:[ |
|
1646 |
actions addAll:listOfActionsOrBlock. |
|
1647 |
]. |
|
1648 |
title := titleWhenAsking. |
|
1649 |
]. |
|
1650 |
]. |
|
1651 |
||
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1652 |
interval := crsrPos-1 to:crsrPos. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1653 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1654 |
source := codeView contentsAsString string. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1655 |
partialSource := source copyTo:crsrPos. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1656 |
|
4524 | 1657 |
methodOrNilArg isNil ifTrue:[ |
4926 | 1658 |
(partialSource endsWith:Character cr) ifTrue:[ |
1659 |
partialSource := partialSource copyButLast. |
|
1660 |
]. |
|
4591 | 1661 |
"/ first try parsing the current cursor line. |
1662 |
"/ this helps doIts in a workspace, where additional garbage is often before the actual expression to be evaluated |
|
1663 |
(i := partialSource lastIndexOf:Character cr) ~~ 0 ifTrue:[ |
|
1664 |
"/ because cursorPositions and node-positions are required elsewhere to be correct, |
|
1665 |
"/ I cannot just snip off the line and parse that one alone (later corrections will do so at wrong position). |
|
4926 | 1666 |
"/ Instead, create a copy of the whole source, with the stuff before the cursor line being blanked out. |
1667 |
"/ However, because somewhere else, we fetch characters from the codeView using the index, |
|
1668 |
"/ we must preserve the line structure (i.e. keep crs). |
|
4591 | 1669 |
cursorLineSource := partialSource copy. |
4926 | 1670 |
1 to:i do:[:pos | |
1671 |
(cursorLineSource at:pos) ~= Character cr ifTrue:[ |
|
1672 |
cursorLineSource at:pos put:Character space. |
|
1673 |
] |
|
1674 |
]. |
|
4591 | 1675 |
self |
1676 |
tryCodeCompletionWithSource:cursorLineSource nodeInterval:interval |
|
1677 |
at:crsrPos mustBeExpression:true |
|
5080 | 1678 |
into:suggestionCollector. |
4591 | 1679 |
]. |
4524 | 1680 |
]. |
4933 | 1681 |
|
5076 | 1682 |
"/ suggestions isEmptyOrNil ifTrue:[ |
1683 |
"/ "/ try parsing the partial source (from beginning up to the cursor) |
|
1684 |
"/ self |
|
1685 |
"/ tryCodeCompletionWithSource:partialSource nodeInterval:interval |
|
1686 |
"/ at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil]) |
|
5080 | 1687 |
"/ into:suggestionCollector. |
5076 | 1688 |
"/ ]. |
1689 |
||
4933 | 1690 |
suggestions isEmptyOrNil ifTrue:[ |
5076 | 1691 |
"/ try parsing the whole source |
1692 |
self |
|
1693 |
tryCodeCompletionWithSource:source nodeInterval:interval |
|
1694 |
at:crsrPos mustBeExpression:false |
|
5080 | 1695 |
into:suggestionCollector |
5076 | 1696 |
]. |
1697 |
||
1698 |
suggestions isNil ifTrue:[ |
|
4933 | 1699 |
"/ try parsing the partial source (from beginning up to the cursor) |
1700 |
self |
|
1701 |
tryCodeCompletionWithSource:partialSource nodeInterval:interval |
|
1702 |
at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil]) |
|
5080 | 1703 |
into:suggestionCollector. |
5076 | 1704 |
]. |
1705 |
||
1706 |
suggestions isEmptyOrNil ifTrue:[ |
|
1707 |
"/ nothing found |
|
1708 |
^ self |
|
4933 | 1709 |
]. |
1710 |
actionBlock value:suggestions value:actions value:title. |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1711 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1712 |
"Created: / 18-09-2013 / 15:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1713 |
! ! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1714 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1715 |
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1716 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1717 |
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1718 |
<resource: #obsolete> |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1719 |
"OBSOLETE; migrating to use the the new 'xxx: into:' protocol. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1720 |
contextOrNil is the current context, if this is called from the debugger; |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1721 |
nil, if called from the browser. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1722 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1723 |
This is not yet done, sigh" |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1724 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1725 |
^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1726 |
|
4238 | 1727 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
4346 | 1728 |
"Modified: / 28-08-2013 / 17:15:25 / cg" |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1729 |
"Modified: / 18-09-2013 / 14:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4352 | 1730 |
! |
1731 |
||
1732 |
codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1733 |
<resource: #obsolete> |
4524 | 1734 |
^ self |
4548 | 1735 |
codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
4238 | 1736 |
! ! |
1737 |
||
1738 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers'! |
|
1739 |
||
4548 | 1740 |
askUserForCompletion:what for:codeView at:position from:allTheBest |
4238 | 1741 |
|list choice lastChoice| |
1742 |
||
1743 |
"/ cg: until the new stuff works,... |
|
1744 |
^ self old_askUserForCompletion:what for:codeView from:allTheBest. |
|
1745 |
||
4346 | 1746 |
"/ allTheBest isEmpty ifTrue:[ |
1747 |
"/ ^ nil |
|
1748 |
"/ ]. |
|
1749 |
"/ allTheBest size == 1 ifTrue:[ |
|
1750 |
"/ ^ allTheBest first |
|
1751 |
"/ ]. |
|
1752 |
"/ list := allTheBest. |
|
1753 |
"/ LastChoices notNil ifTrue:[ |
|
1754 |
"/ lastChoice := LastChoices at:what ifAbsent:nil. |
|
1755 |
"/ lastChoice notNil ifTrue:[ |
|
1756 |
"/ list := { lastChoice allBold } , (list copyWithout:lastChoice). |
|
1757 |
"/ ]. |
|
1758 |
"/ ]. |
|
4548 | 1759 |
"/ choice := Tools::CodeCompletionMenu |
4346 | 1760 |
"/ openFor:codeView |
1761 |
"/ at:position |
|
1762 |
"/ with:allTheBest. |
|
1763 |
"/ LastChoices isNil ifTrue:[ |
|
1764 |
"/ LastChoices := Dictionary new. |
|
1765 |
"/ ]. |
|
1766 |
"/ LastChoices at:what put:choice. |
|
1767 |
"/ ^ choice string |
|
4238 | 1768 |
|
1769 |
"Created: / 16-02-2010 / 10:09:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 1770 |
"Modified: / 28-08-2013 / 16:41:35 / cg" |
4238 | 1771 |
! |
1772 |
||
1773 |
askUserForCompletion:what for:codeView from:allTheBest |
|
1774 |
|list resources choice lastChoice| |
|
1775 |
||
1776 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
1777 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
1778 |
||
1779 |
list := allTheBest. |
|
1780 |
LastChoices notNil ifTrue:[ |
|
4548 | 1781 |
lastChoice := LastChoices at:what ifAbsent:nil. |
1782 |
lastChoice notNil ifTrue:[ |
|
1783 |
list := {lastChoice. nil. } , (list copyWithout:lastChoice). |
|
1784 |
]. |
|
4238 | 1785 |
]. |
1786 |
||
1787 |
list size < 30 ifTrue:[ |
|
4548 | 1788 |
|menu idx exitKey| |
1789 |
||
1790 |
menu := PopUpMenu labels:list. |
|
1791 |
menu hideOnKeyFilter:[:key | |hide| |
|
1792 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
1793 |
hide ifTrue:[ |
|
1794 |
exitKey := key. |
|
1795 |
]. |
|
1796 |
hide]. |
|
1797 |
||
1798 |
idx := menu startUp. |
|
1799 |
idx == 0 ifTrue:[ |
|
1800 |
exitKey notNil ifTrue:[ |
|
1801 |
codeView keyPress:exitKey x:0 y:0. |
|
1802 |
]. |
|
1803 |
^ nil |
|
1804 |
]. |
|
1805 |
choice := list at:idx. |
|
4238 | 1806 |
] ifFalse:[ |
4548 | 1807 |
resources := codeView application isNil |
1808 |
ifTrue:[ codeView resources] |
|
1809 |
ifFalse:[ codeView application resources ]. |
|
1810 |
||
1811 |
choice := Dialog |
|
1812 |
choose:(resources string:'Choose ',what) |
|
1813 |
fromList:list |
|
1814 |
lines:20 |
|
1815 |
title:(resources string:'Code completion'). |
|
1816 |
choice isNil ifTrue:[^ nil]. |
|
4238 | 1817 |
]. |
1818 |
||
1819 |
LastChoices isNil ifTrue:[ |
|
4548 | 1820 |
LastChoices := Dictionary new. |
4238 | 1821 |
]. |
1822 |
LastChoices at:what put:choice. |
|
1823 |
^ choice |
|
1824 |
||
1825 |
"Created: / 10-11-2006 / 14:00:53 / cg" |
|
1826 |
! |
|
1827 |
||
5106 | 1828 |
codeCompletionForBlockArgument:node into:actionBlock |
1829 |
! |
|
1830 |
||
4382 | 1831 |
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock |
4352 | 1832 |
"looking for all symbols is way too much and inprecise; |
1833 |
experiment: only present symbols which are used by the class, |
|
4544 | 1834 |
and classes in that class category, or at least: implemented as method. |
1835 |
We'll see..." |
|
4352 | 1836 |
|
4382 | 1837 |
|sym possibleCompletions longest editAction start stop addSymbol |
1838 |
parentSelector parent symbolSelectorClass| |
|
4238 | 1839 |
|
4302 | 1840 |
"/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 1841 |
|
4382 | 1842 |
start := (nodeOrNil ? tokenOrNil) start. |
1843 |
stop := (nodeOrNil ? tokenOrNil) stop. |
|
4352 | 1844 |
(codeView characterAtCharacterPosition:stop) == $' ifTrue:[ |
5031 | 1845 |
^ self. |
4352 | 1846 |
]. |
1847 |
||
4382 | 1848 |
sym := (nodeOrNil ? tokenOrNil) value. |
4544 | 1849 |
possibleCompletions := Set new. |
4238 | 1850 |
|
4352 | 1851 |
addSymbol := |
5031 | 1852 |
[:aSymbol | |
1853 |
(aSymbol startsWith:sym) ifTrue:[ |
|
1854 |
(aSymbol = sym) ifFalse:[ |
|
1855 |
possibleCompletions add:aSymbol |
|
1856 |
]. |
|
1857 |
]. |
|
1858 |
]. |
|
4352 | 1859 |
|
4382 | 1860 |
(nodeOrNil notNil |
1861 |
and:[ (parent := nodeOrNil parent) notNil |
|
1862 |
and:[ parent isMessage ]]) ifTrue:[ |
|
5031 | 1863 |
parentSelector := parent selector. |
1864 |
( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[ |
|
1865 |
symbolSelectorClass := self classOfNode:parent receiver. |
|
1866 |
]. |
|
1867 |
( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[ |
|
1868 |
"/ assume that send-target will be self. |
|
1869 |
(methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[ |
|
1870 |
addSymbol value:(methodOrNil selector,'Changed'). |
|
1871 |
]. |
|
1872 |
symbolSelectorClass := classOrNil. |
|
1873 |
]. |
|
1874 |
( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[ |
|
1875 |
symbolSelectorClass := self classOfNode:parent arguments second. |
|
1876 |
]. |
|
5074 | 1877 |
|
1878 |
"/ actually, I found that this gives good suggestions. |
|
1879 |
symbolSelectorClass isNil ifTrue:[ |
|
1880 |
symbolSelectorClass := classOrNil. |
|
1881 |
]. |
|
1882 |
||
5031 | 1883 |
symbolSelectorClass notNil ifTrue:[ |
1884 |
symbolSelectorClass withAllSuperclassesDo:[:cls | |
|
1885 |
cls ~~ Object ifTrue:[ |
|
1886 |
cls ~~ Model ifTrue:[ |
|
1887 |
cls methodDictionary keysDo:addSymbol. |
|
1888 |
] |
|
1889 |
] |
|
1890 |
] |
|
1891 |
]. |
|
4382 | 1892 |
]. |
1893 |
||
4368 | 1894 |
(considerAll or:[classOrNil isNil]) ifTrue:[ |
5031 | 1895 |
Smalltalk allClassesDo:[:cls | |
1896 |
cls theNonMetaclass methodDictionary keys do:addSymbol. |
|
1897 |
cls theMetaclass methodDictionary keys do:addSymbol. |
|
1898 |
]. |
|
1899 |
||
1900 |
"/ Symbol allInstancesDo:addSymbol. |
|
4368 | 1901 |
] ifFalse:[ |
5031 | 1902 |
Smalltalk allClassesInCategory:classOrNil do:[:cls | |
1903 |
cls theNonMetaclass instAndClassMethodsDo:[:mthd | |
|
1904 |
mthd usedSymbols do:addSymbol |
|
1905 |
] |
|
1906 |
]. |
|
4238 | 1907 |
]. |
4352 | 1908 |
|
5031 | 1909 |
"/ add symbolic literals (especially for spec methods) |
1910 |
classOrNil notNil ifTrue:[ |
|
1911 |
classOrNil theMetaclass instAndClassMethodsDo:[:mthd | |
|
1912 |
mthd literalsDo:[:lit | |
|
1913 |
lit isSymbol ifTrue:[ addSymbol value: lit ] |
|
1914 |
]. |
|
1915 |
]. |
|
1916 |
]. |
|
1917 |
||
4544 | 1918 |
possibleCompletions := possibleCompletions asOrderedCollection sort. |
4352 | 1919 |
|
1920 |
longest := possibleCompletions longestCommonPrefix. |
|
1921 |
possibleCompletions remove:longest ifAbsent:[]. |
|
1922 |
possibleCompletions addFirst: longest. |
|
1923 |
||
1924 |
editAction := |
|
5031 | 1925 |
[:chosenIndex | |
1926 |
|chosen oldSym oldLen newLen| |
|
1927 |
||
1928 |
chosen := possibleCompletions at:chosenIndex. |
|
1929 |
chosen notNil ifTrue:[ |
|
1930 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
1931 |
start := start + 1. |
|
1932 |
]. |
|
1933 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
1934 |
start := start + 1. |
|
1935 |
]. |
|
1936 |
||
1937 |
oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
1938 |
||
1939 |
codeView |
|
1940 |
undoableDo:[ |
|
1941 |
codeView replaceFromCharacterPosition:start to:stop with:chosen |
|
1942 |
] |
|
1943 |
info:'Completion'. |
|
1944 |
||
1945 |
(chosen startsWith:oldSym) ifTrue:[ |
|
1946 |
oldLen := stop - start + 1. |
|
1947 |
newLen := chosen size. |
|
1948 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
1949 |
codeView dontReplaceSelectionOnInput |
|
1950 |
]. |
|
1951 |
] |
|
1952 |
]. |
|
4352 | 1953 |
|
1954 |
actionBlock value:possibleCompletions value:editAction value:'symbol'. |
|
4238 | 1955 |
|
1956 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1957 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
1958 |
! |
|
1959 |
||
1960 |
codeCompletionForMessage:node into:actionBlock |
|
5031 | 1961 |
"find good completions for a message selector in a message-send node" |
1962 |
||
5071 | 1963 |
|selector lcSelector bestSelectors parentSelector newParentSelector bestSelectors2 bestWithParenthesis allBest numArgs |
4548 | 1964 |
newParts nSelParts oldLen newLen selectorParts |
5112 | 1965 |
parentNode nodeReceiver "selectorsSentInCode" selectorsImplementedInClass |
5044 | 1966 |
editAction parentNodeClassIfKnown |
5038 | 1967 |
receiverNodeClassIfKnown |
5071 | 1968 |
offerParenthisationAroundNode parenthesisAroundIndex parentNodeToParenthesize |
1969 |
offerValueInsertion valueToInsert valueToInsertIndex valueInfo |
|
5043 | 1970 |
classesFromAssignmentsToReceiver otherMessagesToReceiver |
5103 | 1971 |
canParenthesize classesOfReceiver| |
5040 | 1972 |
|
5112 | 1973 |
Verbose == true ifTrue:[ |
1974 |
Transcript show:'node '; show:node; show:' ; '. |
|
1975 |
Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
|
1976 |
]. |
|
1977 |
||
5038 | 1978 |
offerParenthisationAroundNode := nil. |
5071 | 1979 |
offerValueInsertion := false. |
5040 | 1980 |
|
4238 | 1981 |
selector := node selector. |
4936 | 1982 |
lcSelector := selector asLowercase. |
4352 | 1983 |
parentNode := node parent. |
4408 | 1984 |
nodeReceiver := node receiver. |
5103 | 1985 |
nodeReceiver notNil ifTrue:[ |
1986 |
classesOfReceiver := self classesOfNode:nodeReceiver. |
|
1987 |
]. |
|
5112 | 1988 |
Verbose == true ifTrue:[ |
1989 |
Transcript show:node; show:' -> '; showCR:classesOfReceiver. |
|
1990 |
( node isVariable and:[node name = 'self']) ifTrue:[self halt]. |
|
1991 |
]. |
|
1992 |
||
4366 | 1993 |
"/ if there is already space before the cursor, and the parent node is not a message, |
4620 | 1994 |
"/ do not attempt to complete the current message. |
4366 | 1995 |
"/ If it is a message, we will look for parent-message completion also below (best2 stuff) |
5385 | 1996 |
(codeView characterBeforeCursor ? Character space) isSeparator ifTrue:[ |
5038 | 1997 |
selector isKeyword ifFalse:[ |
5041 | 1998 |
self codeCompletionForMessageTo:node into:actionBlock. |
5040 | 1999 |
^ self |
4610 | 2000 |
]. |
4352 | 2001 |
]. |
5040 | 2002 |
|
4620 | 2003 |
"/ only do this if the node-message has no parents around |
2004 |
node parentheses isEmptyOrNil ifTrue:[ |
|
5112 | 2005 |
Verbose == true ifTrue:[ |
2006 |
Transcript show:'try for: '; showCR:nodeReceiver |
|
2007 |
]. |
|
2008 |
bestSelectors := self findBest:nodeReceiver for:selector |
|
2009 |
inClasses:classesOfReceiver |
|
4620 | 2010 |
] ifFalse:[ |
2011 |
bestSelectors := OrderedCollection new. |
|
2012 |
]. |
|
5040 | 2013 |
|
4548 | 2014 |
"/ if the receiver is a real variable, |
4386 | 2015 |
"/ we can look for other messages being sent to that variable in the current method. |
5042 | 2016 |
"/ Also, if there are assignments to it (like constants or '<class> new'), use that as a hint... |
4548 | 2017 |
(tree notNil |
4610 | 2018 |
and:[ nodeReceiver isVariable |
2019 |
and:[ nodeReceiver isSelf not |
|
2020 |
and:[ nodeReceiver isSuper not ]]]) |
|
4366 | 2021 |
ifTrue:[ |
5042 | 2022 |
|receiverName possibleClasses possibleClassesFromOtherSends| |
5040 | 2023 |
|
2024 |
receiverName := nodeReceiver name. |
|
2025 |
||
5043 | 2026 |
classesFromAssignmentsToReceiver := self classesFromAssignmentTo:receiverName in:tree. |
2027 |
||
5040 | 2028 |
possibleClasses := classesFromAssignmentsToReceiver. |
2029 |
possibleClasses isEmpty ifTrue:[ |
|
2030 |
"/ messages sent |
|
5043 | 2031 |
otherMessagesToReceiver := self messagesSentTo:receiverName in:tree. |
5042 | 2032 |
otherMessagesToReceiver remove:selector ifAbsent:[]. |
2033 |
||
5040 | 2034 |
otherMessagesToReceiver notEmpty ifTrue:[ |
2035 |
"/ classes which respond to all |
|
2036 |
possibleClassesFromOtherSends := |
|
2037 |
Smalltalk |
|
2038 |
allClassesForWhich:[:cls | |
|
2039 |
cls isLoaded |
|
2040 |
and:[ otherMessagesToReceiver |
|
2041 |
conform:[:eachSelectorSent | cls canUnderstand:eachSelectorSent]] |
|
2042 |
]. |
|
2043 |
possibleClasses := possibleClasses , possibleClassesFromOtherSends. |
|
2044 |
]. |
|
4610 | 2045 |
]. |
5040 | 2046 |
|
4933 | 2047 |
"/ if the receiver is a classVar/classInstVar, |
4610 | 2048 |
"/ include the class of its current value and UndefinedObject. |
2049 |
"/ This helps to complete class methods and (lazy) initializer code. |
|
2050 |
(classOrNil notNil) ifTrue:[ |
|
2051 |
|tryValue currentValue| |
|
5040 | 2052 |
|
4610 | 2053 |
tryValue := false. |
5040 | 2054 |
(classOrNil theNonMetaclass allClassVarNames includes: receiverName) ifTrue:[ |
4610 | 2055 |
tryValue := true. |
5040 | 2056 |
currentValue := classOrNil theNonMetaclass classVarAt:receiverName. |
4610 | 2057 |
] ifFalse:[ |
5040 | 2058 |
(classOrNil isMeta and:[ classOrNil allInstVarNames includes: receiverName ]) ifTrue:[ |
4610 | 2059 |
tryValue := true. |
5040 | 2060 |
currentValue := classOrNil theNonMetaclass instVarNamed:receiverName. |
4610 | 2061 |
]. |
2062 |
]. |
|
2063 |
tryValue ifTrue:[ |
|
2064 |
possibleClasses := { currentValue class } , possibleClasses. |
|
2065 |
]. |
|
2066 |
]. |
|
5040 | 2067 |
|
4610 | 2068 |
(possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[ |
4933 | 2069 |
bestSelectors := |
2070 |
(possibleClasses |
|
2071 |
collectAll:[:eachClass | |
|
2072 |
Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true. |
|
2073 |
] as:Set) asOrderedCollection. |
|
5040 | 2074 |
|
4619 | 2075 |
"/ if any of those is a prefix-keyword of the selector, |
2076 |
"/ do not offer it (i.e. ifTrue:ifFalse: is already present, don't offer ifTrue:ifFalse: again. |
|
2077 |
bestSelectors := bestSelectors reject: [:sel | (selector startsWith: sel) or: [selector endsWith: sel]]. |
|
4610 | 2078 |
]. |
4619 | 2079 |
]. |
5040 | 2080 |
|
4352 | 2081 |
"/ if we are behind a keyword messages colon, |
2082 |
"/ only look for matching prefix selectors; |
|
2083 |
"/ also, a good completion is to insert an argument; |
|
2084 |
"/ the name of the variable from the implementation, as comment, and selected might be a good one!! |
|
5038 | 2085 |
"/ Array new:1 |
4352 | 2086 |
selector isKeyword ifTrue:[ |
5385 | 2087 |
(node arguments size = selector argumentCount) ifTrue:[ |
5040 | 2088 |
offerParenthisationAroundNode := node. |
5042 | 2089 |
"/ Transcript show:'2:'; showCR:node. |
5038 | 2090 |
]. |
5040 | 2091 |
|
4610 | 2092 |
codeView characterBeforeCursor == $: ifTrue:[ |
5038 | 2093 |
(bestSelectors select:[:sel | sel asLowercase startsWith:lcSelector]) isEmpty ifTrue:[ |
4610 | 2094 |
"/ nothing better around |
5080 | 2095 |
|argIndex argNames argNameStrings impls| |
5040 | 2096 |
|
4610 | 2097 |
argIndex := node selectorParts size. |
2098 |
argNames := Set new. |
|
5080 | 2099 |
argNameStrings := OrderedCollection new. |
4610 | 2100 |
impls := Smalltalk allImplementorsOf:selector. |
2101 |
impls size < 10 ifTrue:[ |
|
2102 |
impls do:[:eachImplClass | |
|
2103 |
|mthd argName| |
|
5040 | 2104 |
|
4610 | 2105 |
mthd := (eachImplClass compiledMethodAt:selector). |
4764 | 2106 |
argName := (mthd methodArgNames ? #()) at:argIndex ifAbsent:nil. |
2107 |
argName notNil ifTrue:[ |
|
5080 | 2108 |
(argNames includes:argName) ifFalse:[ |
2109 |
argNames add:argName. |
|
2110 |
argNameStrings add:(argName allItalic,' hint only: argName in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate). |
|
2111 |
]. |
|
4764 | 2112 |
]. |
4610 | 2113 |
]. |
5080 | 2114 |
argNameStrings notEmptyOrNil ifTrue: [ |
2115 |
argNameStrings := argNameStrings asOrderedCollection sort. |
|
2116 |
actionBlock value:argNameStrings value:[:selIndex | ] value: 'argument name hint'. |
|
4610 | 2117 |
^ self. |
2118 |
] |
|
2119 |
] |
|
5038 | 2120 |
]. |
4610 | 2121 |
]. |
4369 | 2122 |
] ifFalse:[ |
4610 | 2123 |
"/ when completing a non-keyword AND the parent is a keyword message, |
5080 | 2124 |
"/ only consider longer keyword messages or unary messages. |
2125 |
"/ unless the node is parenthesized |
|
2126 |
node hasParentheses ifFalse:[ |
|
2127 |
(parentNode notNil and:[ parentNode isKeywordMessage ]) ifTrue:[ |
|
2128 |
bestSelectors := bestSelectors select:[:sel | sel isUnarySelector or:[ sel startsWith:sel]] |
|
2129 |
] |
|
4610 | 2130 |
] |
4352 | 2131 |
]. |
5040 | 2132 |
|
2133 |
"/ bestSelectors := bestSelectors asOrderedCollection. |
|
2134 |
"/ bestSelectors sort:[:a :b | a size < b size]. |
|
2135 |
||
5038 | 2136 |
(selector isUnarySelector and:[ parentNode notNil and:[ parentNode isMessage ]]) ifTrue:[ |
5058 | 2137 |
(parentSelector := parentNode selector) isKeyword ifTrue:[ |
4610 | 2138 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
2139 |
"/ i.e. look if there is a longer keyword possible |
|
5058 | 2140 |
newParentSelector := parentSelector,selector. |
5112 | 2141 |
bestSelectors2 := self |
2142 |
findBest:(parentNode receiver) for:newParentSelector |
|
2143 |
inClasses:(self classesOfNode:parentNode receiver). |
|
5058 | 2144 |
bestSelectors2 := bestSelectors2 select:[:sel | sel isKeyword and:[ sel startsWith:parentSelector]]. |
4610 | 2145 |
bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size]. |
2146 |
bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel]. |
|
5040 | 2147 |
|
5038 | 2148 |
"/ if the parent has a valid selector, offer parenthization |
5058 | 2149 |
(Smalltalk someImplementorOf:parentSelector) notNil ifTrue:[ |
5038 | 2150 |
offerParenthisationAroundNode := parentNode. |
5040 | 2151 |
"/ Transcript show:'2:'; showCR:parentNode. |
5038 | 2152 |
]. |
4610 | 2153 |
] ifFalse:[ |
2154 |
|kwSels| |
|
5040 | 2155 |
|
5103 | 2156 |
"/ if its a unary message AND the parent is a unary or binary node, |
2157 |
"/ try again, sending the partial message |
|
4610 | 2158 |
"/ as a keyword to the parent node. |
5103 | 2159 |
"/ this is the case when after "foo binOp bar if", or "foo unOp bar if" |
2160 |
"/ which should include ifTrue: in the suggestion result. |
|
2161 |
||
2162 |
"/ suggestion will transform from (the incorrectly parsed) |
|
4610 | 2163 |
"/ foo == (shift if) |
5103 | 2164 |
"/ |
4610 | 2165 |
"/ nonKWsel-msg(parent) |
2166 |
"/ / \ |
|
2167 |
"/ / \ |
|
2168 |
"/ rcvr sel-unary(node) |
|
2169 |
"/ / |
|
2170 |
"/ / |
|
2171 |
"/ arg |
|
2172 |
"/ |
|
2173 |
"/ into: |
|
2174 |
"/ (foo == shift) if |
|
2175 |
"/ |
|
2176 |
"/ nonKWsel-msg(parent) |
|
2177 |
"/ / \ |
|
2178 |
"/ / \ |
|
2179 |
"/ rcvr sel-unary(node) |
|
2180 |
"/ / |
|
2181 |
"/ / |
|
2182 |
"/ arg |
|
5040 | 2183 |
|
5103 | 2184 |
"/ but only do this, if typing to the end of the parent message |
2185 |
"/ (i.e. after (foo == shift) <- |
|
2186 |
"/ or after foo bar baz <- |
|
2187 |
"/ not if typing into an existing message |
|
2188 |
"/ (i.e. into foo == shift <- more |
|
2189 |
"/ or into foo bar <- baz |
|
2190 |
codeView characterPositionOfCursor >= parentNode stop ifTrue:[ |
|
5112 | 2191 |
kwSels := self |
2192 |
findBest:parentNode for:selector |
|
2193 |
inClasses:(self classesOfNode:parentNode). |
|
5103 | 2194 |
kwSels := kwSels select:[:sel | sel isKeyword]. |
2195 |
||
2196 |
kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size]. |
|
5040 | 2197 |
|
5103 | 2198 |
bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel]. |
5040 | 2199 |
|
5103 | 2200 |
"/ these need to go to bestSelectors (see editAction) |
2201 |
parentNodeClassIfKnown := self classOfNode:parentNode. |
|
2202 |
(parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[ |
|
2203 |
"/ this is so common, that it deserves a special case: |
|
2204 |
"/ if we complete an if after some boolean message e.g '(a == b) if' |
|
2205 |
"/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic) |
|
2206 |
bestSelectors := self |
|
2207 |
withoutSelectorsUnlikelyFor:parentNodeClassIfKnown |
|
2208 |
from:bestSelectors |
|
2209 |
forPartial:selector. |
|
2210 |
kwSels := self |
|
2211 |
withoutSelectorsUnlikelyFor:parentNodeClassIfKnown |
|
2212 |
from:kwSels |
|
2213 |
forPartial:selector. |
|
2214 |
||
2215 |
"/ put keyword selectors in front, because they are very likely |
|
2216 |
bestSelectors := kwSels , bestSelectors. |
|
2217 |
] ifFalse:[ |
|
2218 |
"/ put them at the end |
|
2219 |
bestSelectors := bestSelectors , kwSels. |
|
2220 |
]. |
|
2221 |
] |
|
4610 | 2222 |
] |
4358 | 2223 |
]. |
5040 | 2224 |
|
5038 | 2225 |
(selector isUnarySelector and:[ node isMessage ]) ifTrue:[ |
4610 | 2226 |
receiverNodeClassIfKnown := self classOfNode:nodeReceiver. |
2227 |
(receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[ |
|
2228 |
"/ this is so common, that it deserves a special case: |
|
2229 |
"/ if we complete an if after some boolean message e.g '(a == b) if' |
|
2230 |
"/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic) |
|
2231 |
bestSelectors := self |
|
2232 |
withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown |
|
2233 |
from:bestSelectors |
|
2234 |
forPartial:selector. |
|
2235 |
]. |
|
4375 | 2236 |
]. |
5043 | 2237 |
|
5044 | 2238 |
Verbose == true ifTrue:[ |
2239 |
Transcript show:'parentNode: '; showCR:parentNode. |
|
2240 |
Transcript show:'parentNode: '; showCR:parentNode class. |
|
2241 |
Transcript show:'sel: '; showCR:selector. |
|
2242 |
]. |
|
5043 | 2243 |
|
2244 |
canParenthesize := false. |
|
2245 |
parentNode notNil ifTrue:[ |
|
2246 |
parentNode isMessage ifTrue:[ |
|
2247 |
(((parentNode selector isUnarySelector not) and:[selector isUnarySelector]) |
|
2248 |
or:[ ((parentNode selector isKeyword) and:[selector isBinarySelector]) ]) ifTrue:[ |
|
2249 |
canParenthesize := true. |
|
2250 |
] |
|
2251 |
] ifFalse:[ |
|
2252 |
offerParenthisationAroundNode isNil ifTrue:[ |
|
2253 |
selector isKeyword ifTrue:[ |
|
2254 |
offerParenthisationAroundNode := node. |
|
2255 |
]. |
|
2256 |
]. |
|
2257 |
]. |
|
2258 |
]. |
|
2259 |
canParenthesize ifTrue:[ |
|
5038 | 2260 |
"/ completing an already existing keyword or binary message with something starting with |
4610 | 2261 |
"/ if, and, or or while. |
5203 | 2262 |
"/ Here, offer a special completion which inserts parentheses / brackets around the already |
4610 | 2263 |
"/ existing message. Do this only, if the existing message makes sense. |
5038 | 2264 |
"/ expr wh |
2265 |
"/ -> |
|
2266 |
"/ [expr] whileXX:[] |
|
5040 | 2267 |
true "(( |
5038 | 2268 |
#( 'ifTrue' 'ifFalse' 'and' 'or' 'do' 'keysAndValuesDo' 'whileTrue' 'whileFalse' 'ensure' 'on') |
5040 | 2269 |
) contains:[:part | part startsWith:selector])" ifTrue:[ |
5038 | 2270 |
(Smalltalk someImplementorOf:parentNode selector) notNil ifTrue:[ |
4610 | 2271 |
|selsP selsB| |
5040 | 2272 |
|
5038 | 2273 |
selsP := #( 'ifTrue:' 'ifFalse:' 'and' 'or' 'do' 'keysAndValuesDo' ) |
4610 | 2274 |
select:[:sel | sel startsWith:selector] |
5038 | 2275 |
thenCollect:[:sel | '(',parentNode selector,') ',sel]. |
5040 | 2276 |
( #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' ) contains:[:sel | sel startsWith:selector]) |
2277 |
ifFalse:[ |
|
2278 |
selsP := selsP copyWith:'(',parentNode selector,') ',selector |
|
2279 |
]. |
|
5038 | 2280 |
selsB := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' ) |
4610 | 2281 |
select:[:sel | sel startsWith:selector] |
5038 | 2282 |
thenCollect:[:sel | '[',parentNode selector,'] ',sel]. |
2283 |
parentNodeToParenthesize := parentNode. |
|
2284 |
bestWithParenthesis := selsP , selsB. |
|
4610 | 2285 |
]. |
2286 |
]. |
|
4421 | 2287 |
] ifFalse:[ |
5038 | 2288 |
"/ also offer adding brackets for a while expression |
2289 |
"/ expr wh |
|
2290 |
"/ -> |
|
2291 |
"/ [expr] whileXX:[] |
|
2292 |
(( |
|
2293 |
#( 'whileTrue' 'whileFalse' 'ensure' 'on') |
|
2294 |
) contains:[:part | part startsWith:selector]) ifTrue:[ |
|
2295 |
(node receiver isBlock) ifFalse:[ |
|
2296 |
|sels| |
|
5040 | 2297 |
|
5038 | 2298 |
(node receiver isMessage not |
2299 |
or:[ (Smalltalk someImplementorOf:node receiver selector) notNil ]) ifTrue:[ |
|
2300 |
sels := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' ) |
|
2301 |
select:[:sel | sel startsWith:selector] |
|
2302 |
thenCollect:[:sel | '[...] ',sel]. |
|
2303 |
parentNodeToParenthesize := node receiver. |
|
2304 |
bestWithParenthesis := sels. |
|
2305 |
]. |
|
2306 |
]. |
|
4610 | 2307 |
]. |
4416 | 2308 |
]. |
5040 | 2309 |
|
5419 | 2310 |
allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()) asOrderedCollection. |
5043 | 2311 |
self sortSelectors:allBest forSelector:selector lcSelector:lcSelector. |
4936 | 2312 |
|
4388 | 2313 |
"/ sort: prefixes first. |
5058 | 2314 |
parentSelector notNil ifTrue:[ |
5044 | 2315 |
allBest := self |
2316 |
splitSelectorList:allBest |
|
2317 |
by:[:sel | |
|
5031 | 2318 |
(sel asLowercase startsWith:lcSelector) |
5058 | 2319 |
or:[sel startsWith:parentSelector]]. |
4388 | 2320 |
]. |
5040 | 2321 |
|
4358 | 2322 |
"/ if receiver is super, always include the method's own selector |
4408 | 2323 |
nodeReceiver isSuper ifTrue:[ |
4610 | 2324 |
(tree isMethod) ifTrue:[ |
2325 |
|mSel| |
|
5040 | 2326 |
|
4610 | 2327 |
mSel := tree selector. |
2328 |
mSel notNil ifTrue:[ |
|
2329 |
(mSel startsWith:selector) ifTrue:[ |
|
2330 |
"/ already the word before the cursor? |
|
2331 |
(mSel ~= selector) ifTrue:[ |
|
5419 | 2332 |
allBest removeAndAddFirst:mSel. |
4610 | 2333 |
] |
2334 |
] |
|
2335 |
] |
|
2336 |
] |
|
4238 | 2337 |
]. |
5040 | 2338 |
|
5071 | 2339 |
"/ another convenient hack; |
2340 |
"/ if we have just typed in foo == |
|
2341 |
"/ and the value of foo is a known literal, |
|
2342 |
"/ offer inserting this literal. This is great in a debugger... |
|
2343 |
( #(#'==' #'=' #'~=' #'~~') includes:selector ) ifTrue:[ |
|
2344 |
|val| |
|
2345 |
||
2346 |
(val := self valueOfNode:nodeReceiver) notNil ifTrue:[ |
|
5285 | 2347 |
"/ this can raise an error, if val does not like to generate a storeString |
2348 |
"/ (it is recursive, or an X11GraphicsContext, for example) |
|
2349 |
Error handle:[:ex | |
|
2350 |
] do:[ |
|
2351 |
valueToInsert := val storeString. |
|
2352 |
offerValueInsertion := true. |
|
2353 |
nodeReceiver isVariable ifTrue:[ |
|
2354 |
valueInfo := ' (current value of %1)' bindWith:nodeReceiver name. |
|
2355 |
] ifFalse:[ |
|
2356 |
valueInfo := ' (current value of expression)'. |
|
2357 |
]. |
|
2358 |
valueInfo := valueInfo withColor:(Color grey). |
|
5071 | 2359 |
]. |
2360 |
]. |
|
2361 |
]. |
|
2362 |
||
2363 |
(allBest isEmptyOrNil |
|
2364 |
and:[bestWithParenthesis isEmptyOrNil |
|
2365 |
and:[offerParenthisationAroundNode isNil |
|
2366 |
and:[offerValueInsertion not]]] |
|
2367 |
) ifTrue:[ |
|
5038 | 2368 |
^ self |
2369 |
]. |
|
5040 | 2370 |
|
5042 | 2371 |
"/ "/ see what is aready sent to this variable inside the code |
2372 |
"/ "/ and also what is assigned to it. |
|
2373 |
"/ nodeReceiver notNil ifTrue:[ |
|
2374 |
"/ nodeReceiver isVariable ifTrue:[ |
|
2375 |
"/ rememberedNodes notNil ifTrue:[ |
|
2376 |
"/ selectorsSentInCode := |
|
2377 |
"/ (rememberedNodes |
|
2378 |
"/ select:[:node | |
|
2379 |
"/ node isMessage |
|
2380 |
"/ and:[node receiver isVariable |
|
2381 |
"/ and:[node receiver name = nodeReceiver name]]] |
|
2382 |
"/ thenCollect:[:node | |
|
2383 |
"/ node selector] |
|
2384 |
"/ ) asSet. |
|
2385 |
"/ ] ifFalse:[ |
|
2386 |
"/ selectorsSentInCode := Set new. |
|
2387 |
"/ tree allMessageNodesDo:[:msg | |
|
2388 |
"/ (msg receiver isVariable |
|
2389 |
"/ and:[msg receiver name = nodeReceiver name] |
|
2390 |
"/ ) ifTrue:[ |
|
2391 |
"/ selectorsSentInCode add:msg selector |
|
2392 |
"/ ]. |
|
2393 |
"/ ]. |
|
2394 |
"/ selectorsSentInCode remove:selector ifAbsent:[]. |
|
2395 |
"/ ]. |
|
2396 |
"/ ]. |
|
2397 |
"/ ]. |
|
2398 |
||
4936 | 2399 |
nodeReceiver notNil ifTrue:[ |
2400 |
|classOrNil| |
|
5042 | 2401 |
|
2402 |
classOrNil := self classOfNode:nodeReceiver. |
|
2403 |
classOrNil isNil ifTrue:[ |
|
2404 |
classesFromAssignmentsToReceiver size == 1 ifTrue:[ |
|
2405 |
classOrNil := classesFromAssignmentsToReceiver anElement |
|
2406 |
]. |
|
2407 |
]. |
|
2408 |
classOrNil notNil ifTrue:[ |
|
2409 |
selectorsImplementedInClass := classOrNil selectors. |
|
2410 |
"/ selectorsImplementedInClass := Set new. |
|
2411 |
"/ classOrNil withAllSuperclassesDo:[:cls | |
|
2412 |
"/ cls theNonMetaclass ~~ Object ifTrue:[ |
|
2413 |
"/ selectorsImplementedInClass addAll:cls selectors. |
|
2414 |
"/ ] |
|
2415 |
"/ ] |
|
4936 | 2416 |
] |
4934 | 2417 |
]. |
4936 | 2418 |
selectorsImplementedInClass notNil ifTrue:[ |
5040 | 2419 |
"/ the one's implemented in the class itself are moved to the top of the list. |
5044 | 2420 |
allBest := self |
2421 |
splitSelectorList:allBest |
|
2422 |
by:[:sel | selectorsImplementedInClass includes:sel]. |
|
4936 | 2423 |
]. |
5042 | 2424 |
otherMessagesToReceiver "selectorsSentInCode" notNil ifTrue:[ |
4610 | 2425 |
"/ the one's already sent in the code are moved to the top of the list. |
5040 | 2426 |
"/ trouble is: parser bails out on error, so most of the time, we only see |
2427 |
"/ selectors sent previously. sigh. |
|
5044 | 2428 |
allBest := self |
2429 |
splitSelectorList:allBest |
|
2430 |
by:[:sel | otherMessagesToReceiver "selectorsSentInCode" includes:sel]. |
|
4238 | 2431 |
]. |
5040 | 2432 |
|
2433 |
"/ this makes it very slow |
|
4548 | 2434 |
"/false ifTrue:[ |
2435 |
"/ srchClass notNil ifTrue:[ |
|
2436 |
"/ implClass := srchClass whichClassIncludesSelector:best. |
|
2437 |
"/ ] ifFalse:[ |
|
2438 |
"/ implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
2439 |
"/ implClass size == 1 ifTrue:[ |
|
2440 |
"/ implClass := implClass first. |
|
2441 |
"/ ] ifFalse:[ |
|
2442 |
"/ implClass := nil |
|
2443 |
"/ ] |
|
2444 |
"/ ]. |
|
2445 |
"/ |
|
2446 |
"/ info := best storeString. |
|
2447 |
"/ implClass notNil ifTrue:[ |
|
5397 | 2448 |
"/ info := implClass name , ' ' , info. |
4548 | 2449 |
"/ ]. |
2450 |
"/ self information:info. |
|
2451 |
"/]. |
|
5040 | 2452 |
|
2453 |
"/ the one's which are a prefix are moved towards the top of the list |
|
5044 | 2454 |
allBest := self splitSelectorList:allBest |
2455 |
by:[:sel | sel notNil and:[sel asLowercase startsWith:lcSelector]]. |
|
5040 | 2456 |
|
2457 |
"/ heuristic hack: |
|
2458 |
"/ 'i' and 'w' generate lists in which ifXXX / whileXXX are not at the top of the list. |
|
2459 |
"/ we know, that those are most often wanted!! |
|
2460 |
selector size <= 2 ifTrue:[ |
|
5044 | 2461 |
allBest := self |
2462 |
splitSelectorList:allBest |
|
2463 |
by:[:sel | |
|
5040 | 2464 |
#(ifTrue: ifFalse: isNil notNil whileTrue whileFalse) includes:sel |
2465 |
]. |
|
2466 |
]. |
|
2467 |
||
2468 |
self sortUsefulSelectorsIn:allBest. "/cosmetics |
|
2469 |
||
2470 |
"/ parenthesizers always at the end. |
|
2471 |
bestWithParenthesis notEmptyOrNil ifTrue:[ |
|
2472 |
allBest := allBest , bestWithParenthesis. |
|
2473 |
]. |
|
2474 |
||
5038 | 2475 |
"/ self at:1 put:#foo |
2476 |
"/ Array new:10 |
|
2477 |
offerParenthisationAroundNode notNil ifTrue:[ |
|
2478 |
allBest := allBest copyWith:( '(',selector,')' ). |
|
2479 |
parenthesisAroundIndex := allBest size. |
|
2480 |
]. |
|
5071 | 2481 |
offerValueInsertion ifTrue:[ |
2482 |
allBest := allBest copyWith:( '... ',(valueToInsert contractTo:30),valueInfo). |
|
2483 |
valueToInsertIndex := allBest size. |
|
2484 |
]. |
|
5040 | 2485 |
|
4548 | 2486 |
editAction := |
4610 | 2487 |
[:index | |
5040 | 2488 |
|crsrPos chosen parenthesisToInsert action| |
2489 |
||
5038 | 2490 |
action := nil. |
4610 | 2491 |
crsrPos := codeView characterPositionOfCursor. |
2492 |
chosen := allBest at:index. |
|
5040 | 2493 |
|
4610 | 2494 |
chosen ~= selector ifTrue:[ |
5038 | 2495 |
(bestWithParenthesis notNil and:[bestWithParenthesis includes:chosen]) ifTrue:[ |
2496 |
"/ for input like: |
|
2497 |
"/ chosen at: 10 if |
|
2498 |
"/ put parenthesis around, and add ifTrue/ifFalse |
|
2499 |
"/ i.e.: (chosen at:10) ifTrue:[] |
|
5040 | 2500 |
|
5038 | 2501 |
"/ for input like: |
2502 |
"/ a > 10 wh |
|
2503 |
"/ put brackets around and add whileTrue/whileFalse |
|
2504 |
"/ i.e.: [a > 10] whileTrue:[] |
|
5040 | 2505 |
parenthesisToInsert := chosen first == $( ifTrue:'()' ifFalse:'[]'. |
2506 |
chosen := (chosen copyFrom:(chosen lastIndexOf:parenthesisToInsert second)+1) withoutSeparators. |
|
5038 | 2507 |
] ifFalse:[ |
2508 |
(offerParenthisationAroundNode notNil and:[index = parenthesisAroundIndex]) ifTrue:[ |
|
2509 |
"/ for input like: |
|
2510 |
"/ Array new:10 |
|
2511 |
"/ put parenthesis around. |
|
2512 |
"/ i.e.: (Array new:10) |
|
2513 |
action := |
|
2514 |
[ |
|
2515 |
codeView insertString:'(' atCharacterPosition:offerParenthisationAroundNode start. |
|
2516 |
codeView insertString:')' atCharacterPosition:offerParenthisationAroundNode stop+2. |
|
2517 |
codeView cursorToCharacterPosition:(offerParenthisationAroundNode stop+2); cursorRight. |
|
2518 |
]. |
|
5071 | 2519 |
] ifFalse:[ |
2520 |
(offerValueInsertion and:[index = valueToInsertIndex]) ifTrue:[ |
|
2521 |
"/ for input like: |
|
2522 |
"/ foo == |
|
2523 |
"/ insert a value |
|
2524 |
"/ i.e.: foo == #someSymbol |
|
2525 |
action := |
|
2526 |
[ |
|
2527 |
codeView characterBeforeCursor isSeparator ifFalse:[ |
|
2528 |
codeView insertStringAtCursor:' '. |
|
2529 |
]. |
|
2530 |
codeView insertStringAtCursor:valueToInsert. |
|
2531 |
"/ codeView cursorRight. |
|
2532 |
]. |
|
2533 |
] |
|
2534 |
]. |
|
4610 | 2535 |
]. |
5040 | 2536 |
|
5038 | 2537 |
action isNil ifTrue:[ |
2538 |
numArgs := chosen numArgs. |
|
2539 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[ |
|
2540 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
2541 |
] ifFalse:[ |
|
2542 |
selectorParts := node selectorParts. |
|
2543 |
]. |
|
2544 |
nSelParts := selectorParts size. |
|
5040 | 2545 |
|
5038 | 2546 |
newParts := chosen asCollectionOfSubstringsSeparatedBy:$:. |
2547 |
newParts := newParts select:[:part | part size > 0]. |
|
5040 | 2548 |
|
5038 | 2549 |
action := |
2550 |
[ |
|
2551 |
|positionOfFirstArg newCursorPosition stop checkForArgumentTemplates |
|
2552 |
newPart oldPartialToken start| |
|
5040 | 2553 |
|
5038 | 2554 |
checkForArgumentTemplates := (selector isUnarySelector and:[chosen isKeywordSelector]). |
2555 |
numArgs > nSelParts ifTrue:[ |
|
2556 |
"/ new selector has more arguments; append them |
|
2557 |
stop := selectorParts last stop. |
|
2558 |
codeView deleteFromCharacterPosition:stop+1 to:crsrPos-1. |
|
5040 | 2559 |
|
5038 | 2560 |
"/ append the rest ... |
2561 |
(numArgs min:newParts size) downTo:(nSelParts+1) do:[:idx | |
|
2562 |
|newPart| |
|
5040 | 2563 |
|
5038 | 2564 |
newPart := newParts at:idx. |
2565 |
newPart := newPart , ':'. |
|
5040 | 2566 |
|
5038 | 2567 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
2568 |
newPart := ':' , newPart. |
|
2569 |
]. |
|
2570 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
5040 | 2571 |
|
5038 | 2572 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
2573 |
"/ remember the leftMost replacement's end as new cursor position |
|
2574 |
newCursorPosition := stop + newPart size |
|
2575 |
]. |
|
2576 |
checkForArgumentTemplates := true. |
|
2577 |
]. |
|
5040 | 2578 |
|
5038 | 2579 |
"/ replace existing parts |
2580 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
2581 |
|skipColon| |
|
5040 | 2582 |
|
5038 | 2583 |
skipColon := 0. |
2584 |
newPart := newParts at:idx. |
|
2585 |
oldPartialToken := selectorParts at:idx. |
|
2586 |
start := oldPartialToken start. |
|
2587 |
stop := oldPartialToken stop. |
|
5040 | 2588 |
|
5038 | 2589 |
(chosen endsWith:$:) ifTrue:[ |
2590 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
2591 |
newPart := newPart , ':'. |
|
2592 |
] ifTrue:[ |
|
2593 |
skipColon := 1. |
|
2594 |
] |
|
2595 |
] ifFalse:[ |
|
2596 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
2597 |
newPart := newPart , ':' |
|
2598 |
] ifFalse:[ |
|
2599 |
|nextChar| |
|
5040 | 2600 |
|
5038 | 2601 |
nextChar := codeView characterAtCharacterPosition:stop+1. |
2602 |
nextChar isSeparator ifFalse:[ |
|
2603 |
nextChar == $. ifFalse:[ |
|
2604 |
newPart := newPart , ' ' |
|
2605 |
]. |
|
2606 |
] |
|
2607 |
] |
|
2608 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
|
2609 |
"/ ] ifFalse:[ |
|
2610 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
2611 |
]. |
|
5040 | 2612 |
|
5038 | 2613 |
oldPartialToken value ~= newPart ifTrue:[ |
2614 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
5040 | 2615 |
|
5038 | 2616 |
oldLen := stop - start + 1. |
2617 |
newLen := newPart size. |
|
5040 | 2618 |
|
5038 | 2619 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
2620 |
"/ remember the leftMost replacement's end as new cursor position |
|
2621 |
newCursorPosition := start + newPart size + skipColon. "/ (newLen-oldLen) + 1. |
|
2622 |
"/ codeView cursorToCharacterPosition:newCursorPosition. |
|
2623 |
]. |
|
2624 |
]. |
|
2625 |
newCursorPosition notNil ifTrue:[ |
|
2626 |
codeView cursorToCharacterPosition:newCursorPosition-1. |
|
2627 |
codeView cursorRight. "/ avoid going to the next line !! |
|
2628 |
]. |
|
2629 |
codeView dontReplaceSelectionOnInput. |
|
5040 | 2630 |
|
5038 | 2631 |
checkForArgumentTemplates ifTrue:[ |
2632 |
"/ add opening brackets, etc. |
|
2633 |
self insertAdditonalStuffAfterSelector:chosen. |
|
2634 |
]. |
|
5040 | 2635 |
parenthesisToInsert notNil ifTrue:[ |
5038 | 2636 |
|sav pos| |
5040 | 2637 |
|
5038 | 2638 |
sav := codeView characterPositionOfCursor-1. |
2639 |
"/ check if already parenthized |
|
5040 | 2640 |
parentNodeToParenthesize hasParentheses ifTrue:[ |
2641 |
pos := parentNodeToParenthesize parentheses first first. |
|
5038 | 2642 |
codeView selectFromCharacterPosition:pos to:pos. |
5040 | 2643 |
codeView replaceSelectionBy:(parenthesisToInsert copyFirst:1) asString. |
2644 |
||
2645 |
pos := parentNodeToParenthesize parentheses first last. |
|
5038 | 2646 |
codeView selectFromCharacterPosition:pos to:pos. |
5040 | 2647 |
codeView replaceSelectionBy:(parenthesisToInsert copyLast:1) asString. |
5038 | 2648 |
codeView cursorToCharacterPosition:sav; cursorRight |
2649 |
] ifFalse:[ |
|
5040 | 2650 |
codeView insertString:(parenthesisToInsert copyLast:1) atCharacterPosition:node receiver stop+1. |
2651 |
codeView insertString:(parenthesisToInsert copyFirst:1) atCharacterPosition:parentNodeToParenthesize start. |
|
5038 | 2652 |
codeView cursorToCharacterPosition:sav+2; cursorRight |
2653 |
]. |
|
2654 |
]. |
|
2655 |
]. |
|
2656 |
]. |
|
5040 | 2657 |
|
4610 | 2658 |
codeView |
5038 | 2659 |
undoableDo:action |
2660 |
info:'Completion'. |
|
4610 | 2661 |
]. |
2662 |
]. |
|
5040 | 2663 |
|
4352 | 2664 |
actionBlock value:allBest value:editAction value:nil. |
4238 | 2665 |
|
2666 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
2667 |
"Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
5041 | 2668 |
"Modified: / 01-05-2016 / 18:36:36 / cg" |
5040 | 2669 |
! |
2670 |
||
2671 |
codeCompletionForMessageTo:node into:actionBlock |
|
5106 | 2672 |
"find good suggestions for a message send to node, with no input yet. |
2673 |
I.e. right after a receiver (w.o. any input yet)" |
|
5040 | 2674 |
|
5080 | 2675 |
|knownClass suggestions selectorsImplementedInClass mostUseful editActions pos| |
5040 | 2676 |
|
5106 | 2677 |
(knownClass := self classOfNode:node) isNil ifTrue:[ |
5109 | 2678 |
self breakPoint:#cg. |
5113 | 2679 |
"/ self classOfNode:node. |
5106 | 2680 |
^ self |
2681 |
]. |
|
2682 |
||
5109 | 2683 |
Verbose == true ifTrue:[ |
2684 |
Transcript show:node; show:' -> '; showCR:knownClass. |
|
2685 |
]. |
|
5040 | 2686 |
selectorsImplementedInClass := Set new. |
2687 |
||
2688 |
knownClass withAllSuperclassesDo:[:cls | |
|
2689 |
cls ~~ Object ifTrue:[ |
|
2690 |
selectorsImplementedInClass addAll:cls selectors. |
|
2691 |
] |
|
2692 |
]. |
|
2693 |
||
2694 |
knownClass isMeta ifTrue:[ |
|
2695 |
selectorsImplementedInClass := |
|
2696 |
selectorsImplementedInClass reject:[:sel | |
|
2697 |
|mthd| |
|
2698 |
||
2699 |
mthd := knownClass lookupMethodFor:sel. |
|
2700 |
mthd notNil and:[mthd category startsWith: 'documentation'] |
|
2701 |
]. |
|
2702 |
||
2703 |
knownClass theNonMetaclass isAbstract ifTrue:[ |
|
2704 |
mostUseful := selectorsImplementedInClass select:[:sel | |
|
2705 |
knownClass implements:sel |
|
2706 |
] |
|
2707 |
] ifFalse:[ |
|
2708 |
mostUseful := selectorsImplementedInClass select:[:sel | |
|
2709 |
|mthd| |
|
2710 |
||
2711 |
mthd := knownClass lookupMethodFor:sel. |
|
2712 |
mthd notNil and:[mthd category startsWith: 'instance'] |
|
2713 |
]. |
|
2714 |
] |
|
2715 |
] ifFalse:[ |
|
2716 |
mostUseful := |
|
2717 |
#( |
|
2718 |
"/ blocks |
|
2719 |
ifTrue: ifFalse: whileTrue: whileFalse: on:do: ensure: |
|
2720 |
whileTrue whileFalse loop |
|
2721 |
"/ any |
|
2722 |
isNil notNil isEmpty notEmpty |
|
2723 |
). |
|
2724 |
]. |
|
2725 |
||
2726 |
mostUseful notNil ifTrue:[ |
|
2727 |
suggestions := |
|
2728 |
(selectorsImplementedInClass select:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort |
|
2729 |
, |
|
2730 |
(selectorsImplementedInClass reject:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort. |
|
2731 |
] ifFalse:[ |
|
2732 |
suggestions := selectorsImplementedInClass asNewOrderedCollection sort. |
|
2733 |
]. |
|
2734 |
||
5043 | 2735 |
suggestions := suggestions reject:[:sel | sel first == $_]. |
5040 | 2736 |
self sortUsefulSelectorsIn:suggestions. "/cosmetics |
5041 | 2737 |
|
2738 |
pos := codeView characterPositionOfCursor. |
|
5080 | 2739 |
editActions := suggestions collect:[:word | |
2740 |
self editActionToReplaceCodeFrom:pos to:pos-1 by:word. |
|
2741 |
]. |
|
2742 |
actionBlock value:suggestions value:editActions value:nil. |
|
5040 | 2743 |
|
2744 |
"Created: / 01-05-2016 / 17:01:21 / cg" |
|
5041 | 2745 |
"Modified: / 01-05-2016 / 18:54:03 / cg" |
4238 | 2746 |
! |
2747 |
||
4548 | 2748 |
codeCompletionForMethodSpec:node |
4238 | 2749 |
"completion in a method's selector pattern" |
2750 |
||
4548 | 2751 |
self |
5312 | 2752 |
codeCompletionForMethodSpec:node |
2753 |
into: |
|
2754 |
[:suggestions :action :whatIsIt | |
|
2755 |
||
2756 |
|chosen| |
|
2757 |
||
2758 |
chosen := self askUserForCompletion:whatIsIt for:codeView |
|
2759 |
at:node start from:suggestions. |
|
2760 |
chosen notNil ifTrue:[ |
|
2761 |
action value:(suggestions indexOf:chosen) |
|
2762 |
]. |
|
2763 |
]. |
|
4352 | 2764 |
|
2765 |
"/ |crsrPos |
|
2766 |
"/ selectorSoFar matchingSelectors |
|
4548 | 2767 |
"/ selectors distances best rest |
2768 |
"/ allExistingMethods nameBag namesByCount selectors1 selectors2| |
|
4352 | 2769 |
"/ |
2770 |
"/ crsrPos := codeView characterPositionOfCursor - 1. |
|
2771 |
"/ |
|
2772 |
"/ selectorSoFar := ''. |
|
2773 |
"/ node selectorParts doWithIndex:[:partToken :argNr| |
|
2774 |
"/ |part| |
|
2775 |
"/ |
|
2776 |
"/ part := partToken value. |
|
2777 |
"/ selectorSoFar := selectorSoFar , part. |
|
2778 |
"/ |
|
2779 |
"/ (crsrPos >= partToken start |
|
2780 |
"/ and:[crsrPos <= partToken stop]) ifTrue:[ |
|
2781 |
"/ (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
2782 |
"/ matchingSelectors := Smalltalk allClasses |
|
2783 |
"/ inject:(Set new) |
|
2784 |
"/ into:[:theSet :eachClass | |
|
2785 |
"/ |md| |
|
2786 |
"/ |
|
2787 |
"/ md := eachClass theMetaclass methodDictionary. |
|
2788 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2789 |
"/ theSet. |
|
2790 |
"/ ]. |
|
5312 | 2791 |
"/ "/ don't forget the stuff in the class-line |
4352 | 2792 |
"/ Metaclass withAllSuperclassesDo:[:cls | |
2793 |
"/ matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2794 |
"/ ]. |
|
2795 |
"/ ] ifFalse:[ |
|
2796 |
"/ matchingSelectors := Smalltalk allClasses |
|
2797 |
"/ inject:(Set new) |
|
2798 |
"/ into:[:theSet :eachClass | |
|
2799 |
"/ |md| |
|
2800 |
"/ |
|
2801 |
"/ md := eachClass theNonMetaclass methodDictionary. |
|
2802 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2803 |
"/ theSet. |
|
2804 |
"/ ]. |
|
2805 |
"/ ]. |
|
2806 |
"/ selectors := matchingSelectors asOrderedCollection. |
|
2807 |
"/ |
|
4548 | 2808 |
"/ "/ if there is only one, and user has already entered it, he might want to complete the argument-name |
2809 |
"/ (selectors size == 1 |
|
4352 | 2810 |
"/ and:[selectors first = selectorSoFar]) ifTrue:[ |
2811 |
"/ selectorSoFar numArgs == 0 ifTrue:[ ^ self ]. |
|
2812 |
"/ |
|
2813 |
"/ allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
2814 |
"/ collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
2815 |
"/ nameBag := Bag new. |
|
2816 |
"/ allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
4548 | 2817 |
"/ namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
2818 |
"/ "/ take the one which occurs most often |
|
4352 | 2819 |
"/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]). |
2820 |
"/ |
|
2821 |
"/ codeView |
|
2822 |
"/ undoableDo:[ |
|
2823 |
"/ (crsrPos+1) >= codeView contents size ifTrue:[ |
|
2824 |
"/ codeView paste:best. |
|
2825 |
"/ ] ifFalse:[ |
|
2826 |
"/ codeView insertString:best atCharacterPosition:crsrPos+1. |
|
2827 |
"/ ] |
|
2828 |
"/ ] |
|
2829 |
"/ info:'completion'. |
|
4548 | 2830 |
"/ codeView cursorToCharacterPosition:(crsrPos + best size - 1). |
4352 | 2831 |
"/ ] ifFalse:[ |
2832 |
"/ "the ones implemented in superclasses are shown first" |
|
2833 |
"/ classOrNil notNil ifTrue:[ |
|
2834 |
"/ selectors1 := selectors select:[:sel | classOrNil respondsTo:sel]. "/ in super |
|
2835 |
"/ selectors2 := selectors reject:[:sel | selectors1 includes:sel ]. "/ not in super |
|
2836 |
"/ ] ifFalse:[ |
|
2837 |
"/ selectors1 := selectors |
|
2838 |
"/ ]. |
|
2839 |
"/ |
|
2840 |
"/ distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2841 |
"/ distances sortWith:selectors1. |
|
2842 |
"/ selectors1 reverse. |
|
2843 |
"/ selectors := selectors1. |
|
2844 |
"/ |
|
2845 |
"/ selectors2 notEmptyOrNil ifTrue:[ |
|
2846 |
"/ distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2847 |
"/ distances sortWith:selectors2. |
|
2848 |
"/ selectors2 reverse. |
|
2849 |
"/ selectors1 := selectors1 collect:[:sel | sel allBold]. |
|
2850 |
"/ selectors := selectors1,selectors2. |
|
2851 |
"/ ]. |
|
4548 | 2852 |
"/ |
4352 | 2853 |
"/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors. |
2854 |
"/ best isNil ifTrue:[^ self]. |
|
2855 |
"/ |
|
2856 |
"/ rest := best copyFrom:selectorSoFar size. |
|
2857 |
"/ codeView |
|
4548 | 2858 |
"/ undoableDo:[ |
2859 |
"/ codeView |
|
2860 |
"/ replaceFromCharacterPosition:crsrPos+1 |
|
2861 |
"/ to:crsrPos+1 |
|
2862 |
"/ with:rest |
|
4352 | 2863 |
"/ ] |
2864 |
"/ info:'Completion'. |
|
4548 | 2865 |
"/ codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
4352 | 2866 |
"/ ]. |
4548 | 2867 |
"/ codeView cursorRight. "/ kludge to make it visible |
4352 | 2868 |
"/ ]. |
2869 |
"/ ]. |
|
4238 | 2870 |
|
2871 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
2872 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
2873 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2874 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
2875 |
! |
|
2876 |
||
4352 | 2877 |
codeCompletionForMethodSpec:node into:actionBlock |
4238 | 2878 |
"completion in a method's selector pattern" |
2879 |
||
4370 | 2880 |
|crsrPos crsrLine crsrCol |
4238 | 2881 |
selectorSoFar matchingSelectors |
5146 | 2882 |
selectors allExistingMethods nameBag namesByCount |
5044 | 2883 |
allSelectors |
2884 |
selectorsForIsXXXTests selectorsSentInClass selectorsImplementedInSuper |
|
2885 |
editAction editActionForArg argNames selectorsForVars |
|
2886 |
selectorTypedSoFar addIfNotYetImplemented alreadyOK| |
|
2887 |
||
2888 |
allSelectors := Set new. |
|
4548 | 2889 |
|
2890 |
"/ Transcript showCR:'m'. |
|
4370 | 2891 |
crsrLine := codeView cursorLine. |
2892 |
crsrCol := codeView cursorCol. |
|
4238 | 2893 |
crsrPos := codeView characterPositionOfCursor - 1. |
2894 |
||
4691 | 2895 |
selectorTypedSoFar := node selector. |
2896 |
selectorTypedSoFar isUnarySelector ifTrue:[ |
|
4618 | 2897 |
"/ user has just begun to edit a selector. |
2898 |
"/ often, a good completion are the names of instVars for which no corresponding getter/setter exists |
|
2899 |
classOrNil notNil ifTrue:[ |
|
5044 | 2900 |
selectorsForVars := Set new. |
2901 |
selectorsImplementedInSuper := Set new. |
|
2902 |
selectorsSentInClass := Set new. |
|
2903 |
selectorsForIsXXXTests := Set new. |
|
2904 |
||
2905 |
addIfNotYetImplemented := |
|
2906 |
[:list :sel | |
|
2907 |
sel ~= selectorTypedSoFar ifTrue:[ |
|
2908 |
(allSelectors includes:sel) ifFalse:[ |
|
2909 |
(classOrNil implements:sel asSymbol) ifFalse:[ |
|
2910 |
selectorsForVars add:sel. |
|
2911 |
allSelectors add:sel. |
|
2912 |
]. |
|
2913 |
]. |
|
2914 |
]. |
|
2915 |
]. |
|
2916 |
||
4618 | 2917 |
classOrNil instVarNames do:[:nm | |
4691 | 2918 |
(nm startsWith:selectorTypedSoFar) ifTrue:[ |
5044 | 2919 |
addIfNotYetImplemented value:selectorsForVars value:nm. |
2920 |
addIfNotYetImplemented value:selectorsForVars value:(nm,':'). |
|
4618 | 2921 |
] |
2922 |
]. |
|
2923 |
classOrNil isMeta ifTrue:[ |
|
2924 |
classOrNil theNonMetaclass classVarNames do:[:nm | |
|
2925 |
|nmSel| |
|
2926 |
||
2927 |
nmSel := nm asLowercaseFirst. |
|
4691 | 2928 |
(nmSel startsWith:selectorTypedSoFar) ifTrue:[ |
5044 | 2929 |
addIfNotYetImplemented value:selectorsForVars value:nmSel. |
2930 |
addIfNotYetImplemented value:selectorsForVars value:(nmSel,':'). |
|
2931 |
] |
|
4618 | 2932 |
]. |
2933 |
] ifFalse:[ |
|
2934 |
"/ isXXX ? |
|
4691 | 2935 |
(('is',classOrNil nameWithoutPrefix) startsWith:selectorTypedSoFar ) ifTrue:[ |
5044 | 2936 |
addIfNotYetImplemented value:selectorsForIsXXXTests value:('is',classOrNil nameWithoutPrefix). |
4618 | 2937 |
]. |
2938 |
]. |
|
4691 | 2939 |
|
2940 |
"/ and also messages sent by the class itself |
|
2941 |
classOrNil methodsDo:[:m | |
|
2942 |
m messagesSentToSelf do:[:sel | |
|
2943 |
(sel startsWith:selectorTypedSoFar) ifTrue:[ |
|
5044 | 2944 |
addIfNotYetImplemented value:selectorsSentInClass value:sel. |
4691 | 2945 |
] |
2946 |
] |
|
2947 |
]. |
|
2948 |
classOrNil isMeta ifFalse:[ |
|
2949 |
classOrNil theMetaclass methodsDo:[:m | |
|
2950 |
m messagesSent do:[:sel | |
|
2951 |
(sel startsWith:selectorTypedSoFar) ifTrue:[ |
|
5044 | 2952 |
addIfNotYetImplemented value:selectorsSentInClass value:sel. |
2953 |
] |
|
2954 |
] |
|
2955 |
] |
|
2956 |
]. |
|
2957 |
"/ and also messages implemented by superclasses (except Object) |
|
2958 |
classOrNil allSuperclassesDo:[:eachSuperclass | |
|
2959 |
eachSuperclass ~~ Object ifTrue:[ |
|
2960 |
eachSuperclass methodDictionary keysDo:[:sel | |
|
2961 |
(sel startsWith:selectorTypedSoFar) ifTrue:[ |
|
2962 |
addIfNotYetImplemented value:selectorsImplementedInSuper value:sel. |
|
4691 | 2963 |
] |
2964 |
] |
|
2965 |
] |
|
2966 |
]. |
|
4618 | 2967 |
]. |
4371 | 2968 |
]. |
2969 |
||
4238 | 2970 |
selectorSoFar := ''. |
5044 | 2971 |
matchingSelectors := Set new. |
2972 |
||
4238 | 2973 |
node selectorParts doWithIndex:[:partToken :argNr| |
4618 | 2974 |
|part| |
2975 |
||
2976 |
part := partToken value. |
|
2977 |
selectorSoFar := selectorSoFar , part. |
|
2978 |
||
5044 | 2979 |
(crsrPos >= partToken start |
2980 |
and:[crsrPos <= partToken stop |
|
2981 |
or:[ (crsrPos == (partToken stop+1)) |
|
2982 |
and:[codeView characterBeforeCursor == Character space]] ] |
|
2983 |
) ifTrue:[ |
|
4618 | 2984 |
(classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
5044 | 2985 |
Smalltalk |
2986 |
allClassesDo:[:eachClass | |
|
2987 |
|md| |
|
2988 |
||
2989 |
md := eachClass theMetaclass methodDictionary. |
|
2990 |
matchingSelectors addAll:(md keys |
|
2991 |
select:[:sel |sel startsWith:selectorSoFar]). |
|
2992 |
]. |
|
2993 |
"/ do not forget the stuff in the class-line |
|
4618 | 2994 |
Metaclass withAllSuperclassesDo:[:cls | |
5044 | 2995 |
matchingSelectors addAll:(cls methodDictionary keys |
2996 |
select:[:sel |sel startsWith:selectorSoFar]). |
|
4618 | 2997 |
]. |
2998 |
] ifFalse:[ |
|
5044 | 2999 |
Smalltalk |
3000 |
allClassesDo:[:eachClass | |
|
3001 |
|md| |
|
3002 |
||
3003 |
md := eachClass theNonMetaclass methodDictionary. |
|
3004 |
matchingSelectors addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
3005 |
]. |
|
4618 | 3006 |
]. |
5044 | 3007 |
]. |
3008 |
]. |
|
3009 |
alreadyOK := matchingSelectors includes:selectorTypedSoFar. |
|
3010 |
matchingSelectors remove:selectorTypedSoFar ifAbsent:[]. |
|
3011 |
||
3012 |
selectors := Set new. |
|
3013 |
selectors addAll:matchingSelectors. |
|
3014 |
||
3015 |
selectorsForVars notNil ifTrue:[ selectors addAll:selectorsForVars ]. |
|
3016 |
selectorsSentInClass notNil ifTrue:[ selectors addAll:selectorsSentInClass ]. |
|
3017 |
selectorsImplementedInSuper notNil ifTrue:[ selectors addAll:selectorsImplementedInSuper ]. |
|
3018 |
selectorsForIsXXXTests notNil ifTrue:[ selectors addAll:selectorsForIsXXXTests ]. |
|
3019 |
||
3020 |
selectors := selectors asOrderedCollection. |
|
3021 |
selectors sort:[:a :b | a size < b size]. |
|
3022 |
selectorsForVars notEmptyOrNil ifTrue:[ |
|
3023 |
selectors := self |
|
3024 |
splitSelectorList:selectors |
|
3025 |
by:[:sel | selectorsForVars includes:sel]. |
|
3026 |
]. |
|
3027 |
selectorsSentInClass notEmptyOrNil ifTrue:[ |
|
3028 |
selectors := self |
|
3029 |
splitSelectorList:selectors |
|
3030 |
by:[:sel | selectorsSentInClass includes:sel]. |
|
3031 |
]. |
|
3032 |
selectorsImplementedInSuper notEmptyOrNil ifTrue:[ |
|
3033 |
selectors := self |
|
3034 |
splitSelectorList:selectors |
|
3035 |
by:[:sel | selectorsImplementedInSuper includes:sel]. |
|
3036 |
]. |
|
3037 |
selectorsForIsXXXTests notEmptyOrNil ifTrue:[ |
|
3038 |
selectors := self |
|
3039 |
splitSelectorList:selectors |
|
3040 |
by:[:sel | selectorsForIsXXXTests includes:sel]. |
|
3041 |
]. |
|
3042 |
||
3043 |
selectors size > 100 ifTrue:[ |
|
3044 |
selectors := selectors copyTo:100. |
|
3045 |
]. |
|
3046 |
||
3047 |
"/ if there is only one, and user has already entered it, |
|
3048 |
"/ he might want to complete the argument-name |
|
3049 |
(alreadyOK and:[selectorSoFar numArgs > 0]) ifTrue:[ |
|
3050 |
allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
3051 |
collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
3052 |
nameBag := Bag new. |
|
3053 |
allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
3054 |
namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
|
3055 |
namesByCount := namesByCount copyToMax:5. |
|
3056 |
||
3057 |
"/ take the one which occurs most often |
|
3058 |
argNames := (namesByCount collect:[:a | a key]). |
|
3059 |
argNames do:[:eachArgName | |
|
3060 |
selectors add:('%1 %2 %3' |
|
5089 | 3061 |
bindWith:(selectorSoFar withColor:Color darkGrey) |
5044 | 3062 |
with:eachArgName |
5089 | 3063 |
with:('(argument)' allItalic withColor:Color darkGrey)). |
5044 | 3064 |
]. |
3065 |
||
3066 |
editActionForArg := |
|
3067 |
[:chosenItem | |
|
3068 |
|chosenName| |
|
3069 |
||
3070 |
chosenName := chosenItem |
|
3071 |
copyFrom:(selectorSoFar size+2) |
|
3072 |
to:(chosenItem indexOfSeparatorStartingAt:selectorSoFar size+2)-1. |
|
4618 | 3073 |
codeView |
3074 |
undoableDo:[ |
|
5044 | 3075 |
(crsrPos+1) >= codeView contents size ifTrue:[ |
3076 |
codeView paste:chosenName. |
|
3077 |
codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1). |
|
3078 |
] ifFalse:[ |
|
3079 |
codeView cursorToCharacterPosition:crsrPos. |
|
3080 |
codeView cursorRight. |
|
3081 |
codeView insertStringAtCursor:chosenName. |
|
3082 |
codeView selectFromCharacterPosition:crsrPos+1 to:crsrPos+1+chosenName size-1. |
|
3083 |
codeView dontReplaceSelectionOnInput |
|
3084 |
]. |
|
4618 | 3085 |
] |
5044 | 3086 |
info:'argname completion'. |
4618 | 3087 |
]. |
5044 | 3088 |
]. |
3089 |
||
3090 |
"/ no, still more possibilities for the selector. |
|
3091 |
"/ the ones implemented in superclasses are shown first. |
|
5146 | 3092 |
(classOrNil notNil and:[classOrNil superclass notNil]) ifTrue:[ |
5044 | 3093 |
selectors := self |
3094 |
splitSelectorList:selectors |
|
3095 |
by:[:sel | classOrNil superclass implements:sel]. |
|
3096 |
]. |
|
3097 |
||
3098 |
"/"/ distances := selectors collect:[:each | each spellAgainst:selectorSoFar]. |
|
3099 |
"/"/ distances sortWith:selectors. |
|
3100 |
"/"/ selectors reverse. |
|
3101 |
||
3102 |
editAction := |
|
3103 |
[:selectedCompletionIndex | |
|
3104 |
|chosen rest| |
|
3105 |
||
3106 |
chosen := selectors at:selectedCompletionIndex. |
|
3107 |
(editActionForArg notNil and:[ chosen includesSeparator ]) ifTrue:[ |
|
3108 |
editActionForArg value:chosen. |
|
3109 |
] ifFalse:[ |
|
3110 |
rest := chosen copyFrom:selectorSoFar size + 1. |
|
3111 |
codeView |
|
3112 |
undoableDo:[ |
|
3113 |
codeView insertString:rest atLine:crsrLine col:crsrCol. |
|
3114 |
] |
|
3115 |
info:'Completion'. |
|
3116 |
codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
|
3117 |
codeView cursorRight. "/ kludge to make it visible |
|
3118 |
]. |
|
4618 | 3119 |
]. |
5044 | 3120 |
|
3121 |
actionBlock |
|
3122 |
value:selectors |
|
3123 |
value:editAction |
|
3124 |
value:'selector'. |
|
4238 | 3125 |
|
3126 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
3127 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
3128 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3129 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
3130 |
! |
|
3131 |
||
5106 | 3132 |
codeCompletionForTempVariable:node into:actionBlock |
3133 |
! |
|
3134 |
||
4238 | 3135 |
codeCompletionForVariable:node into:actionBlock |
3136 |
|nonMetaClass crsrPos nm parent |
|
3137 |
allVariables allDistances variablesAlreadyAdded nodeVal |
|
5081 | 3138 |
char getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc |
3139 |
globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart editActions suggestions nameIsOK longerNames setOfNames otherArgNames |
|
5076 | 3140 |
suggestionsWithInfo isLeftSideOfAssignment| |
5040 | 3141 |
|
4302 | 3142 |
"/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 3143 |
classOrNil notNil ifTrue:[ |
4559 | 3144 |
nonMetaClass := classOrNil theNonMetaclass. |
4238 | 3145 |
]. |
5040 | 3146 |
|
4238 | 3147 |
nm := node name. |
5076 | 3148 |
parent := node parent. |
3149 |
isLeftSideOfAssignment := false. |
|
3150 |
||
3151 |
(parent notNil) ifTrue:[ |
|
3152 |
(parent isMessage) ifTrue:[ |
|
3153 |
node == parent receiver ifTrue:[ |
|
3154 |
selectorOfMessageToNode := parent selector |
|
3155 |
] |
|
3156 |
] ifFalse:[ |
|
3157 |
(parent isAssignment) ifTrue:[ |
|
3158 |
isLeftSideOfAssignment := (node == node parent variable). |
|
3159 |
]. |
|
3160 |
]. |
|
3161 |
]. |
|
3162 |
||
5040 | 3163 |
crsrPos := codeView characterPositionOfCursor. |
3164 |
||
4238 | 3165 |
"/ if we are behind the variable and a space has already been entered, |
3166 |
"/ the user is probably looking for a message selector. |
|
3167 |
"/ If the variable represents a global, present its instance creation messages |
|
5040 | 3168 |
char := codeView characterBeforeCursor. |
5076 | 3169 |
|
3170 |
(isLeftSideOfAssignment not and:[char == Character space]) ifTrue:[ |
|
4559 | 3171 |
nm knownAsSymbol ifTrue:[ |
3172 |
classOrNil isNil ifTrue:[ |
|
3173 |
nodeVal := Smalltalk at:nm asSymbol. |
|
3174 |
] ifFalse:[ |
|
3175 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
3176 |
]. |
|
3177 |
nodeVal isBehavior ifTrue:[ |
|
4954 | 3178 |
|selectors selectors1 selectors2| |
3179 |
||
3180 |
selectors1 := OrderedSet new. |
|
3181 |
selectors2 := OrderedSet new. |
|
3182 |
nodeVal class |
|
3183 |
withAllSuperclassesDo:[:cls | |
|
3184 |
cls methodDictionary keysAndValuesDo:[:sel :mthd | |
|
3185 |
|cat| |
|
3186 |
cat := mthd category asLowercase. |
|
3187 |
cat = 'instance creation' ifTrue:[ |
|
3188 |
selectors1 add:sel |
|
3189 |
] ifFalse:[ |
|
3190 |
"/ other category: look if it sends new, new: etc. |
|
3191 |
(mthd messagesSent includesAny:#(new new: basicNew basicNew:)) ifTrue:[ |
|
3192 |
selectors2 add:sel |
|
3193 |
]. |
|
3194 |
] |
|
3195 |
] |
|
3196 |
]. |
|
5040 | 3197 |
|
4954 | 3198 |
selectors := selectors1 order sort , #('-') , selectors2 order sort. |
5080 | 3199 |
editActions := selectors collect:[:word | self editActionToInsert:word]. |
3200 |
actionBlock value:selectors value:editActions value:nil. |
|
3201 |
"/ editAction := |
|
3202 |
"/ [:answer | |
|
3203 |
"/ |s| |
|
3204 |
"/ s := answer isInteger ifTrue:[selectors at:answer] ifFalse:[answer]. |
|
3205 |
"/ codeView |
|
3206 |
"/ undoableDo:[ |
|
3207 |
"/ codeView insertString:s atCharacterPosition:crsrPos. |
|
3208 |
"/ codeView cursorToCharacterPosition:crsrPos+s size. |
|
3209 |
"/ ] |
|
3210 |
"/ info:'completion'. |
|
3211 |
"/ ]. |
|
3212 |
"/ actionBlock value:selectors value:editAction value:nil. |
|
4559 | 3213 |
^ self. |
3214 |
]. |
|
3215 |
]. |
|
4238 | 3216 |
]. |
5040 | 3217 |
|
4352 | 3218 |
"/ this is pure voodoo magic (tries to make a good spelling weight, |
3219 |
"/ by weighting the number of startsWith characters into the spelling distance...) |
|
4238 | 3220 |
getDistanceComputeBlockWithWeight := |
4559 | 3221 |
[:weight | |
3222 |
[:each | |
|
3223 |
|dist factor| |
|
3224 |
||
3225 |
dist := each spellAgainst:nm. |
|
3226 |
factor := 1. |
|
3227 |
||
5027 | 3228 |
"/ bump the weight-factor if the name string is included |
3229 |
(each includesString:nm) ifTrue:[ |
|
3230 |
(each startsWith:nm) ifTrue:[ |
|
3231 |
factor := 6 * weight * nm size. |
|
5360 | 3232 |
] ifFalse:[ |
3233 |
(each endsWith:nm) ifTrue:[ |
|
3234 |
factor := 5 * weight * nm size. |
|
3235 |
] ifFalse:[ |
|
3236 |
nm size > 1 ifTrue:[ |
|
3237 |
factor := 4 * weight * nm size |
|
3238 |
]. |
|
5027 | 3239 |
]. |
3240 |
]. |
|
4559 | 3241 |
] ifFalse:[ |
5027 | 3242 |
(each includesString:nm caseSensitive:false) ifTrue:[ |
3243 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
3244 |
factor := 4 * weight * nm size. |
|
3245 |
] ifFalse:[ |
|
5360 | 3246 |
(each asLowercase endsWith:nm asLowercase) ifTrue:[ |
3247 |
factor := 3 * weight * nm size. |
|
3248 |
] ifFalse:[ |
|
3249 |
nm size > 1 ifTrue:[ |
|
3250 |
factor := 2 * weight * nm size. |
|
3251 |
] |
|
5027 | 3252 |
] |
3253 |
] |
|
3254 |
] |
|
3255 |
]. |
|
4559 | 3256 |
dist := dist + (weight*factor). |
3257 |
||
3258 |
each -> (dist * weight) |
|
3259 |
] |
|
3260 |
]. |
|
4238 | 3261 |
|
3262 |
nameIsOK := false. |
|
3263 |
addWithFactorBlock := |
|
4559 | 3264 |
[:eachNames :factor | |
4689 | 3265 |
|distanceComputeBlock| |
3266 |
||
3267 |
distanceComputeBlock := (getDistanceComputeBlockWithWeight value:factor). |
|
4559 | 3268 |
eachNames do:[:nameToAdd | |
5040 | 3269 |
(nameToAdd = nm) ifTrue:[ |
3270 |
nameIsOK := true |
|
3271 |
] ifFalse:[ "/ not again |
|
4559 | 3272 |
(variablesAlreadyAdded includes:nameToAdd) ifFalse:[ "/ not again |
3273 |
variablesAlreadyAdded add:nameToAdd. |
|
3274 |
allVariables add:nameToAdd. |
|
4689 | 3275 |
allDistances add:(distanceComputeBlock value:nameToAdd). |
4559 | 3276 |
] |
3277 |
] |
|
3278 |
] |
|
3279 |
]. |
|
4238 | 3280 |
|
3281 |
nm isUppercaseFirst ifTrue:[ |
|
4559 | 3282 |
globalFactor := 2. "/ favour globals |
3283 |
localFactor := 1. |
|
4238 | 3284 |
] ifFalse:[ |
4559 | 3285 |
globalFactor := 1. "/ favour locals |
3286 |
localFactor := 2. |
|
4238 | 3287 |
]. |
3288 |
||
3289 |
variablesAlreadyAdded := Set new. |
|
3290 |
allVariables := OrderedCollection new. |
|
3291 |
allDistances := OrderedCollection new. |
|
3292 |
||
3293 |
"/ are we in the method's selector spec ? |
|
4548 | 3294 |
(parent notNil |
4238 | 3295 |
and:[parent isMethod |
3296 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
4559 | 3297 |
"/ yes - |
4784 | 3298 |
"/ now that's cool: look how the name of this argument is in other implementations |
4559 | 3299 |
"/ of this method, and take that as a basis of the selection |
3300 |
||
3301 |
implementors := SystemBrowser |
|
3302 |
findImplementorsOf:(parent selector) |
|
3303 |
in:(Smalltalk allClasses) |
|
3304 |
ignoreCase:false. |
|
3305 |
"/ which argument is it |
|
3306 |
argIdx := parent arguments indexOf:node. |
|
3307 |
implementors size > 50 ifTrue:[ |
|
3308 |
implementors := implementors asOrderedCollection copyTo:50. |
|
3309 |
]. |
|
3310 |
namesUsed := implementors |
|
3311 |
collect:[:eachImplementor | |
|
3312 |
|parseTree| |
|
3313 |
parseTree := eachImplementor parseTree. |
|
3314 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
3315 |
ifFalse:nil |
|
3316 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
3317 |
thenSelect:[:a | a notNil]. |
|
3318 |
||
3319 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
3320 |
||
4784 | 3321 |
"/ try some commonly used arg names, such as aBoolean, anInteger, etc. |
3322 |
nm size > 1 ifTrue:[ |
|
3323 |
|tryClassNamesWith| |
|
3324 |
||
3325 |
((nm startsWith:'a') and:[(nm at:2) isUppercase]) ifTrue:[ |
|
3326 |
tryClassNamesWith := 'a' |
|
3327 |
] ifFalse:[ |
|
3328 |
(nm size > 2 and:[ (nm startsWith:'an') and:[(nm at:3) isUppercase]]) ifTrue:[ |
|
3329 |
tryClassNamesWith := 'an'. |
|
3330 |
]. |
|
3331 |
]. |
|
3332 |
tryClassNamesWith notNil ifTrue:[ |
|
3333 |
addWithFactorBlock |
|
3334 |
value:(Smalltalk keys |
|
3335 |
collect:[:className | tryClassNamesWith,className] |
|
3336 |
thenSelect:[:name | name startsWith:nm]) |
|
3337 |
value:(1.5 * localFactor) |
|
3338 |
]. |
|
3339 |
]. |
|
3340 |
||
4559 | 3341 |
classOrNil notNil ifTrue:[ |
3342 |
"/ also, look for the keyword before the argument, |
|
3343 |
"/ and see if there is such an instVar |
|
3344 |
"/ if so, add it with -Arg |
|
3345 |
parent selector isKeyword ifTrue:[ |
|
3346 |
kwPart := parent selector keywords at:argIdx. |
|
3347 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
|
3348 |
addWithFactorBlock |
|
3349 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
3350 |
value:(1 * localFactor). |
|
3351 |
]. |
|
3352 |
]. |
|
3353 |
"/ look for the variable names of any other method in that class |
|
3354 |
otherArgNames := Set new. |
|
3355 |
classOrNil methodDictionary keysAndValuesDo:[:sel :mthd | |
|
3356 |
|parseTree| |
|
3357 |
parseTree := mthd parseTree. |
|
3358 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
3359 |
ifFalse:nil |
|
3360 |
ifTrue:[ otherArgNames addAll:(parseTree arguments collect:[:each | each name])] ]. |
|
3361 |
addWithFactorBlock value:otherArgNames value:(1.5 * localFactor). |
|
3362 |
]. |
|
5043 | 3363 |
addWithFactorBlock |
3364 |
value:(codeView previousReplacements |
|
3365 |
collect:[:p | p value asString] |
|
3366 |
thenSelect:[:s | s isValidSmalltalkIdentifier]) |
|
3367 |
value:(1.3 * localFactor). |
|
4238 | 3368 |
] ifFalse:[ |
4559 | 3369 |
"/ locals in the block/method |
5040 | 3370 |
|names nameSpace| |
4559 | 3371 |
|
3372 |
names := OrderedCollection withAll:node allVariablesOnScope. |
|
3373 |
setOfNames := Set withAll:names. |
|
3374 |
||
3375 |
rememberedScopeNodes notNil ifTrue:[ |
|
3376 |
"/ notNil when a parseError occurred. |
|
3377 |
rememberedScopeNodes do:[:eachScope | |
|
3378 |
(eachScope isMethod or:[eachScope isBlock]) ifTrue:[ |
|
3379 |
eachScope argumentNames do:[:eachName | |
|
3380 |
(setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ] |
|
3381 |
] |
|
3382 |
] ifFalse:[ |
|
3383 |
eachScope isSequence ifTrue:[ |
|
3384 |
eachScope temporaryNames do:[:eachName | |
|
3385 |
(setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ] |
|
3386 |
] |
|
3387 |
] ifFalse:[ |
|
3388 |
] |
|
3389 |
]. |
|
3390 |
"/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt]. |
|
3391 |
]. |
|
5040 | 3392 |
|
4559 | 3393 |
rememberedScopeNodes do:[:eachScope | |
3394 |
eachScope variableNodesDo:[:var | |
|
3395 |
(setOfNames includes:var name) ifFalse:[ |
|
3396 |
names add:var name. setOfNames add:var name |
|
3397 |
] |
|
3398 |
] |
|
3399 |
] |
|
3400 |
] ifFalse:[ |
|
5076 | 3401 |
"/ tree must be there; in order to get as-yet-undeclared method locals |
3402 |
"/ (further down the code), add them also |
|
4559 | 3403 |
tree variableNodesDo:[:var | |
5076 | 3404 |
|name| |
3405 |
||
3406 |
name := var name. |
|
3407 |
(name first isLowercase or:[isLeftSideOfAssignment not]) ifTrue:[ |
|
3408 |
(setOfNames includes:name) ifFalse:[ |
|
3409 |
names add:name. |
|
3410 |
setOfNames add:name |
|
3411 |
] |
|
4559 | 3412 |
] |
3413 |
] |
|
3414 |
]. |
|
3415 |
||
3416 |
addWithFactorBlock value:names value:(4 * localFactor). |
|
3417 |
||
3418 |
classOrNil notNil ifTrue:[ |
|
3419 |
"/ instance variables |
|
3420 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
3421 |
||
3422 |
"/ inherited instance variables |
|
3423 |
classOrNil superclass notNil ifTrue:[ |
|
3424 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
3425 |
]. |
|
3426 |
]. |
|
3427 |
||
3428 |
"/ magic: |
|
3429 |
"/ if the node to be expanded is the receiver in a message, look for the selector sent to it |
|
3430 |
"/ give names which respond to those messages a higher weight |
|
3431 |
selectorOfMessageToNode notNil ifTrue:[ |
|
3432 |
|responders nonResponders| |
|
3433 |
||
3434 |
"/ responding to that messsage |
|
4365 | 3435 |
"/ self halt. |
4559 | 3436 |
classOrNil notNil ifTrue:[ |
3437 |
"/ private classes |
|
3438 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3439 |
value:(2.75 * globalFactor). |
|
3440 |
||
3441 |
"/ class variables |
|
3442 |
names := nonMetaClass classVarNames. |
|
3443 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3444 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3445 |
||
3446 |
addWithFactorBlock value:responders value:(3.0 * globalFactor). |
|
3447 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3448 |
||
3449 |
"/ superclass var names |
|
3450 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
3451 |
names := superClass classVarNames. |
|
3452 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3453 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3454 |
||
3455 |
addWithFactorBlock value:responders value:(2.75 * globalFactor). |
|
3456 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
3457 |
]. |
|
3458 |
||
5076 | 3459 |
isLeftSideOfAssignment ifFalse:[ |
3460 |
"/ namespace vars |
|
3461 |
classOrNil topNameSpace ~~ Smalltalk ifTrue:[ |
|
3462 |
names := classOrNil topNameSpace keys. |
|
3463 |
names := names reject:[:nm | nm includes:$:]. |
|
3464 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3465 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3466 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3467 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
3468 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3469 |
]. |
|
4559 | 3470 |
]. |
3471 |
]. |
|
3472 |
||
5076 | 3473 |
isLeftSideOfAssignment ifFalse:[ |
3474 |
"/ globals |
|
3475 |
names := Smalltalk keys. |
|
3476 |
names := names reject: |
|
3477 |
[:nm | |
|
3478 |
(nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not] |
|
3479 |
]. |
|
3480 |
names := names reject:[:nm | nm startsWith:'Undeclared:::' ]. |
|
3481 |
||
3482 |
names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection. |
|
3483 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3484 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3485 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
3486 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3487 |
]. |
|
3488 |
||
3489 |
isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars |
|
3490 |
classOrNil notNil ifTrue:[ |
|
3491 |
"/ pool variables |
|
3492 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3493 |
|pool names| |
|
3494 |
||
3495 |
pool := Smalltalk at:poolName. |
|
5224 | 3496 |
pool notNil ifTrue:[ |
3497 |
names := pool classVarNames. |
|
3498 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3499 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3500 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3501 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
3502 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
3503 |
]. |
|
5076 | 3504 |
]. |
3505 |
] |
|
4559 | 3506 |
] |
3507 |
] ifFalse:[ |
|
3508 |
classOrNil notNil ifTrue:[ |
|
5076 | 3509 |
isLeftSideOfAssignment ifFalse:[ |
3510 |
"/ private classes |
|
3511 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3512 |
value:(2.75 * globalFactor). |
|
3513 |
]. |
|
3514 |
||
4559 | 3515 |
"/ class variables |
3516 |
addWithFactorBlock value:nonMetaClass classVarNames value:(3.0 * globalFactor). |
|
3517 |
nonMetaClass superclass notNil ifTrue:[ |
|
3518 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.5 * globalFactor). |
|
3519 |
]. |
|
3520 |
||
5076 | 3521 |
isLeftSideOfAssignment ifFalse:[ |
3522 |
"/ namespace vars |
|
3523 |
classOrNil topNameSpace ~~ Smalltalk ifTrue:[ |
|
3524 |
names := classOrNil topNameSpace keys. |
|
3525 |
names := names reject:[:nm | nm includes:$:]. |
|
3526 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3527 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3528 |
]. |
|
3529 |
"/ namespace vars |
|
3530 |
((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[ |
|
3531 |
names := nameSpace isNameSpace ifTrue:[nameSpace keys] ifFalse:[nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
3532 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3533 |
names := names reject:[:nm | nm includes:$:]. |
|
3534 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3535 |
]. |
|
4559 | 3536 |
]. |
5076 | 3537 |
isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars |
3538 |
"/ pool variables |
|
3539 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3540 |
|pool names| |
|
3541 |
||
3542 |
pool := Smalltalk at:poolName. |
|
3543 |
pool isNil ifTrue:[ |
|
3544 |
Transcript showCR:'non existent pool: ',poolName |
|
3545 |
] ifFalse:[ |
|
3546 |
names := pool classVarNames. |
|
3547 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3548 |
] |
|
3549 |
]. |
|
4559 | 3550 |
]. |
5076 | 3551 |
]. |
3552 |
||
3553 |
isLeftSideOfAssignment ifFalse:[ |
|
3554 |
"/ globals |
|
3555 |
names := OrderedCollection new. |
|
3556 |
Smalltalk keysDo:[:k | |
|
3557 |
(k isUppercaseFirst |
|
3558 |
and:[ (k startsWith:'Undeclared:::') not |
|
3559 |
and:[ ((k includes:$:) and:[ (k includesString:'::') not]) not ]]) ifTrue:[ |
|
3560 |
names add:k |
|
4559 | 3561 |
] |
3562 |
]. |
|
5076 | 3563 |
|
3564 |
"/ only consider all globals, if the first char of the completed name is uppercase; |
|
3565 |
"/ otherwise, only consider names with a caseInsensitve prefix match |
|
3566 |
nm first isUppercase ifFalse:[ |
|
3567 |
names := names select:[:globalName | globalName asLowercase startsWith: nm]. |
|
3568 |
]. |
|
3569 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
4665 | 3570 |
]. |
4559 | 3571 |
]. |
3572 |
||
5076 | 3573 |
isLeftSideOfAssignment ifFalse:[ |
3574 |
"/ pseudos - assuming that thisContext is seldom used. |
|
3575 |
"/ also assuming, that nil is short so its usually typed in. |
|
3576 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
3577 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
3578 |
addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor). |
|
3579 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
|
3580 |
]. |
|
4238 | 3581 |
]. |
3582 |
||
3583 |
allDistances isEmpty ifTrue:[^ self]. |
|
3584 |
||
4410 | 3585 |
"/ nope (foo := foo + 1) should be possible!! |
3586 |
"/ (parent notNil and:[parent isAssignment]) ifTrue:[ |
|
3587 |
"/ "/ remove the left side of the assignment (to avoid foo := foo suggestions) |
|
3588 |
"/ |i| |
|
3589 |
"/ |
|
3590 |
"/ i := allDistances findFirst:[:entry | entry key = parent variable name]. |
|
3591 |
"/ i ~~ 0 ifTrue:[ |
|
3592 |
"/ allDistances removeAtIndex:i |
|
3593 |
"/ ]. |
|
3594 |
"/ ]. |
|
4385 | 3595 |
|
4238 | 3596 |
bestAssoc := allDistances at:1. |
3597 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
4559 | 3598 |
ifTrue:[el] |
3599 |
ifFalse:[best] |
|
3600 |
]. |
|
4548 | 3601 |
|
3602 |
allDistances sort:[:a :b | |
|
4559 | 3603 |
a value > b value ifTrue:[ |
3604 |
true |
|
3605 |
] ifFalse:[ |
|
3606 |
a value = b value ifTrue:[ |
|
3607 |
a key < b key |
|
3608 |
] ifFalse:[ |
|
3609 |
false |
|
3610 |
] |
|
3611 |
] |
|
3612 |
]. |
|
4352 | 3613 |
|
3614 |
allTheBest := allDistances. |
|
3615 |
||
4238 | 3616 |
nameIsOK ifTrue:[ |
4559 | 3617 |
"/ if the name already exists, only allow longer names, if there are |
5360 | 3618 |
longerNames := allTheBest select:[:assoc | (assoc key startsWith:nm) or:[assoc key endsWith:nm]]. |
5033 | 3619 |
longerNames size < 30 ifTrue:[ |
3620 |
longerNames := allTheBest select:[:assoc | assoc key includesString:nm caseSensitive:false]. |
|
3621 |
]. |
|
5040 | 3622 |
longerNames isEmpty ifTrue:[ |
3623 |
"/ no better name |
|
3624 |
^ self |
|
4559 | 3625 |
]. |
5040 | 3626 |
allTheBest := longerNames. |
4238 | 3627 |
]. |
5040 | 3628 |
|
5033 | 3629 |
allTheBest size > 20 ifTrue:[ |
3630 |
allTheBest := allTheBest copyTo:20. |
|
3631 |
"/ "/ remove all those which are below some threshold or are a prefix |
|
3632 |
"/ 0.2 to:0.9 by:0.1 do:[:delta | |
|
3633 |
"/ |bestValue n| |
|
3634 |
"/ |
|
3635 |
"/ "/ if still too many, remove more and more |
|
3636 |
"/ allTheBest size > 50 ifTrue:[ |
|
3637 |
"/ bestValue := bestAssoc value * delta. |
|
3638 |
"/ n := allTheBest select:[:entry | (entry key startsWith:nm) or:[ entry value >= bestValue ]]. |
|
3639 |
"/ n size >= 15 ifTrue:[ allTheBest := n ]. |
|
3640 |
"/ ] |
|
3641 |
"/ ]. |
|
3642 |
"/ allTheBest size > 20 ifTrue:[ |
|
3643 |
"/ "/ remove all those which are below some threshold |
|
3644 |
"/ 0.2 to:0.9 by:0.1 do:[:delta | |
|
3645 |
"/ |bestValue n| |
|
3646 |
"/ "/ if still too many, remove more and more |
|
3647 |
"/ allTheBest size > 20 ifTrue:[ |
|
3648 |
"/ bestValue := bestAssoc value * delta. |
|
3649 |
"/ allTheBest := allTheBest select:[:entry | entry value >= bestValue ]. |
|
3650 |
"/ ] |
|
3651 |
"/ ]. |
|
3652 |
"/ ]. |
|
4238 | 3653 |
]. |
3654 |
suggestions := allTheBest collect:[:assoc | assoc key]. |
|
3655 |
||
4352 | 3656 |
"/ finally, the trick is to bring them into a reasonable order... |
3657 |
"/ sort the prefix matchers by length, the others by spelling distance |
|
3658 |
"/ and bring the prefix-matchers towards the beginning |
|
3659 |
suggestions := ((suggestions select:[:s | s startsWith:nm]) sort:[:a :b | a size < b size ]) |
|
4559 | 3660 |
, |
3661 |
(suggestions reject:[:s | s startsWith:nm]). |
|
4352 | 3662 |
|
4417 | 3663 |
"/ if super is among them, add a full call to the completions |
3664 |
(suggestions includes:'super') ifTrue:[ |
|
4559 | 3665 |
(tree notNil |
3666 |
and:[ tree isMethod ]) ifTrue:[ |
|
3667 |
Error handle:[:ex | |
|
3668 |
Transcript showCR:'parse error in code completion ignored'. |
|
3669 |
] do:[ |
|
3670 |
suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.'). |
|
3671 |
] |
|
3672 |
]. |
|
4417 | 3673 |
]. |
4238 | 3674 |
|
4620 | 3675 |
suggestionsWithInfo := |
3676 |
suggestions |
|
3677 |
collect:[:eachName | |
|
5040 | 3678 |
|val kind valAndKind printString| |
3679 |
||
3680 |
valAndKind := self valueAndKindOfVariable:eachName. |
|
3681 |
valAndKind isNil ifTrue:[ |
|
4620 | 3682 |
eachName |
3683 |
] ifFalse:[ |
|
5040 | 3684 |
val := valAndKind first. |
3685 |
kind := valAndKind second. |
|
3686 |
||
3687 |
val isBehavior ifTrue:[ |
|
3688 |
val isLoaded ifFalse:[ |
|
5090 | 3689 |
eachName,' (= ', ('autoloaded class in ',(val category ? 'unknown category')) allItalic,' )' |
5040 | 3690 |
] ifTrue:[ |
3691 |
val isNameSpace ifTrue:[ |
|
3692 |
eachName,' ( ', 'namespace' allItalic,' )' |
|
3693 |
] ifFalse:[ |
|
5090 | 3694 |
eachName,' (= ', ('class in ',(val category ? 'unknown category')) allItalic,' )' |
5040 | 3695 |
] |
3696 |
] |
|
3697 |
] ifFalse:[ |
|
3698 |
"/ Parser findBest:30 selectorsFor:'isLite' in:nil forCompletion:true |
|
3699 |
||
3700 |
(val isLiteral and:[ (printString := val printString) size < 15 ]) ifTrue:[ |
|
5090 | 3701 |
eachName,' (= ',printString allItalic,' )' |
5040 | 3702 |
] ifFalse:[ |
5370 | 3703 |
eachName,' (= ',val class nameWithArticle allItalic,' )' |
5040 | 3704 |
]. |
3705 |
]. |
|
4620 | 3706 |
]. |
3707 |
]. |
|
3708 |
||
5081 | 3709 |
editActions := suggestions collect:[:word | |
5080 | 3710 |
self editActionToReplaceNode:node by:word. |
3711 |
]. |
|
3712 |
actionBlock value:suggestionsWithInfo value:editActions value:nil. |
|
4238 | 3713 |
|
3714 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
3715 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
5041 | 3716 |
"Modified: / 01-05-2016 / 18:45:07 / cg" |
3717 |
! |
|
3718 |
||
5080 | 3719 |
editActionToInsert:aString |
3720 |
^ [:index | |
|
3721 |
codeView |
|
3722 |
undoableDo:[ |
|
3723 |
codeView insertSelectedStringAtCursor:aString. |
|
3724 |
codeView dontReplaceSelectionOnInput |
|
3725 |
] |
|
3726 |
info:'Completion'. |
|
3727 |
]. |
|
3728 |
! |
|
3729 |
||
3730 |
editActionToInsertFromSuggestions:suggestions |
|
3731 |
^ [:index | |
|
3732 |
|answer| |
|
3733 |
||
3734 |
answer := suggestions at:index. |
|
3735 |
codeView |
|
3736 |
undoableDo:[ |
|
3737 |
codeView insertSelectedStringAtCursor:answer. |
|
3738 |
codeView dontReplaceSelectionOnInput |
|
3739 |
] |
|
3740 |
info:'Completion'. |
|
3741 |
]. |
|
3742 |
! |
|
3743 |
||
3744 |
editActionToReplaceCodeFrom:start to:stop by:aString |
|
3745 |
^ [:index | |
|
3746 |
|oldVar oldLen newLen insertWithSpace| |
|
3747 |
||
3748 |
insertWithSpace := false. |
|
3749 |
||
3750 |
start <= stop ifTrue:[ |
|
3751 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
3752 |
] ifFalse:[ |
|
3753 |
codeView characterBeforeCursor == Character space ifTrue:[ |
|
3754 |
insertWithSpace := true. |
|
3755 |
]. |
|
3756 |
]. |
|
3757 |
||
3758 |
oldLen := stop - start + 1. |
|
3759 |
newLen := aString size. |
|
3760 |
||
3761 |
codeView |
|
3762 |
undoableDo:[ |
|
3763 |
insertWithSpace ifTrue:[ |
|
3764 |
codeView insertSelectedStringAtCursor:aString |
|
3765 |
] ifFalse:[ |
|
3766 |
codeView replaceFromCharacterPosition:start to:stop with:aString. |
|
3767 |
||
3768 |
(aString startsWith:oldVar) ifTrue:[ |
|
3769 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3770 |
] ifFalse:[ |
|
3771 |
codeView selectFromCharacterPosition:start to:start+newLen-1. |
|
3772 |
]. |
|
3773 |
]. |
|
3774 |
codeView dontReplaceSelectionOnInput |
|
3775 |
] |
|
3776 |
info:'Completion'. |
|
3777 |
||
3778 |
]. |
|
3779 |
||
3780 |
"Created: / 01-05-2016 / 18:47:40 / cg" |
|
3781 |
! |
|
3782 |
||
5041 | 3783 |
editActionToReplaceCodeFrom:start to:stop byWordIn:suggestions |
3784 |
^ [:index | |
|
3785 |
|answer oldVar oldLen newLen insertWithSpace| |
|
3786 |
||
3787 |
insertWithSpace := false. |
|
3788 |
||
3789 |
answer := suggestions at:index. |
|
3790 |
start <= stop ifTrue:[ |
|
3791 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
3792 |
] ifFalse:[ |
|
3793 |
codeView characterBeforeCursor == Character space ifTrue:[ |
|
3794 |
insertWithSpace := true. |
|
3795 |
]. |
|
3796 |
]. |
|
3797 |
||
3798 |
oldLen := stop - start + 1. |
|
3799 |
newLen := answer size. |
|
3800 |
||
3801 |
codeView |
|
3802 |
undoableDo:[ |
|
3803 |
insertWithSpace ifTrue:[ |
|
3804 |
codeView insertSelectedStringAtCursor:answer |
|
3805 |
] ifFalse:[ |
|
3806 |
codeView replaceFromCharacterPosition:start to:stop with:answer. |
|
3807 |
||
3808 |
(answer startsWith:oldVar) ifTrue:[ |
|
3809 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3810 |
] ifFalse:[ |
|
3811 |
codeView selectFromCharacterPosition:start to:start+newLen-1. |
|
3812 |
]. |
|
3813 |
]. |
|
3814 |
codeView dontReplaceSelectionOnInput |
|
3815 |
] |
|
3816 |
info:'Completion'. |
|
3817 |
||
3818 |
]. |
|
3819 |
||
3820 |
"Created: / 01-05-2016 / 18:47:40 / cg" |
|
3821 |
! |
|
3822 |
||
5080 | 3823 |
editActionToReplaceNode:node by:word |
3824 |
^ self editActionToReplaceCodeFrom:node start to:node stop by:word |
|
3825 |
||
3826 |
"Created: / 01-05-2016 / 18:44:09 / cg" |
|
3827 |
! |
|
3828 |
||
5041 | 3829 |
editActionToReplaceNode:node byWordIn:suggestions |
5114 | 3830 |
^ self editActionToReplaceCodeFrom:(node start) to:(node stop) byWordIn:suggestions |
5041 | 3831 |
|
3832 |
"Created: / 01-05-2016 / 18:44:09 / cg" |
|
4238 | 3833 |
! |
3834 |
||
5112 | 3835 |
findBest:node for:selector inClasses:srchClassesArg |
3836 |
|srchClasses bestSelectors |
|
3837 |
allMessagesSentToVariable classesImplementingAllMessages| |
|
3838 |
||
3839 |
srchClasses := srchClassesArg. |
|
3840 |
Verbose == true ifTrue:[ |
|
3841 |
Transcript show:'node: '; showCR:node. |
|
3842 |
Transcript show:'srchClasses: '; showCR:srchClasses. |
|
3843 |
]. |
|
3844 |
||
3845 |
srchClasses isEmptyOrNil ifTrue:[ |
|
3846 |
node isVariable ifTrue:[ |
|
3847 |
allMessagesSentToVariable := Set new. |
|
3848 |
rememberedNodes do:[:eachNode | |
|
3849 |
eachNode allMessageNodesDo:[:eachMessage | |
|
3850 |
|msgReceiver msgSelector| |
|
3851 |
||
3852 |
(msgReceiver := eachMessage receiver) isVariable ifTrue:[ |
|
3853 |
msgReceiver name = node name ifTrue:[ |
|
3854 |
(msgSelector := eachMessage selector) ~= selector ifTrue:[ |
|
3855 |
allMessagesSentToVariable add:msgSelector |
|
3856 |
] |
|
3857 |
] |
|
3858 |
] |
|
3859 |
] |
|
3860 |
]. |
|
3861 |
allMessagesSentToVariable notEmpty ifTrue:[ |
|
3862 |
"/ consider classes which implement all those messages. |
|
3863 |
classesImplementingAllMessages := Smalltalk allImplementorsOf:(allMessagesSentToVariable first). |
|
3864 |
allMessagesSentToVariable do:[:eachSelector | |
|
3865 |
classesImplementingAllMessages := classesImplementingAllMessages |
|
3866 |
select:[:cls | cls implements:eachSelector]. |
|
3867 |
]. |
|
3868 |
srchClasses := classesImplementingAllMessages. |
|
3869 |
]. |
|
3870 |
]. |
|
3871 |
]. |
|
3872 |
bestSelectors := Set new. |
|
3873 |
srchClasses isEmptyOrNil ifTrue:[ |
|
3874 |
bestSelectors addAll:( Parser findBest:50 selectorsFor:selector in:nil forCompletion:true ). |
|
3875 |
Verbose == true ifTrue:[ |
|
3876 |
Transcript show:'bestSelectors (1): '; showCR:bestSelectors. |
|
3877 |
]. |
|
3878 |
] ifFalse:[ |
|
3879 |
srchClasses do:[:srchClass | |
|
3880 |
|bestForThisClass| |
|
3881 |
||
3882 |
bestForThisClass := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true. |
|
3883 |
bestForThisClass := self |
|
3884 |
withoutSelectorsUnlikelyFor:srchClass |
|
3885 |
from:bestForThisClass |
|
3886 |
forPartial:selector. |
|
3887 |
Verbose == true ifTrue:[ |
|
3888 |
Transcript show:'bestSelectors (2): '; showCR:bestForThisClass. |
|
3889 |
]. |
|
3890 |
bestSelectors addAll:bestForThisClass. |
|
3891 |
]. |
|
3892 |
]. |
|
3893 |
"/ remove the already typed-in selector itself, in case. |
|
3894 |
bestSelectors remove:selector ifAbsent:[]. |
|
3895 |
bestSelectors := bestSelectors asOrderedCollection. |
|
3896 |
^ bestSelectors |
|
3897 |
! |
|
3898 |
||
4238 | 3899 |
findNodeForInterval:interval in:source |
5272 | 3900 |
^ self class findNodeForInterval:interval in:source |
4238 | 3901 |
|
3902 |
"Modified: / 06-07-2011 / 12:42:53 / cg" |
|
3903 |
! |
|
3904 |
||
3905 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
|
3906 |
^ self |
|
4548 | 3907 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3908 |
mustBeMethod:false |
|
4238 | 3909 |
|
3910 |
"Modified: / 16-09-2011 / 14:52:28 / cg" |
|
3911 |
! |
|
3912 |
||
3913 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod |
|
3914 |
"if mustBeMethod is true, do not try a regular expression (as in a workspace)." |
|
3915 |
||
4352 | 3916 |
^ self |
4548 | 3917 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3918 |
mustBeMethod:mustBeMethod mustBeExpression:false |
|
4352 | 3919 |
! |
3920 |
||
3921 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression |
|
5070 | 3922 |
"parse source, and find the node which is in the given interval |
3923 |
(typically a selection or a word in the source). |
|
5040 | 3924 |
|
3925 |
parse it as expression or method; |
|
3926 |
if mustBeMethod is true, do not try as expression; |
|
3927 |
if mustBeExpression is true, do not try as method |
|
3928 |
expression syntax parsing is done in workspaces (doIt). |
|
3929 |
||
3930 |
Big hack as workaround a limitation of RBParser: |
|
3931 |
in case of an error, the parent chain of a node is usually not yet set. |
|
3932 |
(because the code is written as: |
|
3933 |
parentNode addChild:(self parseChild) |
|
3934 |
and the parent-chain of the parsed child is set in addChild). |
|
5070 | 3935 |
However: |
5040 | 3936 |
when doing code completion, having invalid syntax to parse is the normal case. |
5070 | 3937 |
|
5040 | 3938 |
Workaround: |
5070 | 3939 |
remember created nodes as the parse proceeds. |
3940 |
Thus, I can construct a partial the parent chain. |
|
5040 | 3941 |
" |
4367 | 3942 |
|
4548 | 3943 |
|intersectingNodes smallestIntersectingNode firstIntersectingNode |
3944 |
lastIntersectingNode onErrorBlock |
|
4373 | 3945 |
nodeGenerationHook parserClass parser currentScopeNodes bestNode| |
4238 | 3946 |
|
3947 |
interval isEmpty ifTrue: [^ nil]. |
|
5040 | 3948 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3949 |
languageOrNil notNil ifTrue:[ |
4934 | 3950 |
parserClass := languageOrNil parserClass. |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3951 |
] ifFalse:[ |
4934 | 3952 |
classOrNil notNil ifTrue:[ |
3953 |
parserClass := classOrNil programmingLanguage parserClass. |
|
3954 |
] |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3955 |
]. |
4548 | 3956 |
parserClass notNil ifTrue:[ |
4934 | 3957 |
"/ hack |
3958 |
parserClass == Parser ifTrue: [ |
|
3959 |
parserClass := RBParser. |
|
3960 |
]. |
|
4373 | 3961 |
] ifFalse:[ |
4934 | 3962 |
parserClass := RBParser. |
4373 | 3963 |
]. |
3964 |
parserClass isNil ifTrue: [^ nil]. |
|
4238 | 3965 |
|
4361 | 3966 |
rememberedScopeNodes := nil. |
4434 | 3967 |
rememberedNodes := OrderedCollection new. |
4361 | 3968 |
|
4238 | 3969 |
"/ LastSource := nil. |
3970 |
source = LastSource ifTrue:[ |
|
4934 | 3971 |
tree := LastParseTree. |
3972 |
tokens := LastScanTokens. |
|
4238 | 3973 |
] ifFalse:[ |
4934 | 3974 |
intersectingNodes := OrderedCollection new. |
3975 |
currentScopeNodes := IdentitySet new. |
|
3976 |
||
3977 |
onErrorBlock := |
|
3978 |
[:str :err :nodesSoFar | |
|
3979 |
|nodes| |
|
3980 |
||
3981 |
allowErrors ifTrue:[ |
|
3982 |
rememberedScopeNodes := currentScopeNodes. |
|
3983 |
firstIntersectingNode notNil ifTrue:[ |
|
3984 |
^ firstIntersectingNode |
|
3985 |
]. |
|
3986 |
nodesSoFar notNil ifTrue:[ |
|
3987 |
nodes := nodesSoFar asOrderedCollection |
|
3988 |
collect:[:nd | nd whichNodeIntersects:interval] |
|
3989 |
thenSelect:[:nd | nd notNil ]. |
|
3990 |
nodes size == 1 ifTrue:[ |
|
3991 |
^ nodes first |
|
3992 |
]. |
|
3993 |
] |
|
3994 |
]. |
|
3995 |
nil |
|
3996 |
]. |
|
3997 |
||
3998 |
self debuggingCodeFor:#cg is:[ |
|
3999 |
Transcript show:'looking for: '; showCR:interval. |
|
4000 |
]. |
|
4001 |
||
4002 |
nodeGenerationHook := |
|
4003 |
[:node | |
|
4004 |
rememberedNodes add:node. |
|
4005 |
||
4006 |
"/ would like to return here as soon as the node has been created by the parser; |
|
4007 |
"/ however, at that time, its parent(chain) is not yet created and so we might not know |
|
4008 |
"/ what the semantic interpretation (especially: scope of variable) will be. |
|
4009 |
"/ therefore, we parse all, and return the found node at the end. |
|
4010 |
(node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[ |
|
4011 |
currentScopeNodes add:node. |
|
4012 |
] ifFalse:[ |
|
5075 | 4013 |
"/ self debuggingCodeFor:#cg is:[ |
4014 |
"/ node isMessage ifTrue:[ |
|
4015 |
"/ Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop. |
|
4016 |
"/ ]. |
|
4017 |
"/ ]. |
|
4934 | 4018 |
|
4019 |
(node intersectsInterval:interval) ifTrue:[ |
|
4020 |
self debuggingCodeFor:#cg is:[ |
|
4021 |
Transcript showCR:'yes'. |
|
4022 |
]. |
|
4023 |
intersectingNodes add:node. |
|
4024 |
firstIntersectingNode isNil ifTrue:[ |
|
4025 |
firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node |
|
4026 |
] ifFalse:[ |
|
4027 |
|lenNode lenSmallest| |
|
4028 |
||
4029 |
lenNode := (node stop - node start). |
|
4030 |
lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start). |
|
4031 |
lenNode < lenSmallest ifTrue:[ |
|
4032 |
smallestIntersectingNode := node. |
|
4033 |
]. |
|
4034 |
node start > lastIntersectingNode start ifTrue:[ |
|
4035 |
lastIntersectingNode := node. |
|
4036 |
]. |
|
4037 |
]. |
|
4038 |
]. |
|
4039 |
]. |
|
4040 |
]. |
|
4041 |
||
4042 |
"/ one of the big problems when using the RBParser here is |
|
4043 |
"/ that it behaves badly when a syntax error is encountered; |
|
4044 |
"/ for example, a node's parent is usually set AFTER the children are |
|
4045 |
"/ completely parsed (for example, a blockNode gets the parent-method only |
|
4046 |
"/ after parsing). Thus, when an error is encountered, we cannot walk |
|
4047 |
"/ the parent chain, and therefore will not see the outer locals/args of |
|
4048 |
"/ an inner scope (allVariablesOnScope returns only a partial set). |
|
4049 |
"/ A walkaround is to remember Method/Block nodes as created in the above node generation. |
|
4050 |
"/ The disadvantage of it is that we do not have correct scope information, until the node's |
|
4051 |
"/ parent gets set eventually, thus we might consider locals from sibling blocks. |
|
4052 |
"/ See rememberedScopeNodes handling above. |
|
4053 |
"/ Those other nodes are only remembered for failed parses; |
|
4054 |
"/ if the parse is ok, rememberedScopeNodes will be nil. |
|
4055 |
||
4056 |
mustBeExpression ifFalse:[ |
|
4057 |
tree := parserClass |
|
4058 |
parseMethod: source |
|
4059 |
setup:[:p | |
|
4060 |
parser := p. |
|
4061 |
p rememberNodes:true. |
|
4062 |
p rememberTokens:true. |
|
4063 |
p nodeGenerationCallback:nodeGenerationHook |
|
4064 |
] |
|
4065 |
onError: onErrorBlock. |
|
4066 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
|
4067 |
]. |
|
4068 |
||
4069 |
mustBeMethod ifTrue:[ |
|
4070 |
"/ only cache parsed methods |
|
4071 |
tree notNil ifTrue:[ |
|
4072 |
LastSource := source. |
|
4073 |
LastParseTree := tree. |
|
4074 |
LastScanTokens := tokens. |
|
4075 |
]. |
|
4076 |
] ifFalse:[ |
|
4077 |
(tree isNil or:[firstIntersectingNode isNil]) ifTrue:[ |
|
4078 |
"/ try as an expression |
|
4079 |
tree := parserClass |
|
4080 |
parseExpression: source |
|
4081 |
setup:[:p | |
|
4082 |
parser := p. |
|
4083 |
p rememberNodes:true. |
|
4084 |
p rememberTokens:true. |
|
4085 |
p nodeGenerationCallback:nodeGenerationHook |
|
4086 |
] |
|
4087 |
onError: onErrorBlock. |
|
4088 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
|
4089 |
]. |
|
4090 |
]. |
|
4091 |
lastIntersectingNode notNil ifTrue:[ |
|
4092 |
self debuggingCodeFor:#cg is:[ |
|
4093 |
Transcript show:'last: '; showCR:lastIntersectingNode. |
|
4094 |
]. |
|
4095 |
^ lastIntersectingNode |
|
4096 |
]. |
|
4097 |
"/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ]. |
|
4238 | 4098 |
]. |
4099 |
||
4367 | 4100 |
bestNode := self findNodeForInterval:interval inParseTree:tree. |
4101 |
self debuggingCodeFor:#cg is:[ |
|
4934 | 4102 |
Transcript show:'best: '; showCR:bestNode. |
4367 | 4103 |
]. |
4104 |
^ bestNode |
|
4238 | 4105 |
|
4106 |
"Created: / 16-09-2011 / 14:52:08 / cg" |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
4107 |
"Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5040 | 4108 |
"Modified (comment): / 01-05-2016 / 10:05:10 / cg" |
4238 | 4109 |
! |
4110 |
||
4111 |
findNodeForInterval:interval inParseTree:parseTree |
|
4112 |
|node| |
|
4113 |
||
4114 |
interval isEmpty ifTrue: [^ nil]. |
|
4115 |
parseTree isNil ifTrue:[^ nil]. |
|
4116 |
||
4117 |
node := parseTree whichNodeIsContainedBy:interval. |
|
4118 |
node isNil ifTrue:[ |
|
4548 | 4119 |
node := parseTree whichNodeIntersects:interval. |
4120 |
node isNil ifTrue: [ |
|
4121 |
node := self findNodeIn:parseTree forInterval:interval |
|
4122 |
]. |
|
4238 | 4123 |
]. |
4124 |
^ node |
|
4125 |
||
4126 |
"Modified: / 10-11-2006 / 13:13:58 / cg" |
|
4127 |
! |
|
4128 |
||
5272 | 4129 |
findNodeIn:aTree forInterval:anInterval |
4130 |
^ self class findNodeIn:aTree forInterval:anInterval |
|
4238 | 4131 |
|
4132 |
"Modified: / 20-11-2006 / 12:31:12 / cg" |
|
4133 |
! |
|
4134 |
||
4421 | 4135 |
insertAdditonalStuffAfterSelector:chosenCompletion |
4136 |
|optionalExtraSpace| |
|
4137 |
||
4548 | 4138 |
optionalExtraSpace := (codeView characterAfterCursor isSeparator) |
5080 | 4139 |
ifTrue:[''] |
4140 |
ifFalse:[' ']. |
|
4421 | 4141 |
|
4142 |
( |
|
5080 | 4143 |
#( |
4144 |
'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:' |
|
4145 |
'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:' |
|
4146 |
) includes:chosenCompletion |
|
4421 | 4147 |
) ifTrue:[ |
5080 | 4148 |
codeView insertStringAtCursor:('[',optionalExtraSpace,']'). |
4149 |
"/ codeView cursorLeft:1+extra size. |
|
4421 | 4150 |
]. |
4151 |
( |
|
5080 | 4152 |
#( |
4153 |
'collect:' 'select:' 'reject:' 'do:' |
|
4154 |
) includes:chosenCompletion |
|
4421 | 4155 |
) ifTrue:[ |
5080 | 4156 |
codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace). |
4157 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 4158 |
]. |
4159 |
( |
|
5080 | 4160 |
#( |
4161 |
'contains:' 'findFirst:' 'detect:' |
|
4162 |
) includes:chosenCompletion |
|
4421 | 4163 |
) ifTrue:[ |
5080 | 4164 |
codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace). |
4165 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 4166 |
]. |
4167 |
( |
|
5080 | 4168 |
#( |
4169 |
'remove:ifAbsent:' 'detect:ifNone:' |
|
4170 |
) includes:chosenCompletion |
|
4421 | 4171 |
) ifTrue:[ |
5080 | 4172 |
codeView insertStringAtCursor:('[]',optionalExtraSpace). |
4173 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 4174 |
]. |
4175 |
! |
|
4176 |
||
5043 | 4177 |
messagesSentTo:varName in:aTree |
5080 | 4178 |
|messagesToReceiver collector| |
4179 |
||
4180 |
collector := |
|
4181 |
[:node | |
|
5043 | 4182 |
(node isMessage |
4183 |
and:[node receiver isVariable |
|
4184 |
and:[node receiver name = varName]]) ifTrue:[ |
|
4185 |
messagesToReceiver add:(node selector) |
|
4186 |
]. |
|
4187 |
]. |
|
5080 | 4188 |
|
4189 |
"/ collect messages sent |
|
4190 |
messagesToReceiver := Set new. |
|
4191 |
"/ remembered nodes is nonNil if parser aborted with error |
|
4192 |
rememberedNodes notNil ifTrue:[ |
|
4193 |
rememberedNodes do:collector. |
|
5043 | 4194 |
] ifFalse:[ |
5080 | 4195 |
tree allMessageNodesDo:collector. |
5043 | 4196 |
]. |
4197 |
^ messagesToReceiver |
|
4198 |
! |
|
4199 |
||
4238 | 4200 |
old_askUserForCompletion:what for:codeView from:allTheBest |
4201 |
|list resources choice lastChoice| |
|
4202 |
||
4203 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
4204 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
4205 |
||
4206 |
list := allTheBest. |
|
4207 |
LastChoices notNil ifTrue:[ |
|
4548 | 4208 |
lastChoice := LastChoices at:what ifAbsent:nil. |
4209 |
lastChoice notNil ifTrue:[ |
|
4210 |
"/ move tha last choice to the top of the list, if it is in. |
|
4211 |
(list includes: lastChoice) ifTrue:[ |
|
4212 |
(list indexOf: lastChoice) < 10 ifTrue:[ |
|
4213 |
list := {lastChoice allBold } , (list copyWithout:lastChoice). |
|
4214 |
] |
|
4215 |
] |
|
4216 |
]. |
|
4238 | 4217 |
]. |
4218 |
||
4219 |
list size < 30 ifTrue:[ |
|
4548 | 4220 |
|menu idx exitKey| |
4221 |
||
4222 |
menu := PopUpMenu labels:list. |
|
4223 |
menu hideOnKeyFilter:[:key | |hide| |
|
4224 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
4225 |
hide ifTrue:[ |
|
4226 |
exitKey := key. |
|
4227 |
]. |
|
4228 |
hide]. |
|
4229 |
menu memorizeLastSelection:3 "sigh, not 1 because of heading!!". |
|
4230 |
idx := menu startUpWithHeading:'Choose ',what. |
|
4231 |
idx == 0 ifTrue:[ |
|
4232 |
exitKey notNil ifTrue:[ |
|
4233 |
codeView keyPress:exitKey x:0 y:0. |
|
4234 |
]. |
|
4235 |
^ nil |
|
4236 |
]. |
|
4237 |
choice := list at:idx. |
|
4238 | 4238 |
] ifFalse:[ |
4548 | 4239 |
resources := codeView application isNil |
4240 |
ifTrue:[ codeView resources] |
|
4241 |
ifFalse:[ codeView application resources ]. |
|
4242 |
||
4243 |
choice := Dialog |
|
4244 |
choose:(resources string:'Choose ',what) |
|
4245 |
fromList:list |
|
4246 |
lines:20 |
|
4247 |
initialSelection:(list firstIfEmpty:nil) |
|
4248 |
title:(resources string:'Code completion'). |
|
4249 |
choice isNil ifTrue:[^ nil]. |
|
4238 | 4250 |
]. |
4301 | 4251 |
choice := choice string. |
4238 | 4252 |
|
4253 |
LastChoices isNil ifTrue:[ |
|
4548 | 4254 |
LastChoices := Dictionary new. |
4238 | 4255 |
]. |
4256 |
LastChoices at:what put:choice. |
|
4257 |
^ choice |
|
4258 |
||
4259 |
"Created: / 16-02-2010 / 09:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 4260 |
"Modified: / 28-08-2013 / 15:28:01 / cg" |
4238 | 4261 |
! |
4262 |
||
5043 | 4263 |
sortSelectors:list forSelector:selector lcSelector:lcSelector |
4264 |
list sort: [:a :b | |
|
4265 |
|aBeforeB| |
|
4266 |
||
4267 |
(a startsWith:selector) ifTrue:[ |
|
4268 |
(b startsWith:selector) ifFalse:[ |
|
4269 |
aBeforeB := true |
|
4270 |
] |
|
4271 |
] ifFalse:[ |
|
4272 |
(b startsWith:selector) ifTrue:[ |
|
4273 |
aBeforeB := false |
|
4274 |
] |
|
4275 |
]. |
|
4276 |
aBeforeB isNil ifTrue:[ |
|
4277 |
aBeforeB := a asLowercase < b asLowercase. |
|
4278 |
(a asLowercase startsWith:lcSelector) ifTrue:[ |
|
4279 |
(b asLowercase startsWith:lcSelector) ifFalse:[ |
|
4280 |
aBeforeB := true |
|
4281 |
] |
|
4282 |
] ifFalse:[ |
|
4283 |
(b asLowercase startsWith:lcSelector) ifTrue:[ |
|
4284 |
aBeforeB := false |
|
4285 |
] |
|
4286 |
]. |
|
4287 |
]. |
|
4288 |
aBeforeB |
|
4289 |
]. |
|
4290 |
! |
|
4291 |
||
5040 | 4292 |
sortUsefulSelectorsIn:selectorList |
4293 |
"/ cosmetics: |
|
4294 |
"/ ifTrue / whileTrue should come before ifFalse/whileFalse |
|
4295 |
#( |
|
4296 |
ifTrue: ifFalse: |
|
4297 |
ifTrue:ifFalse: ifFalse:ifTrue: |
|
4298 |
whileTrue: whileFalse: |
|
4299 |
whileTrue whileFalse |
|
4300 |
whileTrue: whileTrue |
|
4301 |
whileFalse: whileFalse |
|
4302 |
new: basicNew: |
|
4303 |
new basicNew |
|
4304 |
) pairWiseDo:[:sel1 :sel2 | |
|
4305 |
|idx1 idx2| |
|
4306 |
||
4307 |
(idx1 := selectorList indexOf:sel1) ~~ 0 ifTrue:[ |
|
4308 |
(idx2 := selectorList indexOf:sel2) ~~ 0 ifTrue:[ |
|
4309 |
idx1 > idx2 ifTrue:[ |
|
4310 |
selectorList swap:idx1 with:idx2 |
|
4311 |
] |
|
4312 |
] |
|
4313 |
]. |
|
4314 |
]. |
|
4315 |
||
4316 |
"Created: / 01-05-2016 / 17:48:02 / cg" |
|
4317 |
! |
|
4318 |
||
5044 | 4319 |
splitSelectorList:list by:condition |
4320 |
|part1 part2 newList| |
|
4321 |
||
4322 |
part1 := list select:condition. |
|
4323 |
part2 := list reject:condition. |
|
4324 |
part1 isEmpty ifTrue:[ |
|
4325 |
newList := part2. |
|
4326 |
] ifFalse:[ |
|
4327 |
part2 isEmpty ifTrue:[ |
|
4328 |
newList := part1. |
|
4329 |
] ifFalse:[ |
|
4330 |
newList := part1 , part2. |
|
4331 |
] |
|
4332 |
]. |
|
4333 |
^ newList |
|
4334 |
! |
|
4335 |
||
4238 | 4336 |
treeForCode:source allowErrors:allowErrors |
4337 |
|tree| |
|
4338 |
||
4339 |
source = LastSource ifTrue:[ |
|
4548 | 4340 |
tree := LastParseTree. |
4238 | 4341 |
] ifFalse:[ |
4548 | 4342 |
tree := RBParser |
4343 |
parseMethod:source |
|
4344 |
onError: [:str :err :nodesSoFar :parserOrNil| |
|
4345 |
allowErrors ifTrue:[ |
|
4346 |
"/ parserOrNil isNil if raised by the scanner |
|
4347 |
parserOrNil notNil ifTrue:[ |
|
4348 |
^ parserOrNil currentMethodNode |
|
4349 |
] |
|
4350 |
]. |
|
4351 |
^ nil |
|
4352 |
] |
|
4353 |
proceedAfterError:false |
|
4354 |
rememberNodes:true. |
|
4355 |
||
4356 |
tree notNil ifTrue:[ |
|
4357 |
LastSource := source. |
|
4358 |
LastParseTree := tree. |
|
4359 |
] |
|
4238 | 4360 |
]. |
4361 |
^ tree |
|
4362 |
||
4363 |
"Modified: / 13-01-2012 / 11:54:30 / cg" |
|
4352 | 4364 |
! |
4365 |
||
4524 | 4366 |
tryCodeCompletionWithSource:source nodeInterval:interval at:characterPositionOfCursor mustBeExpression:mustBeExpression into:actionBlock |
4548 | 4367 |
"this is tried multiple times; |
4931 | 4368 |
first with cursor line only |
4369 |
then with the source copied up to the cursor position, |
|
4370 |
then with the full source. |
|
4381 | 4371 |
Either one may give better results (for example, when completing |
4352 | 4372 |
after a keyword selector, and the remaining code would lead to a syntactically |
4373 |
legal, but stupid message send to be parsed... |
|
4374 |
(which happens often after inserting)" |
|
4375 |
||
5040 | 4376 |
|node nodeParent checkedNode characterBeforeCursor| |
4352 | 4377 |
|
4378 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
4379 |
"/ we will not find a node for a long time (stepping back more and more, |
|
4380 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
4381 |
"/ without any progress. |
|
4382 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
4383 |
"/ as it parses the code. Stop, when the interval is hit. |
|
4384 |
"/ that will also work for syntactic incorrect source code. |
|
4524 | 4385 |
(mustBeExpression not and:[methodOrNil notNil or:[classOrNil notNil]]) ifTrue:[ |
4931 | 4386 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
5040 | 4387 |
]. |
4352 | 4388 |
node isNil ifTrue:[ |
4931 | 4389 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true. |
4390 |
node isNil ifTrue:[ |
|
4391 |
"/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'. |
|
4392 |
self information:'No parseNode found (syntax error before or in comment?)'. |
|
4393 |
^ self. |
|
4394 |
]. |
|
4352 | 4395 |
]. |
5106 | 4396 |
"/ (source startsWith:'sel') ifTrue:[self halt]. |
4544 | 4397 |
nodeParent := node parent. |
4352 | 4398 |
|
4399 |
(node isVariable |
|
4544 | 4400 |
and:[ nodeParent notNil |
4401 |
and:[ nodeParent isMessage |
|
4368 | 4402 |
and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[ |
4931 | 4403 |
node := nodeParent. |
4404 |
nodeParent := node parent. |
|
4352 | 4405 |
]. |
4931 | 4406 |
characterPositionOfCursor > source size ifTrue:[^ self]. |
4525 | 4407 |
characterBeforeCursor := source at:(characterPositionOfCursor-1 max:1). "/ codeView characterBeforeCursor. |
4352 | 4408 |
characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self]. |
4358 | 4409 |
characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self]. |
5040 | 4410 |
|
4352 | 4411 |
node isVariable ifTrue:[ |
5040 | 4412 |
|nodeIsInTemporaries nodeIsInBlockArguments nodeIsInMethodArguments | |
4413 |
||
4931 | 4414 |
nodeIsInTemporaries := |
4415 |
nodeParent notNil |
|
4416 |
and:[ nodeParent isSequence |
|
4417 |
and:[ nodeParent temporaries notEmptyOrNil |
|
5040 | 4418 |
and:[ node stop <= nodeParent temporaries last stop ]]]. |
4419 |
||
4420 |
nodeIsInBlockArguments := |
|
4421 |
node blockScope notNil |
|
4422 |
and:[ node blockScope arguments notEmptyOrNil |
|
4423 |
and:[ node stop <= node blockScope arguments last stop ]]. |
|
4424 |
||
4425 |
(nodeIsInBlockArguments not and:[rememberedScopeNodes notNil]) ifTrue:[ |
|
4426 |
"/ sigh - parent (and therefore blockScope) is unknown if parser has error |
|
4427 |
nodeIsInBlockArguments := |
|
4428 |
rememberedScopeNodes |
|
4429 |
contains:[:scope | |
|
4430 |
(scope isMethod or:[scope isBlock]) |
|
4431 |
and:[scope arguments notEmpty |
|
4432 |
and:[scope arguments first start <= node start |
|
4433 |
and:[scope arguments last stop >= node stop]]]. |
|
4434 |
]. |
|
4435 |
]. |
|
5106 | 4436 |
nodeIsInTemporaries ifTrue:[ self codeCompletionForTempVariable:node into:actionBlock. ^ self ]. |
4437 |
nodeIsInBlockArguments ifTrue:[ self codeCompletionForBlockArgument:node into:actionBlock. ^ self ]. |
|
5040 | 4438 |
|
4439 |
"/ for variable completion, cursor must be right after the node |
|
4440 |
codeView characterPositionOfCursor = (node stop + 1) ifTrue:[ |
|
4441 |
codeView characterBeforeCursor ~= Character space ifTrue:[ |
|
4931 | 4442 |
self codeCompletionForVariable:node into:actionBlock. |
5035 | 4443 |
^ self. |
5040 | 4444 |
]. |
5043 | 4445 |
]. |
4446 |
"/ nodeParent isNil or:[nodeParent isMessage not] |
|
5040 | 4447 |
]. |
4448 |
||
5035 | 4449 |
false ifTrue:[ |
4450 |
codeView characterPositionOfCursor = (node stop + 2) ifTrue:[ |
|
5040 | 4451 |
|classes cls| |
5035 | 4452 |
"/ after a variable; |
4453 |
"/ offer local messages, if receiver type is known |
|
4454 |
classes := (self classesOfNode:node). |
|
4455 |
classes notEmptyOrNil ifTrue:[ |
|
4456 |
classes size > 1 ifTrue:[ |
|
4457 |
cls := classes anElement. |
|
4458 |
] ifFalse:[ |
|
4459 |
cls := Behavior commonSuperclassOf:classes. |
|
4460 |
] |
|
4461 |
]. |
|
4462 |
cls notNil ifTrue:[ |
|
4463 |
|clsSelectors moreSelectors| |
|
4464 |
||
4465 |
"/ completion in a message-send |
|
4466 |
clsSelectors := cls methodDictionary keys. "/ Parser findBest:50 selectorsFor:'' in:cls forCompletion:true. |
|
4467 |
clsSelectors size < 30 ifTrue:[ |
|
4468 |
cls superclass notNil ifTrue:[ |
|
4469 |
moreSelectors := cls superclass methodDictionary keys. |
|
4470 |
clsSelectors size + moreSelectors size < 30 ifTrue:[ |
|
4471 |
clsSelectors := clsSelectors , moreSelectors. |
|
4472 |
]. |
|
4473 |
]. |
|
4474 |
]. |
|
4475 |
"/ self codeCompletionForMessage:checkedNode into:actionBlock. |
|
4476 |
actionBlock value:clsSelectors value:nil value:nil. |
|
4477 |
^ self. |
|
4478 |
] |
|
4479 |
] |
|
4480 |
]. |
|
4367 | 4481 |
|
4352 | 4482 |
node isLiteral ifTrue:[ |
4931 | 4483 |
"/ however, user may want to complete a symbol inside a literal array!! |
4484 |
node value isArray ifTrue:[ |
|
4485 |
node token isLiteralArray ifTrue:[ |
|
4486 |
|elementBeforeCursor searcher| |
|
4487 |
||
4488 |
elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil. |
|
4489 |
elementBeforeCursor isNil ifTrue:[ |
|
4490 |
searcher := |
|
4491 |
[:tok :check | |
|
4492 |
tok isLiteralArray ifTrue:[ |
|
4493 |
tok value inject:nil into:[:found :el | found ifNil:[searcher value:el value:check]] |
|
4494 |
] ifFalse:[ |
|
4495 |
(check value:tok) ifTrue:[tok] ifFalse:[nil] |
|
4496 |
] |
|
4497 |
]. |
|
4498 |
elementBeforeCursor := searcher value:node token value:[:anElementToken | characterPositionOfCursor == (anElementToken stop)]. |
|
4499 |
]. |
|
4500 |
(elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[ |
|
4501 |
self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock. |
|
4502 |
^ self. |
|
4503 |
]. |
|
4504 |
]. |
|
4505 |
]. |
|
4506 |
||
4507 |
"/ cursor must be right after the literal |
|
4508 |
characterPositionOfCursor == (node stop + 1) ifFalse:[ |
|
4509 |
^ self |
|
4510 |
]. |
|
4511 |
||
4512 |
node value isSymbol ifTrue:[ |
|
4513 |
self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock. |
|
4514 |
^ self. |
|
4515 |
]. |
|
4516 |
||
4517 |
"/ huh - completing strings, numbers or what? |
|
4518 |
(nodeParent notNil |
|
4519 |
and:[ nodeParent isMessage |
|
4520 |
and:[ nodeParent isKeyword ]]) |
|
4521 |
ifFalse:[ |
|
4522 |
^ self |
|
4523 |
]. |
|
4524 |
"/ no, move up and try completing the outer keyword message (next arg) |
|
4525 |
node := nodeParent. |
|
4526 |
nodeParent := node parent. |
|
4352 | 4527 |
]. |
4528 |
||
5050 | 4529 |
Verbose == true ifTrue:[ |
4530 |
Transcript show:'node is '. |
|
4531 |
Error ignoreIn:[ Transcript show:node ]. |
|
4532 |
Transcript cr. |
|
4533 |
]. |
|
4534 |
||
5080 | 4535 |
"/ if in a keyword-argument position... |
4536 |
node isMessage ifTrue:[ |
|
4537 |
"/ where are we? |
|
5379 | 4538 |
node selectorString last == $: "node selector isSymbol" ifTrue:[ |
5080 | 4539 |
characterBeforeCursor == $: ifTrue:[ |
4540 |
|argIdx senders implementors receiverClasses selectorUpToCursor implementorOfSelectorUpToCursor| |
|
4541 |
"/ about to enter an argument? |
|
4542 |
argIdx := node selectorParts keysAndValuesDetectKey:[:idx :part | |
|
4543 |
part stop == (codeView characterPositionOfCursor-1). |
|
4544 |
] ifNone:nil. |
|
4545 |
argIdx notNil ifTrue:[ |
|
4546 |
selectorUpToCursor := ((node selectorParts collect:#value) copyTo:argIdx) asStringWith:''. |
|
4547 |
implementors := Set new. |
|
4548 |
"/ find senders of this message, and see if they call it with a block argument |
|
4549 |
"/ this takes too long for a completion; |
|
4550 |
"/ Smalltalk allClassesDo:[:cls | |
|
4551 |
"/ cls instAndClassMethodsDo:[:m | |
|
4552 |
"/ (m sendsMessageForWhich:[:sel | sel startsWith:node selector]) ifTrue:[ |
|
4553 |
"/ senders add:m |
|
4554 |
"/ ]. |
|
4555 |
"/ ] |
|
4556 |
"/ ]. |
|
4557 |
"/ therefore, restrict to a max. of 5 classes |
|
4558 |
receiverClasses := self classesOfNode:node receiver. |
|
4559 |
(receiverClasses notEmptyOrNil and:[receiverClasses size <= 5]) ifTrue:[ |
|
4560 |
receiverClasses do:[:eachPossibleReceiverClass | |
|
4561 |
eachPossibleReceiverClass withAllSuperclassesDo:[:cls | |
|
4562 |
cls methodDictionary keysAndValuesDo:[:sel :mthd | |
|
4563 |
(sel startsWith:selectorUpToCursor) ifTrue:[ |
|
4564 |
implementors add:mthd. |
|
4565 |
(sel = selectorUpToCursor) ifTrue:[ |
|
4566 |
implementorOfSelectorUpToCursor := implementorOfSelectorUpToCursor ? mthd |
|
4567 |
]. |
|
4568 |
]. |
|
4569 |
]. |
|
4570 |
] |
|
4571 |
] |
|
4572 |
]. |
|
4573 |
implementorOfSelectorUpToCursor notNil ifTrue:[ |
|
4574 |
|tree argName| |
|
4575 |
||
5123 | 4576 |
SourceCodeManagerError handle:[:ex | |
4577 |
] do:[ |
|
5392 | 4578 |
tree := implementorOfSelectorUpToCursor parseTree. |
4579 |
tree notNil ifTrue:[ |
|
4580 |
argName := tree argumentNames at:argIdx. |
|
4581 |
(argName includesString:'block' caseSensitive:false) ifTrue:[ |
|
4582 |
actionBlock value:{'[ "',argName,'" ]'} |
|
4583 |
value:{ self editActionToInsert:('[ "',argName,'" ]') } |
|
4584 |
value:'block argument' |
|
4585 |
]. |
|
5123 | 4586 |
]. |
4587 |
]. |
|
5080 | 4588 |
] ifFalse:[ |
4589 |
implementors notEmpty ifTrue:[ |
|
5082 | 4590 |
self breakPoint:#cg. |
5080 | 4591 |
]. |
4592 |
]. |
|
4593 |
]. |
|
4594 |
]. |
|
4595 |
]. |
|
4596 |
]. |
|
4597 |
||
5043 | 4598 |
(node isVariable or:[node isBlock and:[node stop notNil]]) ifTrue:[ |
4599 |
(characterPositionOfCursor == (node stop + 1) |
|
4600 |
"/ hack (spaces at end of line) |
|
4601 |
or:[characterPositionOfCursor == (node stop)]) ifTrue:[ |
|
4602 |
codeView characterBeforeCursor == Character space ifTrue:[ |
|
4603 |
self codeCompletionForMessageTo:node into:actionBlock. |
|
4604 |
^ self |
|
4605 |
]. |
|
4606 |
]. |
|
4607 |
]. |
|
5040 | 4608 |
|
5114 | 4609 |
"/ characterBeforeCursor == $) ifTrue:[self halt]. |
5109 | 4610 |
|
4933 | 4611 |
"/ move outward, until we find a message-send node, |
4612 |
"/ or the method's selector pattern node. |
|
4352 | 4613 |
checkedNode := node. |
4614 |
[checkedNode notNil] whileTrue:[ |
|
5322 | 4615 |
(characterPositionOfCursor <= ((checkedNode stop ? source size)+1)) ifTrue:[ |
5041 | 4616 |
"/ Transcript show:'T: '; showCR:node. |
5048 | 4617 |
"/ Transcript showCR:('Inside a ',(checkedNode className)). |
5043 | 4618 |
"/ self information:('Inside a ',(checkedNode className)). |
5040 | 4619 |
(checkedNode isMessage |
4620 |
and:[characterPositionOfCursor < (checkedNode selectorParts first start)]) ifTrue:[ |
|
4621 |
self codeCompletionForMessageTo:checkedNode receiver into:actionBlock. |
|
4622 |
^ self |
|
4623 |
] |
|
4624 |
||
4931 | 4625 |
]. |
4626 |
||
4627 |
checkedNode isMessage ifTrue:[ |
|
4628 |
"/ completion in a message-send |
|
5040 | 4629 |
"/ Transcript showCR:'codeCompletionForMessage'. |
4931 | 4630 |
self codeCompletionForMessage:checkedNode into:actionBlock. |
4631 |
^ self |
|
4632 |
]. |
|
4633 |
checkedNode isMethod ifTrue:[ |
|
4634 |
"/ completion in a method's selector pattern |
|
5040 | 4635 |
"/ Transcript showCR:'codeCompletionForMethodSpec'. |
4931 | 4636 |
self codeCompletionForMethodSpec:checkedNode into:actionBlock. |
4637 |
^ self. |
|
4638 |
]. |
|
5040 | 4639 |
|
4640 |
||
4931 | 4641 |
checkedNode := checkedNode parent. |
4352 | 4642 |
]. |
4643 |
||
5040 | 4644 |
"/ Transcript showCR:'Node is neither variable nor message'. |
4352 | 4645 |
self information:'Node is neither variable nor message.'. |
4646 |
||
4647 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
5041 | 4648 |
"Modified: / 01-05-2016 / 19:00:33 / cg" |
5040 | 4649 |
! |
4650 |
||
5070 | 4651 |
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector |
4652 |
"some heuristics; |
|
4653 |
as best selectors has been chosen by implemented methods for aClass, |
|
4654 |
some of them should be filtered (for example, at:/at:put:, which are |
|
4655 |
found in object, but only make sense for variable objects or those which do |
|
4656 |
implement at:put: themself. |
|
4657 |
I have currently no better idea than hardcoding stuff I found irritating..." |
|
4658 |
||
4659 |
|selectors noNilChecks noIsXXXChecks noNoXXXChecks noBecome |
|
5112 | 4660 |
noIndexedSetters noIndexedGetters noSizeQueries docSelectors| |
5070 | 4661 |
|
4662 |
aClass isNil ifTrue:[ ^ selectorsArg ]. |
|
4663 |
||
4664 |
noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := false. |
|
4665 |
noIndexedSetters := noIndexedGetters := noSizeQueries := false. |
|
4666 |
||
4667 |
selectors := (selectorsArg ? #()) asOrderedCollection. |
|
4668 |
||
4669 |
self tracePoint:#cg message:aClass. |
|
4670 |
||
5112 | 4671 |
aClass isMeta ifTrue:[ |
4672 |
docSelectors := #(copyright documentation examples |
|
4673 |
version version_CVS version_SVN version_HG). |
|
4674 |
selectors := selectors reject:[:sel | docSelectors includes:sel]. |
|
4675 |
]. |
|
4676 |
||
5070 | 4677 |
"/ actually meaning booleans here |
4678 |
(aClass == True or:[aClass == False]) ifTrue:[ |
|
4679 |
noNilChecks := noBecome := true. |
|
4680 |
(partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ]. |
|
4681 |
(partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ]. |
|
4682 |
]. |
|
4683 |
||
4684 |
(aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ]. |
|
4685 |
(aClass includesBehavior: Symbol) ifTrue:[ noNilChecks := noBecome := noIndexedSetters := true ]. |
|
4686 |
(aClass includesBehavior: Number) ifTrue:[ noBecome := true ]. |
|
4687 |
(aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := true ]. |
|
4688 |
||
4689 |
(aClass isMeta) ifTrue:[ |
|
4690 |
noNilChecks := noBecome := true. |
|
4691 |
"/ remove messages which are only defined in Object and non-meta classes. |
|
4692 |
selectors := selectors reject: |
|
4693 |
[:sel | |
|
4694 |
(Object implements:sel) |
|
4695 |
and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]] |
|
4696 |
]. |
|
4697 |
]. |
|
4698 |
||
4699 |
aClass isVariable ifFalse:[ |
|
4700 |
noIndexedGetters := noIndexedSetters := noSizeQueries := true. |
|
4701 |
]. |
|
4702 |
||
4703 |
noIndexedSetters ifTrue:[ |
|
4704 |
#( #'at:put:' #'basicAt:put:') do:[:indexAccessSelector | |
|
4705 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
|
4706 |
selectors := selectors copyWithout:indexAccessSelector. |
|
4707 |
]. |
|
4708 |
]. |
|
4709 |
]. |
|
4710 |
noIndexedGetters ifTrue:[ |
|
4711 |
#( #'at:' #'basicAt:') do:[:indexAccessSelector | |
|
4712 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
|
4713 |
selectors := selectors copyWithout:indexAccessSelector. |
|
4714 |
]. |
|
4715 |
]. |
|
4716 |
]. |
|
4717 |
noSizeQueries ifTrue:[ |
|
4718 |
#( #size #basicSize ) do:[:indexAccessSelector | |
|
4719 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
|
4720 |
selectors := selectors copyWithout:indexAccessSelector. |
|
4721 |
]. |
|
4722 |
]. |
|
4723 |
]. |
|
4724 |
||
4725 |
noNilChecks ifTrue:[ |
|
4726 |
selectors removeAllFoundIn:#( |
|
4727 |
'isNil' 'notNil' |
|
4728 |
'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:' |
|
4729 |
'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:' |
|
4730 |
'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:' |
|
4731 |
). |
|
4732 |
]. |
|
4733 |
noIsXXXChecks ifTrue:[ |
|
4734 |
"/ get rid of all isXXX selectors |
|
4735 |
selectors := selectors reject:[:sel | sel startsWith:'is']. |
|
4736 |
]. |
|
4737 |
noNoXXXChecks ifTrue:[ |
|
4738 |
"/ get rid of all notXXX selectors |
|
4739 |
selectors := selectors reject:[:sel | sel startsWith:'no']. |
|
4740 |
]. |
|
4741 |
noBecome ifTrue:[ |
|
4742 |
"/ get rid of all become* selectors |
|
4743 |
selectors := selectors reject:[:sel | sel startsWith:'become']. |
|
4744 |
selectors remove:#oneWayBecome: ifAbsent:[]. |
|
4745 |
selectors := selectors reject:[:sel | sel startsWith:'changeClassTo']. |
|
4746 |
]. |
|
4747 |
||
4748 |
"/ actually: directly implemented selectors are more likely, so move them to top |
|
4749 |
selectors := (selectors select:[:sel | aClass implements:sel]) |
|
4750 |
, |
|
4751 |
(selectors reject:[:sel | aClass implements:sel]). |
|
4752 |
||
4753 |
^ selectors |
|
4754 |
! ! |
|
4755 |
||
4238 | 4756 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'! |
4757 |
||
4758 |
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView |
|
4759 |
|sym possibleCompletions best start stop oldLen newLen oldVar| |
|
4760 |
||
4761 |
sym := node value. |
|
4762 |
possibleCompletions := OrderedCollection new. |
|
4763 |
||
4764 |
Symbol allInstancesDo:[:existingSym | |
|
4548 | 4765 |
(existingSym startsWith:sym) ifTrue:[ |
4766 |
(existingSym = sym) ifFalse:[ |
|
4767 |
possibleCompletions add:existingSym |
|
4768 |
]. |
|
4769 |
]. |
|
4238 | 4770 |
]. |
4771 |
possibleCompletions sort. |
|
4772 |
||
4773 |
best := possibleCompletions longestCommonPrefix. |
|
4774 |
(best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[ |
|
4548 | 4775 |
best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions. |
4776 |
best isNil ifTrue:[^ self]. |
|
4238 | 4777 |
]. |
4778 |
||
4779 |
"/ self showInfo:best. |
|
4780 |
||
4781 |
start := node start. |
|
4782 |
stop := node stop. |
|
4783 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
4548 | 4784 |
start := start + 1. |
4238 | 4785 |
]. |
4786 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
4548 | 4787 |
start := start + 1. |
4788 |
stop := stop - 1. |
|
4238 | 4789 |
]. |
4790 |
||
4791 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
4792 |
||
4793 |
codeView |
|
4548 | 4794 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
4795 |
info:'Completion'. |
|
4238 | 4796 |
|
4797 |
(best startsWith:oldVar) ifTrue:[ |
|
4548 | 4798 |
oldLen := stop - start + 1. |
4799 |
newLen := best size. |
|
4800 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
4801 |
codeView dontReplaceSelectionOnInput |
|
4238 | 4802 |
]. |
4803 |
||
4804 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4805 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
4806 |
! |
|
4807 |
||
4345 | 4808 |
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView |
5044 | 4809 |
"going to be OBSOLETE" |
4810 |
||
4548 | 4811 |
|selector |
4547 | 4812 |
bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best numArgs |
4548 | 4813 |
newParts nSelParts oldLen newLen selectorParts |
4345 | 4814 |
findBest parentNode selectorInBest selector2InBest2 |
5044 | 4815 |
parser selectorsSentInCode selectorsImplementedInClass |
4346 | 4816 |
varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass| |
4345 | 4817 |
|
4818 |
RefactoryTyper notNil ifTrue:[ |
|
4710 | 4819 |
"/ refactory package also provides a (very limited) typer; |
4820 |
"/ ask it for its oppinion as well (temporary - will vanish, once we have a better typer) |
|
4821 |
(node receiver isVariable) ifTrue:[ |
|
4822 |
varName := node receiver name. |
|
4823 |
varName isUppercaseFirst ifTrue:[ |
|
4824 |
] ifFalse:[ |
|
4825 |
tree := RBParser |
|
4826 |
parseMethod:codeView contents string |
|
4827 |
onError:[:aString :pos | nil]. |
|
4828 |
tree notNil ifTrue:[ |
|
4829 |
rbTypes := RefactoryTyper |
|
4830 |
classesFor: varName |
|
4831 |
in: tree |
|
4832 |
model: nil |
|
4833 |
ignoredSelectors:(Array with:node selector). |
|
4834 |
rbTypes size > 0 ifTrue:[ |
|
4835 |
rbTypes size > 1 ifTrue:[ |
|
4836 |
rbTypes remove:ProtoObject ifAbsent:[]. |
|
4837 |
rbTypes remove:Autoload ifAbsent:[]. |
|
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
4838 |
(Smalltalk includesKey:#ObsoleteObject) ifTrue:[ |
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
4839 |
rbTypes remove:(Smalltalk at:#ObsoleteObject) ifAbsent:[]. |
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
4840 |
] |
4710 | 4841 |
]. |
4842 |
rbTypes size == 1 ifTrue:[ |
|
4843 |
rbType := rbTypes first. |
|
4844 |
] ifFalse:[ |
|
4845 |
rbType := Class commonSuperclassOf:rbTypes |
|
4846 |
]. |
|
4847 |
(rbType notNil "and:[rbType ~= Object]") ifTrue:[ |
|
4848 |
bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true. |
|
4849 |
]. |
|
4850 |
] |
|
4851 |
] |
|
4852 |
] |
|
4853 |
]. |
|
4345 | 4854 |
]. |
4855 |
||
4856 |
classOrNil notNil ifTrue:[ |
|
4710 | 4857 |
parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true. |
4858 |
selectorsSentInCode := parser messagesSent. |
|
4548 | 4859 |
]. |
4345 | 4860 |
classOrNil notNil ifTrue:[ |
4936 | 4861 |
selectorsImplementedInClass := Set new. |
4862 |
classOrNil withAllSuperclassesDo:[:cls | |
|
4863 |
cls theNonMetaclass ~~ Object ifTrue:[ |
|
4864 |
selectorsImplementedInClass addAll:cls selectors. |
|
4865 |
] |
|
4866 |
] |
|
4345 | 4867 |
]. |
4868 |
||
4869 |
findBest := [:node :selector | |
|
5035 | 4870 |
|srchClasses bestSelectors bestPrefixes| |
4710 | 4871 |
|
4933 | 4872 |
codeView withCursor:(Cursor questionMark) do:[ |
5035 | 4873 |
srchClasses := self classesOfNode:node receiver. |
4874 |
srchClasses notNil ifTrue:[ |
|
4875 |
bestSelectors := Set new. |
|
4876 |
srchClasses do:[:each | |
|
4877 |
bestSelectors addAll:(Parser findBest:30 selectorsFor:selector in:each forCompletion:true). |
|
4878 |
] |
|
4710 | 4879 |
] ifFalse:[ |
4880 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true. |
|
4881 |
]. |
|
4882 |
]. |
|
4883 |
||
4884 |
(bestSelectors includes:selector) ifTrue:[ |
|
4885 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
|
4886 |
]. |
|
4887 |
bestSelectors |
|
4345 | 4888 |
]. |
4889 |
||
4890 |
selector := node selector. |
|
4891 |
bestSelectors := findBest value:node value:selector. |
|
4892 |
||
4893 |
parentNode := node parent. |
|
4894 |
||
4895 |
parentIsKeywordMessage := |
|
4710 | 4896 |
(parentNode notNil |
4897 |
and:[ parentNode isMessage |
|
5038 | 4898 |
and:[ parentNode selector isKeyword]]). |
4346 | 4899 |
parentIsBinaryMessage := |
4710 | 4900 |
(parentNode notNil |
4901 |
and:[ parentNode isMessage |
|
4902 |
and:[ parentNode selector isBinarySelector]]). |
|
4345 | 4903 |
|
4904 |
tryParent := false. |
|
4905 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
|
4548 | 4906 |
(node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[ |
4710 | 4907 |
tryParent := true. |
4345 | 4908 |
] ifFalse:[ |
4710 | 4909 |
"/ if the parent is an instance creation message, take that as lookup class. |
4910 |
(node isMessage |
|
4911 |
and:[ node receiver isMessage |
|
4912 |
and:[ node receiver receiver isVariable |
|
4913 |
and:[ node receiver receiver name isUppercaseFirst |
|
4914 |
and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[ |
|
4915 |
rcvrClass := Smalltalk classNamed:(node receiver receiver name). |
|
4916 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
4917 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true. |
|
4918 |
] ifFalse:[ |
|
4919 |
"/ also, if nothing was found |
|
4920 |
(bestSelectors isEmpty |
|
4921 |
and:[ parentNode notNil |
|
4922 |
and:[ parentNode isMessage ]]) ifTrue:[ |
|
4923 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
4924 |
"/ selector2 := parentNode selector. |
|
4925 |
"/ selector2 := selector2,selector. |
|
4926 |
bestSelectors := findBest value:parentNode value:selector. |
|
4927 |
] |
|
4928 |
] |
|
4345 | 4929 |
]. |
4930 |
tryParent ifTrue:[ |
|
4710 | 4931 |
selector2 := parentNode selector,selector. |
4932 |
bestSelectors2 := findBest value:parentNode value:selector2. |
|
4345 | 4933 |
]. |
4346 | 4934 |
bestSelectorsFromRB notEmptyOrNil ifTrue:[ |
4710 | 4935 |
bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]). |
4346 | 4936 |
]. |
4345 | 4937 |
|
4938 |
"/ if the parent is a keyword selector, the child cannot |
|
4346 | 4939 |
(parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[ |
5038 | 4940 |
bestSelectors := bestSelectors reject:[:sel | sel isKeyword] |
4345 | 4941 |
]. |
4942 |
||
4943 |
bestSelectors2 isEmptyOrNil ifTrue:[ |
|
4710 | 4944 |
allBest := bestSelectors. |
4345 | 4945 |
] ifFalse:[ |
4710 | 4946 |
bestSelectors isEmptyOrNil ifTrue:[ |
4947 |
allBest := bestSelectors2 |
|
4948 |
] ifFalse:[ |
|
4949 |
selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]). |
|
4950 |
selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]). |
|
4951 |
||
4952 |
(selectorInBest not and:[ selector2InBest2 ]) ifTrue:[ |
|
4953 |
"/ selector2 is more likely |
|
4954 |
allBest := bestSelectors2 |
|
4955 |
] ifFalse:[ |
|
4956 |
(selectorInBest and:[ selector2InBest2 not ]) ifTrue:[ |
|
4957 |
"/ selector more likely |
|
4958 |
allBest := bestSelectors |
|
4959 |
] ifFalse:[ |
|
4960 |
"/ assume same likelyness |
|
4961 |
||
4962 |
allBest := bestSelectors isEmpty |
|
4963 |
ifTrue:[ bestSelectors2 ] |
|
4964 |
ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ]. |
|
4965 |
] |
|
4966 |
]. |
|
4967 |
]. |
|
4345 | 4968 |
]. |
4969 |
||
4970 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
|
4971 |
||
4972 |
selectorsImplementedInClass notNil ifTrue:[ |
|
4710 | 4973 |
"/ the ones implemented in the receiver class are moved to the top of the list. |
5044 | 4974 |
allBest := self |
4975 |
splitSelectorList:allBest |
|
4976 |
by:[:sel | selectorsImplementedInClass includes:sel]. |
|
4345 | 4977 |
]. |
4978 |
selectorsSentInCode notNil ifTrue:[ |
|
4710 | 4979 |
"/ the ones already sent in the code are moved to the top of the list. |
5044 | 4980 |
allBest := self |
4981 |
splitSelectorList:allBest |
|
4982 |
by:[:sel | selectorsSentInCode includes:sel]. |
|
4345 | 4983 |
]. |
4984 |
||
4985 |
"/ the ones which are a prefix are moved towards the top of the list |
|
5044 | 4986 |
allBest := self |
4987 |
splitSelectorList:allBest |
|
4988 |
by:[:sel | sel notNil and:[sel startsWith:selector]]. |
|
4345 | 4989 |
|
4990 |
best := allBest first. |
|
4991 |
allBest size > 1 ifTrue:[ |
|
4710 | 4992 |
"allBest size < 20 ifTrue:[ |
4993 |
|idx| |
|
4994 |
||
4995 |
idx := (PopUpMenu labels:allBest) startUp. |
|
4996 |
idx == 0 ifTrue:[ ^ self]. |
|
4997 |
best := allBest at:idx. |
|
4998 |
] ifFalse:[ |
|
4999 |
allBest remove:nil ifAbsent:[]. |
|
5000 |
best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest. |
|
5001 |
||
5002 |
]." |
|
5003 |
allBest remove:nil ifAbsent:[]. |
|
5004 |
best := self askUserForCompletion:('Selector for "%1"' bindWith:selector) for:codeView at: node selectorParts first start from:allBest. |
|
5005 |
best isEmptyOrNil ifTrue:[^ self]. |
|
5006 |
best = '-' ifTrue:[^ self]. |
|
4345 | 5007 |
]. |
5008 |
||
4547 | 5009 |
"/ srchClass notNil ifTrue:[ |
5010 |
"/ implClass := srchClass whichClassIncludesSelector:best. |
|
5011 |
"/ ] ifFalse:[ |
|
5012 |
"/ implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
5013 |
"/ implClass size == 1 ifTrue:[ |
|
5014 |
"/ implClass := implClass first. |
|
5015 |
"/ ] ifFalse:[ |
|
5016 |
"/ implClass := nil |
|
5017 |
"/ ] |
|
5018 |
"/ ]. |
|
5019 |
"/ |
|
5020 |
"/ info := best storeString. |
|
5021 |
"/ implClass notNil ifTrue:[ |
|
5397 | 5022 |
"/ info := implClass name , ' ' , info. |
4547 | 5023 |
"/ ]. |
5024 |
"/ self information:info. |
|
4345 | 5025 |
|
5026 |
best ~= selector ifTrue:[ |
|
4710 | 5027 |
numArgs := best numArgs. |
5028 |
||
5029 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[ |
|
5030 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
5031 |
] ifFalse:[ |
|
5032 |
selectorParts := node selectorParts. |
|
5033 |
]. |
|
5034 |
nSelParts := selectorParts size. |
|
5035 |
||
5036 |
newParts := best asCollectionOfSubstringsSeparatedBy:$:. |
|
5037 |
newParts := newParts select:[:part | part size > 0]. |
|
5038 |
||
5039 |
codeView |
|
5040 |
undoableDo:[ |
|
5041 |
|newCursorPosition stop| |
|
5042 |
||
5043 |
numArgs > nSelParts ifTrue:[ |
|
5044 |
stop := selectorParts last stop. |
|
5045 |
||
5046 |
"/ append the rest ... |
|
5047 |
numArgs downTo:nSelParts+1 do:[:idx | |
|
5048 |
|newPart| |
|
5049 |
||
5050 |
newPart := newParts at:idx. |
|
5051 |
(best endsWith:$:) ifTrue:[ |
|
5052 |
newPart := newPart , ':' |
|
5053 |
]. |
|
5054 |
||
5055 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
|
5056 |
newPart := ':' , newPart. |
|
5057 |
]. |
|
5058 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
5059 |
||
5060 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
|
5061 |
newCursorPosition := stop + newPart size. |
|
5062 |
] |
|
5063 |
]. |
|
5064 |
||
5065 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
5066 |
|newPart oldPartialToken start stop nextChar| |
|
5067 |
||
5068 |
newPart := newParts at:idx. |
|
5069 |
oldPartialToken := selectorParts at:idx. |
|
5070 |
start := oldPartialToken start. |
|
5071 |
stop := oldPartialToken stop. |
|
5072 |
||
5038 | 5073 |
(best isKeyword) ifTrue:[ |
4710 | 5074 |
(oldPartialToken value endsWith:$:) ifTrue:[ |
5075 |
newPart := newPart , ':' |
|
5076 |
] ifFalse:[ |
|
5077 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
5078 |
newPart := newPart , ':' |
|
5079 |
] |
|
5080 |
] |
|
5081 |
] ifFalse:[ |
|
5082 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
5083 |
newPart := newPart , ':' |
|
5084 |
] ifFalse:[ |
|
5085 |
nextChar := codeView characterAtCharacterPosition:stop+1. |
|
5086 |
nextChar isSeparator ifFalse:[ |
|
5087 |
(').' includes:nextChar) ifFalse:[ |
|
5088 |
newPart := newPart , ' ' |
|
5089 |
]. |
|
5090 |
] |
|
5091 |
] |
|
4345 | 5092 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
5093 |
"/ ] ifFalse:[ |
|
5094 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
4710 | 5095 |
]. |
5096 |
||
5097 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
5098 |
||
5099 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
5100 |
newCursorPosition isNil ifTrue:[ |
|
5101 |
oldLen := stop - start + 1. |
|
5102 |
newLen := newPart size. |
|
5103 |
||
5104 |
newCursorPosition := stop + (newLen-oldLen) |
|
5105 |
]. |
|
5106 |
]. |
|
5107 |
||
5108 |
codeView cursorToCharacterPosition:newCursorPosition. |
|
5109 |
codeView cursorRight. "/ avoid going to the next line !! |
|
5110 |
||
5111 |
((best endsWith:':') and:[numArgs == 1]) ifTrue:[ |
|
5112 |
|impls impl| |
|
5113 |
||
5114 |
"/ see if it expects a block argument (heuristic) |
|
5115 |
best := best asSymbol. |
|
5116 |
(node notNil |
|
5117 |
and:[classOrNil notNil |
|
5118 |
and:[node receiver isSelf]]) ifTrue:[ |
|
5119 |
(impl := classOrNil whichClassImplements:best) isNil ifTrue:[ |
|
5120 |
impls := #(). |
|
5121 |
Screen current beep. |
|
5122 |
] ifFalse:[ |
|
5123 |
impls := { impl } |
|
5124 |
] |
|
5125 |
] ifFalse:[ |
|
5126 |
impls := Smalltalk allImplementorsOf:best. |
|
5127 |
]. |
|
5128 |
(impls contains:[:cls | |
|
5129 |
|argName| |
|
5130 |
||
5131 |
argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase. |
|
5132 |
(argName includesString:'block') or:[ (argName includesString:'action')]] |
|
5133 |
) ifTrue:[ |
|
5134 |
codeView insertStringAtCursor:'[' |
|
5135 |
]. |
|
5136 |
]. |
|
5137 |
codeView dontReplaceSelectionOnInput. |
|
5138 |
] |
|
5139 |
info:'Completion'. |
|
4345 | 5140 |
]. |
5141 |
||
5142 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
5038 | 5143 |
"Modified: / 30-04-2016 / 18:21:21 / cg" |
4845
6a5c44a7d42e
Removed dependency on stx:libboss, stx:libjava and stx:libjavascript
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4830
diff
changeset
|
5144 |
"Modified: / 25-09-2015 / 07:39:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4345 | 5145 |
! |
5146 |
||
4238 | 5147 |
codeCompletionForVariable:node inClass:classOrNil codeView:codeView |
4277 | 5148 |
|parent nonMetaClass crsrPos nm |
4238 | 5149 |
allVariables allDistances best nodeVal |
5150 |
char start stop oldLen newLen oldVar |
|
4485 | 5151 |
getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc |
4238 | 5152 |
globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart| |
5153 |
||
5154 |
classOrNil notNil ifTrue:[ |
|
5253 | 5155 |
nonMetaClass := classOrNil theNonMetaclass. |
4238 | 5156 |
]. |
5157 |
||
5158 |
nm := node name. |
|
5159 |
||
5160 |
"/ if we are behind the variable and a space has already been entered, |
|
5161 |
"/ the user is probably looking for a message selector. |
|
5162 |
"/ If the variable represents a global, present its instance creation messages |
|
5163 |
crsrPos := codeView characterPositionOfCursor. |
|
5164 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
|
5165 |
char isSeparator ifTrue:[ |
|
5253 | 5166 |
classOrNil isNil ifTrue:[ |
5167 |
nodeVal := Smalltalk at:nm asSymbol. |
|
5168 |
] ifFalse:[ |
|
5169 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
5170 |
]. |
|
5171 |
nodeVal isBehavior ifTrue:[ |
|
5172 |
|methods menu exitKey idx| |
|
5173 |
||
5174 |
methods := nodeVal class methodDictionary values |
|
5175 |
select:[:m | |cat| |
|
5176 |
cat := m category asLowercase. |
|
5177 |
cat = 'instance creation' |
|
5178 |
]. |
|
5179 |
||
5180 |
menu := PopUpMenu labels:(methods collect:[:each | each selector]). |
|
5181 |
menu hideOnKeyFilter:[:key | |hide| |
|
5182 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
5183 |
hide ifTrue:[ |
|
5184 |
exitKey := key. |
|
5185 |
]. |
|
5186 |
hide]. |
|
5187 |
||
5188 |
idx := menu startUp. |
|
5189 |
idx == 0 ifTrue:[ |
|
5190 |
exitKey notNil ifTrue:[ |
|
5191 |
codeView keyPress:exitKey x:0 y:0. |
|
5192 |
]. |
|
5193 |
^ self |
|
5194 |
]. |
|
5195 |
best := (methods at:idx) selector. |
|
5196 |
codeView |
|
5197 |
undoableDo:[ |
|
5198 |
codeView insertString:best atCharacterPosition:crsrPos. |
|
5199 |
codeView cursorToCharacterPosition:crsrPos+best size. |
|
5200 |
] |
|
5201 |
info:'completion'. |
|
5202 |
^ self. |
|
5203 |
]. |
|
4238 | 5204 |
]. |
5205 |
||
4277 | 5206 |
((parent := node parent) notNil and:[parent isMessage]) ifTrue:[ |
5253 | 5207 |
node == parent receiver ifTrue:[ |
5208 |
selectorOfMessageToNode := parent selector |
|
5209 |
] |
|
4238 | 5210 |
]. |
5211 |
||
5212 |
getDistanceComputeBlockWithWeight := |
|
5253 | 5213 |
[:weight | |
5214 |
[:each | |
|
5215 |
|dist factor| |
|
5216 |
||
5217 |
dist := each spellAgainst:nm. |
|
5218 |
factor := 1. |
|
5219 |
||
5220 |
(each startsWith:nm) ifTrue:[ |
|
5221 |
factor := 6 * nm size. |
|
5222 |
] ifFalse:[ |
|
5223 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
5224 |
factor := 4 * nm size. |
|
5360 | 5225 |
] ifFalse:[ |
5226 |
(each endsWith:nm) ifTrue:[ |
|
5227 |
factor := 3 * nm size. |
|
5228 |
] ifFalse:[ |
|
5229 |
(each asLowercase endsWith:nm asLowercase) ifTrue:[ |
|
5230 |
factor := 2 * nm size. |
|
5231 |
] |
|
5232 |
] |
|
5233 |
] |
|
5253 | 5234 |
]. |
5235 |
dist := dist + (weight*factor). |
|
5236 |
||
5237 |
each -> (dist * weight) |
|
5238 |
] |
|
5239 |
]. |
|
4238 | 5240 |
|
5241 |
addWithFactorBlock := |
|
5253 | 5242 |
[:eachNames :factor | |namesToAdd| |
5243 |
namesToAdd := eachNames select:[:nameToAdd | nameToAdd ~= nm ]. |
|
5244 |
namesToAdd := namesToAdd reject:[:each | allVariables includes:each ]. |
|
5245 |
allVariables addAll:namesToAdd. |
|
5246 |
allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)). |
|
5247 |
]. |
|
4238 | 5248 |
|
5249 |
nm isUppercaseFirst ifTrue:[ |
|
5253 | 5250 |
globalFactor := 2. "/ favour globals |
5251 |
localFactor := 1. |
|
4238 | 5252 |
] ifFalse:[ |
5253 | 5253 |
globalFactor := 1. "/ favour locals |
5254 |
localFactor := 2. |
|
4238 | 5255 |
]. |
5256 |
||
5257 |
allVariables := OrderedCollection new. |
|
5258 |
allDistances := OrderedCollection new. |
|
5259 |
||
4308 | 5260 |
"/ are we in the method's selector spec ? |
4548 | 5261 |
((parent := node parent) notNil |
4277 | 5262 |
and:[parent isMethod |
5263 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
5253 | 5264 |
"/ now that's cool: look how the naem of this argument is in other implementations |
5265 |
"/ of this method, and take that as a basis of the selection |
|
5266 |
||
5267 |
implementors := SystemBrowser |
|
5268 |
findImplementorsOf:(parent selector) |
|
5269 |
in:(Smalltalk allClasses) |
|
5270 |
ignoreCase:false. |
|
5271 |
"/ which argument is it |
|
5272 |
argIdx := parent arguments indexOf:node. |
|
5273 |
implementors size > 50 ifTrue:[ |
|
5274 |
implementors := implementors asOrderedCollection copyTo:50. |
|
5275 |
]. |
|
5276 |
namesUsed := implementors |
|
5277 |
collect:[:eachImplementor | |
|
5278 |
|parseTree| |
|
5279 |
parseTree := eachImplementor parseTree. |
|
5280 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
5281 |
ifFalse:nil |
|
5282 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
5283 |
thenSelect:[:a | a notNil] as:Set. |
|
5284 |
||
5285 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
5286 |
||
5287 |
classOrNil notNil ifTrue:[ |
|
5288 |
"/ also, look for the keyword before the argument, |
|
5289 |
"/ and see if there is such an instVar |
|
5290 |
"/ if so, add it with -Arg |
|
5291 |
parent selector isKeyword ifTrue:[ |
|
5292 |
kwPart := parent selector keywords at:argIdx. |
|
5293 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
|
5294 |
addWithFactorBlock |
|
5295 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
5296 |
value:(1 * localFactor). |
|
5297 |
]. |
|
5298 |
]. |
|
5299 |
] |
|
4238 | 5300 |
] ifFalse:[ |
5253 | 5301 |
classOrNil notNil ifTrue:[ |
5302 |
"/ locals in the block/method |
|
5303 |
|names| |
|
5304 |
||
5305 |
names := node allVariablesOnScope. |
|
5306 |
"/ if there were no variables (due to a parse error) |
|
5307 |
"/ do another parse and see what we have |
|
5308 |
names isEmpty ifTrue:[ |
|
5309 |
tree := self treeForCode:(codeView contentsAsString string) allowErrors:true. |
|
5310 |
"/ better if we already have a body (include locals then) |
|
5311 |
"/ otherwise, only the arguments are considered |
|
5312 |
tree notNil ifTrue:[ |
|
5313 |
names := (tree body ? tree) allVariablesOnScope. |
|
5314 |
] |
|
5315 |
]. |
|
5316 |
||
5317 |
addWithFactorBlock value:names value:(4 * localFactor). |
|
5318 |
||
5319 |
"/ instance variables |
|
5320 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
5321 |
||
5322 |
"/ inherited instance variables |
|
5323 |
classOrNil superclass notNil ifTrue:[ |
|
5324 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
5325 |
]. |
|
5326 |
]. |
|
5327 |
||
5328 |
selectorOfMessageToNode notNil ifTrue:[ |
|
5329 |
|names responders nonResponders| |
|
5330 |
||
5331 |
"/ responding to that messsage |
|
5332 |
||
5333 |
classOrNil notNil ifTrue:[ |
|
5334 |
"/ private classes |
|
5335 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
5336 |
value:(1.75 * globalFactor). |
|
5337 |
||
5338 |
"/ class variables |
|
5339 |
names := nonMetaClass classVarNames. |
|
5340 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
5341 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
5342 |
||
5343 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
5344 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
5345 |
||
5346 |
"/ superclass var names |
|
5347 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
5348 |
names := superClass classVarNames. |
|
5349 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
5350 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
5351 |
||
5352 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
|
5353 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
5354 |
]. |
|
5355 |
||
5356 |
"/ namespace vars |
|
5357 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
5358 |
names := classOrNil topNameSpace keys. |
|
5359 |
names := names reject:[:nm | nm includes:$:]. |
|
5360 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
5361 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5362 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5363 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
5364 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
5365 |
]. |
|
5366 |
]. |
|
5367 |
||
5368 |
"/ globals |
|
5369 |
names := Smalltalk keys. |
|
5370 |
"/ names := names reject:[:nm | nm includes:$:]. |
|
5371 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
5372 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5373 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5374 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
5375 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
5376 |
||
5377 |
"/ pool variables |
|
5378 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
5379 |
|pool| |
|
5380 |
||
5381 |
pool := Smalltalk at:poolName. |
|
5382 |
names := pool classVarNames. |
|
5383 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
5384 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5385 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
5386 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
5387 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
5388 |
]. |
|
5389 |
] ifFalse:[ |
|
5390 |
|names| |
|
5391 |
||
5392 |
classOrNil notNil ifTrue:[ |
|
5393 |
"/ private classes |
|
5394 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
5395 |
value:(1.75 * globalFactor). |
|
5396 |
||
5397 |
"/ class variables |
|
5398 |
addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor). |
|
5399 |
classOrNil superclass notNil ifTrue:[ |
|
5400 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor). |
|
5401 |
]. |
|
5402 |
||
5403 |
"/ namespace vars |
|
5404 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
5405 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
5406 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
5407 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
5408 |
]. |
|
5409 |
||
5410 |
"/ pool variables |
|
5411 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
5412 |
|pool| |
|
5413 |
||
5414 |
pool := Smalltalk at:poolName. |
|
5415 |
names := pool classVarNames. |
|
5416 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
5417 |
]. |
|
5418 |
]. |
|
5419 |
||
5420 |
"/ globals |
|
5421 |
names := Smalltalk keys. |
|
5422 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
5423 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
5424 |
]. |
|
5425 |
||
5426 |
"/ pseudos - assuming that thisContext is seldom used. |
|
5427 |
"/ also assuming, that nil is short so its usually typed in. |
|
5428 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
5429 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
5430 |
addWithFactorBlock value:#('super' 'false') value:(2 * localFactor). |
|
5431 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
|
5432 |
addWithFactorBlock value:#('true') value:(1 * localFactor). |
|
5433 |
addWithFactorBlock value:#('false') value:(1 * localFactor). |
|
4238 | 5434 |
]. |
5435 |
||
5436 |
allDistances isEmpty ifTrue:[^ self]. |
|
5437 |
bestAssoc := allDistances at:1. |
|
5438 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
5253 | 5439 |
ifTrue:[el] |
5440 |
ifFalse:[best] |
|
5441 |
]. |
|
4548 | 5442 |
|
5443 |
allDistances sort:[:a :b | |
|
5253 | 5444 |
a value > b value ifTrue:[ |
5445 |
true |
|
5446 |
] ifFalse:[ |
|
5447 |
a value = b value ifTrue:[ |
|
5448 |
a key < b key |
|
5449 |
] ifFalse:[ |
|
5450 |
false |
|
5451 |
] |
|
5452 |
] |
|
5453 |
]. |
|
4340 | 5454 |
((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[ |
5253 | 5455 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)]. |
5456 |
allTheBest size > 15 ifTrue:[ |
|
5457 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)]. |
|
5458 |
]. |
|
4238 | 5459 |
]. |
5460 |
||
4524 | 5461 |
start := node start. |
5462 |
stop := node stop. |
|
5463 |
||
4548 | 5464 |
best := self askUserForCompletion:('Variable for "%1"' bindWith:node name) |
5253 | 5465 |
for:codeView at: start |
5466 |
from:(allTheBest collect:[:assoc | assoc key]). |
|
4238 | 5467 |
best isNil ifTrue:[^ self]. |
5468 |
||
5469 |
"/ self showInfo:best. |
|
5470 |
||
5471 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
5472 |
||
5473 |
codeView |
|
5253 | 5474 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
5475 |
info:'Completion'. |
|
4238 | 5476 |
|
5477 |
(best startsWith:oldVar) ifTrue:[ |
|
5253 | 5478 |
oldLen := stop - start + 1. |
5479 |
newLen := best size. |
|
5480 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
5481 |
codeView dontReplaceSelectionOnInput |
|
4238 | 5482 |
]. |
5483 |
||
5484 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
5485 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 5486 |
"Modified: / 28-08-2013 / 15:37:28 / cg" |
4238 | 5487 |
! ! |
5488 |
||
5109 | 5489 |
!DoWhatIMeanSupport methodsFor:'helpers-naive type inference'! |
5490 |
||
5491 |
addClassesFromAssignmentTo:varName in:aTree to:setOfTypes |
|
5492 |
"/ assignments... |
|
5493 |
||
5494 |
aTree allAssignmentNodesDo:[:eachAssignmentNode | |
|
5495 |
|leftSide| |
|
5496 |
||
5497 |
leftSide := eachAssignmentNode variable. |
|
5498 |
leftSide name = varName ifTrue:[ |
|
5499 |
self |
|
5500 |
addClassesOfExpression:eachAssignmentNode value |
|
5501 |
inClass:classOrNil to:setOfTypes. |
|
5502 |
] |
|
5503 |
]. |
|
5504 |
^ setOfTypes. |
|
5505 |
! |
|
5506 |
||
5507 |
addClassesFromMessagesSentTo:varNode in:aTree to:setOfTypes |
|
5508 |
"/ from the set of messages sent at other places, |
|
5509 |
"/ try to find classes, which respond to all those. |
|
5510 |
||
5511 |
|varName allSelectors candidates| |
|
5512 |
||
5513 |
varName := varNode name. |
|
5514 |
||
5515 |
allSelectors := IdentitySet new. |
|
5516 |
aTree allMessageNodesDo:[:eachMessageNode | |
|
5517 |
|rcvr| |
|
5518 |
||
5519 |
rcvr := eachMessageNode receiver. |
|
5520 |
(rcvr isVariable and:[rcvr name = varName]) ifTrue:[ |
|
5521 |
allSelectors add:eachMessageNode selector |
|
5522 |
] |
|
5523 |
]. |
|
5524 |
||
5324 | 5525 |
"/ the selector being completed must be ignored here |
5109 | 5526 |
(varNode parent notNil and:[varNode parent isMessage]) ifTrue:[ |
5527 |
allSelectors remove:(varNode parent selector) ifAbsent:[]. |
|
5528 |
]. |
|
5529 |
||
5530 |
"/ now look for classes which implement all of them |
|
5531 |
candidates := SystemBrowser findRespondersOfAll:allSelectors in:nil ignoreCase:false. |
|
5532 |
candidates remove:Object ifAbsent:[]. |
|
5533 |
setOfTypes addAll:candidates. |
|
5534 |
^ setOfTypes. |
|
5535 |
! |
|
5536 |
||
5537 |
addClassesOfBlockVarForWellknownBlocks:variableNode inScope:blockScope to:setOfTypes |
|
5538 |
|blockParent blockParentSelector exNode isHandler| |
|
5539 |
||
5540 |
blockParent := blockScope parent. |
|
5541 |
(blockParent notNil and:[blockParent isMessage]) ifFalse:[^ setOfTypes]. |
|
5542 |
||
5543 |
blockParentSelector := blockParent selector. |
|
5544 |
||
5545 |
"/ if the parent of the block is an enumeration message, and the receiver is known, |
|
5546 |
"/ we know the type of argument. |
|
5547 |
( #(do: keysAndValuesDo: select: collect:) includes:blockParent selector) ifTrue:[ |
|
5548 |
|collection| |
|
5549 |
||
5550 |
collection := self valueOfNode:blockParent receiver. |
|
5551 |
collection notNil ifTrue:[ |
|
5552 |
(collection isKindOf:Collection) ifTrue:[ |
|
5553 |
collection notEmpty ifTrue:[ |
|
5554 |
|someElement| |
|
5555 |
someElement := collection anElement. |
|
5556 |
setOfTypes add:someElement class. |
|
5557 |
^ setOfTypes |
|
5558 |
]. |
|
5559 |
]. |
|
5560 |
]. |
|
5561 |
]. |
|
5562 |
||
5563 |
"/ because we type-in those so often, it is great to get |
|
5564 |
"/ better info on the ex parameter... (and it's a low hanging fruit) |
|
5565 |
( blockParentSelector == #handle:do: ) ifTrue:[ |
|
5566 |
exNode := blockParent receiver. |
|
5567 |
isHandler := (blockScope == (blockParent arguments at:1)). |
|
5568 |
]. |
|
5569 |
( blockParentSelector == #on:do: ) ifTrue:[ |
|
5133 | 5570 |
"/ self halt. |
5109 | 5571 |
exNode := blockParent arg1. |
5572 |
isHandler := (blockScope == (blockParent arguments at:2)). |
|
5573 |
]. |
|
5574 |
exNode notNil ifTrue:[ |
|
5575 |
|cls exClass| |
|
5576 |
||
5577 |
((cls := (self valueOfNode:exNode)) notNil and:[cls isBehavior]) ifTrue:[ |
|
5578 |
exClass := cls |
|
5579 |
] ifFalse:[ |
|
5580 |
exClass := Exception |
|
5581 |
]. |
|
5582 |
setOfTypes add:exClass. |
|
5583 |
^ self |
|
5584 |
]. |
|
5585 |
^ setOfTypes |
|
5586 |
! |
|
5587 |
||
5588 |
addClassesOfExpression:expr inClass:classOrNil to:setOfTypes |
|
5589 |
|cls exprVal varName varScope instVarClass classVarClass poolVarClass sym| |
|
5131 | 5590 |
|
5109 | 5591 |
expr isLiteral ifTrue:[ |
5592 |
exprVal := expr value. |
|
5593 |
cls := exprVal class. |
|
5594 |
(exprVal isArray or:[ exprVal isByteArray or:[ exprVal isString ]]) ifTrue:[ |
|
5595 |
exprVal isImmutable ifTrue:[ |
|
5596 |
setOfTypes add:cls mutableClass. |
|
5597 |
^ setOfTypes. |
|
5598 |
] |
|
5599 |
]. |
|
5600 |
setOfTypes add:cls. |
|
5601 |
^ setOfTypes. |
|
5602 |
]. |
|
5603 |
||
5604 |
expr isBlock ifTrue:[ |
|
5605 |
setOfTypes add:Block. |
|
5606 |
^ setOfTypes. |
|
5607 |
]. |
|
5608 |
||
5131 | 5609 |
thisContext isRecursive ifTrue:[^ setOfTypes]. |
5610 |
||
5109 | 5611 |
expr isVariable ifTrue:[ |
5612 |
varName := expr name. |
|
5613 |
varName = 'self' ifTrue:[ |
|
5272 | 5614 |
instanceOrNil notNil ifTrue:[ |
5615 |
setOfTypes add:(instanceOrNil class). |
|
5616 |
] ifFalse:[ |
|
5617 |
setOfTypes add:(classOrNil ? UndefinedObject). |
|
5618 |
]. |
|
5109 | 5619 |
^ setOfTypes |
5620 |
]. |
|
5621 |
varName = 'super' ifTrue:[ |
|
5622 |
classOrNil isNil |
|
5623 |
ifTrue:[setOfTypes add:Object] |
|
5624 |
ifFalse:[setOfTypes add:classOrNil superclass]. |
|
5625 |
^ setOfTypes. |
|
5626 |
]. |
|
5627 |
varName = 'thisContext' ifTrue:[ |
|
5628 |
setOfTypes add:Context. |
|
5629 |
^ setOfTypes |
|
5630 |
]. |
|
5631 |
||
5632 |
varScope := expr whoDefines: varName. |
|
5633 |
(varScope notNil) ifTrue:[ |
|
5634 |
varScope isSequence ifTrue:[ |
|
5635 |
varScope := varScope parent. |
|
5636 |
]. |
|
5637 |
||
5638 |
(varScope isBlock) ifTrue:[ |
|
5639 |
self addClassesOfBlockVarForWellknownBlocks:expr inScope:varScope to:setOfTypes. |
|
5640 |
self addClassesFromAssignmentTo:varName in:varScope to:setOfTypes. |
|
5641 |
self addClassesFromMessagesSentTo:expr in:varScope to:setOfTypes. |
|
5642 |
^ setOfTypes |
|
5643 |
]. |
|
5644 |
(varScope isMethod) ifTrue:[ |
|
5645 |
self addClassesFromAssignmentTo:varName in:varScope to:setOfTypes. |
|
5646 |
self addClassesFromMessagesSentTo:expr in:varScope to:setOfTypes. |
|
5647 |
^ setOfTypes |
|
5648 |
]. |
|
5649 |
]. |
|
5650 |
||
5651 |
classOrNil notNil ifTrue:[ |
|
5652 |
"/ inst var |
|
5653 |
instVarClass := classOrNil whichClassDefinesInstVar:varName. |
|
5654 |
instVarClass notNil ifTrue:[ |
|
5655 |
setOfTypes addAll:(self classesOfInstVarNamed:varName inClass:instVarClass). |
|
5656 |
^ setOfTypes |
|
5657 |
]. |
|
5658 |
||
5659 |
"/ class vars |
|
5660 |
classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:varName. |
|
5661 |
classVarClass notNil ifTrue:[ |
|
5662 |
"/ see what is currently there |
|
5663 |
setOfTypes add:(classVarClass classVarAt:varName asSymbol) class. |
|
5664 |
^ setOfTypes |
|
5665 |
]. |
|
5666 |
varName isUppercaseFirst ifTrue:[ |
|
5667 |
"/ private class |
|
5668 |
varName knownAsSymbol ifTrue:[ |
|
5669 |
cls := classOrNil theNonMetaclass privateClassesAt:varName asSymbol. |
|
5670 |
cls notNil ifTrue:[ |
|
5671 |
setOfTypes add:(cls theMetaclass). |
|
5672 |
^ setOfTypes |
|
5673 |
]. |
|
5674 |
]. |
|
5675 |
]. |
|
5676 |
"/ pool vars |
|
5677 |
poolVarClass := classOrNil theNonMetaclass whichPoolDefinesPoolVar:varName. |
|
5678 |
poolVarClass notNil ifTrue:[ |
|
5679 |
"/ see what is currently there |
|
5680 |
setOfTypes add:(poolVarClass classVarAt:varName asSymbol) class. |
|
5681 |
^ setOfTypes |
|
5682 |
]. |
|
5683 |
]. |
|
5684 |
||
5685 |
varName isUppercaseFirst ifTrue:[ |
|
5686 |
sym := varName asSymbolIfInterned. |
|
5687 |
sym notNil ifTrue:[ |
|
5688 |
exprVal := (Smalltalk at:sym). |
|
5689 |
exprVal notNil ifTrue:[ |
|
5690 |
setOfTypes add:(exprVal class). |
|
5691 |
] |
|
5692 |
]. |
|
5693 |
]. |
|
5694 |
^ setOfTypes |
|
5695 |
]. |
|
5696 |
||
5697 |
(exprVal := self valueOfNode:expr) notNil ifTrue:[ |
|
5698 |
"/ knowing the value is always great!! |
|
5699 |
setOfTypes add:exprVal class. |
|
5700 |
^ setOfTypes. |
|
5701 |
]. |
|
5702 |
||
5703 |
expr isMessage ifTrue:[ |
|
5704 |
self addClassesOfMessage:expr inClass:classOrNil to:setOfTypes. |
|
5705 |
^ setOfTypes |
|
5706 |
]. |
|
5707 |
||
5708 |
^ setOfTypes |
|
5131 | 5709 |
|
5710 |
"Modified: / 07-06-2016 / 11:33:19 / cg" |
|
5109 | 5711 |
! |
5712 |
||
5713 |
addClassesOfInstVarNamed:varName inClass:aClass to:setOfTypes |
|
5714 |
|instIndex type| |
|
5715 |
||
5716 |
instIndex := aClass instVarIndexFor:varName. |
|
5717 |
||
5718 |
"/ ask the class |
|
5719 |
(type := aClass typeOfInstVarNamed:varName) notNil ifTrue:[ |
|
5720 |
type isCollection ifTrue:[ |
|
5721 |
setOfTypes addAll:type. |
|
5722 |
] ifFalse:[ |
|
5723 |
setOfTypes add:type. |
|
5724 |
]. |
|
5725 |
^ setOfTypes |
|
5726 |
]. |
|
5727 |
||
5728 |
"/ look for instances |
|
5729 |
aClass allSubInstancesDo:[:i | |
|
5730 |
|varClass| |
|
5731 |
varClass := (i instVarAt:instIndex) class. |
|
5732 |
setOfTypes add:varClass. |
|
5733 |
]. |
|
5734 |
||
5735 |
"/ look for assignments in code |
|
5736 |
aClass withAllSubclassesDo:[:eachClass | |
|
5737 |
eachClass methodDictionary do:[:m | |
|
5738 |
|tree code visitor| |
|
5739 |
||
5740 |
"/ quick check |
|
5125 | 5741 |
SourceCodeManagerError handle:[:ex | |
5742 |
] do:[ |
|
5743 |
code := m source. |
|
5744 |
]. |
|
5109 | 5745 |
(code notNil and:[code includesString:varName]) ifTrue:[ |
5746 |
tree := Parser parse:code class:eachClass. |
|
5747 |
(tree notNil and:[tree ~~ #Error]) ifTrue:[ |
|
5748 |
visitor := PluggableParseNodeVisitor new. |
|
5749 |
visitor |
|
5750 |
actionForNodeClass:AssignmentNode |
|
5751 |
put:[:node | |
|
5752 |
|val expr exprSelector| |
|
5753 |
||
5754 |
node variable name = varName ifTrue:[ |
|
5755 |
expr := node expression. |
|
5756 |
"/ only look for wellknown types on the right side. |
|
5757 |
expr isLiteral ifTrue:[ |
|
5758 |
val := expr evaluate. |
|
5759 |
val isArray ifTrue:[ |
|
5760 |
setOfTypes add:Array |
|
5761 |
] ifFalse:[ |
|
5762 |
setOfTypes add:val class |
|
5763 |
]. |
|
5764 |
] ifFalse:[ |
|
5765 |
expr isMessage ifTrue:[ |
|
5766 |
exprSelector := expr selector. |
|
5767 |
( #(+ - * /) includes:exprSelector ) ifTrue:[ |
|
5768 |
setOfTypes add:Number |
|
5769 |
] ifFalse:[ |
|
5770 |
( #(// size) includes:exprSelector ) ifTrue:[ |
|
5771 |
setOfTypes add:Integer |
|
5772 |
] ifFalse:[ |
|
5773 |
( #(copy shallowCopy) includes:exprSelector ) ifTrue:[ |
|
5774 |
] ifFalse:[ |
|
5775 |
( #(new new: basicNew basicNew:) includes:exprSelector ) ifTrue:[ |
|
5776 |
expr receiver isGlobal ifTrue:[ |
|
5777 |
setOfTypes add:expr receiver evaluate |
|
5778 |
]. |
|
5779 |
] ifFalse:[ |
|
5780 |
self breakPoint:#cg. |
|
5781 |
] |
|
5782 |
] |
|
5783 |
] |
|
5784 |
] |
|
5785 |
]. |
|
5786 |
]. |
|
5787 |
]. |
|
5788 |
true "/ yes - visit subnodes |
|
5789 |
]. |
|
5790 |
visitor visit:tree. |
|
5791 |
]. |
|
5792 |
] |
|
5793 |
] |
|
5794 |
]. |
|
5795 |
^ setOfTypes |
|
5796 |
! |
|
5797 |
||
5798 |
addClassesOfMessage:expr inClass:classOrNil to:setOfTypes |
|
5799 |
|valClass |
|
5800 |
msgSelector msgReceiver msgArg1 |
|
5801 |
receiverClasses receiverClass |
|
5802 |
arg1Classes arg1Value mthd| |
|
5803 |
||
5804 |
msgSelector := expr selector. |
|
5805 |
||
5806 |
"/ heuristic: quickly assume boolean for some: |
|
5807 |
( |
|
5808 |
#( |
|
5809 |
isNil notNil isEmpty isEmptyOrNil notEmpty notEmptyOrNil |
|
5810 |
> >= < <= = == ~ ~= |
|
5811 |
knownAsSymbol |
|
5812 |
isMeta |
|
5813 |
includes: contains: |
|
5814 |
not and: or: |
|
5815 |
exists atEnd positive negative odd even |
|
5816 |
) includes:msgSelector |
|
5817 |
) ifTrue:[ |
|
5818 |
setOfTypes add:True. "/ use True, because Boolean does not include the full protocol |
|
5819 |
^ setOfTypes |
|
5820 |
]. |
|
5821 |
||
5822 |
msgReceiver := expr receiver. |
|
5823 |
||
5824 |
"/ some hardwired knowledge here |
|
5825 |
receiverClasses := self classesOfNode:msgReceiver. |
|
5826 |
receiverClass := receiverClasses size == 1 ifTrue:[receiverClasses anElement] ifFalse:[nil]. |
|
5827 |
||
5828 |
receiverClass notNil ifTrue:[ |
|
5829 |
"/ follow Smalltalk at: to see what is there |
|
5830 |
receiverClass == Smalltalk ifTrue:[ |
|
5831 |
msgSelector == #at: ifTrue:[ |
|
5832 |
msgArg1 := expr arg1. |
|
5833 |
msgArg1 isLiteralSymbol ifTrue:[ |
|
5834 |
arg1Value := Smalltalk at:msgArg1 value. |
|
5835 |
arg1Value notNil ifTrue:[ |
|
5836 |
setOfTypes add:arg1Value class. |
|
5837 |
^ setOfTypes. |
|
5838 |
] |
|
5839 |
] |
|
5840 |
]. |
|
5841 |
]. |
|
5842 |
||
5843 |
"/ usually return something of the receiver's type |
|
5844 |
( #(copy shallowCopy copyWith: , ) includes:msgSelector ) ifTrue:[ |
|
5845 |
setOfTypes addAll:receiverClasses. |
|
5846 |
^ setOfTypes. |
|
5847 |
]. |
|
5848 |
||
5849 |
( msgSelector == #class ) ifTrue:[ |
|
5850 |
setOfTypes add:(receiverClass class). |
|
5851 |
^ setOfTypes |
|
5852 |
]. |
|
5853 |
||
5854 |
receiverClass isBehavior ifTrue:[ |
|
5855 |
( #(compiledMethodAt:) includes:msgSelector) ifTrue:[ |
|
5856 |
setOfTypes add:Method. |
|
5857 |
^ setOfTypes |
|
5858 |
]. |
|
5859 |
( #(superclass) includes:msgSelector) ifTrue:[ |
|
5860 |
receiverClass isMeta ifTrue:[ |
|
5861 |
setOfTypes add:Metaclass. |
|
5862 |
] ifFalse:[ |
|
5863 |
setOfTypes add:Class. |
|
5864 |
]. |
|
5865 |
^ setOfTypes |
|
5866 |
]. |
|
5867 |
( #(theNonMetaclass theMetaclass) includes:msgSelector) ifTrue:[ |
|
5868 |
receiverClass isMeta ifTrue:[ |
|
5869 |
setOfTypes add:Metaclass. |
|
5870 |
^ setOfTypes |
|
5871 |
]. |
|
5872 |
setOfTypes add:(receiverClass perform:msgSelector) class. |
|
5873 |
^ setOfTypes |
|
5874 |
]. |
|
5875 |
||
5876 |
mthd := receiverClass lookupMethodFor:msgSelector. |
|
5877 |
receiverClass isMeta ifTrue:[ |
|
5878 |
( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: msgSelector ) ifTrue:[ |
|
5879 |
setOfTypes add:receiverClass theNonMetaclass. |
|
5880 |
^ setOfTypes. |
|
5881 |
]. |
|
5882 |
"/ if that method sends one of new/basicNew/new:/basicNew:, assume it returns an instance of itself |
|
5883 |
mthd notNil ifTrue:[ |
|
5884 |
( mthd sendsAny:#( #'new' #'basicNew' #'new:' #'basicNew:' )) ifTrue:[ |
|
5885 |
setOfTypes add:receiverClass theNonMetaclass. |
|
5886 |
^ setOfTypes |
|
5887 |
]. |
|
5888 |
]. |
|
5889 |
] ifFalse:[ |
|
5890 |
mthd notNil ifTrue:[ |
|
5891 |
(ParseTreeSearcher methodIsSetterMethod:mthd) ifTrue:[ |
|
5892 |
setOfTypes add:receiverClass. |
|
5893 |
^ setOfTypes |
|
5894 |
] |
|
5895 |
] |
|
5896 |
] |
|
5897 |
]. |
|
5898 |
]. |
|
5899 |
||
5900 |
((msgSelector startsWith:'as') |
|
5901 |
and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ] |
|
5902 |
) ifTrue:[ |
|
5903 |
setOfTypes add:valClass. |
|
5904 |
^ setOfTypes |
|
5905 |
]. |
|
5906 |
||
5907 |
((msgSelector startsWith:'is') |
|
5908 |
and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ] |
|
5909 |
) ifTrue:[ |
|
5910 |
setOfTypes add:True. "/ True - not boolean; it does not contain the full protocol (would not find ifTrue:) |
|
5911 |
^ setOfTypes. |
|
5912 |
]. |
|
5913 |
||
5914 |
#( |
|
5915 |
size SmallInteger |
|
5916 |
hash SmallInteger |
|
5917 |
identityHash SmallInteger |
|
5918 |
class Class |
|
5919 |
theMetaclass Metaclass |
|
5920 |
theNonMetaclass Class |
|
5921 |
fork Process |
|
5922 |
newProcess Process |
|
5923 |
) pairWiseDo:[:sel :clsName | |
|
5924 |
msgSelector == sel ifTrue:[ |
|
5925 |
setOfTypes add:(Smalltalk at:clsName). |
|
5926 |
^ setOfTypes. |
|
5927 |
]. |
|
5928 |
]. |
|
5929 |
||
5930 |
( #( bitAnd: bitOr: bitShift: rightShift: >> << highBit lowBit ) includes:msgSelector) ifTrue:[ |
|
5931 |
"/ assume integer |
|
5932 |
||
5933 |
setOfTypes add:Integer. |
|
5934 |
^ setOfTypes |
|
5935 |
]. |
|
5936 |
( #( + - * // \\ ) includes:msgSelector) ifTrue:[ |
|
5937 |
"/ assume numeric |
|
5938 |
||
5939 |
setOfTypes add:Number. |
|
5940 |
^ setOfTypes |
|
5941 |
]. |
|
5942 |
msgSelector == #/ ifTrue:[ |
|
5943 |
((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Number]) ifTrue:[ |
|
5944 |
setOfTypes add:Number. |
|
5945 |
^ setOfTypes. |
|
5946 |
]. |
|
5947 |
msgArg1 := expr arguments at:1 ifAbsent:nil. |
|
5948 |
msgArg1 isNil ifTrue:[^ setOfTypes]. |
|
5949 |
arg1Classes := ((self classesOfNode:msgArg1) ? #()). |
|
5950 |
(arg1Classes contains:[:cls | cls includesBehavior:Number]) ifTrue:[ |
|
5951 |
setOfTypes add:Number. |
|
5952 |
^ setOfTypes |
|
5953 |
]. |
|
5954 |
]. |
|
5955 |
( #( construct: / ) includes:msgSelector) ifTrue:[ |
|
5956 |
((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Filename]) ifTrue:[ |
|
5957 |
setOfTypes add:Filename. |
|
5958 |
^ setOfTypes |
|
5959 |
]. |
|
5960 |
]. |
|
5961 |
||
5962 |
^ setOfTypes |
|
5963 |
! |
|
5964 |
||
5965 |
classOfNode:aNode |
|
5966 |
"returns the class of a receiver, if it is well-known. |
|
5967 |
Otherwise nil (either unknown, or multiple possibilities) |
|
5968 |
When showing possible completions for a message, |
|
5969 |
it is a good idea to know what the kind receiver is." |
|
5970 |
||
5971 |
| classes | |
|
5972 |
||
5973 |
classes := self classesOfNode:aNode. |
|
5974 |
classes size == 1 ifTrue:[ |
|
5975 |
^ classes anElement |
|
5976 |
]. |
|
5977 |
self breakPoint:#cg. |
|
5978 |
^ nil |
|
5979 |
! |
|
5980 |
||
5981 |
classesFromAssignmentTo:varName in:aTree |
|
5982 |
^ self addClassesFromAssignmentTo:varName in:aTree to:IdentitySet new |
|
5983 |
! |
|
5984 |
||
5985 |
classesOfInstVarNamed:varName inClass:aClass |
|
5986 |
^ self addClassesOfInstVarNamed:varName inClass:aClass to:(IdentitySet new) |
|
5987 |
! |
|
5988 |
||
5989 |
classesOfNode:aNode |
|
5990 |
"returns the set of possible classes of a parsenode. |
|
5991 |
or nil if unknown. |
|
5992 |
When showing possible completions for a message, |
|
5993 |
it is a good idea to know what the kind receiver is." |
|
5994 |
||
5995 |
^ self addClassesOfExpression:aNode inClass:classOrNil to:(IdentitySet new). |
|
5996 |
! |
|
5997 |
||
5998 |
isNonDestructive:aMessageNode whenSentTo:receiverValue |
|
5999 |
"return true, if it is safe to send aSelector to receiverValue |
|
6000 |
(i.e. has no side effects)" |
|
6001 |
||
6002 |
|selector method impl arg1Value| |
|
6003 |
||
6004 |
selector := aMessageNode selector. |
|
6005 |
||
6006 |
impl := receiverValue class whichClassIncludesSelector:selector. |
|
6007 |
||
6008 |
( #( |
|
6009 |
basicSize basicAt: |
|
6010 |
class theMetaclass theNonMetaclass ) includes:selector |
|
6011 |
) ifTrue:[ |
|
6012 |
^ true. |
|
6013 |
]. |
|
6014 |
||
6015 |
selector == #size ifTrue:[ |
|
6016 |
"/ mhm - be conservative; someone might have redefined #size |
|
6017 |
"/ more hardwired stuff. |
|
6018 |
((impl == Object) or:[(impl == String) or:[impl isSubclassOf:Collection]]) ifTrue:[ |
|
6019 |
^ true. |
|
6020 |
]. |
|
6021 |
]. |
|
6022 |
selector == #at: ifTrue:[ |
|
6023 |
"/ mhm - be conservative; someone might have redefined #at: and do something there |
|
6024 |
"/ more hardwired stuff. |
|
6025 |
arg1Value := self valueOfNode:(aMessageNode arg1). |
|
6026 |
arg1Value notNil ifTrue:[ |
|
6027 |
receiverValue == Smalltalk ifTrue:[ |
|
6028 |
^ arg1Value isSymbol |
|
6029 |
]. |
|
6030 |
||
6031 |
((impl == Object) or:[(impl == String) or:[(impl isSubclassOf:Collection)]]) ifTrue:[ |
|
6032 |
^ true. |
|
6033 |
]. |
|
6034 |
]. |
|
6035 |
]. |
|
6036 |
||
6037 |
selector argumentCount == 0 ifTrue:[ |
|
6038 |
"/ follow non-destructive accessors |
|
6039 |
method := receiverValue class lookupMethodFor:selector. |
|
6040 |
method notNil ifTrue:[ |
|
6041 |
(ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[ |
|
6042 |
"/ we can savely call that method to get the current value |
|
6043 |
^ true. |
|
6044 |
]. |
|
6045 |
]. |
|
6046 |
]. |
|
6047 |
||
6048 |
^ false |
|
6049 |
! |
|
6050 |
||
6051 |
valueAndKindOfVariable:aVariableName |
|
6052 |
"when showing possible completions for a variable, |
|
6053 |
it is a good idea to know what the reveiver's value is. |
|
6054 |
Sigh - returns nil as value both if unknown AND if a real nil is there" |
|
6055 |
||
6056 |
|nodeVal con classInstVarClass classVarClass privateClass pool sym nameSpace topNameSpace| |
|
6057 |
||
6058 |
aVariableName isUppercaseFirst ifTrue:[ |
|
6059 |
classOrNil notNil ifTrue:[ |
|
6060 |
classOrNil isMeta ifTrue:[ |
|
6061 |
"/ class instVars |
|
6062 |
(classInstVarClass := classOrNil whichClassDefinesInstVar:aVariableName) notNil ifTrue:[ |
|
6063 |
nodeVal := classInstVarClass theNonMetaclass instVarNamed:aVariableName. |
|
6064 |
^ { nodeVal . #classInstVariable } |
|
6065 |
]. |
|
6066 |
]. |
|
6067 |
"/ class vars |
|
6068 |
(classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:aVariableName) notNil ifTrue:[ |
|
6069 |
nodeVal := classVarClass classVarAt:aVariableName asSymbol. |
|
6070 |
^ { nodeVal . #classVariable } |
|
6071 |
]. |
|
6072 |
||
6073 |
privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil. |
|
6074 |
privateClass notNil ifTrue:[ |
|
6075 |
nodeVal := privateClass. |
|
6076 |
^ { nodeVal . #privateClass } |
|
6077 |
]. |
|
6078 |
pool := classOrNil theNonMetaclass whichPoolDefinesPoolVar:aVariableName. |
|
6079 |
pool notNil ifTrue:[ |
|
6080 |
nodeVal := pool classVarAt:aVariableName. |
|
6081 |
^ { nodeVal . #poolVariable } |
|
6082 |
]. |
|
5118 | 6083 |
(sym := aVariableName asSymbolIfInterned) notNil ifTrue:[ |
6084 |
((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[ |
|
6085 |
nameSpace isNameSpace ifTrue:[ |
|
6086 |
nodeVal := nameSpace at:sym. |
|
6087 |
(nodeVal notNil or:[nameSpace includesKey:sym]) ifTrue:[ |
|
6088 |
^ { nodeVal . #nameSpaceVariable } |
|
6089 |
]. |
|
6090 |
]. |
|
6091 |
nodeVal := nameSpace privateClassNamed:sym. |
|
6092 |
(nodeVal notNil) ifTrue:[ |
|
6093 |
^ { nodeVal . #privateClass } |
|
6094 |
]. |
|
6095 |
]. |
|
6096 |
((topNameSpace := classOrNil topNameSpace) notNil |
|
6097 |
and:[topNameSpace ~~ nameSpace |
|
6098 |
and:[topNameSpace ~~ Smalltalk]]) ifTrue:[ |
|
6099 |
nodeVal := topNameSpace at:sym. |
|
6100 |
(nodeVal notNil or:[topNameSpace includesKey:sym]) ifTrue:[ |
|
6101 |
^ { nodeVal . #nameSpaceVariable } |
|
6102 |
]. |
|
6103 |
]. |
|
6104 |
]. |
|
5109 | 6105 |
]. |
6106 |
(sym := aVariableName asSymbolIfInterned) notNil ifTrue:[ |
|
6107 |
nodeVal := Smalltalk at:sym. |
|
6108 |
(nodeVal notNil or:[Smalltalk includesKey:sym]) ifTrue:[ |
|
6109 |
^ { nodeVal . #global } |
|
6110 |
] |
|
6111 |
]. |
|
6112 |
||
6113 |
"/ 'evaluate' the variable (like in a browser's codeView) |
|
6114 |
"/ mhmh - will we catch workspace vars then? |
|
5118 | 6115 |
Error ignoreIn:[ |
5109 | 6116 |
nodeVal := Parser new evaluate:aVariableName in:classOrNil receiver:classOrNil. |
6117 |
]. |
|
6118 |
nodeVal notNil ifTrue:[ |
|
6119 |
^ { nodeVal . #global } |
|
6120 |
]. |
|
6121 |
^ nil |
|
6122 |
]. |
|
6123 |
||
6124 |
aVariableName = 'self' ifTrue:[ |
|
6125 |
contextOrNil notNil ifTrue:[ |
|
6126 |
^ { contextOrNil receiver . #pseudoVar } |
|
6127 |
]. |
|
6128 |
(classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
6129 |
"/ ^ { classOrNil . #pseudoVar } |
|
6130 |
^ { classOrNil theNonMetaclass . #pseudoVar } |
|
6131 |
]. |
|
6132 |
^ nil |
|
6133 |
]. |
|
6134 |
||
6135 |
contextOrNil notNil ifTrue:[ |
|
6136 |
"/ in the debugger, we know more |
|
6137 |
con := contextOrNil. |
|
6138 |
[ con notNil ] whileTrue:[ |
|
6139 |
"/ a local in the context? |
|
6140 |
((con argAndVarNames ? #()) includes:aVariableName) ifTrue:[ |
|
6141 |
nodeVal := con argsAndVars at:(con argAndVarNames indexOf:aVariableName) ifAbsent:nil. |
|
6142 |
nodeVal notNil ifTrue:[ |
|
6143 |
^ { nodeVal . #argument } |
|
6144 |
]. |
|
6145 |
]. |
|
6146 |
con := con home. |
|
6147 |
]. |
|
5370 | 6148 |
"/ an instvar? |
5109 | 6149 |
(contextOrNil receiver class allInstVarNames includes:aVariableName) ifTrue:[ |
5370 | 6150 |
contextOrNil receiver isProtoObject ifFalse:[ |
6151 |
nodeVal := contextOrNil receiver instVarNamed:aVariableName. |
|
6152 |
]. |
|
5109 | 6153 |
nodeVal notNil ifTrue:[ |
6154 |
^ { nodeVal . #instanceVariable } |
|
6155 |
]. |
|
6156 |
]. |
|
6157 |
]. |
|
6158 |
^ nil |
|
6159 |
||
6160 |
"Created: / 01-05-2016 / 12:40:05 / cg" |
|
6161 |
! |
|
6162 |
||
6163 |
valueOfNode:aNode |
|
6164 |
"when showing possible completions for a message, |
|
6165 |
it is a good idea to know what the reveiver's value is. |
|
6166 |
Sigh - returns nil both if unknown AND if a real nil is there." |
|
6167 |
||
5368 | 6168 |
|nodeSelector nodeReceiver receiverValue arg1Value| |
5109 | 6169 |
|
6170 |
aNode isLiteral ifTrue:[ |
|
6171 |
^ aNode value |
|
6172 |
]. |
|
6173 |
aNode isVariable ifTrue:[ |
|
6174 |
^ self valueOfVariable:aNode name. |
|
6175 |
]. |
|
6176 |
||
6177 |
aNode isMessage ifTrue:[ |
|
6178 |
nodeSelector := aNode selector. |
|
6179 |
nodeReceiver := aNode receiver. |
|
6180 |
||
6181 |
"/ some hardwired knowledge here |
|
6182 |
classOrNil notNil ifTrue:[ |
|
6183 |
(nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[ |
|
6184 |
^ classOrNil |
|
6185 |
]. |
|
6186 |
]. |
|
6187 |
||
6188 |
receiverValue := self valueOfNode:nodeReceiver. |
|
6189 |
receiverValue notNil ifTrue:[ |
|
5368 | 6190 |
(self isNonDestructive:aNode whenSentTo:receiverValue) ifTrue:[ |
6191 |
[ |
|
6192 |
nodeSelector argumentCount == 1 ifTrue:[ |
|
6193 |
arg1Value := self valueOfNode:(aNode arg1). |
|
5109 | 6194 |
^ receiverValue perform: nodeSelector with: arg1Value. |
5368 | 6195 |
]. |
6196 |
^ receiverValue perform: nodeSelector. |
|
6197 |
] on:Error do:[ |
|
6198 |
^ nil |
|
6199 |
] |
|
5109 | 6200 |
]. |
6201 |
]. |
|
6202 |
]. |
|
6203 |
||
6204 |
^ nil |
|
6205 |
||
6206 |
"Created: / 28-08-2013 / 16:34:53 / cg" |
|
6207 |
! |
|
6208 |
||
6209 |
valueOfVariable:aVariableName |
|
6210 |
"when showing possible completions for a variable, |
|
6211 |
it is a good idea to know what the reveiver's value is. |
|
6212 |
Sigh - returns nil both if unknown AND if a real nil is there." |
|
6213 |
||
6214 |
|valueAndKind| |
|
6215 |
||
6216 |
(valueAndKind := self valueAndKindOfVariable:aVariableName) notNil ifTrue:[ |
|
6217 |
self assert:valueAndKind isArray. |
|
6218 |
^ valueAndKind first. |
|
6219 |
]. |
|
6220 |
^ nil |
|
6221 |
||
5225 | 6222 |
"Modified: / 26-08-2016 / 14:16:16 / cg" |
5109 | 6223 |
! ! |
6224 |
||
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6225 |
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6226 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6227 |
bestName:bestNameArg matchingNames:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6228 |
^ self with:bestNameArg with:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6229 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6230 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6231 |
self bestName:123 matchingNames:345 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6232 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6233 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6234 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6235 |
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6236 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6237 |
bestName |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6238 |
^ self at:1 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6239 |
! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6240 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6241 |
matchingNames |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6242 |
^ self at:2 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6243 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
6244 |
|
2376 | 6245 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
6246 |
||
4281 | 6247 |
version |
4784 | 6248 |
^ '$Header$' |
4281 | 6249 |
! |
6250 |
||
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
6251 |
version_CVS |
4784 | 6252 |
^ '$Header$' |
4830
d4cd05d0d643
Removed breakpoint in DWIM - likely won;'t be fixed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4823
diff
changeset
|
6253 |
! |
d4cd05d0d643
Removed breakpoint in DWIM - likely won;'t be fixed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4823
diff
changeset
|
6254 |
|
d4cd05d0d643
Removed breakpoint in DWIM - likely won;'t be fixed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4823
diff
changeset
|
6255 |
version_HG |
d4cd05d0d643
Removed breakpoint in DWIM - likely won;'t be fixed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4823
diff
changeset
|
6256 |
|
d4cd05d0d643
Removed breakpoint in DWIM - likely won;'t be fixed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4823
diff
changeset
|
6257 |
^ '$Changeset: <not expanded> $' |
2376 | 6258 |
! ! |
4194 | 6259 |