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