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