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