author | Claus Gittinger <cg@exept.de> |
Fri, 13 Feb 2015 22:00:46 +0100 | |
changeset 4710 | 94634917ce8f |
parent 4691 | b8baa7c905ef |
child 4711 | 1c2e635489e5 |
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:[ |
1231 |
^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg |
|
1232 |
]. |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1233 |
]. |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1234 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1235 |
"/ 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
|
1236 |
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
|
1237 |
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
|
1238 |
|
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1239 |
"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
|
1240 |
! ! |
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1241 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1242 |
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'! |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1243 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1244 |
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1245 |
"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
|
1246 |
(cursor position, characters around cursor etc.) and calling back into actionBlock, passing |
4591 | 1247 |
the info as argument. |
1248 |
The interface has been defined in that way |
|
1249 |
(and tight coupling with internals of the editor) because |
|
1250 |
1) the completer needs to know about the text around the cursor position |
|
1251 |
2) the edit operation for completion may be non-trivial |
|
1252 |
(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
|
1253 |
For example, in many situations, both a completion of a unary selector before the cursor, |
4591 | 1254 |
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
|
1255 |
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
|
1256 |
perform the completion. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1257 |
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
|
1258 |
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
|
1259 |
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
|
1260 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1261 |
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
|
1262 |
or nil, if called from the browser. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1263 |
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
|
1264 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1265 |
languageOrNil := STXJavaScriptLanguage instance. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1266 |
methodOrNil := methodOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1267 |
classOrNil := classOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1268 |
codeView := codeViewArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1269 |
contextOrNil := contextOrNilArg. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1270 |
|
4423
c21baefab5d0
Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4422
diff
changeset
|
1271 |
JavaScriptCompletionEngine notNil ifTrue:[ |
4591 | 1272 |
JavaScriptCompletionEngine new |
1273 |
completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock. |
|
4548 | 1274 |
]. |
4423
c21baefab5d0
Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4422
diff
changeset
|
1275 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1276 |
self information:'Not yet supported'. |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1277 |
|
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1278 |
"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
|
1279 |
"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
|
1280 |
! ! |
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1281 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1282 |
!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
|
1283 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1284 |
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1285 |
|
4379 | 1286 |
"OBSOLETE; migrating to use the the new 'xxx: into:' protocol. |
4352 | 1287 |
contextOrNil is the current context, if this is called from the debugger; |
4238 | 1288 |
nil, if called from the browser. |
1289 |
If nonNil, we can make better guesses, because we actually know what a variable's type is. |
|
1290 |
This is not yet done, sigh" |
|
4548 | 1291 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1292 |
|crsrPos char interval source node parent checkedNode instanceOrNilArg |
4710 | 1293 |
forceNewMessageSend classOfReceiver prevChar| |
4238 | 1294 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1295 |
languageOrNil := SmalltalkLanguage instance. |
4238 | 1296 |
classOrNil := classOrNilArg. |
1297 |
codeView := codeViewArg. |
|
1298 |
||
1299 |
crsrPos := codeView characterPositionOfCursor"-1". |
|
1300 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
4301 | 1301 |
"/ Transcript show:crsrPos; show:' '; showCR:char. |
4238 | 1302 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
4710 | 1303 |
crsrPos := crsrPos - 1. |
1304 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
4238 | 1305 |
]. |
1306 |
||
1307 |
interval := codeView selectedInterval. |
|
4301 | 1308 |
"/ Transcript show:'iv: '; showCR:interval. |
4238 | 1309 |
interval isEmpty ifTrue:[ |
4710 | 1310 |
interval := crsrPos"-1" to:crsrPos. |
1311 |
"/ Transcript show:'iv2: '; showCR:interval. |
|
4238 | 1312 |
]. |
1313 |
||
1314 |
source := codeView contentsAsString string. |
|
1315 |
source := source copyTo:crsrPos. |
|
1316 |
||
1317 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
1318 |
"/ we will not find a node for a long time (stepping back more and more, |
|
1319 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
1320 |
"/ without any progress. |
|
1321 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
1322 |
"/ as it parses the code. Stop, when the interval is hit. |
|
1323 |
"/ that will also work for syntactic incorrect source code. |
|
1324 |
classOrNil notNil ifTrue:[ |
|
4710 | 1325 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
1326 |
"/ Transcript show:'nd1: '; showCR:node. |
|
4238 | 1327 |
]. |
1328 |
node isNil ifTrue:[ |
|
4710 | 1329 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false. |
1330 |
"/ Transcript show:'nd2 try: '; showCR:node. |
|
1331 |
node isNil ifTrue:[ |
|
1332 |
"/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'. |
|
1333 |
self breakPoint:#cg. |
|
1334 |
"/ self information:'No parseNode found (syntax error before or in comment?)'. |
|
1335 |
^ self. |
|
1336 |
] |
|
4238 | 1337 |
]. |
1338 |
||
4346 | 1339 |
forceNewMessageSend := false. |
1340 |
||
1341 |
"/ if there a separator between the variable's name and the cursor position... |
|
4710 | 1342 |
prevChar := codeView characterBeforeCursor. |
1343 |
(prevChar isSeparator or:[ ')}]''' includes:prevChar ]) ifTrue:[ |
|
1344 |
(node isVariable |
|
1345 |
and:[ (parent := node parent) notNil |
|
1346 |
and:[ parent isMessage ]] |
|
1347 |
) ifTrue:[ |
|
1348 |
"/ completion after a variable node... |
|
1349 |
parent isKeyword ifTrue:[ |
|
1350 |
"/ and it is a keyword message, we complete the keyword message instead |
|
1351 |
node := parent. |
|
1352 |
] ifFalse:[ |
|
1353 |
"/ otherwise, a unary message is probably intended to be sent to the variable. |
|
1354 |
"/ (however, no character is available to determine what is useful) |
|
1355 |
forceNewMessageSend := true. |
|
1356 |
]. |
|
1357 |
] ifFalse:[ |
|
1358 |
(node isMessage and:[node isUnary]) ifTrue:[ |
|
1359 |
"/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo) |
|
1360 |
"/ |
|
1361 |
forceNewMessageSend := true. |
|
4346 | 1362 |
"/ "/ can we see what we get from foo? |
4548 | 1363 |
"/ classOfReceiver := self |
4346 | 1364 |
"/ classOfReceiver:node receiver |
1365 |
"/ inClass:classOrNil instance:instanceOrNil context:contextOrNil. |
|
1366 |
"/ classOfReceiver notNil ifTrue:[ |
|
1367 |
"/ |mthd| |
|
1368 |
"/ |
|
1369 |
"/ mthd := classOfReceiver lookupMethodFor:node selector. |
|
1370 |
"/ mthd notNil ifTrue:[ |
|
1371 |
"/ self halt. |
|
1372 |
"/ (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[ |
|
1373 |
"/ forceNewMessageSend := true. |
|
1374 |
"/ ] |
|
1375 |
"/ ] |
|
1376 |
"/ ]. |
|
4710 | 1377 |
] |
1378 |
] |
|
4346 | 1379 |
]. |
1380 |
||
1381 |
forceNewMessageSend ifTrue:[ |
|
4710 | 1382 |
"/ completion with nothing to start (right after a variable) |
1383 |
"/ see what the variable can understand and present the most useful stuff (very thin ice here) |
|
1384 |
classOfReceiver := self classOfNode:node. |
|
1385 |
classOfReceiver isNil ifTrue:[ |
|
1386 |
"/ it does not make sense to offer anything, if we don't have any idea of what this |
|
1387 |
"/ will be... |
|
1388 |
Screen current beep. |
|
1389 |
] ifFalse:[ |
|
1390 |
|superClass possible choice| |
|
1391 |
||
1392 |
possible := classOfReceiver selectors. |
|
1393 |
superClass := classOfReceiver superclass. |
|
1394 |
[superClass notNil and:[(possible size + superClass selectors size) < 50]] whileTrue:[ |
|
1395 |
possible := possible,superClass selectors. |
|
1396 |
superClass := superClass superclass. |
|
1397 |
]. |
|
1398 |
possible := possible copy sort. |
|
1399 |
choice := self askUserForCompletion:('Message to "%1"' bindWith:node name) for:codeView from:possible. |
|
1400 |
choice isNil ifTrue:[ |
|
1401 |
Screen current beep. |
|
1402 |
^ self |
|
1403 |
]. |
|
1404 |
||
1405 |
codeView |
|
1406 |
undoableDo:[ |
|
1407 |
codeView insertStringAtCursor:choice |
|
1408 |
] |
|
1409 |
info:'Completion'. |
|
1410 |
]. |
|
1411 |
^ self |
|
4238 | 1412 |
]. |
1413 |
||
1414 |
node isVariable ifTrue:[ |
|
4710 | 1415 |
self codeCompletionForVariable:node inClass:classOrNil codeView:codeView. |
1416 |
^ self. |
|
4238 | 1417 |
]. |
1418 |
node isLiteral ifTrue:[ |
|
4710 | 1419 |
node value isSymbol ifTrue:[ |
1420 |
self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView. |
|
1421 |
^ self. |
|
1422 |
]. |
|
1423 |
^ self "/ huh - strings or what? |
|
4238 | 1424 |
]. |
1425 |
||
1426 |
checkedNode := node. |
|
1427 |
[checkedNode notNil] whileTrue:[ |
|
4710 | 1428 |
checkedNode isMessage ifTrue:[ |
1429 |
"/ completion in a message-send |
|
1430 |
contextOrNilArg notNil ifTrue:[ |
|
4329 | 1431 |
"/ |rcvrNode idx rcvr val| |
1432 |
"/ |
|
1433 |
"/ (rcvrNode := checkedNode receiver) isVariable ifTrue:[ |
|
1434 |
"/ rcvrNode isSelf ifTrue:[ |
|
1435 |
"/ classOrNil := contextOrNil receiver class. |
|
1436 |
"/ ] ifFalse:[ |
|
1437 |
"/ (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1438 |
"/ val := contextOrNil argsAndVars at:idx. |
|
1439 |
"/ classOrNil := val class. |
|
1440 |
"/ ] ifFalse:[ |
|
1441 |
"/ (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1442 |
"/ val := contextOrNil receiver instVarNamed:rcvrNode name. |
|
1443 |
"/ classOrNil := val class. |
|
1444 |
"/ ] |
|
1445 |
"/ ] |
|
1446 |
"/ ] |
|
1447 |
"/ ]. |
|
4710 | 1448 |
instanceOrNilArg := contextOrNilArg receiver |
1449 |
]. |
|
1450 |
self |
|
1451 |
codeCompletionForMessage:checkedNode |
|
1452 |
inClass:classOrNil instance:instanceOrNilArg |
|
1453 |
context:contextOrNilArg codeView:codeView. |
|
1454 |
^ self |
|
1455 |
]. |
|
1456 |
checkedNode isMethod ifTrue:[ |
|
1457 |
"/ completion in a method's selector pattern |
|
1458 |
self codeCompletionForMethodSpec:checkedNode. |
|
1459 |
^ self. |
|
1460 |
]. |
|
1461 |
checkedNode := checkedNode parent. |
|
4238 | 1462 |
]. |
1463 |
||
1464 |
self information:'Node is neither variable nor message.'. |
|
1465 |
||
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1466 |
"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
|
1467 |
! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1468 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1469 |
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
|
1470 |
"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
|
1471 |
(cursor position, characters around cursor etc.) and calling back into actionBlock, passing |
4591 | 1472 |
the info as argument. |
1473 |
The interface has been defined in that way |
|
1474 |
(and tight coupling with internals of the editor) because |
|
1475 |
1) the completer needs to know about the text around the cursor position |
|
1476 |
2) the edit operation for completion may be non-trivial |
|
1477 |
(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
|
1478 |
For example, in many situations, both a completion of a unary selector before the cursor, |
4591 | 1479 |
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
|
1480 |
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
|
1481 |
perform the completion. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1482 |
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
|
1483 |
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
|
1484 |
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
|
1485 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1486 |
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
|
1487 |
or nil, if called from the browser. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1488 |
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
|
1489 |
|
4524 | 1490 |
|crsrPos char interval i source partialSource cursorLineSource |
1491 |
suggestions actions title| |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1492 |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
1493 |
languageOrNil := SmalltalkLanguage instance. |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1494 |
methodOrNil := methodOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1495 |
classOrNil := classOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1496 |
codeView := codeViewArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1497 |
contextOrNil := contextOrNilArg. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1498 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1499 |
"/ classOrNil isNil ifTrue:[ |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1500 |
"/ self information:'No class'. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1501 |
"/ ^ self. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1502 |
"/ ]. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1503 |
|
4524 | 1504 |
crsrPos := codeView characterPositionOfCursor. |
4592 | 1505 |
char := codeView characterAtCharacterPosition:(crsrPos-1 max:1). |
4591 | 1506 |
[crsrPos > 1 and:[char isSeparator "or:['.' includes:char]"]] whileTrue:[ |
1507 |
crsrPos := crsrPos - 1. |
|
1508 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
1509 |
]. |
|
1510 |
||
1511 |
char = $. ifTrue:[ |
|
1512 |
"/ either at end of statement or after a character constant |
|
1513 |
crsrPos == 1 ifTrue:[^ self]. |
|
1514 |
(codeView characterAtCharacterPosition:crsrPos-1) == $$ ifFalse:[^ self]. |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1515 |
]. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1516 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1517 |
interval := crsrPos-1 to:crsrPos. |
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 |
source := codeView contentsAsString string. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1520 |
partialSource := source copyTo:crsrPos. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1521 |
|
4524 | 1522 |
methodOrNilArg isNil ifTrue:[ |
4591 | 1523 |
"/ first try parsing the current cursor line. |
1524 |
"/ this helps doIts in a workspace, where additional garbage is often before the actual expression to be evaluated |
|
1525 |
(i := partialSource lastIndexOf:Character cr) ~~ 0 ifTrue:[ |
|
1526 |
"/ because cursorPositions and node-positions are required elsewhere to be correct, |
|
1527 |
"/ I cannot just snip off the line and parse that one alone (later corrections will do so at wrong position). |
|
1528 |
"/ Instead, create a copy of the whole source, with the stuff before the cursor lne being blanked out. |
|
1529 |
cursorLineSource := partialSource copy. |
|
1530 |
cursorLineSource from:1 to:i put:Character space. |
|
1531 |
self |
|
1532 |
tryCodeCompletionWithSource:cursorLineSource nodeInterval:interval |
|
1533 |
at:crsrPos mustBeExpression:true |
|
1534 |
into:[:listOfSuggestions :listOfActions :titleWhenAsking | |
|
1535 |
suggestions := listOfSuggestions. |
|
1536 |
actions := listOfActions. |
|
1537 |
title := titleWhenAsking. |
|
1538 |
]. |
|
1539 |
suggestions notEmptyOrNil ifTrue:[ |
|
1540 |
actionBlock value:suggestions value:actions value:title. |
|
1541 |
^ self. |
|
1542 |
]. |
|
1543 |
]. |
|
4524 | 1544 |
]. |
1545 |
||
1546 |
"/ try parsing the partial source (from beginning up to the cursor) |
|
4548 | 1547 |
self |
4591 | 1548 |
tryCodeCompletionWithSource:partialSource nodeInterval:interval |
1549 |
at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil]) |
|
1550 |
into:[:listOfSuggestions :listOfActions :titleWhenAsking | |
|
1551 |
suggestions := listOfSuggestions. |
|
1552 |
actions := listOfActions. |
|
1553 |
title := titleWhenAsking. |
|
1554 |
"/ suggestions1 size>100 ifTrue:[ self halt]. |
|
1555 |
]. |
|
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1556 |
|
4524 | 1557 |
suggestions notEmptyOrNil ifTrue:[ |
4591 | 1558 |
actionBlock value:suggestions value:actions value:title. |
1559 |
^ self. |
|
4524 | 1560 |
]. |
1561 |
||
1562 |
"/ then try parsing the whole source (from beginning up to the cursor) |
|
4548 | 1563 |
self |
4591 | 1564 |
tryCodeCompletionWithSource:source nodeInterval:interval |
1565 |
at:crsrPos mustBeExpression:false |
|
1566 |
into:[:listOfSuggestions :listOfActions :titleWhenAsking | |
|
1567 |
suggestions := listOfSuggestions. |
|
1568 |
actions := listOfActions. |
|
1569 |
title := titleWhenAsking. |
|
1570 |
]. |
|
4524 | 1571 |
suggestions notEmptyOrNil ifTrue:[ |
4591 | 1572 |
actionBlock value:suggestions value:actions value:title. |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1573 |
]. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1574 |
|
4392
9570ef5f05c3
Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4391
diff
changeset
|
1575 |
"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
|
1576 |
! ! |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1577 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1578 |
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'! |
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 |
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1581 |
<resource: #obsolete> |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1582 |
"OBSOLETE; migrating to use the the new 'xxx: into:' protocol. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1583 |
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
|
1584 |
nil, if called from the browser. |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1585 |
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
|
1586 |
This is not yet done, sigh" |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1587 |
|
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1588 |
^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg |
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1589 |
|
4238 | 1590 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
4346 | 1591 |
"Modified: / 28-08-2013 / 17:15:25 / cg" |
4391
903ec83fb9cd
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4390
diff
changeset
|
1592 |
"Modified: / 18-09-2013 / 14:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4352 | 1593 |
! |
1594 |
||
1595 |
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
|
1596 |
<resource: #obsolete> |
4524 | 1597 |
^ self |
4548 | 1598 |
codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
4238 | 1599 |
! ! |
1600 |
||
1601 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers'! |
|
1602 |
||
4548 | 1603 |
askUserForCompletion:what for:codeView at:position from:allTheBest |
4238 | 1604 |
|list choice lastChoice| |
1605 |
||
1606 |
"/ cg: until the new stuff works,... |
|
1607 |
^ self old_askUserForCompletion:what for:codeView from:allTheBest. |
|
1608 |
||
4346 | 1609 |
"/ allTheBest isEmpty ifTrue:[ |
1610 |
"/ ^ nil |
|
1611 |
"/ ]. |
|
1612 |
"/ allTheBest size == 1 ifTrue:[ |
|
1613 |
"/ ^ allTheBest first |
|
1614 |
"/ ]. |
|
1615 |
"/ list := allTheBest. |
|
1616 |
"/ LastChoices notNil ifTrue:[ |
|
1617 |
"/ lastChoice := LastChoices at:what ifAbsent:nil. |
|
1618 |
"/ lastChoice notNil ifTrue:[ |
|
1619 |
"/ list := { lastChoice allBold } , (list copyWithout:lastChoice). |
|
1620 |
"/ ]. |
|
1621 |
"/ ]. |
|
4548 | 1622 |
"/ choice := Tools::CodeCompletionMenu |
4346 | 1623 |
"/ openFor:codeView |
1624 |
"/ at:position |
|
1625 |
"/ with:allTheBest. |
|
1626 |
"/ LastChoices isNil ifTrue:[ |
|
1627 |
"/ LastChoices := Dictionary new. |
|
1628 |
"/ ]. |
|
1629 |
"/ LastChoices at:what put:choice. |
|
1630 |
"/ ^ choice string |
|
4238 | 1631 |
|
1632 |
"Created: / 16-02-2010 / 10:09:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 1633 |
"Modified: / 28-08-2013 / 16:41:35 / cg" |
4238 | 1634 |
! |
1635 |
||
1636 |
askUserForCompletion:what for:codeView from:allTheBest |
|
1637 |
|list resources choice lastChoice| |
|
1638 |
||
1639 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
1640 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
1641 |
||
1642 |
list := allTheBest. |
|
1643 |
LastChoices notNil ifTrue:[ |
|
4548 | 1644 |
lastChoice := LastChoices at:what ifAbsent:nil. |
1645 |
lastChoice notNil ifTrue:[ |
|
1646 |
list := {lastChoice. nil. } , (list copyWithout:lastChoice). |
|
1647 |
]. |
|
4238 | 1648 |
]. |
1649 |
||
1650 |
list size < 30 ifTrue:[ |
|
4548 | 1651 |
|menu idx exitKey| |
1652 |
||
1653 |
menu := PopUpMenu labels:list. |
|
1654 |
menu hideOnKeyFilter:[:key | |hide| |
|
1655 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
1656 |
hide ifTrue:[ |
|
1657 |
exitKey := key. |
|
1658 |
]. |
|
1659 |
hide]. |
|
1660 |
||
1661 |
idx := menu startUp. |
|
1662 |
idx == 0 ifTrue:[ |
|
1663 |
exitKey notNil ifTrue:[ |
|
1664 |
codeView keyPress:exitKey x:0 y:0. |
|
1665 |
]. |
|
1666 |
^ nil |
|
1667 |
]. |
|
1668 |
choice := list at:idx. |
|
4238 | 1669 |
] ifFalse:[ |
4548 | 1670 |
resources := codeView application isNil |
1671 |
ifTrue:[ codeView resources] |
|
1672 |
ifFalse:[ codeView application resources ]. |
|
1673 |
||
1674 |
choice := Dialog |
|
1675 |
choose:(resources string:'Choose ',what) |
|
1676 |
fromList:list |
|
1677 |
lines:20 |
|
1678 |
title:(resources string:'Code completion'). |
|
1679 |
choice isNil ifTrue:[^ nil]. |
|
4238 | 1680 |
]. |
1681 |
||
1682 |
LastChoices isNil ifTrue:[ |
|
4548 | 1683 |
LastChoices := Dictionary new. |
4238 | 1684 |
]. |
1685 |
LastChoices at:what put:choice. |
|
1686 |
^ choice |
|
1687 |
||
1688 |
"Created: / 10-11-2006 / 14:00:53 / cg" |
|
1689 |
! |
|
1690 |
||
4358 | 1691 |
classOfNode:aNode |
4548 | 1692 |
"when showing possible completions for a message, |
4422 | 1693 |
it is a good idea to know what the kind receiver is." |
4352 | 1694 |
|
4427 | 1695 |
| nm nodeVal receiverClass nodeSelector nodeReceiver mthd| |
4346 | 1696 |
|
4418 | 1697 |
aNode isBlock ifTrue:[ |
4548 | 1698 |
^ Block |
4418 | 1699 |
]. |
4422 | 1700 |
|
1701 |
(nodeVal := self valueOfNode:aNode) notNil ifTrue:[ |
|
4548 | 1702 |
"/ knowing the value is always great!! |
1703 |
^ nodeVal class |
|
4422 | 1704 |
]. |
1705 |
||
4358 | 1706 |
aNode isVariable ifTrue:[ |
4548 | 1707 |
nm := aNode name. |
1708 |
nm = 'self' ifTrue:[ |
|
1709 |
classOrNil isNil ifTrue:[^ UndefinedObject]. |
|
1710 |
^ classOrNil |
|
1711 |
]. |
|
1712 |
nm = 'super' ifTrue:[ |
|
1713 |
classOrNil isNil ifTrue:[^ Object]. |
|
1714 |
^ classOrNil superclass |
|
1715 |
]. |
|
4422 | 1716 |
|
1717 |
"/ classOrNil notNil ifTrue:[ |
|
1718 |
"/ (classOrNil allInstVarNames includes:nm) ifTrue:[ |
|
1719 |
"/ "/ could look at existing instances here... |
|
1720 |
"/ self breakPoint:#cg. |
|
1721 |
"/ ]. |
|
1722 |
"/ ]. |
|
4548 | 1723 |
^ nil |
4346 | 1724 |
]. |
1725 |
||
4358 | 1726 |
aNode isMessage ifTrue:[ |
4548 | 1727 |
nodeSelector := aNode selector. |
1728 |
nodeReceiver := aNode receiver. |
|
1729 |
||
1730 |
"/ some hardwired knowlegde here |
|
1731 |
receiverClass := self classOfNode:nodeReceiver. |
|
1732 |
receiverClass notNil ifTrue:[ |
|
1733 |
nodeSelector == #class ifTrue:[ |
|
1734 |
^ receiverClass class |
|
1735 |
]. |
|
1736 |
||
1737 |
receiverClass isBehavior ifTrue:[ |
|
1738 |
mthd := receiverClass lookupMethodFor:nodeSelector. |
|
1739 |
receiverClass isMeta ifTrue:[ |
|
1740 |
( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: nodeSelector ) ifTrue:[ |
|
1741 |
^ receiverClass theNonMetaclass |
|
1742 |
]. |
|
1743 |
"/ if that method sends one of new/basicNew/new:/basicNew:, assume it returns an instance of itself |
|
1744 |
mthd notNil ifTrue:[ |
|
1745 |
( mthd sendsAny:#( #'new' #'basicNew' #'new:' #'basicNew:' )) ifTrue:[ |
|
1746 |
^ receiverClass theNonMetaclass |
|
1747 |
]. |
|
1748 |
]. |
|
1749 |
] ifFalse:[ |
|
1750 |
mthd notNil ifTrue:[ |
|
1751 |
(ParseTreeSearcher methodIsSetterMethod:mthd) ifTrue:[ |
|
1752 |
^ receiverClass. |
|
1753 |
] |
|
1754 |
] |
|
1755 |
] |
|
1756 |
]. |
|
1757 |
]. |
|
1758 |
classOrNil notNil ifTrue:[ |
|
1759 |
(nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[ |
|
1760 |
^ classOrNil class |
|
1761 |
]. |
|
1762 |
]. |
|
1763 |
||
1764 |
(nodeSelector = #'asFilename') ifTrue:[ |
|
1765 |
^ Filename |
|
1766 |
]. |
|
1767 |
(nodeSelector = #'asOrderedCollection') ifTrue:[ |
|
1768 |
^ OrderedCollection |
|
1769 |
]. |
|
1770 |
(nodeSelector = #'asArray') ifTrue:[ |
|
1771 |
^ Array |
|
1772 |
]. |
|
1773 |
(nodeSelector = #'asSet') ifTrue:[ |
|
1774 |
^ Set |
|
1775 |
]. |
|
1776 |
(nodeSelector = #'size') ifTrue:[ |
|
1777 |
^ SmallInteger |
|
1778 |
]. |
|
1779 |
||
1780 |
"/ some wellknown boolean returners (need better type inference here) |
|
1781 |
(#( isNil notNil not isEmptyOrNil notEmptyOrNil notEmpty isEmpty |
|
1782 |
isBehavior isMeta |
|
1783 |
= ~= == ~~ > >= < <= |
|
1784 |
includes: contains: |
|
1785 |
and: or: |
|
1786 |
exists atEnd |
|
1787 |
) includes:nodeSelector ) ifTrue:[ |
|
1788 |
^ True "/ Boolean - not boolean; it does not contain the full protocol (would not find ifTrue:) |
|
1789 |
]. |
|
1790 |
||
1791 |
( #( + - * / // \\ ) includes:nodeSelector) ifTrue:[ |
|
1792 |
"/ assume numeric |
|
1793 |
^ Number |
|
1794 |
]. |
|
1795 |
||
1796 |
( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[ |
|
1797 |
"/ assume behavior |
|
1798 |
^ Behavior |
|
1799 |
]. |
|
4346 | 1800 |
]. |
1801 |
^ nil |
|
1802 |
||
1803 |
"Created: / 28-08-2013 / 16:34:53 / cg" |
|
1804 |
! |
|
1805 |
||
4382 | 1806 |
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock |
4352 | 1807 |
"looking for all symbols is way too much and inprecise; |
1808 |
experiment: only present symbols which are used by the class, |
|
4544 | 1809 |
and classes in that class category, or at least: implemented as method. |
1810 |
We'll see..." |
|
4352 | 1811 |
|
4382 | 1812 |
|sym possibleCompletions longest editAction start stop addSymbol |
1813 |
parentSelector parent symbolSelectorClass| |
|
4238 | 1814 |
|
4302 | 1815 |
"/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 1816 |
|
4382 | 1817 |
start := (nodeOrNil ? tokenOrNil) start. |
1818 |
stop := (nodeOrNil ? tokenOrNil) stop. |
|
4352 | 1819 |
(codeView characterAtCharacterPosition:stop) == $' ifTrue:[ |
4548 | 1820 |
^ self. |
4352 | 1821 |
]. |
1822 |
||
4382 | 1823 |
sym := (nodeOrNil ? tokenOrNil) value. |
4544 | 1824 |
possibleCompletions := Set new. |
4238 | 1825 |
|
4352 | 1826 |
addSymbol := |
4548 | 1827 |
[:aSymbol | |
1828 |
(aSymbol startsWith:sym) ifTrue:[ |
|
1829 |
(aSymbol = sym) ifFalse:[ |
|
1830 |
possibleCompletions add:aSymbol |
|
1831 |
]. |
|
1832 |
]. |
|
1833 |
]. |
|
4352 | 1834 |
|
4382 | 1835 |
(nodeOrNil notNil |
1836 |
and:[ (parent := nodeOrNil parent) notNil |
|
1837 |
and:[ parent isMessage ]]) ifTrue:[ |
|
4548 | 1838 |
parentSelector := parent selector. |
1839 |
( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[ |
|
1840 |
symbolSelectorClass := self classOfNode:parent receiver. |
|
1841 |
]. |
|
1842 |
( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[ |
|
1843 |
"/ assume that send-target will be self. |
|
1844 |
(methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[ |
|
1845 |
addSymbol value:(methodOrNil selector,'Changed'). |
|
1846 |
]. |
|
1847 |
symbolSelectorClass := classOrNil. |
|
1848 |
]. |
|
1849 |
( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[ |
|
1850 |
symbolSelectorClass := self classOfNode:parent arguments second. |
|
1851 |
]. |
|
1852 |
||
1853 |
symbolSelectorClass notNil ifTrue:[ |
|
1854 |
symbolSelectorClass withAllSuperclassesDo:[:cls | |
|
1855 |
cls ~~ Object ifTrue:[ |
|
1856 |
cls ~~ Model ifTrue:[ |
|
1857 |
cls methodDictionary keysDo:addSymbol. |
|
1858 |
] |
|
1859 |
] |
|
1860 |
] |
|
1861 |
]. |
|
4382 | 1862 |
]. |
1863 |
||
4368 | 1864 |
(considerAll or:[classOrNil isNil]) ifTrue:[ |
4548 | 1865 |
Smalltalk allClassesDo:[:cls | |
1866 |
cls theNonMetaclass methodDictionary keys do:addSymbol. |
|
1867 |
cls theMetaclass methodDictionary keys do:addSymbol. |
|
1868 |
]. |
|
1869 |
||
1870 |
"/ Symbol allInstancesDo:addSymbol. |
|
4368 | 1871 |
] ifFalse:[ |
4548 | 1872 |
Smalltalk allClassesInCategory:classOrNil do:[:cls | |
1873 |
cls theNonMetaclass instAndClassMethodsDo:[:mthd | |
|
1874 |
mthd usedSymbols do:addSymbol |
|
1875 |
] |
|
1876 |
]. |
|
4238 | 1877 |
]. |
4352 | 1878 |
|
4544 | 1879 |
possibleCompletions := possibleCompletions asOrderedCollection sort. |
4352 | 1880 |
|
1881 |
longest := possibleCompletions longestCommonPrefix. |
|
1882 |
possibleCompletions remove:longest ifAbsent:[]. |
|
1883 |
possibleCompletions addFirst: longest. |
|
1884 |
||
1885 |
editAction := |
|
4548 | 1886 |
[:chosenIndex | |
1887 |
|chosen oldSym oldLen newLen| |
|
1888 |
||
1889 |
chosen := possibleCompletions at:chosenIndex. |
|
1890 |
chosen notNil ifTrue:[ |
|
1891 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
1892 |
start := start + 1. |
|
1893 |
]. |
|
1894 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
1895 |
start := start + 1. |
|
1896 |
]. |
|
1897 |
||
1898 |
oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
1899 |
||
1900 |
codeView |
|
1901 |
undoableDo:[ |
|
1902 |
codeView replaceFromCharacterPosition:start to:stop with:chosen |
|
1903 |
] |
|
1904 |
info:'Completion'. |
|
1905 |
||
1906 |
(chosen startsWith:oldSym) ifTrue:[ |
|
1907 |
oldLen := stop - start + 1. |
|
1908 |
newLen := chosen size. |
|
1909 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
1910 |
codeView dontReplaceSelectionOnInput |
|
1911 |
]. |
|
1912 |
] |
|
1913 |
]. |
|
4352 | 1914 |
|
1915 |
actionBlock value:possibleCompletions value:editAction value:'symbol'. |
|
4238 | 1916 |
|
1917 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1918 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
1919 |
! |
|
1920 |
||
1921 |
codeCompletionForMessage:node into:actionBlock |
|
4548 | 1922 |
|selector srchClass implClass |
4416 | 1923 |
bestSelectors selector2 bestSelectors2 bestSelectors3 allBest best info numArgs |
4548 | 1924 |
newParts nSelParts oldLen newLen selectorParts |
1925 |
findBest parentNode nodeReceiver selectorsSentInCode split editAction parentNodeClassIfKnown |
|
4408 | 1926 |
receiverNodeClassIfKnown| |
4238 | 1927 |
|
4302 | 1928 |
"/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 1929 |
|
4620 | 1930 |
findBest := |
1931 |
[:node :selector | |
|
1932 |
|srchClass srchClasses bestSelectors bestPrefixes |
|
1933 |
allMessagesSentToVariable classesImplementingAllMessages| |
|
1934 |
||
1935 |
srchClass := self classOfNode:node. |
|
1936 |
||
1937 |
srchClass isNil ifTrue:[ |
|
1938 |
node isVariable ifTrue:[ |
|
1939 |
allMessagesSentToVariable := Set new. |
|
1940 |
rememberedNodes do:[:eachNode | |
|
1941 |
eachNode allMessageNodes do:[:eachMessage | |
|
1942 |
eachMessage receiver isVariable ifTrue:[ |
|
1943 |
eachMessage receiver name = node name ifTrue:[ |
|
1944 |
eachMessage selector ~= selector ifTrue:[ |
|
1945 |
allMessagesSentToVariable add:eachMessage selector |
|
1946 |
] |
|
4610 | 1947 |
] |
1948 |
] |
|
1949 |
] |
|
1950 |
]. |
|
4620 | 1951 |
allMessagesSentToVariable notEmpty ifTrue:[ |
1952 |
"/ consider classes which implement all those messages. |
|
1953 |
classesImplementingAllMessages := Smalltalk allImplementorsOf:(allMessagesSentToVariable first). |
|
1954 |
allMessagesSentToVariable do:[:eachSelector | |
|
1955 |
classesImplementingAllMessages := classesImplementingAllMessages |
|
1956 |
select:[:cls | cls implements:eachSelector]. |
|
1957 |
]. |
|
1958 |
srchClasses := classesImplementingAllMessages. |
|
1959 |
]. |
|
4610 | 1960 |
]. |
1961 |
]. |
|
4620 | 1962 |
bestSelectors := Set new. |
1963 |
srchClasses isEmptyOrNil ifTrue:[ srchClasses := Array with:srchClass ]. |
|
1964 |
srchClasses do:[:srchClass | |
|
1965 |
|bestForThisClass| |
|
1966 |
||
1967 |
bestForThisClass := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true. |
|
1968 |
bestForThisClass := self |
|
1969 |
withoutSelectorsUnlikelyFor:srchClass |
|
1970 |
from:bestForThisClass |
|
1971 |
forPartial:selector. |
|
1972 |
bestSelectors addAll:bestForThisClass. |
|
1973 |
]. |
|
1974 |
(bestSelectors includes:selector) ifTrue:[ |
|
1975 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
|
1976 |
]. |
|
1977 |
bestSelectors := bestSelectors asOrderedCollection. |
|
1978 |
bestSelectors |
|
4610 | 1979 |
]. |
4238 | 1980 |
|
1981 |
selector := node selector. |
|
4352 | 1982 |
parentNode := node parent. |
4408 | 1983 |
nodeReceiver := node receiver. |
4352 | 1984 |
|
4366 | 1985 |
"/ if there is already space before the cursor, and the parent node is not a message, |
4620 | 1986 |
"/ do not attempt to complete the current message. |
4366 | 1987 |
"/ If it is a message, we will look for parent-message completion also below (best2 stuff) |
4352 | 1988 |
(codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[ |
4610 | 1989 |
(parentNode notNil and:[ parentNode isMessage ]) ifFalse:[ |
1990 |
^ self. |
|
1991 |
]. |
|
4352 | 1992 |
]. |
1993 |
||
4620 | 1994 |
"/ only do this if the node-message has no parents around |
1995 |
node parentheses isEmptyOrNil ifTrue:[ |
|
1996 |
bestSelectors := findBest value:nodeReceiver value:selector. |
|
1997 |
] ifFalse:[ |
|
1998 |
bestSelectors := OrderedCollection new. |
|
1999 |
]. |
|
4548 | 2000 |
|
2001 |
"/ if the receiver is a real variable, |
|
4386 | 2002 |
"/ we can look for other messages being sent to that variable in the current method. |
4408 | 2003 |
"/ Also, if there is are assignment to it (like constants or '<class> new'), use that as a hint... |
4548 | 2004 |
(tree notNil |
4610 | 2005 |
and:[ nodeReceiver isVariable |
2006 |
and:[ nodeReceiver isSelf not |
|
2007 |
and:[ nodeReceiver isSuper not ]]]) |
|
4366 | 2008 |
ifTrue:[ |
4610 | 2009 |
|classesFromAssignmentsToReceiver otherMessagesToReceiver possibleClasses possibleClassesFromOtherSends| |
2010 |
||
2011 |
classesFromAssignmentsToReceiver := tree allAssignmentNodes |
|
2012 |
collect:[:eachAssignmentNode | |
|
2013 |
|cls| |
|
2014 |
||
2015 |
(nodeReceiver = eachAssignmentNode variable |
|
2016 |
and:[ (cls := self classOfNode:eachAssignmentNode value) notNil ] |
|
2017 |
) ifTrue:[ |
|
2018 |
cls |
|
2019 |
] ifFalse:[ |
|
2020 |
nil |
|
2021 |
] |
|
2022 |
] |
|
2023 |
thenSelect:[:classOrNil | classOrNil notNil]. |
|
2024 |
||
2025 |
possibleClasses := classesFromAssignmentsToReceiver. |
|
2026 |
||
2027 |
otherMessagesToReceiver := tree allMessageNodes |
|
2028 |
select:[:eachMessageNode | |
|
2029 |
nodeReceiver = eachMessageNode receiver |
|
2030 |
and:[ selector ~= eachMessageNode selector]] |
|
2031 |
thenCollect:[:eachNode | eachNode selector]. |
|
2032 |
otherMessagesToReceiver notEmpty ifTrue:[ |
|
2033 |
otherMessagesToReceiver := otherMessagesToReceiver asSet. |
|
2034 |
possibleClassesFromOtherSends := |
|
2035 |
Smalltalk allClassesForWhich: |
|
2036 |
[:cls | |
|
2037 |
cls isLoaded |
|
2038 |
and:[ otherMessagesToReceiver |
|
2039 |
conform:[:eachSelectorSent | cls includesSelector: "canUnderstand:" eachSelectorSent]] |
|
2040 |
]. |
|
2041 |
possibleClasses := possibleClasses , possibleClassesFromOtherSends. |
|
2042 |
]. |
|
2043 |
||
2044 |
"/ if the receiver is a class/classInstVar, |
|
2045 |
"/ include the class of its current value and UndefinedObject. |
|
2046 |
"/ This helps to complete class methods and (lazy) initializer code. |
|
2047 |
(classOrNil notNil) ifTrue:[ |
|
2048 |
|tryValue currentValue| |
|
2049 |
||
2050 |
tryValue := false. |
|
2051 |
(classOrNil theNonMetaclass allClassVarNames includes: nodeReceiver name) ifTrue:[ |
|
2052 |
tryValue := true. |
|
2053 |
currentValue := classOrNil theNonMetaclass classVarAt:nodeReceiver name. |
|
2054 |
] ifFalse:[ |
|
2055 |
(classOrNil isMeta and:[ classOrNil allInstVarNames includes: nodeReceiver name ]) ifTrue:[ |
|
2056 |
tryValue := true. |
|
2057 |
currentValue := classOrNil theNonMetaclass instVarNamed:nodeReceiver name. |
|
2058 |
]. |
|
2059 |
]. |
|
2060 |
tryValue ifTrue:[ |
|
2061 |
currentValue notNil ifTrue:[ possibleClasses := { UndefinedObject } , possibleClasses ]. |
|
2062 |
possibleClasses := { currentValue class } , possibleClasses. |
|
2063 |
]. |
|
2064 |
]. |
|
2065 |
||
2066 |
(possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[ |
|
2067 |
bestSelectors := Set new. |
|
2068 |
possibleClasses do:[:eachClass | |
|
2069 |
|bestSelectorsForClass| |
|
2070 |
||
2071 |
bestSelectorsForClass := Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true. |
|
2072 |
bestSelectors addAll:bestSelectorsForClass. |
|
2073 |
]. |
|
4619 | 2074 |
bestSelectors := bestSelectors asOrderedCollection. |
2075 |
||
2076 |
"/ if any of those is a prefix-keyword of the selector, |
|
2077 |
"/ do not offer it (i.e. ifTrue:ifFalse: is already present, don't offer ifTrue:ifFalse: again. |
|
2078 |
bestSelectors := bestSelectors reject: [:sel | (selector startsWith: sel) or: [selector endsWith: sel]]. |
|
4610 | 2079 |
]. |
4619 | 2080 |
]. |
4366 | 2081 |
|
4352 | 2082 |
"/ if we are behind a keyword messages colon, |
2083 |
"/ only look for matching prefix selectors; |
|
2084 |
"/ also, a good completion is to insert an argument; |
|
2085 |
"/ the name of the variable from the implementation, as comment, and selected might be a good one!! |
|
2086 |
selector isKeyword ifTrue:[ |
|
4610 | 2087 |
codeView characterBeforeCursor == $: ifTrue:[ |
2088 |
bestSelectors := bestSelectors select:[:sel | sel startsWith:selector]. |
|
2089 |
bestSelectors isEmpty ifTrue:[ |
|
2090 |
"/ nothing better around |
|
2091 |
|argIndex argNames impls| |
|
2092 |
||
2093 |
argIndex := node selectorParts size. |
|
2094 |
argNames := Set new. |
|
2095 |
impls := Smalltalk allImplementorsOf:selector. |
|
2096 |
impls size < 10 ifTrue:[ |
|
2097 |
impls do:[:eachImplClass | |
|
2098 |
|mthd argName| |
|
2099 |
||
2100 |
mthd := (eachImplClass compiledMethodAt:selector). |
|
2101 |
argName := mthd methodArgNames at:argIndex. |
|
2102 |
argNames add:(argName,' in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate). |
|
2103 |
]. |
|
2104 |
argNames notEmptyOrNil ifTrue: [ |
|
2105 |
argNames := argNames asOrderedCollection sort. |
|
2106 |
actionBlock |
|
2107 |
value:argNames |
|
2108 |
value:[:selIndex | |
|
2109 |
] |
|
2110 |
value: 'argument name hint'. |
|
2111 |
^ self. |
|
2112 |
] |
|
2113 |
] |
|
2114 |
] |
|
2115 |
]. |
|
4369 | 2116 |
] ifFalse:[ |
4610 | 2117 |
"/ when completing a non-keyword AND the parent is a keyword message, |
2118 |
"/ only consider longer keyword messages or unary messages |
|
2119 |
(parentNode notNil and:[ parentNode isMessage and:[parentNode selector isKeywordSelector ]]) ifTrue:[ |
|
2120 |
bestSelectors := bestSelectors select:[:sel | sel isUnarySelector ] |
|
2121 |
] |
|
4352 | 2122 |
]. |
2123 |
||
4358 | 2124 |
bestSelectors := bestSelectors asOrderedCollection sort:[:a :b | a size < b size]. |
4548 | 2125 |
(selector isUnarySelector |
2126 |
and:[ parentNode notNil |
|
4358 | 2127 |
and:[ parentNode isMessage ]]) ifTrue:[ |
4610 | 2128 |
(selector2 := parentNode selector) isKeywordSelector ifTrue:[ |
2129 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
|
2130 |
"/ i.e. look if there is a longer keyword possible |
|
2131 |
selector2 := selector2,selector. |
|
2132 |
bestSelectors2 := findBest value:parentNode receiver value:selector2. |
|
2133 |
bestSelectors2 := bestSelectors2 select:[:sel | sel isKeywordSelector and:[ sel startsWith:selector2]]. |
|
2134 |
bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size]. |
|
2135 |
bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel]. |
|
2136 |
] ifFalse:[ |
|
2137 |
|kwSels| |
|
2138 |
||
2139 |
"/ if its a unary message AND the parent is a unary or binary node, try again, sending the partial message |
|
2140 |
"/ as a keyword to the parent node. |
|
2141 |
"/ this is the case when after "foo binOp bar if", which should include ifTrue: in the result. |
|
2142 |
"/ transform from |
|
2143 |
"/ foo == (shift if) |
|
2144 |
"/ nonKWsel-msg(parent) |
|
2145 |
"/ / \ |
|
2146 |
"/ / \ |
|
2147 |
"/ rcvr sel-unary(node) |
|
2148 |
"/ / |
|
2149 |
"/ / |
|
2150 |
"/ arg |
|
2151 |
"/ |
|
2152 |
"/ into: |
|
2153 |
"/ (foo == shift) if |
|
2154 |
"/ |
|
2155 |
"/ nonKWsel-msg(parent) |
|
2156 |
"/ / \ |
|
2157 |
"/ / \ |
|
2158 |
"/ rcvr sel-unary(node) |
|
2159 |
"/ / |
|
2160 |
"/ / |
|
2161 |
"/ arg |
|
2162 |
||
2163 |
kwSels := findBest value:parentNode value:selector. |
|
2164 |
kwSels := kwSels select:[:sel | sel isKeywordSelector]. |
|
2165 |
||
2166 |
kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size]. |
|
2167 |
||
2168 |
bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel]. |
|
2169 |
||
2170 |
"/ these need to go to bestSelectors (see editAction) |
|
2171 |
parentNodeClassIfKnown := self classOfNode:parentNode. |
|
2172 |
(parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[ |
|
2173 |
"/ this is so common, that it deserves a special case: |
|
2174 |
"/ if we complete an if after some boolean message e.g '(a == b) if' |
|
2175 |
"/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic) |
|
2176 |
bestSelectors := self |
|
2177 |
withoutSelectorsUnlikelyFor:parentNodeClassIfKnown |
|
2178 |
from:bestSelectors |
|
2179 |
forPartial:selector. |
|
2180 |
kwSels := self |
|
2181 |
withoutSelectorsUnlikelyFor:parentNodeClassIfKnown |
|
2182 |
from:kwSels |
|
2183 |
forPartial:selector. |
|
2184 |
||
2185 |
"/ put keyword selectors in front, because they are very likely |
|
2186 |
bestSelectors := kwSels , bestSelectors. |
|
2187 |
] ifFalse:[ |
|
2188 |
"/ put them at the end |
|
2189 |
bestSelectors := bestSelectors , kwSels. |
|
2190 |
]. |
|
2191 |
] |
|
4358 | 2192 |
]. |
2193 |
||
4548 | 2194 |
(selector isUnarySelector |
4375 | 2195 |
and:[ node isMessage ]) ifTrue:[ |
4610 | 2196 |
receiverNodeClassIfKnown := self classOfNode:nodeReceiver. |
2197 |
(receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[ |
|
2198 |
"/ this is so common, that it deserves a special case: |
|
2199 |
"/ if we complete an if after some boolean message e.g '(a == b) if' |
|
2200 |
"/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic) |
|
2201 |
bestSelectors := self |
|
2202 |
withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown |
|
2203 |
from:bestSelectors |
|
2204 |
forPartial:selector. |
|
2205 |
]. |
|
4375 | 2206 |
]. |
4548 | 2207 |
(selector isUnarySelector |
4416 | 2208 |
and:[ parentNode notNil |
2209 |
and:[ parentNode isMessage |
|
2210 |
and:[ parentNode selector isKeyword ]]]) ifTrue:[ |
|
4610 | 2211 |
"/ completing an already existing keyword message with somthing starting with |
2212 |
"/ if, and, or or while. |
|
2213 |
"/ here, offer a special completion which inserts parenthesis / brackets around the already |
|
2214 |
"/ existing message. Do this only, if the existing message makes sense. |
|
2215 |
(( |
|
2216 |
#( 'ifTrue' 'ifFalse' 'and' 'or' 'whileTrue' 'whileFalse' ) |
|
2217 |
) contains:[:part | part startsWith:selector]) ifTrue:[ |
|
2218 |
(Smalltalk allImplementorsOf:parentNode selector) notEmpty ifTrue:[ |
|
2219 |
|selsP selsB| |
|
2220 |
||
2221 |
selsP := #( 'ifTrue:' 'ifFalse:' ) |
|
2222 |
select:[:sel | sel startsWith:selector] |
|
2223 |
thenCollect:[:sel | '() ',sel]. |
|
2224 |
selsB := #( 'whileTrue:' 'whileFalse:' ) |
|
2225 |
select:[:sel | sel startsWith:selector] |
|
2226 |
thenCollect:[:sel | '[] ',sel]. |
|
2227 |
bestSelectors3 := selsP , selsB. |
|
2228 |
]. |
|
2229 |
]. |
|
4421 | 2230 |
] ifFalse:[ |
4610 | 2231 |
"/ also offer adding brackets around a while expression |
2232 |
(node receiver isBlock) ifFalse:[ |
|
2233 |
|sels| |
|
2234 |
||
2235 |
sels := #( 'whileTrue:' 'whileFalse:' ) |
|
2236 |
select:[:sel | sel startsWith:selector] |
|
2237 |
thenCollect:[:sel | '[] ',sel]. |
|
2238 |
bestSelectors3 := sels. |
|
2239 |
]. |
|
4416 | 2240 |
]. |
4375 | 2241 |
|
4358 | 2242 |
allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()). |
4408 | 2243 |
|
4548 | 2244 |
split := |
4610 | 2245 |
[:list :splitHow | |
2246 |
|part1 part2 all| |
|
2247 |
||
2248 |
part1 := list select:splitHow. |
|
2249 |
part2 := list reject:splitHow. |
|
2250 |
part1 isEmpty ifTrue:[ |
|
2251 |
all := part2. |
|
2252 |
] ifFalse:[ |
|
2253 |
part2 isEmpty ifTrue:[ |
|
2254 |
all := part1. |
|
2255 |
] ifFalse:[ |
|
2256 |
all := part1 , part2. |
|
2257 |
] |
|
2258 |
]. |
|
2259 |
all |
|
2260 |
]. |
|
4388 | 2261 |
"/ sort: prefixes first. |
2262 |
selector2 notNil ifTrue:[ |
|
4610 | 2263 |
allBest := split value:allBest value:[:sel | (sel startsWith:selector) or:[sel startsWith:selector2]]. |
4388 | 2264 |
]. |
4358 | 2265 |
|
2266 |
"/ if receiver is super, always include the method's own selector |
|
4408 | 2267 |
nodeReceiver isSuper ifTrue:[ |
4610 | 2268 |
(tree isMethod) ifTrue:[ |
2269 |
|mSel| |
|
2270 |
||
2271 |
mSel := tree selector. |
|
2272 |
mSel notNil ifTrue:[ |
|
2273 |
(mSel startsWith:selector) ifTrue:[ |
|
2274 |
"/ already the word before the cursor? |
|
2275 |
(mSel ~= selector) ifTrue:[ |
|
2276 |
allBest remove:mSel ifAbsent:[]. |
|
2277 |
allBest addFirst:mSel. |
|
2278 |
] |
|
2279 |
] |
|
2280 |
] |
|
2281 |
] |
|
4238 | 2282 |
]. |
2283 |
||
4416 | 2284 |
allBest := (bestSelectors3 ? #()) , allBest. |
4238 | 2285 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
2286 |
||
2287 |
selectorsSentInCode notNil ifTrue:[ |
|
4610 | 2288 |
"/ the one's already sent in the code are moved to the top of the list. |
2289 |
allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel]. |
|
4238 | 2290 |
]. |
4548 | 2291 |
|
2292 |
"/ the one's which are a prefix are moved towards the top of the list |
|
2293 |
allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]]. |
|
2294 |
||
2295 |
"/false ifTrue:[ |
|
2296 |
"/ srchClass notNil ifTrue:[ |
|
2297 |
"/ implClass := srchClass whichClassIncludesSelector:best. |
|
2298 |
"/ ] ifFalse:[ |
|
2299 |
"/ implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
2300 |
"/ implClass size == 1 ifTrue:[ |
|
2301 |
"/ implClass := implClass first. |
|
2302 |
"/ ] ifFalse:[ |
|
2303 |
"/ implClass := nil |
|
2304 |
"/ ] |
|
2305 |
"/ ]. |
|
2306 |
"/ |
|
2307 |
"/ info := best storeString. |
|
2308 |
"/ implClass notNil ifTrue:[ |
|
2309 |
"/ info := implClass name , ' >> ' , info. |
|
2310 |
"/ ]. |
|
2311 |
"/ self information:info. |
|
2312 |
"/]. |
|
2313 |
||
2314 |
editAction := |
|
4610 | 2315 |
[:index | |
2316 |
|crsrPos chosen parentsToInsert| |
|
2317 |
||
2318 |
crsrPos := codeView characterPositionOfCursor. |
|
2319 |
chosen := allBest at:index. |
|
2320 |
||
2321 |
chosen ~= selector ifTrue:[ |
|
2322 |
(bestSelectors3 notNil and:[bestSelectors3 includes:chosen]) ifTrue:[ |
|
2323 |
parentsToInsert := chosen copyTo:2. |
|
2324 |
chosen := chosen copyFrom:4. |
|
2325 |
]. |
|
2326 |
||
2327 |
numArgs := chosen numArgs. |
|
2328 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[ |
|
2329 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
2330 |
] ifFalse:[ |
|
2331 |
selectorParts := node selectorParts. |
|
2332 |
]. |
|
2333 |
nSelParts := selectorParts size. |
|
2334 |
||
2335 |
newParts := chosen asCollectionOfSubstringsSeparatedBy:$:. |
|
2336 |
newParts := newParts select:[:part | part size > 0]. |
|
2337 |
||
2338 |
codeView |
|
2339 |
undoableDo:[ |
|
2340 |
|positionOfFirstArg newCursorPosition stop checkForArgumentTemplates |
|
2341 |
newPart oldPartialToken start| |
|
2342 |
||
2343 |
checkForArgumentTemplates := (selector isUnarySelector and:[chosen isKeywordSelector]). |
|
2344 |
numArgs > nSelParts ifTrue:[ |
|
2345 |
"/ new selector has more arguments; append them |
|
2346 |
stop := selectorParts last stop. |
|
2347 |
codeView deleteFromCharacterPosition:stop+1 to:crsrPos-1. |
|
2348 |
||
2349 |
"/ append the rest ... |
|
2350 |
numArgs downTo:nSelParts+1 do:[:idx | |
|
2351 |
|newPart| |
|
2352 |
||
2353 |
newPart := newParts at:idx. |
|
2354 |
newPart := newPart , ':'. |
|
2355 |
||
2356 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
|
2357 |
newPart := ':' , newPart. |
|
2358 |
]. |
|
2359 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
2360 |
||
2361 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
|
2362 |
"/ remember the leftMost replacement's end as new cursor position |
|
2363 |
newCursorPosition := stop + newPart size |
|
2364 |
]. |
|
2365 |
checkForArgumentTemplates := true. |
|
2366 |
]. |
|
2367 |
||
2368 |
"/ replace existing parts |
|
2369 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
2370 |
|skipColon| |
|
2371 |
||
2372 |
skipColon := 0. |
|
2373 |
newPart := newParts at:idx. |
|
2374 |
oldPartialToken := selectorParts at:idx. |
|
2375 |
start := oldPartialToken start. |
|
2376 |
stop := oldPartialToken stop. |
|
2377 |
||
2378 |
(chosen endsWith:$:) ifTrue:[ |
|
2379 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
2380 |
newPart := newPart , ':'. |
|
2381 |
] ifTrue:[ |
|
2382 |
skipColon := 1. |
|
2383 |
] |
|
2384 |
] ifFalse:[ |
|
2385 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
2386 |
newPart := newPart , ':' |
|
2387 |
] ifFalse:[ |
|
2388 |
|nextChar| |
|
2389 |
||
2390 |
nextChar := codeView characterAtCharacterPosition:stop+1. |
|
2391 |
nextChar isSeparator ifFalse:[ |
|
2392 |
nextChar == $. ifFalse:[ |
|
2393 |
newPart := newPart , ' ' |
|
2394 |
]. |
|
2395 |
] |
|
2396 |
] |
|
2397 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
|
2398 |
"/ ] ifFalse:[ |
|
2399 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
2400 |
]. |
|
2401 |
||
2402 |
oldPartialToken value ~= newPart ifTrue:[ |
|
2403 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
2404 |
||
2405 |
oldLen := stop - start + 1. |
|
2406 |
newLen := newPart size. |
|
2407 |
||
2408 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
2409 |
"/ remember the leftMost replacement's end as new cursor position |
|
2410 |
newCursorPosition := start + newPart size + skipColon. "/ (newLen-oldLen) + 1. |
|
2411 |
"/ codeView cursorToCharacterPosition:newCursorPosition. |
|
2412 |
]. |
|
2413 |
]. |
|
2414 |
newCursorPosition notNil ifTrue:[ |
|
2415 |
codeView cursorToCharacterPosition:newCursorPosition-1. |
|
2416 |
codeView cursorRight. "/ avoid going to the next line !! |
|
2417 |
]. |
|
2418 |
codeView dontReplaceSelectionOnInput. |
|
2419 |
||
2420 |
checkForArgumentTemplates ifTrue:[ |
|
2421 |
"/ add opening brackets, etc. |
|
2422 |
self insertAdditonalStuffAfterSelector:chosen. |
|
2423 |
]. |
|
2424 |
parentsToInsert notNil ifTrue:[ |
|
2425 |
|sav| |
|
2426 |
||
2427 |
sav := codeView characterPositionOfCursor-1. |
|
2428 |
codeView insertString:(parentsToInsert copyLast:1) atCharacterPosition:node receiver stop+1. |
|
2429 |
codeView insertString:(parentsToInsert copyFirst:1) atCharacterPosition:parentNode start. |
|
2430 |
codeView cursorToCharacterPosition:sav+2; cursorRight |
|
2431 |
]. |
|
2432 |
] |
|
2433 |
info:'Completion'. |
|
2434 |
]. |
|
2435 |
]. |
|
4238 | 2436 |
|
4352 | 2437 |
actionBlock value:allBest value:editAction value:nil. |
4238 | 2438 |
|
2439 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
2440 |
"Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4444 | 2441 |
"Modified: / 06-11-2013 / 16:40:51 / cg" |
4238 | 2442 |
! |
2443 |
||
4548 | 2444 |
codeCompletionForMethodSpec:node |
4238 | 2445 |
"completion in a method's selector pattern" |
2446 |
||
4548 | 2447 |
self |
2448 |
codeCompletionForMethodSpec:node |
|
2449 |
into: |
|
2450 |
[:suggestions :action :whatIsIt | |
|
2451 |
||
2452 |
|chosen| |
|
2453 |
||
2454 |
chosen := self askUserForCompletion:whatIsIt for:codeView |
|
2455 |
at:node start from:suggestions. |
|
2456 |
chosen notNil ifTrue:[ |
|
2457 |
action value:(suggestions indexOf:chosen) |
|
2458 |
]. |
|
2459 |
]. |
|
4352 | 2460 |
|
2461 |
"/ |crsrPos |
|
2462 |
"/ selectorSoFar matchingSelectors |
|
4548 | 2463 |
"/ selectors distances best rest |
2464 |
"/ allExistingMethods nameBag namesByCount selectors1 selectors2| |
|
4352 | 2465 |
"/ |
2466 |
"/ crsrPos := codeView characterPositionOfCursor - 1. |
|
2467 |
"/ |
|
2468 |
"/ selectorSoFar := ''. |
|
2469 |
"/ node selectorParts doWithIndex:[:partToken :argNr| |
|
2470 |
"/ |part| |
|
2471 |
"/ |
|
2472 |
"/ part := partToken value. |
|
2473 |
"/ selectorSoFar := selectorSoFar , part. |
|
2474 |
"/ |
|
2475 |
"/ (crsrPos >= partToken start |
|
2476 |
"/ and:[crsrPos <= partToken stop]) ifTrue:[ |
|
2477 |
"/ (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
2478 |
"/ matchingSelectors := Smalltalk allClasses |
|
2479 |
"/ inject:(Set new) |
|
2480 |
"/ into:[:theSet :eachClass | |
|
2481 |
"/ |md| |
|
2482 |
"/ |
|
2483 |
"/ md := eachClass theMetaclass methodDictionary. |
|
2484 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2485 |
"/ theSet. |
|
2486 |
"/ ]. |
|
2487 |
"/ "/ dont forget the stuff in the class-line |
|
2488 |
"/ Metaclass withAllSuperclassesDo:[:cls | |
|
2489 |
"/ matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2490 |
"/ ]. |
|
2491 |
"/ ] ifFalse:[ |
|
2492 |
"/ matchingSelectors := Smalltalk allClasses |
|
2493 |
"/ inject:(Set new) |
|
2494 |
"/ into:[:theSet :eachClass | |
|
2495 |
"/ |md| |
|
2496 |
"/ |
|
2497 |
"/ md := eachClass theNonMetaclass methodDictionary. |
|
2498 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2499 |
"/ theSet. |
|
2500 |
"/ ]. |
|
2501 |
"/ ]. |
|
2502 |
"/ selectors := matchingSelectors asOrderedCollection. |
|
2503 |
"/ |
|
4548 | 2504 |
"/ "/ if there is only one, and user has already entered it, he might want to complete the argument-name |
2505 |
"/ (selectors size == 1 |
|
4352 | 2506 |
"/ and:[selectors first = selectorSoFar]) ifTrue:[ |
2507 |
"/ selectorSoFar numArgs == 0 ifTrue:[ ^ self ]. |
|
2508 |
"/ |
|
2509 |
"/ allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
2510 |
"/ collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
2511 |
"/ nameBag := Bag new. |
|
2512 |
"/ allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
4548 | 2513 |
"/ namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
2514 |
"/ "/ take the one which occurs most often |
|
4352 | 2515 |
"/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]). |
2516 |
"/ |
|
2517 |
"/ codeView |
|
2518 |
"/ undoableDo:[ |
|
2519 |
"/ (crsrPos+1) >= codeView contents size ifTrue:[ |
|
2520 |
"/ codeView paste:best. |
|
2521 |
"/ ] ifFalse:[ |
|
2522 |
"/ codeView insertString:best atCharacterPosition:crsrPos+1. |
|
2523 |
"/ ] |
|
2524 |
"/ ] |
|
2525 |
"/ info:'completion'. |
|
4548 | 2526 |
"/ codeView cursorToCharacterPosition:(crsrPos + best size - 1). |
4352 | 2527 |
"/ ] ifFalse:[ |
2528 |
"/ "the ones implemented in superclasses are shown first" |
|
2529 |
"/ classOrNil notNil ifTrue:[ |
|
2530 |
"/ selectors1 := selectors select:[:sel | classOrNil respondsTo:sel]. "/ in super |
|
2531 |
"/ selectors2 := selectors reject:[:sel | selectors1 includes:sel ]. "/ not in super |
|
2532 |
"/ ] ifFalse:[ |
|
2533 |
"/ selectors1 := selectors |
|
2534 |
"/ ]. |
|
2535 |
"/ |
|
2536 |
"/ distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2537 |
"/ distances sortWith:selectors1. |
|
2538 |
"/ selectors1 reverse. |
|
2539 |
"/ selectors := selectors1. |
|
2540 |
"/ |
|
2541 |
"/ selectors2 notEmptyOrNil ifTrue:[ |
|
2542 |
"/ distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2543 |
"/ distances sortWith:selectors2. |
|
2544 |
"/ selectors2 reverse. |
|
2545 |
"/ selectors1 := selectors1 collect:[:sel | sel allBold]. |
|
2546 |
"/ selectors := selectors1,selectors2. |
|
2547 |
"/ ]. |
|
4548 | 2548 |
"/ |
4352 | 2549 |
"/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors. |
2550 |
"/ best isNil ifTrue:[^ self]. |
|
2551 |
"/ |
|
2552 |
"/ rest := best copyFrom:selectorSoFar size. |
|
2553 |
"/ codeView |
|
4548 | 2554 |
"/ undoableDo:[ |
2555 |
"/ codeView |
|
2556 |
"/ replaceFromCharacterPosition:crsrPos+1 |
|
2557 |
"/ to:crsrPos+1 |
|
2558 |
"/ with:rest |
|
4352 | 2559 |
"/ ] |
2560 |
"/ info:'Completion'. |
|
4548 | 2561 |
"/ codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
4352 | 2562 |
"/ ]. |
4548 | 2563 |
"/ codeView cursorRight. "/ kludge to make it visible |
4352 | 2564 |
"/ ]. |
2565 |
"/ ]. |
|
4238 | 2566 |
|
2567 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
2568 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
2569 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2570 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
2571 |
! |
|
2572 |
||
4352 | 2573 |
codeCompletionForMethodSpec:node into:actionBlock |
4238 | 2574 |
"completion in a method's selector pattern" |
2575 |
||
4370 | 2576 |
|crsrPos crsrLine crsrCol |
4238 | 2577 |
selectorSoFar matchingSelectors |
4548 | 2578 |
selectors distances best rest |
4437 | 2579 |
allExistingMethods nameBag namesByCount selectors1 selectors2 selectors0 |
4691 | 2580 |
editAction argNames selectorsForVars |
2581 |
selectorTypedSoFar| |
|
4238 | 2582 |
|
4437 | 2583 |
selectors := OrderedCollection new. |
4548 | 2584 |
selectors0 := OrderedCollection new. |
2585 |
||
2586 |
"/ Transcript showCR:'m'. |
|
4370 | 2587 |
crsrLine := codeView cursorLine. |
2588 |
crsrCol := codeView cursorCol. |
|
4238 | 2589 |
crsrPos := codeView characterPositionOfCursor - 1. |
2590 |
||
4691 | 2591 |
selectorTypedSoFar := node selector. |
2592 |
selectorTypedSoFar isUnarySelector ifTrue:[ |
|
4618 | 2593 |
"/ user has just begun to edit a selector. |
2594 |
"/ often, a good completion are the names of instVars for which no corresponding getter/setter exists |
|
2595 |
classOrNil notNil ifTrue:[ |
|
2596 |
selectorsForVars := OrderedCollection new. |
|
2597 |
classOrNil instVarNames do:[:nm | |
|
4691 | 2598 |
(nm startsWith:selectorTypedSoFar) ifTrue:[ |
4618 | 2599 |
(classOrNil implements:nm asSymbol) ifFalse:[ selectorsForVars add:nm]. |
2600 |
(classOrNil implements:nm asMutator) ifFalse:[ selectorsForVars add:(nm,':')]. |
|
2601 |
] |
|
2602 |
]. |
|
2603 |
classOrNil isMeta ifTrue:[ |
|
2604 |
classOrNil theNonMetaclass classVarNames do:[:nm | |
|
2605 |
|nmSel| |
|
2606 |
||
2607 |
nmSel := nm asLowercaseFirst. |
|
4691 | 2608 |
(nmSel startsWith:selectorTypedSoFar) ifTrue:[ |
4618 | 2609 |
(classOrNil implements:nmSel asSymbol) ifFalse:[ selectorsForVars add:nmSel]. |
2610 |
(classOrNil implements:nmSel asMutator) ifFalse:[ selectorsForVars add:(nmSel,':')]. |
|
2611 |
] |
|
2612 |
]. |
|
2613 |
] ifFalse:[ |
|
2614 |
"/ isXXX ? |
|
4691 | 2615 |
(('is',classOrNil nameWithoutPrefix) startsWith:selectorTypedSoFar ) ifTrue:[ |
4618 | 2616 |
selectors0 add:('is',classOrNil nameWithoutPrefix). |
2617 |
]. |
|
2618 |
]. |
|
4691 | 2619 |
|
2620 |
"/ and also messages sent by the class itself |
|
2621 |
classOrNil methodsDo:[:m | |
|
2622 |
m messagesSentToSelf do:[:sel | |
|
2623 |
(sel startsWith:selectorTypedSoFar) ifTrue:[ |
|
2624 |
(classOrNil implements:sel) ifFalse:[ selectorsForVars add:sel]. |
|
2625 |
] |
|
2626 |
] |
|
2627 |
]. |
|
2628 |
classOrNil isMeta ifFalse:[ |
|
2629 |
classOrNil theMetaclass methodsDo:[:m | |
|
2630 |
m messagesSent do:[:sel | |
|
2631 |
(sel startsWith:selectorTypedSoFar) ifTrue:[ |
|
2632 |
(classOrNil implements:sel) ifFalse:[ selectorsForVars add:sel]. |
|
2633 |
] |
|
2634 |
] |
|
2635 |
] |
|
2636 |
]. |
|
4618 | 2637 |
]. |
4371 | 2638 |
]. |
2639 |
||
4238 | 2640 |
selectorSoFar := ''. |
2641 |
node selectorParts doWithIndex:[:partToken :argNr| |
|
4618 | 2642 |
|part| |
2643 |
||
2644 |
part := partToken value. |
|
2645 |
selectorSoFar := selectorSoFar , part. |
|
2646 |
||
2647 |
(crsrPos >= partToken start |
|
2648 |
and:[crsrPos <= partToken stop]) ifTrue:[ |
|
2649 |
(classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
2650 |
matchingSelectors := Smalltalk allClasses |
|
2651 |
inject:(Set new) |
|
2652 |
into:[:theSet :eachClass | |
|
2653 |
|md| |
|
2654 |
||
2655 |
md := eachClass theMetaclass methodDictionary. |
|
2656 |
theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2657 |
theSet. |
|
2658 |
]. |
|
2659 |
"/ dont forget the stuff in the class-line |
|
2660 |
Metaclass withAllSuperclassesDo:[:cls | |
|
2661 |
matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2662 |
]. |
|
2663 |
] ifFalse:[ |
|
2664 |
matchingSelectors := Smalltalk allClasses |
|
2665 |
inject:(Set new) |
|
2666 |
into:[:theSet :eachClass | |
|
2667 |
|md| |
|
2668 |
||
2669 |
md := eachClass theNonMetaclass methodDictionary. |
|
2670 |
theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2671 |
theSet. |
|
2672 |
]. |
|
2673 |
]. |
|
2674 |
||
2675 |
selectors addAll:matchingSelectors. |
|
2676 |
selectorsForVars notNil ifTrue:[ selectors addAll:selectorsForVars ]. |
|
2677 |
||
2678 |
selectors := selectors sort:[:a :b | a size < b size]. |
|
2679 |
selectors size > 100 ifTrue:[ |
|
2680 |
selectors := selectors copyTo:100. |
|
2681 |
]. |
|
2682 |
||
2683 |
||
2684 |
"/ if there is only one, and user has already entered it, |
|
2685 |
"/ he might want to complete the argument-name |
|
2686 |
(selectors size == 1 |
|
2687 |
and:[selectors first = selectorSoFar]) ifTrue:[ |
|
2688 |
selectorSoFar numArgs == 0 ifTrue:[ ^ self ]. |
|
2689 |
||
2690 |
allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
2691 |
collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
2692 |
nameBag := Bag new. |
|
2693 |
allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
2694 |
namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
|
2695 |
"/ take the one which occurs most often |
|
2696 |
"/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]). |
|
2697 |
argNames := (namesByCount collect:[:a | a key]). |
|
2698 |
editAction := |
|
2699 |
[:chosenIndex | |
|
2700 |
|chosenName| |
|
2701 |
||
2702 |
chosenName := argNames at:chosenIndex. |
|
2703 |
codeView |
|
2704 |
undoableDo:[ |
|
2705 |
(crsrPos+1) >= codeView contents size ifTrue:[ |
|
2706 |
codeView paste:chosenName. |
|
2707 |
codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1). |
|
2708 |
] ifFalse:[ |
|
2709 |
codeView cursorToCharacterPosition:crsrPos. |
|
2710 |
codeView cursorRight. |
|
2711 |
codeView insertStringAtCursor:chosenName. |
|
2712 |
codeView selectFromCharacterPosition:crsrPos+1 to:crsrPos+1+chosenName size-1. |
|
2713 |
codeView dontReplaceSelectionOnInput |
|
2714 |
]. |
|
2715 |
] |
|
2716 |
info:'completion'. |
|
2717 |
]. |
|
2718 |
actionBlock |
|
2719 |
value:argNames |
|
2720 |
value:editAction |
|
2721 |
value:'argument'. |
|
2722 |
||
2723 |
^ self. |
|
2724 |
||
2725 |
]. |
|
2726 |
||
2727 |
"the ones implemented in superclasses are shown first" |
|
2728 |
classOrNil notNil ifTrue:[ |
|
2729 |
selectors1 := selectors select:[:sel | classOrNil respondsTo:sel]. "/ in super |
|
2730 |
selectors2 := selectors reject:[:sel | selectors1 includes:sel ]. "/ not in super |
|
2731 |
] ifFalse:[ |
|
2732 |
selectors1 := selectors |
|
2733 |
]. |
|
2734 |
||
2735 |
distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2736 |
distances sortWith:selectors1. |
|
2737 |
selectors1 reverse. |
|
2738 |
selectors := selectors1. |
|
2739 |
||
2740 |
selectors2 notEmptyOrNil ifTrue:[ |
|
2741 |
distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2742 |
distances sortWith:selectors2. |
|
2743 |
selectors2 reverse. |
|
2744 |
selectors1 := selectors1 collect:[:sel | sel allBold]. |
|
2745 |
selectors := selectors1,selectors2. |
|
2746 |
]. |
|
2747 |
selectors0 notEmptyOrNil ifTrue:[ |
|
2748 |
selectors := selectors0,selectors. |
|
2749 |
]. |
|
2750 |
||
2751 |
editAction := |
|
2752 |
[:selectedCompletionIndex | |
|
2753 |
||
2754 |
best := selectors at:selectedCompletionIndex. |
|
2755 |
rest := best copyFrom:selectorSoFar size + 1. |
|
2756 |
codeView |
|
2757 |
undoableDo:[ |
|
2758 |
codeView insertString:rest atLine:crsrLine col:crsrCol. |
|
2759 |
] |
|
2760 |
info:'Completion'. |
|
2761 |
codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
|
2762 |
codeView cursorRight. "/ kludge to make it visible |
|
2763 |
]. |
|
2764 |
||
2765 |
"/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors. |
|
2766 |
actionBlock |
|
2767 |
value:selectors |
|
2768 |
value:editAction |
|
2769 |
value:'selector'. |
|
2770 |
]. |
|
4238 | 2771 |
]. |
2772 |
||
2773 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
2774 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
2775 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2776 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
2777 |
! |
|
2778 |
||
2779 |
codeCompletionForVariable:node into:actionBlock |
|
2780 |
|nonMetaClass crsrPos nm parent |
|
2781 |
allVariables allDistances variablesAlreadyAdded nodeVal |
|
4548 | 2782 |
char oldLen newLen |
4485 | 2783 |
getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc |
4366 | 2784 |
globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart |
4620 | 2785 |
editAction suggestions nameIsOK longerNames setOfNames otherArgNames |
2786 |
suggestionsWithInfo| |
|
4238 | 2787 |
|
4302 | 2788 |
"/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 2789 |
classOrNil notNil ifTrue:[ |
4559 | 2790 |
nonMetaClass := classOrNil theNonMetaclass. |
4238 | 2791 |
]. |
2792 |
||
2793 |
nm := node name. |
|
2794 |
||
2795 |
"/ if we are behind the variable and a space has already been entered, |
|
2796 |
"/ the user is probably looking for a message selector. |
|
2797 |
"/ If the variable represents a global, present its instance creation messages |
|
2798 |
crsrPos := codeView characterPositionOfCursor. |
|
2799 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
|
2800 |
char isSeparator ifTrue:[ |
|
4559 | 2801 |
nm knownAsSymbol ifTrue:[ |
2802 |
classOrNil isNil ifTrue:[ |
|
2803 |
nodeVal := Smalltalk at:nm asSymbol. |
|
2804 |
] ifFalse:[ |
|
2805 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
2806 |
]. |
|
2807 |
nodeVal isBehavior ifTrue:[ |
|
2808 |
|methods selectors menu exitKey idx| |
|
2809 |
||
2810 |
methods := nodeVal class methodDictionary values |
|
2811 |
select:[:m | |cat| |
|
2812 |
cat := m category asLowercase. |
|
2813 |
cat = 'instance creation' |
|
2814 |
]. |
|
2815 |
selectors := methods collect:[:each | each selector]. |
|
2816 |
editAction := |
|
2817 |
[:answer | |
|
2818 |
|s| |
|
2819 |
s := answer isInteger ifTrue:[selectors at:answer] ifFalse:[answer]. |
|
2820 |
codeView |
|
2821 |
undoableDo:[ |
|
2822 |
codeView insertString:s atCharacterPosition:crsrPos. |
|
2823 |
codeView cursorToCharacterPosition:crsrPos+s size. |
|
2824 |
] |
|
2825 |
info:'completion'. |
|
2826 |
]. |
|
2827 |
actionBlock |
|
2828 |
value:selectors |
|
2829 |
value:editAction |
|
2830 |
value:nil. |
|
2831 |
^ self. |
|
2832 |
]. |
|
2833 |
]. |
|
4238 | 2834 |
]. |
2835 |
||
2836 |
parent := node parent. |
|
2837 |
(parent notNil and:[parent isMessage]) ifTrue:[ |
|
4559 | 2838 |
node == parent receiver ifTrue:[ |
2839 |
selectorOfMessageToNode := parent selector |
|
2840 |
] |
|
4238 | 2841 |
]. |
2842 |
||
4352 | 2843 |
"/ this is pure voodoo magic (tries to make a good spelling weight, |
2844 |
"/ by weighting the number of startsWith characters into the spelling distance...) |
|
4238 | 2845 |
getDistanceComputeBlockWithWeight := |
4559 | 2846 |
[:weight | |
2847 |
[:each | |
|
2848 |
|dist factor| |
|
2849 |
||
2850 |
dist := each spellAgainst:nm. |
|
2851 |
factor := 1. |
|
2852 |
||
2853 |
(each startsWith:nm) ifTrue:[ |
|
2854 |
factor := 6 * nm size. |
|
2855 |
] ifFalse:[ |
|
2856 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
2857 |
factor := 4 * nm size. |
|
2858 |
]. |
|
2859 |
]. |
|
2860 |
dist := dist + (weight*factor). |
|
2861 |
||
2862 |
each -> (dist * weight) |
|
2863 |
] |
|
2864 |
]. |
|
4238 | 2865 |
|
2866 |
nameIsOK := false. |
|
2867 |
addWithFactorBlock := |
|
4559 | 2868 |
[:eachNames :factor | |
4689 | 2869 |
|distanceComputeBlock| |
2870 |
||
2871 |
distanceComputeBlock := (getDistanceComputeBlockWithWeight value:factor). |
|
4559 | 2872 |
(eachNames includes:nm) ifTrue:[nameIsOK := true]. |
2873 |
eachNames do:[:nameToAdd | |
|
2874 |
(nameToAdd ~= nm) ifTrue:[ "/ not again |
|
2875 |
(variablesAlreadyAdded includes:nameToAdd) ifFalse:[ "/ not again |
|
2876 |
variablesAlreadyAdded add:nameToAdd. |
|
2877 |
allVariables add:nameToAdd. |
|
4689 | 2878 |
allDistances add:(distanceComputeBlock value:nameToAdd). |
4559 | 2879 |
] |
2880 |
] |
|
2881 |
] |
|
2882 |
]. |
|
4238 | 2883 |
|
2884 |
nm isUppercaseFirst ifTrue:[ |
|
4559 | 2885 |
globalFactor := 2. "/ favour globals |
2886 |
localFactor := 1. |
|
4238 | 2887 |
] ifFalse:[ |
4559 | 2888 |
globalFactor := 1. "/ favour locals |
2889 |
localFactor := 2. |
|
4238 | 2890 |
]. |
2891 |
||
2892 |
variablesAlreadyAdded := Set new. |
|
2893 |
allVariables := OrderedCollection new. |
|
2894 |
allDistances := OrderedCollection new. |
|
2895 |
||
2896 |
"/ are we in the method's selector spec ? |
|
4548 | 2897 |
(parent notNil |
4238 | 2898 |
and:[parent isMethod |
2899 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
4559 | 2900 |
"/ yes - |
2901 |
"/ now thats cool: look how the name of this argument is in other implementations |
|
2902 |
"/ of this method, and take that as a basis of the selection |
|
2903 |
||
2904 |
implementors := SystemBrowser |
|
2905 |
findImplementorsOf:(parent selector) |
|
2906 |
in:(Smalltalk allClasses) |
|
2907 |
ignoreCase:false. |
|
2908 |
"/ which argument is it |
|
2909 |
argIdx := parent arguments indexOf:node. |
|
2910 |
implementors size > 50 ifTrue:[ |
|
2911 |
implementors := implementors asOrderedCollection copyTo:50. |
|
2912 |
]. |
|
2913 |
namesUsed := implementors |
|
2914 |
collect:[:eachImplementor | |
|
2915 |
|parseTree| |
|
2916 |
parseTree := eachImplementor parseTree. |
|
2917 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
2918 |
ifFalse:nil |
|
2919 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
2920 |
thenSelect:[:a | a notNil]. |
|
2921 |
||
2922 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
2923 |
||
2924 |
classOrNil notNil ifTrue:[ |
|
2925 |
"/ also, look for the keyword before the argument, |
|
2926 |
"/ and see if there is such an instVar |
|
2927 |
"/ if so, add it with -Arg |
|
2928 |
parent selector isKeyword ifTrue:[ |
|
2929 |
kwPart := parent selector keywords at:argIdx. |
|
2930 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
|
2931 |
addWithFactorBlock |
|
2932 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
2933 |
value:(1 * localFactor). |
|
2934 |
]. |
|
2935 |
]. |
|
2936 |
"/ look for the variable names of any other method in that class |
|
2937 |
otherArgNames := Set new. |
|
2938 |
classOrNil methodDictionary keysAndValuesDo:[:sel :mthd | |
|
2939 |
|parseTree| |
|
2940 |
parseTree := mthd parseTree. |
|
2941 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
2942 |
ifFalse:nil |
|
2943 |
ifTrue:[ otherArgNames addAll:(parseTree arguments collect:[:each | each name])] ]. |
|
2944 |
addWithFactorBlock value:otherArgNames value:(1.5 * localFactor). |
|
2945 |
]. |
|
2946 |
addWithFactorBlock value:(codeView previousReplacements collect:[:p | p value asString]) value:(1.3 * localFactor). |
|
4238 | 2947 |
] ifFalse:[ |
4559 | 2948 |
"/ locals in the block/method |
2949 |
|names| |
|
2950 |
||
2951 |
names := OrderedCollection withAll:node allVariablesOnScope. |
|
2952 |
setOfNames := Set withAll:names. |
|
2953 |
||
2954 |
rememberedScopeNodes notNil ifTrue:[ |
|
2955 |
"/ notNil when a parseError occurred. |
|
2956 |
rememberedScopeNodes do:[:eachScope | |
|
2957 |
(eachScope isMethod or:[eachScope isBlock]) ifTrue:[ |
|
2958 |
eachScope argumentNames do:[:eachName | |
|
2959 |
(setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ] |
|
2960 |
] |
|
2961 |
] ifFalse:[ |
|
2962 |
eachScope isSequence ifTrue:[ |
|
2963 |
eachScope temporaryNames do:[:eachName | |
|
2964 |
(setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ] |
|
2965 |
] |
|
2966 |
] ifFalse:[ |
|
2967 |
] |
|
2968 |
]. |
|
2969 |
"/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt]. |
|
2970 |
]. |
|
2971 |
rememberedScopeNodes do:[:eachScope | |
|
2972 |
eachScope variableNodesDo:[:var | |
|
2973 |
(setOfNames includes:var name) ifFalse:[ |
|
2974 |
names add:var name. setOfNames add:var name |
|
2975 |
] |
|
2976 |
] |
|
2977 |
] |
|
2978 |
] ifFalse:[ |
|
2979 |
"/ tree must be there |
|
2980 |
tree variableNodesDo:[:var | |
|
2981 |
(setOfNames includes:var name) ifFalse:[ |
|
2982 |
names add:var name. setOfNames add:var name |
|
2983 |
] |
|
2984 |
] |
|
2985 |
]. |
|
2986 |
||
2987 |
addWithFactorBlock value:names value:(4 * localFactor). |
|
2988 |
||
2989 |
classOrNil notNil ifTrue:[ |
|
2990 |
"/ instance variables |
|
2991 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
2992 |
||
2993 |
"/ inherited instance variables |
|
2994 |
classOrNil superclass notNil ifTrue:[ |
|
2995 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
2996 |
]. |
|
2997 |
]. |
|
2998 |
||
2999 |
"/ magic: |
|
3000 |
"/ if the node to be expanded is the receiver in a message, look for the selector sent to it |
|
3001 |
"/ give names which respond to those messages a higher weight |
|
3002 |
selectorOfMessageToNode notNil ifTrue:[ |
|
3003 |
|responders nonResponders| |
|
3004 |
||
3005 |
"/ responding to that messsage |
|
4365 | 3006 |
"/ self halt. |
4559 | 3007 |
classOrNil notNil ifTrue:[ |
3008 |
"/ private classes |
|
3009 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3010 |
value:(2.75 * globalFactor). |
|
3011 |
||
3012 |
"/ class variables |
|
3013 |
names := nonMetaClass classVarNames. |
|
3014 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3015 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3016 |
||
3017 |
addWithFactorBlock value:responders value:(3.0 * globalFactor). |
|
3018 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3019 |
||
3020 |
"/ superclass var names |
|
3021 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
3022 |
names := superClass classVarNames. |
|
3023 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3024 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3025 |
||
3026 |
addWithFactorBlock value:responders value:(2.75 * globalFactor). |
|
3027 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
3028 |
]. |
|
3029 |
||
3030 |
"/ namespace vars |
|
3031 |
classOrNil topNameSpace ~~ Smalltalk ifTrue:[ |
|
3032 |
names := classOrNil topNameSpace keys. |
|
3033 |
names := names reject:[:nm | nm includes:$:]. |
|
3034 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3035 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3036 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3037 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
3038 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3039 |
]. |
|
3040 |
]. |
|
3041 |
||
3042 |
"/ globals |
|
3043 |
names := Smalltalk keys. |
|
3044 |
names := names reject: |
|
3045 |
[:nm | |
|
3046 |
(nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not] |
|
3047 |
]. |
|
3048 |
names := names reject:[:nm | nm startsWith:'Undeclared:::' ]. |
|
3049 |
||
3050 |
names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection. |
|
3051 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3052 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3053 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
3054 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3055 |
||
3056 |
classOrNil notNil ifTrue:[ |
|
3057 |
"/ pool variables |
|
3058 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3059 |
|pool names| |
|
3060 |
||
3061 |
pool := Smalltalk at:poolName. |
|
3062 |
names := pool classVarNames. |
|
3063 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3064 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3065 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3066 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
3067 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
3068 |
]. |
|
3069 |
] |
|
3070 |
] ifFalse:[ |
|
3071 |
classOrNil notNil ifTrue:[ |
|
3072 |
"/ private classes |
|
3073 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3074 |
value:(2.75 * globalFactor). |
|
3075 |
||
3076 |
"/ class variables |
|
3077 |
addWithFactorBlock value:nonMetaClass classVarNames value:(3.0 * globalFactor). |
|
3078 |
nonMetaClass superclass notNil ifTrue:[ |
|
3079 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.5 * globalFactor). |
|
3080 |
]. |
|
3081 |
||
3082 |
"/ namespace vars |
|
3083 |
classOrNil topNameSpace ~~ Smalltalk ifTrue:[ |
|
3084 |
names := classOrNil topNameSpace keys. |
|
3085 |
names := names reject:[:nm | nm includes:$:]. |
|
3086 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3087 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3088 |
]. |
|
3089 |
"/ namespace vars |
|
3090 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
3091 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
3092 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3093 |
names := names reject:[:nm | nm includes:$:]. |
|
3094 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3095 |
]. |
|
3096 |
||
3097 |
"/ pool variables |
|
3098 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3099 |
|pool names| |
|
3100 |
||
3101 |
pool := Smalltalk at:poolName. |
|
3102 |
pool isNil ifTrue:[ |
|
3103 |
Transcript showCR:'non existent pool: ',poolName |
|
3104 |
] ifFalse:[ |
|
3105 |
names := pool classVarNames. |
|
3106 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3107 |
] |
|
3108 |
]. |
|
3109 |
]. |
|
3110 |
||
3111 |
"/ globals |
|
4665 | 3112 |
names := OrderedCollection new. |
3113 |
Smalltalk keysDo:[:k | |
|
3114 |
(k isUppercaseFirst |
|
3115 |
and:[ (k startsWith:'Undeclared:::') not |
|
3116 |
and:[ ((k includes:$:) and:[ (k includesString:'::') not]) not ]]) ifTrue:[ |
|
3117 |
names add:k |
|
3118 |
] |
|
3119 |
]. |
|
4559 | 3120 |
|
3121 |
"/ only consider all globals, if the first char of the completed name is uppercase; |
|
3122 |
"/ otherwise, only consider names with a caseInsensitve prefix match |
|
4665 | 3123 |
nm first isUppercase ifFalse:[ |
4559 | 3124 |
names := names select:[:globalName | globalName asLowercase startsWith: nm]. |
3125 |
]. |
|
3126 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
3127 |
]. |
|
3128 |
||
3129 |
"/ pseudos - assuming that thisContext is seldom used. |
|
3130 |
"/ also assuming, that nil is short so its usually typed in. |
|
3131 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
3132 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
3133 |
addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor). |
|
3134 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
|
4238 | 3135 |
]. |
3136 |
||
3137 |
allDistances isEmpty ifTrue:[^ self]. |
|
3138 |
||
4410 | 3139 |
"/ nope (foo := foo + 1) should be possible!! |
3140 |
"/ (parent notNil and:[parent isAssignment]) ifTrue:[ |
|
3141 |
"/ "/ remove the left side of the assignment (to avoid foo := foo suggestions) |
|
3142 |
"/ |i| |
|
3143 |
"/ |
|
3144 |
"/ i := allDistances findFirst:[:entry | entry key = parent variable name]. |
|
3145 |
"/ i ~~ 0 ifTrue:[ |
|
3146 |
"/ allDistances removeAtIndex:i |
|
3147 |
"/ ]. |
|
3148 |
"/ ]. |
|
4385 | 3149 |
|
4238 | 3150 |
bestAssoc := allDistances at:1. |
3151 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
4559 | 3152 |
ifTrue:[el] |
3153 |
ifFalse:[best] |
|
3154 |
]. |
|
4548 | 3155 |
|
3156 |
allDistances sort:[:a :b | |
|
4559 | 3157 |
a value > b value ifTrue:[ |
3158 |
true |
|
3159 |
] ifFalse:[ |
|
3160 |
a value = b value ifTrue:[ |
|
3161 |
a key < b key |
|
3162 |
] ifFalse:[ |
|
3163 |
false |
|
3164 |
] |
|
3165 |
] |
|
3166 |
]. |
|
4352 | 3167 |
|
3168 |
allTheBest := allDistances. |
|
3169 |
||
4238 | 3170 |
nameIsOK ifTrue:[ |
4559 | 3171 |
"/ if the name already exists, only allow longer names, if there are |
3172 |
longerNames := allTheBest select:[:assoc | assoc key startsWith:nm]. |
|
3173 |
longerNames notEmpty ifTrue:[ |
|
3174 |
allTheBest := longerNames. |
|
3175 |
]. |
|
4238 | 3176 |
]. |
3177 |
allTheBest size > 15 ifTrue:[ |
|
4559 | 3178 |
"/ remove all those which are below some threshold or are a prefix |
3179 |
0.4 to:0.9 by:0.1 do:[:delta | |
|
3180 |
"/ if still too many, remove more and more |
|
3181 |
allTheBest size > 15 ifTrue:[ |
|
3182 |
allTheBest := allDistances select:[:entry | (entry key startsWith:nm) or:[ entry value >= (bestAssoc value * delta) ]]. |
|
3183 |
] |
|
3184 |
]. |
|
3185 |
allTheBest size > 15 ifTrue:[ |
|
3186 |
"/ remove all those which are below some threshold |
|
3187 |
0.4 to:0.9 by:0.1 do:[:delta | |
|
3188 |
"/ if still too many, remove more and more |
|
3189 |
allTheBest size > 15 ifTrue:[ |
|
3190 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * delta) ]. |
|
3191 |
] |
|
3192 |
]. |
|
3193 |
]. |
|
4238 | 3194 |
]. |
3195 |
suggestions := allTheBest collect:[:assoc | assoc key]. |
|
3196 |
||
4352 | 3197 |
"/ finally, the trick is to bring them into a reasonable order... |
3198 |
"/ sort the prefix matchers by length, the others by spelling distance |
|
3199 |
"/ and bring the prefix-matchers towards the beginning |
|
3200 |
suggestions := ((suggestions select:[:s | s startsWith:nm]) sort:[:a :b | a size < b size ]) |
|
4559 | 3201 |
, |
3202 |
(suggestions reject:[:s | s startsWith:nm]). |
|
4352 | 3203 |
|
4417 | 3204 |
"/ if super is among them, add a full call to the completions |
3205 |
(suggestions includes:'super') ifTrue:[ |
|
4559 | 3206 |
(tree notNil |
3207 |
and:[ tree isMethod ]) ifTrue:[ |
|
3208 |
Error handle:[:ex | |
|
3209 |
Transcript showCR:'parse error in code completion ignored'. |
|
3210 |
] do:[ |
|
3211 |
suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.'). |
|
3212 |
] |
|
3213 |
]. |
|
4417 | 3214 |
]. |
4620 | 3215 |
"/ self halt. |
4238 | 3216 |
editAction := |
4559 | 3217 |
[:index | |
3218 |
|answer start stop oldVar| |
|
3219 |
||
3220 |
answer := suggestions at:index. |
|
3221 |
||
3222 |
start := node start. |
|
3223 |
stop := node stop. |
|
3224 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
3225 |
||
3226 |
oldLen := stop - start + 1. |
|
3227 |
newLen := answer size. |
|
3228 |
||
3229 |
codeView |
|
3230 |
undoableDo:[ |
|
3231 |
codeView replaceFromCharacterPosition:start to:stop with:(answer). |
|
3232 |
||
3233 |
(answer startsWith:oldVar) ifTrue:[ |
|
3234 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3235 |
] ifFalse:[ |
|
3236 |
codeView selectFromCharacterPosition:start to:start+newLen-1. |
|
3237 |
]. |
|
3238 |
codeView dontReplaceSelectionOnInput |
|
3239 |
] |
|
3240 |
info:'Completion'. |
|
3241 |
||
3242 |
]. |
|
4238 | 3243 |
|
4620 | 3244 |
suggestionsWithInfo := |
3245 |
suggestions |
|
3246 |
collect:[:eachName | |
|
3247 |
|val| |
|
3248 |
||
3249 |
val := self valueOfVariable:eachName. |
|
3250 |
val isNil ifTrue:[ |
|
3251 |
eachName |
|
3252 |
] ifFalse:[ |
|
3253 |
eachName,' (',val class name,')' |
|
3254 |
]. |
|
3255 |
]. |
|
3256 |
||
3257 |
actionBlock value:suggestionsWithInfo value:editAction value:nil. |
|
4238 | 3258 |
|
3259 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
3260 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4314 | 3261 |
"Modified: / 30-07-2013 / 08:36:11 / cg" |
4238 | 3262 |
! |
3263 |
||
3264 |
findNodeForInterval:interval in:source |
|
3265 |
|tree node| |
|
3266 |
||
3267 |
interval isEmpty ifTrue: [^ nil]. |
|
3268 |
RBParser isNil ifTrue: [^ nil]. |
|
3269 |
||
3270 |
source = LastSource ifTrue:[ |
|
4548 | 3271 |
tree := LastParseTree. |
4238 | 3272 |
] ifFalse:[ |
4548 | 3273 |
tree := RBParser |
3274 |
parseMethod:source |
|
3275 |
onError: |
|
3276 |
[:str :err ":nodesSoFar" | |
|
3277 |
"Transcript showCR:'Parse-Error: ',str." |
|
3278 |
nil |
|
3279 |
]. |
|
3280 |
||
3281 |
tree isNil ifTrue:[ |
|
3282 |
"/ try to parse as an expression |
|
3283 |
tree := RBParser |
|
3284 |
parseExpression:source |
|
3285 |
onError: |
|
3286 |
[:str :err ":nodesSoFar" | |
|
3287 |
"Transcript showCR:'Parse-Error: ',str." |
|
3288 |
nil |
|
3289 |
]. |
|
3290 |
||
3291 |
tree isNil ifTrue:[ |
|
3292 |
^ nil |
|
3293 |
]. |
|
3294 |
]. |
|
3295 |
||
3296 |
LastSource := source. |
|
3297 |
LastParseTree := tree. |
|
4238 | 3298 |
]. |
3299 |
||
3300 |
node := tree whichNodeIsContainedBy:interval. |
|
3301 |
node isNil ifTrue: [ |
|
4548 | 3302 |
node := tree bestNodeFor: interval. |
3303 |
node isNil ifTrue: [ |
|
3304 |
node := self findNodeIn:tree forInterval:interval |
|
3305 |
]. |
|
4238 | 3306 |
]. |
3307 |
^ node |
|
3308 |
||
3309 |
"Modified: / 06-07-2011 / 12:42:53 / cg" |
|
3310 |
! |
|
3311 |
||
3312 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
|
3313 |
^ self |
|
4548 | 3314 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3315 |
mustBeMethod:false |
|
4238 | 3316 |
|
3317 |
"Modified: / 16-09-2011 / 14:52:28 / cg" |
|
3318 |
! |
|
3319 |
||
3320 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod |
|
3321 |
"if mustBeMethod is true, do not try a regular expression (as in a workspace)." |
|
3322 |
||
4352 | 3323 |
^ self |
4548 | 3324 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3325 |
mustBeMethod:mustBeMethod mustBeExpression:false |
|
4352 | 3326 |
! |
3327 |
||
3328 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression |
|
3329 |
"parse it as expression or method; |
|
3330 |
if mustBeMethod is true, do not try a regular expressions (as in a workspace); |
|
4367 | 3331 |
if mustBeExpression is true, do not try method" |
3332 |
||
4548 | 3333 |
|intersectingNodes smallestIntersectingNode firstIntersectingNode |
3334 |
lastIntersectingNode onErrorBlock |
|
4373 | 3335 |
nodeGenerationHook parserClass parser currentScopeNodes bestNode| |
4238 | 3336 |
|
3337 |
interval isEmpty ifTrue: [^ nil]. |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3338 |
languageOrNil notNil ifTrue:[ |
4548 | 3339 |
parserClass := languageOrNil parserClass. |
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3340 |
] ifFalse:[ |
4548 | 3341 |
classOrNil notNil ifTrue:[ |
3342 |
parserClass := classOrNil programmingLanguage parserClass. |
|
3343 |
] |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3344 |
]. |
4548 | 3345 |
parserClass notNil ifTrue:[ |
3346 |
"/ hack |
|
3347 |
parserClass == Parser ifTrue: [ |
|
3348 |
parserClass := RBParser. |
|
3349 |
]. |
|
4373 | 3350 |
] ifFalse:[ |
4548 | 3351 |
parserClass := RBParser. |
4373 | 3352 |
]. |
3353 |
parserClass isNil ifTrue: [^ nil]. |
|
4238 | 3354 |
|
4361 | 3355 |
rememberedScopeNodes := nil. |
4434 | 3356 |
rememberedNodes := OrderedCollection new. |
4361 | 3357 |
|
4238 | 3358 |
"/ LastSource := nil. |
3359 |
source = LastSource ifTrue:[ |
|
4548 | 3360 |
tree := LastParseTree. |
3361 |
tokens := LastScanTokens. |
|
4238 | 3362 |
] ifFalse:[ |
4548 | 3363 |
intersectingNodes := OrderedCollection new. |
3364 |
currentScopeNodes := IdentitySet new. |
|
3365 |
||
3366 |
onErrorBlock := |
|
3367 |
[:str :err :nodesSoFar | |
|
3368 |
|nodes| |
|
3369 |
||
3370 |
allowErrors ifTrue:[ |
|
3371 |
rememberedScopeNodes := currentScopeNodes. |
|
3372 |
firstIntersectingNode notNil ifTrue:[ |
|
3373 |
^ firstIntersectingNode |
|
3374 |
]. |
|
3375 |
nodesSoFar notNil ifTrue:[ |
|
3376 |
nodes := nodesSoFar asOrderedCollection |
|
3377 |
collect:[:nd | nd whichNodeIntersects:interval] |
|
3378 |
thenSelect:[:nd | nd notNil ]. |
|
3379 |
nodes size == 1 ifTrue:[ |
|
3380 |
^ nodes first |
|
3381 |
]. |
|
3382 |
] |
|
3383 |
]. |
|
3384 |
nil |
|
3385 |
]. |
|
3386 |
||
3387 |
self debuggingCodeFor:#cg is:[ |
|
3388 |
Transcript show:'looking for: '; showCR:interval. |
|
3389 |
]. |
|
3390 |
||
3391 |
nodeGenerationHook := |
|
3392 |
[:node | |
|
3393 |
rememberedNodes add:node. |
|
3394 |
||
3395 |
"/ would like to return here as soon as the node has been created by the parser; |
|
3396 |
"/ however, at that time, its parent(chain) is not yet created and so we might not know |
|
3397 |
"/ what the semantic interpretation (especially: scope of variable) will be. |
|
3398 |
"/ therefore, we parse all, and return the found node at the end. |
|
3399 |
(node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[ |
|
3400 |
currentScopeNodes add:node. |
|
3401 |
] ifFalse:[ |
|
3402 |
self debuggingCodeFor:#cg is:[ |
|
3403 |
Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop. |
|
3404 |
]. |
|
3405 |
||
3406 |
(node intersectsInterval:interval) ifTrue:[ |
|
3407 |
self debuggingCodeFor:#cg is:[ |
|
3408 |
Transcript showCR:'yes'. |
|
3409 |
]. |
|
3410 |
intersectingNodes add:node. |
|
3411 |
firstIntersectingNode isNil ifTrue:[ |
|
3412 |
firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node |
|
3413 |
] ifFalse:[ |
|
3414 |
|lenNode lenSmallest| |
|
3415 |
||
3416 |
lenNode := (node stop - node start). |
|
3417 |
lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start). |
|
3418 |
lenNode < lenSmallest ifTrue:[ |
|
3419 |
smallestIntersectingNode := node. |
|
3420 |
]. |
|
3421 |
node start > lastIntersectingNode start ifTrue:[ |
|
3422 |
lastIntersectingNode := node. |
|
3423 |
]. |
|
3424 |
]. |
|
3425 |
]. |
|
3426 |
]. |
|
3427 |
]. |
|
3428 |
||
3429 |
"/ one of the big problems when using the RBParser here is |
|
3430 |
"/ that it behaves badly when a syntax error is encountered; |
|
3431 |
"/ for example, a node's parent is usually set AFTER the children are |
|
3432 |
"/ completely parsed (for example, a blockNode gets the parent-method only |
|
3433 |
"/ after parsing). Thus, when an error is encountered, we cannot walk |
|
3434 |
"/ the parent chain, and therefore will not see the outer locals/args of |
|
3435 |
"/ an inner scope (allVariablesOnScope returns only a partial set). |
|
3436 |
"/ A walkaround is to remember Method/Block nodes as created in the above node generation. |
|
3437 |
"/ The disadvantage of it is that we do not have correct scope information, until the nodes |
|
3438 |
"/ parent gets set eventually, this we might consider locals from sibling blocks. |
|
3439 |
"/ See rememberedScopeNodes handling above. |
|
3440 |
"/ Those other nodes are only remembered for failed parses; |
|
3441 |
"/ if the parse is ok, rememberedScopeNodes will be nil. |
|
3442 |
||
3443 |
mustBeExpression ifFalse:[ |
|
3444 |
tree := parserClass |
|
3445 |
parseMethod: source |
|
3446 |
setup:[:p | |
|
3447 |
parser := p. |
|
3448 |
p rememberNodes:true. |
|
3449 |
p rememberTokens:true. |
|
3450 |
p nodeGenerationCallback:nodeGenerationHook |
|
3451 |
] |
|
3452 |
onError: onErrorBlock. |
|
3453 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
|
3454 |
]. |
|
3455 |
||
3456 |
mustBeMethod ifTrue:[ |
|
3457 |
"/ only cache parsed methods |
|
3458 |
tree notNil ifTrue:[ |
|
3459 |
LastSource := source. |
|
3460 |
LastParseTree := tree. |
|
3461 |
LastScanTokens := tokens. |
|
3462 |
]. |
|
3463 |
] ifFalse:[ |
|
3464 |
(tree isNil or:[firstIntersectingNode isNil]) ifTrue:[ |
|
3465 |
"/ try as an expression |
|
3466 |
tree := parserClass |
|
3467 |
parseExpression: source |
|
3468 |
setup:[:p | |
|
3469 |
parser := p. |
|
3470 |
p rememberNodes:true. |
|
3471 |
p rememberTokens:true. |
|
3472 |
p nodeGenerationCallback:nodeGenerationHook |
|
3473 |
] |
|
3474 |
onError: onErrorBlock. |
|
3475 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
|
3476 |
]. |
|
3477 |
]. |
|
3478 |
lastIntersectingNode notNil ifTrue:[ |
|
3479 |
self debuggingCodeFor:#cg is:[ |
|
3480 |
Transcript show:'last: '; showCR:lastIntersectingNode. |
|
3481 |
]. |
|
3482 |
^ lastIntersectingNode |
|
3483 |
]. |
|
3484 |
"/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ]. |
|
4238 | 3485 |
]. |
3486 |
||
4367 | 3487 |
bestNode := self findNodeForInterval:interval inParseTree:tree. |
3488 |
self debuggingCodeFor:#cg is:[ |
|
4548 | 3489 |
Transcript show:'best: '; showCR:bestNode. |
4367 | 3490 |
]. |
3491 |
^ bestNode |
|
4238 | 3492 |
|
3493 |
"Created: / 16-09-2011 / 14:52:08 / cg" |
|
4407
59eecb68b4fb
class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4392
diff
changeset
|
3494 |
"Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4238 | 3495 |
! |
3496 |
||
3497 |
findNodeForInterval:interval inParseTree:parseTree |
|
3498 |
|node| |
|
3499 |
||
3500 |
interval isEmpty ifTrue: [^ nil]. |
|
3501 |
parseTree isNil ifTrue:[^ nil]. |
|
3502 |
||
3503 |
node := parseTree whichNodeIsContainedBy:interval. |
|
3504 |
node isNil ifTrue:[ |
|
4548 | 3505 |
node := parseTree whichNodeIntersects:interval. |
3506 |
node isNil ifTrue: [ |
|
3507 |
node := self findNodeIn:parseTree forInterval:interval |
|
3508 |
]. |
|
4238 | 3509 |
]. |
3510 |
^ node |
|
3511 |
||
3512 |
"Modified: / 10-11-2006 / 13:13:58 / cg" |
|
3513 |
! |
|
3514 |
||
3515 |
findNodeIn:tree forInterval:interval |
|
3516 |
|nodeFound wouldReturn| |
|
3517 |
||
3518 |
nodeFound := nil. |
|
3519 |
tree nodesDo:[:eachNode | |
|
4548 | 3520 |
(eachNode intersectsInterval:interval) ifTrue:[ |
3521 |
(nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[ |
|
3522 |
nodeFound := eachNode |
|
3523 |
] ifFalse:[ |
|
3524 |
(nodeFound parent == eachNode parent |
|
3525 |
and:[ eachNode start >= nodeFound start |
|
3526 |
and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[ |
|
3527 |
] ifFalse:[ |
|
3528 |
(nodeFound parent notNil |
|
3529 |
and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil] |
|
3530 |
] |
|
3531 |
] |
|
3532 |
] ifFalse:[ |
|
3533 |
nodeFound notNil ifTrue:[ |
|
3534 |
"/ already found one - beyond that one; leave |
|
3535 |
wouldReturn notNil ifTrue:[wouldReturn := nodeFound]. |
|
3536 |
] |
|
3537 |
]. |
|
4238 | 3538 |
]. |
3539 |
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt]. |
|
3540 |
^ nodeFound |
|
3541 |
||
3542 |
"Modified: / 20-11-2006 / 12:31:12 / cg" |
|
3543 |
! |
|
3544 |
||
4421 | 3545 |
insertAdditonalStuffAfterSelector:chosenCompletion |
3546 |
|optionalExtraSpace| |
|
3547 |
||
4548 | 3548 |
optionalExtraSpace := (codeView characterAfterCursor isSeparator) |
3549 |
ifTrue:[''] |
|
3550 |
ifFalse:[' ']. |
|
4421 | 3551 |
|
3552 |
( |
|
4548 | 3553 |
#( |
3554 |
'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:' |
|
3555 |
'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:' |
|
3556 |
) includes:chosenCompletion |
|
4421 | 3557 |
) ifTrue:[ |
4548 | 3558 |
codeView insertStringAtCursor:('[',optionalExtraSpace). |
3559 |
"/ codeView cursorLeft:1+extra size. |
|
4421 | 3560 |
]. |
3561 |
( |
|
4548 | 3562 |
#( |
3563 |
'collect:' 'select:' 'reject:' 'do:' |
|
3564 |
) includes:chosenCompletion |
|
4421 | 3565 |
) ifTrue:[ |
4548 | 3566 |
codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace). |
3567 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 3568 |
]. |
3569 |
( |
|
4548 | 3570 |
#( |
3571 |
'contains:' 'findFirst:' 'detect:' |
|
3572 |
) includes:chosenCompletion |
|
4421 | 3573 |
) ifTrue:[ |
4548 | 3574 |
codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace). |
3575 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 3576 |
]. |
3577 |
( |
|
4548 | 3578 |
#( |
3579 |
'remove:ifAbsent:' 'detect:ifNone:' |
|
3580 |
) includes:chosenCompletion |
|
4421 | 3581 |
) ifTrue:[ |
4548 | 3582 |
codeView insertStringAtCursor:('[]',optionalExtraSpace). |
3583 |
codeView cursorLeft:1+optionalExtraSpace size. |
|
4421 | 3584 |
]. |
3585 |
! |
|
3586 |
||
4238 | 3587 |
old_askUserForCompletion:what for:codeView from:allTheBest |
3588 |
|list resources choice lastChoice| |
|
3589 |
||
3590 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
3591 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
3592 |
||
3593 |
list := allTheBest. |
|
3594 |
LastChoices notNil ifTrue:[ |
|
4548 | 3595 |
lastChoice := LastChoices at:what ifAbsent:nil. |
3596 |
lastChoice notNil ifTrue:[ |
|
3597 |
"/ move tha last choice to the top of the list, if it is in. |
|
3598 |
(list includes: lastChoice) ifTrue:[ |
|
3599 |
(list indexOf: lastChoice) < 10 ifTrue:[ |
|
3600 |
list := {lastChoice allBold } , (list copyWithout:lastChoice). |
|
3601 |
] |
|
3602 |
] |
|
3603 |
]. |
|
4238 | 3604 |
]. |
3605 |
||
3606 |
list size < 30 ifTrue:[ |
|
4548 | 3607 |
|menu idx exitKey| |
3608 |
||
3609 |
menu := PopUpMenu labels:list. |
|
3610 |
menu hideOnKeyFilter:[:key | |hide| |
|
3611 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
3612 |
hide ifTrue:[ |
|
3613 |
exitKey := key. |
|
3614 |
]. |
|
3615 |
hide]. |
|
3616 |
menu memorizeLastSelection:3 "sigh, not 1 because of heading!!". |
|
3617 |
idx := menu startUpWithHeading:'Choose ',what. |
|
3618 |
idx == 0 ifTrue:[ |
|
3619 |
exitKey notNil ifTrue:[ |
|
3620 |
codeView keyPress:exitKey x:0 y:0. |
|
3621 |
]. |
|
3622 |
^ nil |
|
3623 |
]. |
|
3624 |
choice := list at:idx. |
|
4238 | 3625 |
] ifFalse:[ |
4548 | 3626 |
resources := codeView application isNil |
3627 |
ifTrue:[ codeView resources] |
|
3628 |
ifFalse:[ codeView application resources ]. |
|
3629 |
||
3630 |
choice := Dialog |
|
3631 |
choose:(resources string:'Choose ',what) |
|
3632 |
fromList:list |
|
3633 |
lines:20 |
|
3634 |
initialSelection:(list firstIfEmpty:nil) |
|
3635 |
title:(resources string:'Code completion'). |
|
3636 |
choice isNil ifTrue:[^ nil]. |
|
4238 | 3637 |
]. |
4301 | 3638 |
choice := choice string. |
4238 | 3639 |
|
3640 |
LastChoices isNil ifTrue:[ |
|
4548 | 3641 |
LastChoices := Dictionary new. |
4238 | 3642 |
]. |
3643 |
LastChoices at:what put:choice. |
|
3644 |
^ choice |
|
3645 |
||
3646 |
"Created: / 16-02-2010 / 09:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 3647 |
"Modified: / 28-08-2013 / 15:28:01 / cg" |
4238 | 3648 |
! |
3649 |
||
3650 |
treeForCode:source allowErrors:allowErrors |
|
3651 |
|tree| |
|
3652 |
||
3653 |
source = LastSource ifTrue:[ |
|
4548 | 3654 |
tree := LastParseTree. |
4238 | 3655 |
] ifFalse:[ |
4548 | 3656 |
tree := RBParser |
3657 |
parseMethod:source |
|
3658 |
onError: [:str :err :nodesSoFar :parserOrNil| |
|
3659 |
allowErrors ifTrue:[ |
|
3660 |
"/ parserOrNil isNil if raised by the scanner |
|
3661 |
parserOrNil notNil ifTrue:[ |
|
3662 |
^ parserOrNil currentMethodNode |
|
3663 |
] |
|
3664 |
]. |
|
3665 |
^ nil |
|
3666 |
] |
|
3667 |
proceedAfterError:false |
|
3668 |
rememberNodes:true. |
|
3669 |
||
3670 |
tree notNil ifTrue:[ |
|
3671 |
LastSource := source. |
|
3672 |
LastParseTree := tree. |
|
3673 |
] |
|
4238 | 3674 |
]. |
3675 |
^ tree |
|
3676 |
||
3677 |
"Modified: / 13-01-2012 / 11:54:30 / cg" |
|
4352 | 3678 |
! |
3679 |
||
4524 | 3680 |
tryCodeCompletionWithSource:source nodeInterval:interval at:characterPositionOfCursor mustBeExpression:mustBeExpression into:actionBlock |
4548 | 3681 |
"this is tried multiple times; |
3682 |
first with cursor line only |
|
3683 |
then with the source copied up to the cursor position, |
|
3684 |
then with the full source. |
|
4381 | 3685 |
Either one may give better results (for example, when completing |
4352 | 3686 |
after a keyword selector, and the remaining code would lead to a syntactically |
3687 |
legal, but stupid message send to be parsed... |
|
3688 |
(which happens often after inserting)" |
|
3689 |
||
4544 | 3690 |
|node nodeParent checkedNode characterBeforeCursor nodeIsInTemporaries| |
4352 | 3691 |
|
3692 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
3693 |
"/ we will not find a node for a long time (stepping back more and more, |
|
3694 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
3695 |
"/ without any progress. |
|
3696 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
3697 |
"/ as it parses the code. Stop, when the interval is hit. |
|
3698 |
"/ that will also work for syntactic incorrect source code. |
|
4524 | 3699 |
(mustBeExpression not and:[methodOrNil notNil or:[classOrNil notNil]]) ifTrue:[ |
4548 | 3700 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
4352 | 3701 |
]. |
3702 |
node isNil ifTrue:[ |
|
4548 | 3703 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true. |
3704 |
node isNil ifTrue:[ |
|
3705 |
"/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'. |
|
3706 |
self information:'No parseNode found (syntax error before or in comment?)'. |
|
3707 |
^ self. |
|
3708 |
]. |
|
4352 | 3709 |
]. |
4544 | 3710 |
nodeParent := node parent. |
4352 | 3711 |
|
3712 |
(node isVariable |
|
4544 | 3713 |
and:[ nodeParent notNil |
3714 |
and:[ nodeParent isMessage |
|
4368 | 3715 |
and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[ |
4548 | 3716 |
node := nodeParent. |
3717 |
nodeParent := node parent. |
|
4352 | 3718 |
]. |
3719 |
||
4525 | 3720 |
characterBeforeCursor := source at:(characterPositionOfCursor-1 max:1). "/ codeView characterBeforeCursor. |
4352 | 3721 |
characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self]. |
4358 | 3722 |
characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self]. |
4352 | 3723 |
|
3724 |
node isVariable ifTrue:[ |
|
4548 | 3725 |
nodeIsInTemporaries := |
3726 |
nodeParent notNil |
|
3727 |
and:[ nodeParent isSequence |
|
3728 |
and:[ nodeParent temporaries notEmptyOrNil |
|
3729 |
and:[ node stop <= nodeParent temporaries last stop ]]]. |
|
3730 |
nodeIsInTemporaries ifFalse:[ |
|
3731 |
"/ cursor must be right after the variable |
|
3732 |
characterPositionOfCursor >= (node stop) ifTrue:[ |
|
3733 |
self codeCompletionForVariable:node into:actionBlock. |
|
3734 |
] |
|
3735 |
]. |
|
3736 |
^ self. |
|
4352 | 3737 |
]. |
4367 | 3738 |
|
4352 | 3739 |
node isLiteral ifTrue:[ |
4548 | 3740 |
"/ however, user may want to complete a symbol inside a literal array!! |
3741 |
node value isArray ifTrue:[ |
|
3742 |
node token isLiteralArray ifTrue:[ |
|
3743 |
|elementBeforeCursor searcher| |
|
3744 |
||
3745 |
elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil. |
|
3746 |
elementBeforeCursor isNil ifTrue:[ |
|
3747 |
searcher := |
|
3748 |
[:tok :check | |
|
3749 |
tok isLiteralArray ifTrue:[ |
|
3750 |
tok value inject:nil into:[:found :el | found ifNil:[searcher value:el value:check]] |
|
3751 |
] ifFalse:[ |
|
3752 |
(check value:tok) ifTrue:[tok] ifFalse:[nil] |
|
3753 |
] |
|
3754 |
]. |
|
3755 |
elementBeforeCursor := searcher value:node token value:[:anElementToken | characterPositionOfCursor == (anElementToken stop)]. |
|
3756 |
]. |
|
3757 |
(elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[ |
|
3758 |
self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock. |
|
3759 |
^ self. |
|
3760 |
]. |
|
3761 |
]. |
|
3762 |
]. |
|
3763 |
||
3764 |
"/ cursor must be right after the literal |
|
3765 |
characterPositionOfCursor == (node stop + 1) ifFalse:[ |
|
3766 |
^ self |
|
3767 |
]. |
|
3768 |
||
3769 |
node value isSymbol ifTrue:[ |
|
3770 |
self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock. |
|
3771 |
^ self. |
|
3772 |
]. |
|
3773 |
||
3774 |
"/ huh - completing strings, numbers or what? |
|
3775 |
(nodeParent notNil |
|
3776 |
and:[ nodeParent isMessage |
|
3777 |
and:[ nodeParent isKeyword ]]) |
|
3778 |
ifFalse:[ |
|
3779 |
^ self |
|
3780 |
]. |
|
3781 |
"/ no, move up and try completing the outer keyword message (next arg) |
|
3782 |
node := nodeParent. |
|
3783 |
nodeParent := node parent. |
|
4352 | 3784 |
]. |
3785 |
||
3786 |
checkedNode := node. |
|
3787 |
[checkedNode notNil] whileTrue:[ |
|
4548 | 3788 |
(characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[ |
3789 |
self information:'Inside a message node'. |
|
3790 |
^ self. |
|
3791 |
]. |
|
3792 |
||
3793 |
checkedNode isMessage ifTrue:[ |
|
3794 |
"/ completion in a message-send |
|
3795 |
self codeCompletionForMessage:checkedNode into:actionBlock. |
|
3796 |
^ self |
|
3797 |
]. |
|
3798 |
checkedNode isMethod ifTrue:[ |
|
3799 |
"/ completion in a method's selector pattern |
|
3800 |
self codeCompletionForMethodSpec:checkedNode into:actionBlock. |
|
3801 |
^ self. |
|
3802 |
]. |
|
3803 |
checkedNode := checkedNode parent. |
|
4352 | 3804 |
]. |
3805 |
||
3806 |
self information:'Node is neither variable nor message.'. |
|
3807 |
||
3808 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
3809 |
"Modified: / 16-09-2011 / 14:54:47 / cg" |
|
4375 | 3810 |
! |
3811 |
||
4422 | 3812 |
valueOfNode:aNode |
4548 | 3813 |
"when showing possible completions for a message, |
4422 | 3814 |
it is a good idea to know what the reveiver's value is. |
3815 |
Sigh - returns nil both if unknown AND if a real nil is there." |
|
3816 |
||
4620 | 3817 |
|nodeSelector nodeReceiver isNonDestructive receiverValue method| |
4422 | 3818 |
|
3819 |
aNode isLiteral ifTrue:[ |
|
4620 | 3820 |
^ aNode value |
4422 | 3821 |
]. |
3822 |
aNode isVariable ifTrue:[ |
|
4620 | 3823 |
^ self valueOfVariable:aNode name. |
4422 | 3824 |
]. |
3825 |
||
3826 |
aNode isMessage ifTrue:[ |
|
4620 | 3827 |
nodeSelector := aNode selector. |
3828 |
nodeReceiver := aNode receiver. |
|
3829 |
||
3830 |
"/ some hardwired knowlegde here |
|
3831 |
classOrNil notNil ifTrue:[ |
|
3832 |
(nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[ |
|
3833 |
^ classOrNil |
|
3834 |
]. |
|
3835 |
]. |
|
3836 |
||
3837 |
isNonDestructive := false. |
|
3838 |
||
3839 |
( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[ |
|
3840 |
isNonDestructive := true. |
|
3841 |
] ifFalse:[ |
|
3842 |
"/ follow non-destructive accessors |
|
3843 |
receiverValue := self valueOfNode:nodeReceiver. |
|
3844 |
receiverValue notNil ifTrue:[ |
|
3845 |
method := receiverValue class lookupMethodFor:nodeSelector. |
|
3846 |
method notNil ifTrue:[ |
|
3847 |
(ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[ |
|
3848 |
"/ we can savely call that method to get the current value |
|
3849 |
^ receiverValue perform: nodeSelector. |
|
3850 |
] |
|
3851 |
]. |
|
3852 |
]. |
|
3853 |
]. |
|
4422 | 3854 |
]. |
3855 |
||
3856 |
^ nil |
|
3857 |
||
3858 |
"Created: / 28-08-2013 / 16:34:53 / cg" |
|
3859 |
! |
|
3860 |
||
4620 | 3861 |
valueOfVariable:aVariableName |
3862 |
"when showing possible completions for a variable, |
|
3863 |
it is a good idea to know what the reveiver's value is. |
|
3864 |
Sigh - returns nil both if unknown AND if a real nil is there." |
|
3865 |
||
3866 |
|nodeVal con privateClass| |
|
3867 |
||
3868 |
aVariableName isUppercaseFirst ifTrue:[ |
|
3869 |
"/ simply 'evaluate' the variable (like in a browser's codeView) |
|
3870 |
"/ mhmh - will we catch workspace vars then? |
|
3871 |
Error handle:[:ex | |
|
3872 |
] do:[ |
|
3873 |
nodeVal := Parser new evaluate:aVariableName in:nil receiver:classOrNil. |
|
3874 |
]. |
|
3875 |
nodeVal notNil ifTrue:[ |
|
3876 |
^ nodeVal |
|
3877 |
]. |
|
3878 |
classOrNil notNil ifTrue:[ |
|
3879 |
(classOrNil theNonMetaclass classVarNames includes:aVariableName) ifTrue:[ |
|
3880 |
nodeVal := classOrNil theNonMetaclass classVarAt:aVariableName. |
|
3881 |
^ nodeVal. |
|
3882 |
]. |
|
3883 |
privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil. |
|
3884 |
privateClass notNil ifTrue:[ |
|
3885 |
nodeVal := privateClass. |
|
3886 |
^ nodeVal. |
|
3887 |
]. |
|
3888 |
]. |
|
3889 |
^ nil |
|
3890 |
]. |
|
3891 |
aVariableName = 'self' ifTrue:[ |
|
3892 |
(classOrNil notNil and:[classOrNil isMeta]) ifTrue:[^ classOrNil theNonMetaclass]. |
|
3893 |
contextOrNil notNil ifTrue:[^ contextOrNil receiver]. |
|
3894 |
^ nil |
|
3895 |
]. |
|
3896 |
||
3897 |
contextOrNil notNil ifTrue:[ |
|
3898 |
con := contextOrNil. |
|
3899 |
[ con notNil ] whileTrue:[ |
|
3900 |
"/ a local in the context? |
|
3901 |
((con argAndVarNames ? #()) includes:aVariableName) ifTrue:[ |
|
3902 |
nodeVal := con argsAndVars at:(con argAndVarNames indexOf:aVariableName) ifAbsent:nil. |
|
3903 |
nodeVal notNil ifTrue:[ |
|
3904 |
^ nodeVal |
|
3905 |
]. |
|
3906 |
]. |
|
3907 |
con := con home. |
|
3908 |
]. |
|
3909 |
"/ an instvar |
|
3910 |
(contextOrNil receiver class allInstVarNames includes:aVariableName) ifTrue:[ |
|
3911 |
nodeVal := contextOrNil receiver instVarNamed:aVariableName. |
|
3912 |
nodeVal notNil ifTrue:[ |
|
3913 |
^ nodeVal |
|
3914 |
]. |
|
3915 |
]. |
|
3916 |
]. |
|
3917 |
^ nil |
|
3918 |
! |
|
3919 |
||
4375 | 3920 |
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector |
4592 | 3921 |
"some heuristics; |
3922 |
as best selectors has been chosen by implemented methods for aClass, |
|
3923 |
some of them should be filtered (for example, at:/at:put:, which are |
|
3924 |
found in object, but only make sense for variable objects or those which do |
|
3925 |
implement at:put: themself. |
|
3926 |
I have currently no better idea than hardcoding stuff I found irritating..." |
|
3927 |
||
4615 | 3928 |
|selectors noNilChecks noIsXXXChecks noNoXXXChecks noBecome |
3929 |
noIndexedSetters noIndexedGetters noSizeQueries| |
|
4408 | 3930 |
|
3931 |
aClass isNil ifTrue:[ ^ selectorsArg ]. |
|
3932 |
||
4615 | 3933 |
noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := false. |
3934 |
noIndexedSetters := noIndexedGetters := noSizeQueries := false. |
|
4375 | 3935 |
|
4548 | 3936 |
selectors := (selectorsArg ? #()) asOrderedCollection. |
4375 | 3937 |
|
3938 |
self tracePoint:#cg message:aClass. |
|
3939 |
||
4592 | 3940 |
"/ actually meaning booleans here |
3941 |
(aClass == True or:[aClass == False]) ifTrue:[ |
|
4615 | 3942 |
noNilChecks := noBecome := true. |
4592 | 3943 |
(partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ]. |
3944 |
(partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ]. |
|
4375 | 3945 |
]. |
3946 |
||
4418 | 3947 |
(aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ]. |
4615 | 3948 |
(aClass includesBehavior: Symbol) ifTrue:[ noNilChecks := noBecome := noIndexedSetters := true ]. |
3949 |
(aClass includesBehavior: Number) ifTrue:[ noBecome := true ]. |
|
3950 |
(aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := true ]. |
|
4418 | 3951 |
|
4548 | 3952 |
(aClass isMeta) ifTrue:[ |
4615 | 3953 |
noNilChecks := noBecome := true. |
4592 | 3954 |
"/ remove messages which are only defined in Object and non-meta classes. |
3955 |
selectors := selectors reject: |
|
3956 |
[:sel | |
|
3957 |
(Object implements:sel) |
|
3958 |
and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]] |
|
3959 |
]. |
|
3960 |
]. |
|
3961 |
||
3962 |
aClass isVariable ifFalse:[ |
|
4615 | 3963 |
noIndexedGetters := noIndexedSetters := noSizeQueries := true. |
3964 |
]. |
|
3965 |
||
3966 |
noIndexedSetters ifTrue:[ |
|
3967 |
#( #'at:put:' #'basicAt:put:') do:[:indexAccessSelector | |
|
3968 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
|
3969 |
selectors := selectors copyWithout:indexAccessSelector. |
|
3970 |
]. |
|
3971 |
]. |
|
3972 |
]. |
|
3973 |
noIndexedGetters ifTrue:[ |
|
3974 |
#( #'at:' #'basicAt:') do:[:indexAccessSelector | |
|
3975 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
|
3976 |
selectors := selectors copyWithout:indexAccessSelector. |
|
3977 |
]. |
|
3978 |
]. |
|
3979 |
]. |
|
3980 |
noSizeQueries ifTrue:[ |
|
3981 |
#( #size #basicSize ) do:[:indexAccessSelector | |
|
4592 | 3982 |
(aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[ |
3983 |
selectors := selectors copyWithout:indexAccessSelector. |
|
3984 |
]. |
|
3985 |
]. |
|
4408 | 3986 |
]. |
3987 |
||
3988 |
noNilChecks ifTrue:[ |
|
4592 | 3989 |
selectors removeAllFoundIn:#( |
3990 |
'isNil' 'notNil' |
|
3991 |
'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:' |
|
3992 |
'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:' |
|
3993 |
'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:' |
|
3994 |
). |
|
4375 | 3995 |
]. |
4408 | 3996 |
noIsXXXChecks ifTrue:[ |
4592 | 3997 |
"/ get rid of all isXXX selectors |
3998 |
selectors := selectors reject:[:sel | sel startsWith:'is']. |
|
4375 | 3999 |
]. |
4418 | 4000 |
noNoXXXChecks ifTrue:[ |
4592 | 4001 |
"/ get rid of all notXXX selectors |
4002 |
selectors := selectors reject:[:sel | sel startsWith:'no']. |
|
4418 | 4003 |
]. |
4615 | 4004 |
noBecome ifTrue:[ |
4005 |
"/ get rid of all become* selectors |
|
4006 |
selectors := selectors reject:[:sel | sel startsWith:'become']. |
|
4007 |
selectors remove:#oneWayBecome: ifAbsent:[]. |
|
4008 |
selectors := selectors reject:[:sel | sel startsWith:'changeClassTo']. |
|
4009 |
]. |
|
4408 | 4010 |
|
4011 |
"/ actually: directly implemented selectors are more likely, so move them to top |
|
4012 |
selectors := (selectors select:[:sel | aClass implements:sel]) |
|
4592 | 4013 |
, |
4014 |
(selectors reject:[:sel | aClass implements:sel]). |
|
4408 | 4015 |
|
4375 | 4016 |
^ selectors |
4238 | 4017 |
! ! |
4018 |
||
4019 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'! |
|
4020 |
||
4021 |
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView |
|
4022 |
|sym possibleCompletions best start stop oldLen newLen oldVar| |
|
4023 |
||
4024 |
sym := node value. |
|
4025 |
possibleCompletions := OrderedCollection new. |
|
4026 |
||
4027 |
Symbol allInstancesDo:[:existingSym | |
|
4548 | 4028 |
(existingSym startsWith:sym) ifTrue:[ |
4029 |
(existingSym = sym) ifFalse:[ |
|
4030 |
possibleCompletions add:existingSym |
|
4031 |
]. |
|
4032 |
]. |
|
4238 | 4033 |
]. |
4034 |
possibleCompletions sort. |
|
4035 |
||
4036 |
best := possibleCompletions longestCommonPrefix. |
|
4037 |
(best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[ |
|
4548 | 4038 |
best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions. |
4039 |
best isNil ifTrue:[^ self]. |
|
4238 | 4040 |
]. |
4041 |
||
4042 |
"/ self showInfo:best. |
|
4043 |
||
4044 |
start := node start. |
|
4045 |
stop := node stop. |
|
4046 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
4548 | 4047 |
start := start + 1. |
4238 | 4048 |
]. |
4049 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
4548 | 4050 |
start := start + 1. |
4051 |
stop := stop - 1. |
|
4238 | 4052 |
]. |
4053 |
||
4054 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
4055 |
||
4056 |
codeView |
|
4548 | 4057 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
4058 |
info:'Completion'. |
|
4238 | 4059 |
|
4060 |
(best startsWith:oldVar) ifTrue:[ |
|
4548 | 4061 |
oldLen := stop - start + 1. |
4062 |
newLen := best size. |
|
4063 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
4064 |
codeView dontReplaceSelectionOnInput |
|
4238 | 4065 |
]. |
4066 |
||
4067 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4068 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
4069 |
! |
|
4070 |
||
4345 | 4071 |
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView |
4548 | 4072 |
|selector |
4547 | 4073 |
bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best numArgs |
4548 | 4074 |
newParts nSelParts oldLen newLen selectorParts |
4345 | 4075 |
findBest parentNode selectorInBest selector2InBest2 |
4548 | 4076 |
parser selectorsSentInCode selectorsImplementedInClass split |
4346 | 4077 |
varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass| |
4345 | 4078 |
|
4079 |
RefactoryTyper notNil ifTrue:[ |
|
4710 | 4080 |
"/ refactory package also provides a (very limited) typer; |
4081 |
"/ ask it for its oppinion as well (temporary - will vanish, once we have a better typer) |
|
4082 |
(node receiver isVariable) ifTrue:[ |
|
4083 |
varName := node receiver name. |
|
4084 |
varName isUppercaseFirst ifTrue:[ |
|
4085 |
] ifFalse:[ |
|
4086 |
tree := RBParser |
|
4087 |
parseMethod:codeView contents string |
|
4088 |
onError:[:aString :pos | nil]. |
|
4089 |
tree notNil ifTrue:[ |
|
4090 |
rbTypes := RefactoryTyper |
|
4091 |
classesFor: varName |
|
4092 |
in: tree |
|
4093 |
model: nil |
|
4094 |
ignoredSelectors:(Array with:node selector). |
|
4095 |
rbTypes size > 0 ifTrue:[ |
|
4096 |
rbTypes size > 1 ifTrue:[ |
|
4097 |
rbTypes remove:ProtoObject ifAbsent:[]. |
|
4098 |
rbTypes remove:Autoload ifAbsent:[]. |
|
4099 |
rbTypes remove:ObsoleteObject ifAbsent:[]. |
|
4100 |
]. |
|
4101 |
rbTypes size == 1 ifTrue:[ |
|
4102 |
rbType := rbTypes first. |
|
4103 |
] ifFalse:[ |
|
4104 |
rbType := Class commonSuperclassOf:rbTypes |
|
4105 |
]. |
|
4106 |
(rbType notNil "and:[rbType ~= Object]") ifTrue:[ |
|
4107 |
bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true. |
|
4108 |
]. |
|
4109 |
] |
|
4110 |
] |
|
4111 |
] |
|
4112 |
]. |
|
4345 | 4113 |
]. |
4114 |
||
4115 |
classOrNil notNil ifTrue:[ |
|
4710 | 4116 |
parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true. |
4117 |
selectorsSentInCode := parser messagesSent. |
|
4548 | 4118 |
]. |
4345 | 4119 |
classOrNil notNil ifTrue:[ |
4710 | 4120 |
selectorsImplementedInClass := classOrNil selectors. |
4345 | 4121 |
]. |
4122 |
||
4123 |
findBest := [:node :selector | |
|
4710 | 4124 |
|srchClass bestSelectors bestPrefixes| |
4125 |
||
4126 |
codeView topView withCursor:(Cursor questionMark) do:[ |
|
4127 |
srchClass := self classOfNode:node receiver. |
|
4128 |
srchClass notNil ifTrue:[ |
|
4129 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true. |
|
4130 |
] ifFalse:[ |
|
4131 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true. |
|
4132 |
]. |
|
4133 |
]. |
|
4134 |
||
4135 |
(bestSelectors includes:selector) ifTrue:[ |
|
4136 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
|
4137 |
]. |
|
4138 |
bestSelectors |
|
4345 | 4139 |
]. |
4140 |
||
4141 |
selector := node selector. |
|
4142 |
bestSelectors := findBest value:node value:selector. |
|
4143 |
||
4144 |
parentNode := node parent. |
|
4145 |
||
4146 |
parentIsKeywordMessage := |
|
4710 | 4147 |
(parentNode notNil |
4148 |
and:[ parentNode isMessage |
|
4149 |
and:[ parentNode selector isKeywordSelector]]). |
|
4346 | 4150 |
parentIsBinaryMessage := |
4710 | 4151 |
(parentNode notNil |
4152 |
and:[ parentNode isMessage |
|
4153 |
and:[ parentNode selector isBinarySelector]]). |
|
4345 | 4154 |
|
4155 |
tryParent := false. |
|
4156 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
|
4548 | 4157 |
(node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[ |
4710 | 4158 |
tryParent := true. |
4345 | 4159 |
] ifFalse:[ |
4710 | 4160 |
"/ if the parent is an instance creation message, take that as lookup class. |
4161 |
(node isMessage |
|
4162 |
and:[ node receiver isMessage |
|
4163 |
and:[ node receiver receiver isVariable |
|
4164 |
and:[ node receiver receiver name isUppercaseFirst |
|
4165 |
and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[ |
|
4166 |
rcvrClass := Smalltalk classNamed:(node receiver receiver name). |
|
4167 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
4168 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true. |
|
4169 |
] ifFalse:[ |
|
4170 |
"/ also, if nothing was found |
|
4171 |
(bestSelectors isEmpty |
|
4172 |
and:[ parentNode notNil |
|
4173 |
and:[ parentNode isMessage ]]) ifTrue:[ |
|
4174 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
4175 |
"/ selector2 := parentNode selector. |
|
4176 |
"/ selector2 := selector2,selector. |
|
4177 |
bestSelectors := findBest value:parentNode value:selector. |
|
4178 |
] |
|
4179 |
] |
|
4345 | 4180 |
]. |
4181 |
tryParent ifTrue:[ |
|
4710 | 4182 |
selector2 := parentNode selector,selector. |
4183 |
bestSelectors2 := findBest value:parentNode value:selector2. |
|
4345 | 4184 |
]. |
4346 | 4185 |
bestSelectorsFromRB notEmptyOrNil ifTrue:[ |
4710 | 4186 |
bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]). |
4346 | 4187 |
]. |
4345 | 4188 |
|
4189 |
"/ if the parent is a keyword selector, the child cannot |
|
4346 | 4190 |
(parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[ |
4710 | 4191 |
bestSelectors := bestSelectors reject:[:sel | sel isKeywordSelector] |
4345 | 4192 |
]. |
4193 |
||
4194 |
bestSelectors2 isEmptyOrNil ifTrue:[ |
|
4710 | 4195 |
allBest := bestSelectors. |
4345 | 4196 |
] ifFalse:[ |
4710 | 4197 |
bestSelectors isEmptyOrNil ifTrue:[ |
4198 |
allBest := bestSelectors2 |
|
4199 |
] ifFalse:[ |
|
4200 |
selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]). |
|
4201 |
selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]). |
|
4202 |
||
4203 |
(selectorInBest not and:[ selector2InBest2 ]) ifTrue:[ |
|
4204 |
"/ selector2 is more likely |
|
4205 |
allBest := bestSelectors2 |
|
4206 |
] ifFalse:[ |
|
4207 |
(selectorInBest and:[ selector2InBest2 not ]) ifTrue:[ |
|
4208 |
"/ selector more likely |
|
4209 |
allBest := bestSelectors |
|
4210 |
] ifFalse:[ |
|
4211 |
"/ assume same likelyness |
|
4212 |
||
4213 |
allBest := bestSelectors isEmpty |
|
4214 |
ifTrue:[ bestSelectors2 ] |
|
4215 |
ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ]. |
|
4216 |
] |
|
4217 |
]. |
|
4218 |
]. |
|
4345 | 4219 |
]. |
4220 |
||
4221 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
|
4222 |
||
4548 | 4223 |
split := |
4710 | 4224 |
[:list :splitHow | |
4225 |
|part1 part2 all| |
|
4226 |
||
4227 |
part1 := list select:splitHow. |
|
4228 |
part2 := list reject:splitHow. |
|
4229 |
part1 isEmpty ifTrue:[ |
|
4230 |
all := part2. |
|
4231 |
] ifFalse:[ |
|
4232 |
part2 isEmpty ifTrue:[ |
|
4233 |
all := part1. |
|
4234 |
] ifFalse:[ |
|
4235 |
all := part1 , part2. |
|
4236 |
] |
|
4237 |
]. |
|
4238 |
all |
|
4239 |
]. |
|
4345 | 4240 |
|
4241 |
selectorsImplementedInClass notNil ifTrue:[ |
|
4710 | 4242 |
"/ the ones implemented in the receiver class are moved to the top of the list. |
4243 |
allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel]. |
|
4345 | 4244 |
]. |
4245 |
selectorsSentInCode notNil ifTrue:[ |
|
4710 | 4246 |
"/ the ones already sent in the code are moved to the top of the list. |
4247 |
allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel]. |
|
4345 | 4248 |
]. |
4249 |
||
4250 |
"/ the ones which are a prefix are moved towards the top of the list |
|
4251 |
allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]]. |
|
4252 |
||
4253 |
best := allBest first. |
|
4254 |
allBest size > 1 ifTrue:[ |
|
4710 | 4255 |
"allBest size < 20 ifTrue:[ |
4256 |
|idx| |
|
4257 |
||
4258 |
idx := (PopUpMenu labels:allBest) startUp. |
|
4259 |
idx == 0 ifTrue:[ ^ self]. |
|
4260 |
best := allBest at:idx. |
|
4261 |
] ifFalse:[ |
|
4262 |
allBest remove:nil ifAbsent:[]. |
|
4263 |
best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest. |
|
4264 |
||
4265 |
]." |
|
4266 |
allBest remove:nil ifAbsent:[]. |
|
4267 |
best := self askUserForCompletion:('Selector for "%1"' bindWith:selector) for:codeView at: node selectorParts first start from:allBest. |
|
4268 |
best isEmptyOrNil ifTrue:[^ self]. |
|
4269 |
best = '-' ifTrue:[^ self]. |
|
4345 | 4270 |
]. |
4271 |
||
4547 | 4272 |
"/ srchClass notNil ifTrue:[ |
4273 |
"/ implClass := srchClass whichClassIncludesSelector:best. |
|
4274 |
"/ ] ifFalse:[ |
|
4275 |
"/ implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
4276 |
"/ implClass size == 1 ifTrue:[ |
|
4277 |
"/ implClass := implClass first. |
|
4278 |
"/ ] ifFalse:[ |
|
4279 |
"/ implClass := nil |
|
4280 |
"/ ] |
|
4281 |
"/ ]. |
|
4282 |
"/ |
|
4283 |
"/ info := best storeString. |
|
4284 |
"/ implClass notNil ifTrue:[ |
|
4285 |
"/ info := implClass name , ' >> ' , info. |
|
4286 |
"/ ]. |
|
4287 |
"/ self information:info. |
|
4345 | 4288 |
|
4289 |
best ~= selector ifTrue:[ |
|
4710 | 4290 |
numArgs := best numArgs. |
4291 |
||
4292 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[ |
|
4293 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
4294 |
] ifFalse:[ |
|
4295 |
selectorParts := node selectorParts. |
|
4296 |
]. |
|
4297 |
nSelParts := selectorParts size. |
|
4298 |
||
4299 |
newParts := best asCollectionOfSubstringsSeparatedBy:$:. |
|
4300 |
newParts := newParts select:[:part | part size > 0]. |
|
4301 |
||
4302 |
codeView |
|
4303 |
undoableDo:[ |
|
4304 |
|newCursorPosition stop| |
|
4305 |
||
4306 |
numArgs > nSelParts ifTrue:[ |
|
4307 |
stop := selectorParts last stop. |
|
4308 |
||
4309 |
"/ append the rest ... |
|
4310 |
numArgs downTo:nSelParts+1 do:[:idx | |
|
4311 |
|newPart| |
|
4312 |
||
4313 |
newPart := newParts at:idx. |
|
4314 |
(best endsWith:$:) ifTrue:[ |
|
4315 |
newPart := newPart , ':' |
|
4316 |
]. |
|
4317 |
||
4318 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
|
4319 |
newPart := ':' , newPart. |
|
4320 |
]. |
|
4321 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
4322 |
||
4323 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
|
4324 |
newCursorPosition := stop + newPart size. |
|
4325 |
] |
|
4326 |
]. |
|
4327 |
||
4328 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
4329 |
|newPart oldPartialToken start stop nextChar| |
|
4330 |
||
4331 |
newPart := newParts at:idx. |
|
4332 |
oldPartialToken := selectorParts at:idx. |
|
4333 |
start := oldPartialToken start. |
|
4334 |
stop := oldPartialToken stop. |
|
4335 |
||
4336 |
(best isKeywordSelector) ifTrue:[ |
|
4337 |
(oldPartialToken value endsWith:$:) ifTrue:[ |
|
4338 |
newPart := newPart , ':' |
|
4339 |
] ifFalse:[ |
|
4340 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
4341 |
newPart := newPart , ':' |
|
4342 |
] |
|
4343 |
] |
|
4344 |
] ifFalse:[ |
|
4345 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
4346 |
newPart := newPart , ':' |
|
4347 |
] ifFalse:[ |
|
4348 |
nextChar := codeView characterAtCharacterPosition:stop+1. |
|
4349 |
nextChar isSeparator ifFalse:[ |
|
4350 |
(').' includes:nextChar) ifFalse:[ |
|
4351 |
newPart := newPart , ' ' |
|
4352 |
]. |
|
4353 |
] |
|
4354 |
] |
|
4345 | 4355 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
4356 |
"/ ] ifFalse:[ |
|
4357 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
4710 | 4358 |
]. |
4359 |
||
4360 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
4361 |
||
4362 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
4363 |
newCursorPosition isNil ifTrue:[ |
|
4364 |
oldLen := stop - start + 1. |
|
4365 |
newLen := newPart size. |
|
4366 |
||
4367 |
newCursorPosition := stop + (newLen-oldLen) |
|
4368 |
]. |
|
4369 |
]. |
|
4370 |
||
4371 |
codeView cursorToCharacterPosition:newCursorPosition. |
|
4372 |
codeView cursorRight. "/ avoid going to the next line !! |
|
4373 |
||
4374 |
((best endsWith:':') and:[numArgs == 1]) ifTrue:[ |
|
4375 |
|impls impl| |
|
4376 |
||
4377 |
"/ see if it expects a block argument (heuristic) |
|
4378 |
best := best asSymbol. |
|
4379 |
(node notNil |
|
4380 |
and:[classOrNil notNil |
|
4381 |
and:[node receiver isSelf]]) ifTrue:[ |
|
4382 |
(impl := classOrNil whichClassImplements:best) isNil ifTrue:[ |
|
4383 |
impls := #(). |
|
4384 |
Screen current beep. |
|
4385 |
] ifFalse:[ |
|
4386 |
impls := { impl } |
|
4387 |
] |
|
4388 |
] ifFalse:[ |
|
4389 |
impls := Smalltalk allImplementorsOf:best. |
|
4390 |
]. |
|
4391 |
(impls contains:[:cls | |
|
4392 |
|argName| |
|
4393 |
||
4394 |
argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase. |
|
4395 |
(argName includesString:'block') or:[ (argName includesString:'action')]] |
|
4396 |
) ifTrue:[ |
|
4397 |
codeView insertStringAtCursor:'[' |
|
4398 |
]. |
|
4399 |
]. |
|
4400 |
codeView dontReplaceSelectionOnInput. |
|
4401 |
] |
|
4402 |
info:'Completion'. |
|
4345 | 4403 |
]. |
4404 |
||
4405 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
4406 |
"Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 4407 |
"Modified: / 28-08-2013 / 15:27:32 / cg" |
4345 | 4408 |
! |
4409 |
||
4238 | 4410 |
codeCompletionForVariable:node inClass:classOrNil codeView:codeView |
4277 | 4411 |
|parent nonMetaClass crsrPos nm |
4238 | 4412 |
allVariables allDistances best nodeVal |
4413 |
char start stop oldLen newLen oldVar |
|
4485 | 4414 |
getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc |
4238 | 4415 |
globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart| |
4416 |
||
4417 |
classOrNil notNil ifTrue:[ |
|
4548 | 4418 |
nonMetaClass := classOrNil theNonMetaclass. |
4238 | 4419 |
]. |
4420 |
||
4421 |
nm := node name. |
|
4422 |
||
4423 |
"/ if we are behind the variable and a space has already been entered, |
|
4424 |
"/ the user is probably looking for a message selector. |
|
4425 |
"/ If the variable represents a global, present its instance creation messages |
|
4426 |
crsrPos := codeView characterPositionOfCursor. |
|
4427 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
|
4428 |
char isSeparator ifTrue:[ |
|
4548 | 4429 |
classOrNil isNil ifTrue:[ |
4430 |
nodeVal := Smalltalk at:nm asSymbol. |
|
4431 |
] ifFalse:[ |
|
4432 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
4433 |
]. |
|
4434 |
nodeVal isBehavior ifTrue:[ |
|
4435 |
|methods menu exitKey idx| |
|
4436 |
||
4437 |
methods := nodeVal class methodDictionary values |
|
4438 |
select:[:m | |cat| |
|
4439 |
cat := m category asLowercase. |
|
4440 |
cat = 'instance creation' |
|
4441 |
]. |
|
4442 |
||
4443 |
menu := PopUpMenu labels:(methods collect:[:each | each selector]). |
|
4444 |
menu hideOnKeyFilter:[:key | |hide| |
|
4445 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
4446 |
hide ifTrue:[ |
|
4447 |
exitKey := key. |
|
4448 |
]. |
|
4449 |
hide]. |
|
4450 |
||
4451 |
idx := menu startUp. |
|
4452 |
idx == 0 ifTrue:[ |
|
4453 |
exitKey notNil ifTrue:[ |
|
4454 |
codeView keyPress:exitKey x:0 y:0. |
|
4455 |
]. |
|
4456 |
^ self |
|
4457 |
]. |
|
4458 |
best := (methods at:idx) selector. |
|
4459 |
codeView |
|
4460 |
undoableDo:[ |
|
4461 |
codeView insertString:best atCharacterPosition:crsrPos. |
|
4462 |
codeView cursorToCharacterPosition:crsrPos+best size. |
|
4463 |
] |
|
4464 |
info:'completion'. |
|
4465 |
^ self. |
|
4466 |
]. |
|
4238 | 4467 |
]. |
4468 |
||
4277 | 4469 |
((parent := node parent) notNil and:[parent isMessage]) ifTrue:[ |
4548 | 4470 |
node == parent receiver ifTrue:[ |
4471 |
selectorOfMessageToNode := parent selector |
|
4472 |
] |
|
4238 | 4473 |
]. |
4474 |
||
4475 |
getDistanceComputeBlockWithWeight := |
|
4548 | 4476 |
[:weight | |
4477 |
[:each | |
|
4478 |
|dist factor| |
|
4479 |
||
4480 |
dist := each spellAgainst:nm. |
|
4481 |
factor := 1. |
|
4482 |
||
4483 |
(each startsWith:nm) ifTrue:[ |
|
4484 |
factor := 6 * nm size. |
|
4485 |
] ifFalse:[ |
|
4486 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
4487 |
factor := 4 * nm size. |
|
4488 |
]. |
|
4489 |
]. |
|
4490 |
dist := dist + (weight*factor). |
|
4491 |
||
4492 |
each -> (dist * weight) |
|
4493 |
] |
|
4494 |
]. |
|
4238 | 4495 |
|
4496 |
addWithFactorBlock := |
|
4548 | 4497 |
[:eachNames :factor | |namesToAdd| |
4498 |
namesToAdd := eachNames select:[:nameToAdd | nameToAdd ~= nm ]. |
|
4499 |
namesToAdd := namesToAdd reject:[:each | allVariables includes:each ]. |
|
4500 |
allVariables addAll:namesToAdd. |
|
4501 |
allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)). |
|
4502 |
]. |
|
4238 | 4503 |
|
4504 |
nm isUppercaseFirst ifTrue:[ |
|
4548 | 4505 |
globalFactor := 2. "/ favour globals |
4506 |
localFactor := 1. |
|
4238 | 4507 |
] ifFalse:[ |
4548 | 4508 |
globalFactor := 1. "/ favour locals |
4509 |
localFactor := 2. |
|
4238 | 4510 |
]. |
4511 |
||
4512 |
allVariables := OrderedCollection new. |
|
4513 |
allDistances := OrderedCollection new. |
|
4514 |
||
4308 | 4515 |
"/ are we in the method's selector spec ? |
4548 | 4516 |
((parent := node parent) notNil |
4277 | 4517 |
and:[parent isMethod |
4518 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
4548 | 4519 |
"/ now thats cool: look how the naem of this argument is in other implementations |
4520 |
"/ of this method, and take that as a basis of the selection |
|
4521 |
||
4522 |
implementors := SystemBrowser |
|
4523 |
findImplementorsOf:(parent selector) |
|
4524 |
in:(Smalltalk allClasses) |
|
4525 |
ignoreCase:false. |
|
4526 |
"/ which argument is it |
|
4527 |
argIdx := parent arguments indexOf:node. |
|
4528 |
implementors size > 50 ifTrue:[ |
|
4529 |
implementors := implementors asOrderedCollection copyTo:50. |
|
4530 |
]. |
|
4531 |
namesUsed := implementors |
|
4532 |
collect:[:eachImplementor | |
|
4533 |
|parseTree| |
|
4534 |
parseTree := eachImplementor parseTree. |
|
4535 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
4536 |
ifFalse:nil |
|
4537 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
4538 |
thenSelect:[:a | a notNil] as:Set. |
|
4539 |
||
4540 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
4541 |
||
4542 |
classOrNil notNil ifTrue:[ |
|
4543 |
"/ also, look for the keyword before the argument, |
|
4544 |
"/ and see if there is such an instVar |
|
4545 |
"/ if so, add it with -Arg |
|
4546 |
parent selector isKeyword ifTrue:[ |
|
4547 |
kwPart := parent selector keywords at:argIdx. |
|
4548 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
|
4549 |
addWithFactorBlock |
|
4550 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
4551 |
value:(1 * localFactor). |
|
4552 |
]. |
|
4553 |
]. |
|
4554 |
] |
|
4238 | 4555 |
] ifFalse:[ |
4548 | 4556 |
classOrNil notNil ifTrue:[ |
4557 |
"/ locals in the block/method |
|
4558 |
|names| |
|
4559 |
||
4560 |
names := node allVariablesOnScope. |
|
4561 |
"/ if there were no variables (due to a parse error) |
|
4562 |
"/ do another parse and see what we have |
|
4563 |
names isEmpty ifTrue:[ |
|
4564 |
tree := self treeForCode:(codeView contentsAsString string) allowErrors:true. |
|
4565 |
"/ better if we already have a body (include locals then) |
|
4566 |
"/ otherwise, only the arguments are considered |
|
4567 |
tree notNil ifTrue:[ |
|
4568 |
names := (tree body ? tree) allVariablesOnScope. |
|
4569 |
] |
|
4570 |
]. |
|
4571 |
||
4572 |
addWithFactorBlock value:names value:(4 * localFactor). |
|
4573 |
||
4574 |
"/ instance variables |
|
4575 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
4576 |
||
4577 |
"/ inherited instance variables |
|
4578 |
classOrNil superclass notNil ifTrue:[ |
|
4579 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
4580 |
]. |
|
4581 |
]. |
|
4582 |
||
4583 |
selectorOfMessageToNode notNil ifTrue:[ |
|
4584 |
|names responders nonResponders| |
|
4585 |
||
4586 |
"/ responding to that messsage |
|
4587 |
||
4588 |
classOrNil notNil ifTrue:[ |
|
4589 |
"/ private classes |
|
4590 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
4591 |
value:(1.75 * globalFactor). |
|
4592 |
||
4593 |
"/ class variables |
|
4594 |
names := nonMetaClass classVarNames. |
|
4595 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
4596 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
4597 |
||
4598 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
4599 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
4600 |
||
4601 |
"/ superclass var names |
|
4602 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
4603 |
names := superClass classVarNames. |
|
4604 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
4605 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
4606 |
||
4607 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
|
4608 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
4609 |
]. |
|
4610 |
||
4611 |
"/ namespace vars |
|
4612 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
4613 |
names := classOrNil topNameSpace keys. |
|
4614 |
names := names reject:[:nm | nm includes:$:]. |
|
4615 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4616 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4617 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4618 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
4619 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
4620 |
]. |
|
4621 |
]. |
|
4622 |
||
4623 |
"/ globals |
|
4624 |
names := Smalltalk keys. |
|
4625 |
"/ names := names reject:[:nm | nm includes:$:]. |
|
4626 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4627 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4628 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4629 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
4630 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
4631 |
||
4632 |
"/ pool variables |
|
4633 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
4634 |
|pool| |
|
4635 |
||
4636 |
pool := Smalltalk at:poolName. |
|
4637 |
names := pool classVarNames. |
|
4638 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4639 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4640 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
4641 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
4642 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
4643 |
]. |
|
4644 |
] ifFalse:[ |
|
4645 |
|names| |
|
4646 |
||
4647 |
classOrNil notNil ifTrue:[ |
|
4648 |
"/ private classes |
|
4649 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
4650 |
value:(1.75 * globalFactor). |
|
4651 |
||
4652 |
"/ class variables |
|
4653 |
addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor). |
|
4654 |
classOrNil superclass notNil ifTrue:[ |
|
4655 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor). |
|
4656 |
]. |
|
4657 |
||
4658 |
"/ namespace vars |
|
4659 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
4660 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
4661 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4662 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
4663 |
]. |
|
4664 |
||
4665 |
"/ pool variables |
|
4666 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
4667 |
|pool| |
|
4668 |
||
4669 |
pool := Smalltalk at:poolName. |
|
4670 |
names := pool classVarNames. |
|
4671 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
4672 |
]. |
|
4673 |
]. |
|
4674 |
||
4675 |
"/ globals |
|
4676 |
names := Smalltalk keys. |
|
4677 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4678 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
4679 |
]. |
|
4680 |
||
4681 |
"/ pseudos - assuming that thisContext is seldom used. |
|
4682 |
"/ also assuming, that nil is short so its usually typed in. |
|
4683 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
4684 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
4685 |
addWithFactorBlock value:#('super' 'false') value:(2 * localFactor). |
|
4686 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
|
4687 |
addWithFactorBlock value:#('true') value:(1 * localFactor). |
|
4688 |
addWithFactorBlock value:#('false') value:(1 * localFactor). |
|
4238 | 4689 |
]. |
4690 |
||
4691 |
allDistances isEmpty ifTrue:[^ self]. |
|
4692 |
bestAssoc := allDistances at:1. |
|
4693 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
4548 | 4694 |
ifTrue:[el] |
4695 |
ifFalse:[best] |
|
4696 |
]. |
|
4697 |
||
4698 |
allDistances sort:[:a :b | |
|
4699 |
a value > b value ifTrue:[ |
|
4700 |
true |
|
4701 |
] ifFalse:[ |
|
4702 |
a value = b value ifTrue:[ |
|
4703 |
a key < b key |
|
4704 |
] ifFalse:[ |
|
4705 |
false |
|
4706 |
] |
|
4707 |
] |
|
4708 |
]. |
|
4340 | 4709 |
((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[ |
4548 | 4710 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)]. |
4711 |
allTheBest size > 15 ifTrue:[ |
|
4712 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)]. |
|
4713 |
]. |
|
4238 | 4714 |
]. |
4715 |
||
4524 | 4716 |
start := node start. |
4717 |
stop := node stop. |
|
4718 |
||
4548 | 4719 |
best := self askUserForCompletion:('Variable for "%1"' bindWith:node name) |
4720 |
for:codeView at: start |
|
4721 |
from:(allTheBest collect:[:assoc | assoc key]). |
|
4238 | 4722 |
best isNil ifTrue:[^ self]. |
4723 |
||
4724 |
"/ self showInfo:best. |
|
4725 |
||
4726 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
4727 |
||
4728 |
codeView |
|
4548 | 4729 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
4730 |
info:'Completion'. |
|
4238 | 4731 |
|
4732 |
(best startsWith:oldVar) ifTrue:[ |
|
4548 | 4733 |
oldLen := stop - start + 1. |
4734 |
newLen := best size. |
|
4735 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
4736 |
codeView dontReplaceSelectionOnInput |
|
4238 | 4737 |
]. |
4738 |
||
4739 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
4740 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 4741 |
"Modified: / 28-08-2013 / 15:37:28 / cg" |
4238 | 4742 |
! ! |
4743 |
||
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4744 |
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4745 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4746 |
bestName:bestNameArg matchingNames:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4747 |
^ self with:bestNameArg with:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4748 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4749 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4750 |
self bestName:123 matchingNames:345 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4751 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4752 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4753 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4754 |
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4755 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4756 |
bestName |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4757 |
^ self at:1 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4758 |
! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4759 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4760 |
matchingNames |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4761 |
^ self at:2 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4762 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
4763 |
|
2376 | 4764 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
4765 |
||
4281 | 4766 |
version |
4710 | 4767 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.218 2015-02-13 21:00:46 cg Exp $' |
4281 | 4768 |
! |
4769 |
||
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
4770 |
version_CVS |
4710 | 4771 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.218 2015-02-13 21:00:46 cg Exp $' |
2376 | 4772 |
! ! |
4194 | 4773 |