author | Claus Gittinger <cg@exept.de> |
Tue, 03 Sep 2013 14:14:25 +0200 | |
changeset 4368 | 442517f0d19d |
parent 4367 | dd00d1570f88 |
child 4369 | 810a78e62f88 |
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 |
|
4352 | 1095 |
"OBSOLETE; migrating to use the into protocol. |
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 |
"/ classOrNil isNil ifTrue:[ |
|
1108 |
"/ self information:'No class'. |
|
1109 |
"/ ^ self. |
|
1110 |
"/ ]. |
|
1111 |
||
1112 |
crsrPos := codeView characterPositionOfCursor"-1". |
|
1113 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
4301 | 1114 |
"/ Transcript show:crsrPos; show:' '; showCR:char. |
4238 | 1115 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
1116 |
crsrPos := crsrPos - 1. |
|
1117 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
1118 |
]. |
|
1119 |
||
1120 |
interval := codeView selectedInterval. |
|
4301 | 1121 |
"/ Transcript show:'iv: '; showCR:interval. |
4238 | 1122 |
interval isEmpty ifTrue:[ |
4301 | 1123 |
interval := crsrPos"-1" to:crsrPos. |
1124 |
"/ Transcript show:'iv2: '; showCR:interval. |
|
4238 | 1125 |
]. |
1126 |
||
1127 |
source := codeView contentsAsString string. |
|
1128 |
source := source copyTo:crsrPos. |
|
1129 |
||
1130 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
1131 |
"/ we will not find a node for a long time (stepping back more and more, |
|
1132 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
1133 |
"/ without any progress. |
|
1134 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
1135 |
"/ as it parses the code. Stop, when the interval is hit. |
|
1136 |
"/ that will also work for syntactic incorrect source code. |
|
1137 |
classOrNil notNil ifTrue:[ |
|
1138 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
|
4301 | 1139 |
"/ Transcript show:'nd1: '; showCR:node. |
4238 | 1140 |
]. |
1141 |
node isNil ifTrue:[ |
|
1142 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false. |
|
4301 | 1143 |
"/ Transcript show:'nd2: '; showCR:node. |
4238 | 1144 |
]. |
1145 |
"/ [node isNil] whileTrue:[ |
|
1146 |
"/ "/ expand to the left ... |
|
1147 |
"/ interval start > 1 ifFalse:[ |
|
1148 |
"/ self information:'No parseNode found'. |
|
1149 |
"/ ^ self. |
|
1150 |
"/ ]. |
|
1151 |
"/ interval start:(interval start - 1). |
|
1152 |
"/ node := self findNodeForInterval:interval in:source allowErrors:true. |
|
1153 |
"/ ]. |
|
1154 |
node isNil ifTrue:[ |
|
4334 | 1155 |
Transcript showCR:'No parseNode found (syntax error before?)'. |
4238 | 1156 |
self breakPoint:#cg. |
4334 | 1157 |
self information:'No parseNode found (syntax error before?)'. |
4238 | 1158 |
^ self. |
1159 |
]. |
|
1160 |
||
4346 | 1161 |
forceNewMessageSend := false. |
1162 |
||
1163 |
"/ if there a separator between the variable's name and the cursor position... |
|
1164 |
(codeView characterBeforeCursor isSeparator |
|
1165 |
or:[ ')}]''' includes:codeView characterBeforeCursor ] |
|
1166 |
) ifTrue:[ |
|
1167 |
(node isVariable |
|
1168 |
and:[ (parent := node parent) notNil |
|
1169 |
and:[ parent isMessage ]] |
|
1170 |
) ifTrue:[ |
|
1171 |
"/ completion after a variable node... |
|
1172 |
parent isKeyword ifTrue:[ |
|
1173 |
"/ and it is a keyword message, we complete the keyword message instead |
|
1174 |
node := parent. |
|
1175 |
] ifFalse:[ |
|
1176 |
"/ otherwise, a unary message is probably intended to be sent to the variable. |
|
1177 |
"/ (however, no character is available to determine what is useful) |
|
1178 |
forceNewMessageSend := true. |
|
1179 |
]. |
|
1180 |
] ifFalse:[ |
|
1181 |
(node isUnary) ifTrue:[ |
|
1182 |
"/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo) |
|
1183 |
"/ |
|
1184 |
forceNewMessageSend := true. |
|
1185 |
"/ "/ can we see what we get from foo? |
|
1186 |
"/ classOfReceiver := self |
|
1187 |
"/ classOfReceiver:node receiver |
|
1188 |
"/ inClass:classOrNil instance:instanceOrNil context:contextOrNil. |
|
1189 |
"/ classOfReceiver notNil ifTrue:[ |
|
1190 |
"/ |mthd| |
|
1191 |
"/ |
|
1192 |
"/ mthd := classOfReceiver lookupMethodFor:node selector. |
|
1193 |
"/ mthd notNil ifTrue:[ |
|
1194 |
"/ self halt. |
|
1195 |
"/ (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[ |
|
1196 |
"/ forceNewMessageSend := true. |
|
1197 |
"/ ] |
|
1198 |
"/ ] |
|
1199 |
"/ ]. |
|
1200 |
] |
|
1201 |
] |
|
1202 |
]. |
|
1203 |
||
1204 |
forceNewMessageSend ifTrue:[ |
|
1205 |
"/ completion with nothing to start (right after a variable) |
|
1206 |
"/ see what the variable can understand and present the most useful stuff (very thin ice here) |
|
4358 | 1207 |
classOfReceiver := self classOfNode:node. |
4346 | 1208 |
classOfReceiver isNil ifTrue:[ |
1209 |
"/ it does not make sense to offer anything, if we don't have any idea of what this |
|
1210 |
"/ will be... |
|
1211 |
Screen current beep. |
|
1212 |
] ifFalse:[ |
|
1213 |
|superClass possible choice| |
|
1214 |
||
1215 |
possible := classOfReceiver selectors. |
|
1216 |
superClass := classOfReceiver superclass. |
|
1217 |
[superClass notNil and:[(possible size + superClass selectors size) < 50]] whileTrue:[ |
|
1218 |
possible := possible,superClass selectors. |
|
1219 |
superClass := superClass superclass. |
|
1220 |
]. |
|
1221 |
possible := possible copy sort. |
|
1222 |
choice := self askUserForCompletion:('Message to "%1"' bindWith:node name) for:codeView from:possible. |
|
1223 |
choice isNil ifTrue:[ |
|
1224 |
Screen current beep. |
|
1225 |
^ self |
|
1226 |
]. |
|
1227 |
||
1228 |
codeView |
|
1229 |
undoableDo:[ |
|
1230 |
codeView insertStringAtCursor:choice |
|
1231 |
] |
|
1232 |
info:'Completion'. |
|
1233 |
]. |
|
1234 |
^ self |
|
4238 | 1235 |
]. |
1236 |
||
1237 |
node isVariable ifTrue:[ |
|
1238 |
self codeCompletionForVariable:node inClass:classOrNil codeView:codeView. |
|
1239 |
^ self. |
|
1240 |
]. |
|
1241 |
node isLiteral ifTrue:[ |
|
1242 |
node value isSymbol ifTrue:[ |
|
1243 |
self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView. |
|
1244 |
^ self. |
|
1245 |
]. |
|
4348 | 1246 |
^ self "/ huh - strings or what? |
4238 | 1247 |
]. |
1248 |
||
1249 |
checkedNode := node. |
|
1250 |
[checkedNode notNil] whileTrue:[ |
|
1251 |
checkedNode isMessage ifTrue:[ |
|
1252 |
"/ completion in a message-send |
|
4326 | 1253 |
contextOrNil notNil ifTrue:[ |
4329 | 1254 |
"/ |rcvrNode idx rcvr val| |
1255 |
"/ |
|
1256 |
"/ (rcvrNode := checkedNode receiver) isVariable ifTrue:[ |
|
1257 |
"/ rcvrNode isSelf ifTrue:[ |
|
1258 |
"/ classOrNil := contextOrNil receiver class. |
|
1259 |
"/ ] ifFalse:[ |
|
1260 |
"/ (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1261 |
"/ val := contextOrNil argsAndVars at:idx. |
|
1262 |
"/ classOrNil := val class. |
|
1263 |
"/ ] ifFalse:[ |
|
1264 |
"/ (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[ |
|
1265 |
"/ val := contextOrNil receiver instVarNamed:rcvrNode name. |
|
1266 |
"/ classOrNil := val class. |
|
1267 |
"/ ] |
|
1268 |
"/ ] |
|
1269 |
"/ ] |
|
1270 |
"/ ]. |
|
1271 |
instanceOrNil := contextOrNil receiver |
|
4326 | 1272 |
]. |
4344 | 1273 |
self |
1274 |
codeCompletionForMessage:checkedNode |
|
1275 |
inClass:classOrNil instance:instanceOrNil |
|
1276 |
context:contextOrNil codeView:codeView. |
|
4238 | 1277 |
^ self |
1278 |
]. |
|
1279 |
checkedNode isMethod ifTrue:[ |
|
1280 |
"/ completion in a method's selector pattern |
|
4352 | 1281 |
self codeCompletionForMethodSpec:checkedNode. |
4238 | 1282 |
^ self. |
1283 |
]. |
|
1284 |
checkedNode := checkedNode parent. |
|
1285 |
]. |
|
1286 |
||
1287 |
self information:'Node is neither variable nor message.'. |
|
1288 |
||
1289 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
4346 | 1290 |
"Modified: / 28-08-2013 / 17:15:25 / cg" |
4352 | 1291 |
! |
1292 |
||
1293 |
codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock |
|
1294 |
"contextOrNil is the current context, if this is called from the debugger; |
|
1295 |
or nil, if called from the browser. |
|
1296 |
If nonNil, we can make better guesses, because we actually know what a variable's type is" |
|
1297 |
||
1298 |
|crsrPos char interval source partialSource suggestions1 suggestions2 actions1 actions2 title1 title2| |
|
1299 |
||
1300 |
methodOrNil := methodOrNilArg. |
|
1301 |
classOrNil := classOrNilArg. |
|
1302 |
codeView := codeViewArg. |
|
1303 |
contextOrNil := contextOrNilArg. |
|
1304 |
||
1305 |
"/ classOrNil isNil ifTrue:[ |
|
1306 |
"/ self information:'No class'. |
|
1307 |
"/ ^ self. |
|
1308 |
"/ ]. |
|
1309 |
||
1310 |
crsrPos := codeView characterPositionOfCursor"-1". |
|
1311 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
1312 |
||
1313 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
|
1314 |
crsrPos := crsrPos - 1. |
|
1315 |
char := codeView characterAtCharacterPosition:crsrPos. |
|
1316 |
]. |
|
1317 |
||
1318 |
interval := crsrPos-1 to:crsrPos. |
|
1319 |
||
1320 |
source := codeView contentsAsString string. |
|
1321 |
partialSource := source copyTo:crsrPos. |
|
1322 |
||
1323 |
self |
|
1324 |
tryCodeCompletionWithSource:partialSource nodeInterval:interval |
|
1325 |
into:[:listOfSuggestions :listOfActions :titleWhenAsking | |
|
1326 |
suggestions1 := listOfSuggestions. |
|
1327 |
actions1 := listOfActions. |
|
1328 |
title1 := titleWhenAsking. |
|
4358 | 1329 |
"/ suggestions1 size>100 ifTrue:[ self halt]. |
4352 | 1330 |
]. |
1331 |
||
1332 |
suggestions1 notEmptyOrNil ifTrue:[ |
|
1333 |
actionBlock value:suggestions1 value:actions1 value:title1. |
|
1334 |
] ifFalse:[ |
|
4353 | 1335 |
self |
1336 |
tryCodeCompletionWithSource:source nodeInterval:interval |
|
1337 |
into:[:listOfSuggestions :listOfActions :titleWhenAsking | |
|
1338 |
suggestions2 := listOfSuggestions. |
|
1339 |
actions2 := listOfActions. |
|
1340 |
title2 := titleWhenAsking. |
|
1341 |
]. |
|
1342 |
||
4352 | 1343 |
suggestions2 notEmptyOrNil ifTrue:[ |
1344 |
actionBlock value:suggestions2 value:actions2 value:title2. |
|
1345 |
] |
|
1346 |
]. |
|
4238 | 1347 |
! ! |
1348 |
||
1349 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers'! |
|
1350 |
||
1351 |
askUserForCompletion:what for:codeView at:position from:allTheBest |
|
1352 |
|list choice lastChoice| |
|
1353 |
||
1354 |
"/ cg: until the new stuff works,... |
|
1355 |
^ self old_askUserForCompletion:what for:codeView from:allTheBest. |
|
1356 |
||
4346 | 1357 |
"/ allTheBest isEmpty ifTrue:[ |
1358 |
"/ ^ nil |
|
1359 |
"/ ]. |
|
1360 |
"/ allTheBest size == 1 ifTrue:[ |
|
1361 |
"/ ^ allTheBest first |
|
1362 |
"/ ]. |
|
1363 |
"/ list := allTheBest. |
|
1364 |
"/ LastChoices notNil ifTrue:[ |
|
1365 |
"/ lastChoice := LastChoices at:what ifAbsent:nil. |
|
1366 |
"/ lastChoice notNil ifTrue:[ |
|
1367 |
"/ list := { lastChoice allBold } , (list copyWithout:lastChoice). |
|
1368 |
"/ ]. |
|
1369 |
"/ ]. |
|
1370 |
"/ choice := Tools::CodeCompletionMenu |
|
1371 |
"/ openFor:codeView |
|
1372 |
"/ at:position |
|
1373 |
"/ with:allTheBest. |
|
1374 |
"/ LastChoices isNil ifTrue:[ |
|
1375 |
"/ LastChoices := Dictionary new. |
|
1376 |
"/ ]. |
|
1377 |
"/ LastChoices at:what put:choice. |
|
1378 |
"/ ^ choice string |
|
4238 | 1379 |
|
1380 |
"Created: / 16-02-2010 / 10:09:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 1381 |
"Modified: / 28-08-2013 / 16:41:35 / cg" |
4238 | 1382 |
! |
1383 |
||
1384 |
askUserForCompletion:what for:codeView from:allTheBest |
|
1385 |
|list resources choice lastChoice| |
|
1386 |
||
1387 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
1388 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
1389 |
||
1390 |
list := allTheBest. |
|
1391 |
LastChoices notNil ifTrue:[ |
|
1392 |
lastChoice := LastChoices at:what ifAbsent:nil. |
|
1393 |
lastChoice notNil ifTrue:[ |
|
1394 |
list := {lastChoice. nil. } , (list copyWithout:lastChoice). |
|
1395 |
]. |
|
1396 |
]. |
|
1397 |
||
1398 |
list size < 30 ifTrue:[ |
|
1399 |
|menu idx exitKey| |
|
1400 |
||
1401 |
menu := PopUpMenu labels:list. |
|
1402 |
menu hideOnKeyFilter:[:key | |hide| |
|
1403 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
1404 |
hide ifTrue:[ |
|
1405 |
exitKey := key. |
|
1406 |
]. |
|
1407 |
hide]. |
|
1408 |
||
1409 |
idx := menu startUp. |
|
1410 |
idx == 0 ifTrue:[ |
|
1411 |
exitKey notNil ifTrue:[ |
|
1412 |
codeView keyPress:exitKey x:0 y:0. |
|
1413 |
]. |
|
1414 |
^ nil |
|
1415 |
]. |
|
1416 |
choice := list at:idx. |
|
1417 |
] ifFalse:[ |
|
1418 |
resources := codeView application isNil |
|
1419 |
ifTrue:[ codeView resources] |
|
1420 |
ifFalse:[ codeView application resources ]. |
|
1421 |
||
1422 |
choice := Dialog |
|
1423 |
choose:(resources string:'Choose ',what) |
|
1424 |
fromList:list |
|
1425 |
lines:20 |
|
1426 |
title:(resources string:'Code completion'). |
|
1427 |
choice isNil ifTrue:[^ nil]. |
|
1428 |
]. |
|
1429 |
||
1430 |
LastChoices isNil ifTrue:[ |
|
1431 |
LastChoices := Dictionary new. |
|
1432 |
]. |
|
1433 |
LastChoices at:what put:choice. |
|
1434 |
^ choice |
|
1435 |
||
1436 |
"Created: / 10-11-2006 / 14:00:53 / cg" |
|
1437 |
! |
|
1438 |
||
4358 | 1439 |
classOfNode:aNode |
4352 | 1440 |
"when showing possible completions for a message, it is a good idea to know what the reveiver |
1441 |
is." |
|
1442 |
||
4364 | 1443 |
| nm nodeVal receiverClass nodeSelector nodeReceiver| |
4346 | 1444 |
|
4358 | 1445 |
aNode isLiteral ifTrue:[ |
1446 |
^ aNode value class |
|
4346 | 1447 |
]. |
4358 | 1448 |
aNode isVariable ifTrue:[ |
1449 |
nm := aNode name. |
|
4346 | 1450 |
nm = 'self' ifTrue:[ |
4358 | 1451 |
classOrNil isNil ifTrue:[^ UndefinedObject]. |
1452 |
^ classOrNil |
|
4346 | 1453 |
]. |
1454 |
nm = 'super' ifTrue:[ |
|
4358 | 1455 |
classOrNil isNil ifTrue:[^ Object]. |
1456 |
^ classOrNil superclass |
|
4346 | 1457 |
]. |
1458 |
nm isUppercaseFirst ifTrue:[ |
|
1459 |
"/ wouldn't it be better to simply 'evaluate' the variable ? |
|
1460 |
Error handle:[:ex | |
|
1461 |
] do:[ |
|
1462 |
|dummyReceiver| |
|
1463 |
||
4358 | 1464 |
dummyReceiver := classOrNil notNil ifTrue:[classOrNil basicNew] ifFalse:[nil]. |
4346 | 1465 |
nodeVal := Parser new evaluate:nm in:nil receiver:dummyReceiver. |
1466 |
]. |
|
1467 |
"/ (Smalltalk includesKey:nm asSymbol) ifTrue:[ |
|
1468 |
"/ nodeVal := Smalltalk at:nm asSymbol. |
|
1469 |
"/ ]. |
|
1470 |
nodeVal notNil ifTrue:[ |
|
1471 |
^ nodeVal class |
|
1472 |
] |
|
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 |
]. |
|
1489 |
]. |
|
1490 |
] |
|
1491 |
]. |
|
1492 |
]. |
|
1493 |
||
4358 | 1494 |
aNode isMessage ifTrue:[ |
4364 | 1495 |
nodeSelector := aNode selector. |
1496 |
nodeReceiver := aNode receiver. |
|
1497 |
||
4352 | 1498 |
"/ some hardwired knowlegde here |
4364 | 1499 |
( #( #'new' #'basicNew' #'new:' #'basicNew:') includes: nodeSelector ) ifTrue:[ |
1500 |
receiverClass := self classOfNode:nodeReceiver. |
|
4346 | 1501 |
receiverClass notNil ifTrue:[ |
1502 |
receiverClass isBehavior ifTrue:[ |
|
1503 |
receiverClass isMeta ifTrue:[ |
|
1504 |
^ receiverClass theNonMetaclass |
|
1505 |
] |
|
1506 |
] |
|
1507 |
]. |
|
1508 |
]. |
|
4358 | 1509 |
classOrNil notNil ifTrue:[ |
4364 | 1510 |
(nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[ |
4358 | 1511 |
^ classOrNil class |
4346 | 1512 |
]. |
1513 |
]. |
|
4364 | 1514 |
(nodeSelector = #'size') ifTrue:[ |
4352 | 1515 |
^ SmallInteger |
1516 |
]. |
|
1517 |
(#( isNil notNil not emptyOrNil notEmptyOrNil notEmpty isEmpty |
|
1518 |
= ~= == ~~ |
|
4364 | 1519 |
includes: contains: |
1520 |
and: or: |
|
1521 |
) includes:nodeSelector ) ifTrue:[ |
|
1522 |
^ True "/ Boolean - not boolean; it does not contain the full protocol (would not find ifTrue:) |
|
4358 | 1523 |
]. |
4364 | 1524 |
( #( + - * / // \\ ) includes:nodeSelector) ifTrue:[ |
4358 | 1525 |
"/ assume numeric |
1526 |
^ Number |
|
4352 | 1527 |
]. |
4346 | 1528 |
]. |
1529 |
^ nil |
|
1530 |
||
1531 |
"Created: / 28-08-2013 / 16:34:53 / cg" |
|
1532 |
! |
|
1533 |
||
4368 | 1534 |
codeCompletionForLiteralSymbol:node considerAll:considerAll into:actionBlock |
4352 | 1535 |
"looking for all symbols is way too much and inprecise; |
1536 |
experiment: only present symbols which are used by the class, |
|
1537 |
and classes in that class category. We'll see..." |
|
1538 |
||
1539 |
|sym possibleCompletions longest editAction start stop addSymbol| |
|
4238 | 1540 |
|
4302 | 1541 |
"/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 1542 |
|
4352 | 1543 |
start := node start. |
1544 |
stop := node stop. |
|
1545 |
(codeView characterAtCharacterPosition:stop) == $' ifTrue:[ |
|
1546 |
^ self. |
|
1547 |
]. |
|
1548 |
||
4238 | 1549 |
sym := node value. |
1550 |
possibleCompletions := OrderedCollection new. |
|
1551 |
||
4352 | 1552 |
addSymbol := |
1553 |
[:aSymbol | |
|
1554 |
(aSymbol startsWith:sym) ifTrue:[ |
|
1555 |
(aSymbol = sym) ifFalse:[ |
|
1556 |
possibleCompletions add:aSymbol |
|
1557 |
]. |
|
4238 | 1558 |
]. |
1559 |
]. |
|
4352 | 1560 |
|
4368 | 1561 |
(considerAll or:[classOrNil isNil]) ifTrue:[ |
1562 |
Symbol allInstancesDo:addSymbol. |
|
1563 |
] ifFalse:[ |
|
4352 | 1564 |
Smalltalk allClassesInCategory:classOrNil do:[:cls | |
1565 |
cls theNonMetaclass instAndClassMethodsDo:[:mthd | |
|
1566 |
mthd usedSymbols do:addSymbol |
|
1567 |
] |
|
1568 |
]. |
|
4238 | 1569 |
]. |
4352 | 1570 |
|
1571 |
possibleCompletions sort. |
|
1572 |
||
1573 |
longest := possibleCompletions longestCommonPrefix. |
|
1574 |
possibleCompletions remove:longest ifAbsent:[]. |
|
1575 |
possibleCompletions addFirst: longest. |
|
1576 |
||
1577 |
editAction := |
|
1578 |
[:chosenIndex | |
|
1579 |
|chosen oldSym oldLen newLen| |
|
1580 |
||
1581 |
chosen := possibleCompletions at:chosenIndex. |
|
1582 |
||
1583 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
1584 |
start := start + 1. |
|
1585 |
]. |
|
1586 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
1587 |
start := start + 1. |
|
1588 |
]. |
|
1589 |
||
1590 |
oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
1591 |
||
1592 |
codeView |
|
1593 |
undoableDo:[ |
|
1594 |
codeView replaceFromCharacterPosition:start to:stop with:chosen |
|
1595 |
] |
|
1596 |
info:'Completion'. |
|
1597 |
||
1598 |
(chosen startsWith:oldSym) ifTrue:[ |
|
1599 |
oldLen := stop - start + 1. |
|
1600 |
newLen := chosen size. |
|
1601 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
1602 |
codeView dontReplaceSelectionOnInput |
|
1603 |
]. |
|
1604 |
]. |
|
1605 |
||
1606 |
actionBlock value:possibleCompletions value:editAction value:'symbol'. |
|
4238 | 1607 |
|
1608 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1609 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
1610 |
! |
|
1611 |
||
1612 |
codeCompletionForMessage:node into:actionBlock |
|
1613 |
|selector srchClass implClass |
|
1614 |
bestSelectors selector2 bestSelectors2 allBest best info numArgs |
|
1615 |
newParts nSelParts oldLen newLen selectorParts |
|
4366 | 1616 |
findBest parentNode selectorsSentInCode split editAction parentNodeClassIfKnown |
1617 |
otherMessagesToReceiver possibleClasses| |
|
4238 | 1618 |
|
4302 | 1619 |
"/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 1620 |
|
1621 |
"/ classOrNil notNil ifTrue:[ |
|
1622 |
"/ parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true. |
|
1623 |
"/ selectorsSentInCode := parser messagesSent. |
|
1624 |
"/ ]. |
|
1625 |
||
1626 |
findBest := [:node :selector | |
|
1627 |
|srchClass bestSelectors bestPrefixes| |
|
1628 |
||
4361 | 1629 |
"/ codeView topView withCursor:(Cursor questionMark) do:[ |
4358 | 1630 |
srchClass := self classOfNode:node. |
4352 | 1631 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true. |
4361 | 1632 |
"/ ]. |
4238 | 1633 |
|
1634 |
(bestSelectors includes:selector) ifTrue:[ |
|
1635 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
|
1636 |
]. |
|
1637 |
bestSelectors |
|
1638 |
]. |
|
1639 |
||
1640 |
selector := node selector. |
|
4352 | 1641 |
parentNode := node parent. |
1642 |
||
4366 | 1643 |
"/ if there is already space before the cursor, and the parent node is not a message, |
1644 |
"/ do not attempty to complete the current message. |
|
1645 |
"/ If it is a message, we will look for parent-message completion also below (best2 stuff) |
|
4352 | 1646 |
(codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[ |
1647 |
(parentNode notNil and:[ parentNode isMessage ]) ifFalse:[ |
|
1648 |
^ self. |
|
1649 |
]. |
|
1650 |
]. |
|
1651 |
||
4358 | 1652 |
bestSelectors := findBest value:node receiver value:selector. |
4238 | 1653 |
|
4366 | 1654 |
"/ if the receiver is a variable, we can look for other messages being sent to |
1655 |
"/ that variable |
|
1656 |
(tree notNil and:[ node receiver isVariable ]) |
|
1657 |
ifTrue:[ |
|
1658 |
otherMessagesToReceiver := tree allMessageNodes |
|
1659 |
select:[:eachMessageNode | |
|
1660 |
node receiver = eachMessageNode receiver |
|
1661 |
and:[ selector ~= eachMessageNode selector]] |
|
1662 |
thenCollect:[:eachNode | eachNode selector]. |
|
1663 |
possibleClasses := Smalltalk allClassesForWhich:[:cls | |
|
1664 |
otherMessagesToReceiver conform:[:eachSelectorSent | cls canUnderstand:eachSelectorSent]]. |
|
1665 |
possibleClasses := possibleClasses select:[:cls | cls isLoaded]. |
|
1666 |
(possibleClasses notEmpty and:[possibleClasses size < 10]) ifTrue:[ |
|
1667 |
bestSelectors := Set new. |
|
1668 |
possibleClasses do:[:eachClass | |
|
1669 |
|bestSelectorsForClass| |
|
1670 |
||
1671 |
bestSelectorsForClass := Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true. |
|
1672 |
bestSelectors addAll:bestSelectorsForClass. |
|
1673 |
]. |
|
1674 |
bestSelectors := bestSelectors asOrderedCollection |
|
1675 |
]. |
|
1676 |
]. |
|
1677 |
||
4352 | 1678 |
"/ if we are behind a keyword messages colon, |
1679 |
"/ only look for matching prefix selectors; |
|
1680 |
"/ also, a good completion is to insert an argument; |
|
1681 |
"/ the name of the variable from the implementation, as comment, and selected might be a good one!! |
|
1682 |
selector isKeyword ifTrue:[ |
|
1683 |
codeView characterBeforeCursor == $: ifTrue:[ |
|
1684 |
bestSelectors := bestSelectors select:[:sel | sel startsWith:selector]. |
|
1685 |
bestSelectors isEmpty ifTrue:[ |
|
1686 |
"/ nothing better around |
|
1687 |
|argIndex argNames impls| |
|
1688 |
||
1689 |
argIndex := node selectorParts size. |
|
1690 |
argNames := Set new. |
|
1691 |
impls := Smalltalk allImplementorsOf:selector. |
|
1692 |
impls size < 10 ifTrue:[ |
|
1693 |
impls do:[:eachImplClass | |
|
1694 |
|mthd argName| |
|
1695 |
||
1696 |
mthd := (eachImplClass compiledMethodAt:selector). |
|
1697 |
argName := mthd methodArgNames at:argIndex. |
|
1698 |
argNames add:(argName,' in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate). |
|
1699 |
]. |
|
1700 |
argNames notEmptyOrNil ifTrue: [ |
|
1701 |
argNames := argNames asOrderedCollection sort. |
|
1702 |
actionBlock |
|
1703 |
value:argNames |
|
1704 |
value:[:selIndex | |
|
1705 |
] |
|
1706 |
value: 'argument name hint'. |
|
1707 |
^ self. |
|
1708 |
] |
|
1709 |
] |
|
1710 |
] |
|
1711 |
]. |
|
1712 |
]. |
|
1713 |
||
4358 | 1714 |
bestSelectors := bestSelectors asOrderedCollection sort:[:a :b | a size < b size]. |
1715 |
||
4238 | 1716 |
(node selector isUnarySelector |
1717 |
and:[ parentNode notNil |
|
4358 | 1718 |
and:[ parentNode isMessage ]]) ifTrue:[ |
1719 |
(selector2 := parentNode selector) isKeywordSelector ifTrue:[ |
|
1720 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
|
1721 |
"/ i.e. look if there is a longer keyword possible |
|
1722 |
selector2 := selector2,selector. |
|
1723 |
bestSelectors2 := findBest value:parentNode receiver value:selector2. |
|
1724 |
bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size]. |
|
1725 |
bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel]. |
|
4238 | 1726 |
] ifFalse:[ |
4358 | 1727 |
|kwSels| |
1728 |
||
1729 |
"/ if its a unary message AND the parent is a unary or binary node, try again, sending the partial message |
|
1730 |
"/ as a keyword to the parent node. |
|
1731 |
"/ this is the case when after "foo binOp bar if", which should include ifTrue: in the result. |
|
1732 |
"/ transform from |
|
1733 |
"/ foo == (shift if) |
|
1734 |
"/ nonKWsel-msg(parent) |
|
1735 |
"/ / \ |
|
1736 |
"/ / \ |
|
1737 |
"/ rcvr sel-unary(node) |
|
1738 |
"/ / |
|
1739 |
"/ / |
|
1740 |
"/ arg |
|
1741 |
"/ |
|
1742 |
"/ into: |
|
1743 |
"/ (foo == shift) if |
|
1744 |
"/ |
|
1745 |
"/ nonKWsel-msg(parent) |
|
1746 |
"/ / \ |
|
1747 |
"/ / \ |
|
1748 |
"/ rcvr sel-unary(node) |
|
1749 |
"/ / |
|
1750 |
"/ / |
|
1751 |
"/ arg |
|
1752 |
||
1753 |
kwSels := findBest value:parentNode value:selector. |
|
1754 |
kwSels := kwSels select:[:sel | sel isKeywordSelector]. |
|
1755 |
||
1756 |
kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size]. |
|
1757 |
||
1758 |
bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel]. |
|
1759 |
||
1760 |
"/ these need to go to bestSelectors (see editAction) |
|
4364 | 1761 |
parentNodeClassIfKnown := self classOfNode:parentNode. |
1762 |
(parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[ |
|
4358 | 1763 |
"/ this is so common, that it deserves a special case: |
1764 |
"/ if we complete an if after some boolean message e.g '(a == b) if' |
|
1765 |
"/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic) |
|
1766 |
bestSelectors := (bestSelectors ? #()) asOrderedCollection. |
|
1767 |
bestSelectors removeAllFoundIn:#( 'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:' |
|
1768 |
'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:' |
|
1769 |
'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:' ). |
|
1770 |
kwSels := (kwSels ? #()) asOrderedCollection. |
|
1771 |
kwSels removeAllFoundIn: #( 'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:' |
|
1772 |
'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:' |
|
1773 |
'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:' ). |
|
1774 |
"/ put them in front, because they are very likely |
|
1775 |
bestSelectors := kwSels , bestSelectors. |
|
4238 | 1776 |
] ifFalse:[ |
4358 | 1777 |
"/ put them at the end |
1778 |
bestSelectors := bestSelectors , kwSels. |
|
1779 |
]. |
|
1780 |
] |
|
1781 |
]. |
|
1782 |
||
1783 |
allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()). |
|
1784 |
||
1785 |
"/ if receiver is super, always include the method's own selector |
|
1786 |
node receiver isSuper ifTrue:[ |
|
4364 | 1787 |
(tree isMethod) ifTrue:[ |
4358 | 1788 |
|mSel| |
1789 |
||
4364 | 1790 |
mSel := tree selector. |
4358 | 1791 |
mSel notNil ifTrue:[ |
1792 |
(mSel startsWith:selector) ifTrue:[ |
|
4364 | 1793 |
"/ already the word before the cursor? |
1794 |
(mSel ~= selector) ifTrue:[ |
|
1795 |
allBest remove:mSel ifAbsent:[]. |
|
1796 |
allBest addFirst:mSel. |
|
1797 |
] |
|
4238 | 1798 |
] |
4358 | 1799 |
] |
1800 |
] |
|
4238 | 1801 |
]. |
1802 |
||
1803 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
|
1804 |
||
1805 |
split := [:list :splitHow | |
|
1806 |
|part1 part2 all| |
|
1807 |
||
1808 |
part1 := list select:splitHow. |
|
1809 |
part2 := list reject:splitHow. |
|
1810 |
part1 isEmpty ifTrue:[ |
|
1811 |
all := part2. |
|
1812 |
] ifFalse:[ |
|
1813 |
part2 isEmpty ifTrue:[ |
|
1814 |
all := part1. |
|
1815 |
] ifFalse:[ |
|
1816 |
all := part1 , part2. |
|
1817 |
] |
|
1818 |
]. |
|
1819 |
all |
|
1820 |
]. |
|
1821 |
||
1822 |
selectorsSentInCode notNil ifTrue:[ |
|
4358 | 1823 |
"/ the one's already sent in the code are moved to the top of the list. |
4238 | 1824 |
allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel]. |
1825 |
]. |
|
1826 |
||
4358 | 1827 |
"/ the on'es which are a prefix are moved towards the top of the list |
4238 | 1828 |
allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]]. |
1829 |
||
1830 |
false ifTrue:[ |
|
1831 |
srchClass notNil ifTrue:[ |
|
1832 |
implClass := srchClass whichClassIncludesSelector:best. |
|
1833 |
] ifFalse:[ |
|
1834 |
implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
1835 |
implClass size == 1 ifTrue:[ |
|
1836 |
implClass := implClass first. |
|
1837 |
] ifFalse:[ |
|
1838 |
implClass := nil |
|
1839 |
] |
|
1840 |
]. |
|
1841 |
||
1842 |
info := best storeString. |
|
1843 |
implClass notNil ifTrue:[ |
|
1844 |
info := implClass name , ' >> ' , info. |
|
1845 |
]. |
|
1846 |
self information:info. |
|
1847 |
]. |
|
4358 | 1848 |
|
4238 | 1849 |
editAction := |
1850 |
[:index | |
|
1851 |
|best| |
|
1852 |
||
1853 |
best := allBest at:index. |
|
1854 |
||
1855 |
best ~= selector ifTrue:[ |
|
1856 |
numArgs := best numArgs. |
|
1857 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[ |
|
1858 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
1859 |
] ifFalse:[ |
|
1860 |
selectorParts := node selectorParts. |
|
1861 |
]. |
|
1862 |
nSelParts := selectorParts size. |
|
1863 |
||
1864 |
newParts := best asCollectionOfSubstringsSeparatedBy:$:. |
|
1865 |
newParts := newParts select:[:part | part size > 0]. |
|
1866 |
||
1867 |
codeView |
|
1868 |
undoableDo:[ |
|
1869 |
|newCursorPosition stop| |
|
1870 |
||
1871 |
numArgs > nSelParts ifTrue:[ |
|
1872 |
stop := selectorParts last stop. |
|
1873 |
||
1874 |
"/ append the rest ... |
|
1875 |
numArgs downTo:nSelParts+1 do:[:idx | |
|
1876 |
|newPart| |
|
1877 |
||
1878 |
newPart := newParts at:idx. |
|
1879 |
(best endsWith:$:) ifTrue:[ |
|
1880 |
newPart := newPart , ':' |
|
1881 |
]. |
|
1882 |
||
1883 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
|
1884 |
newPart := ':' , newPart. |
|
1885 |
]. |
|
1886 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
1887 |
||
1888 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
|
1889 |
newCursorPosition := stop + newPart size. |
|
1890 |
] |
|
1891 |
]. |
|
1892 |
||
1893 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
1894 |
|newPart oldPartialToken start stop| |
|
1895 |
||
1896 |
newPart := newParts at:idx. |
|
1897 |
oldPartialToken := selectorParts at:idx. |
|
1898 |
start := oldPartialToken start. |
|
1899 |
stop := oldPartialToken stop. |
|
1900 |
||
1901 |
(best endsWith:$:) ifTrue:[ |
|
1902 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
1903 |
newPart := newPart , ':' |
|
1904 |
] |
|
1905 |
] ifFalse:[ |
|
1906 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
1907 |
newPart := newPart , ':' |
|
1908 |
] ifFalse:[ |
|
1909 |
(codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[ |
|
1910 |
newPart := newPart , ' ' |
|
1911 |
] |
|
1912 |
] |
|
1913 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
|
1914 |
"/ ] ifFalse:[ |
|
1915 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
1916 |
]. |
|
1917 |
||
1918 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
1919 |
||
1920 |
oldLen := stop - start + 1. |
|
1921 |
newLen := newPart size. |
|
1922 |
||
1923 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
1924 |
newCursorPosition := stop + (newLen-oldLen). |
|
1925 |
]. |
|
1926 |
codeView cursorToCharacterPosition:newCursorPosition. |
|
1927 |
codeView cursorRight. "/ avoid going to the next line !! |
|
1928 |
codeView dontReplaceSelectionOnInput. |
|
1929 |
] |
|
1930 |
info:'Completion'. |
|
1931 |
]. |
|
1932 |
]. |
|
1933 |
||
4352 | 1934 |
actionBlock value:allBest value:editAction value:nil. |
4238 | 1935 |
|
1936 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
1937 |
"Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4311 | 1938 |
"Modified: / 27-07-2013 / 16:34:10 / cg" |
4238 | 1939 |
! |
1940 |
||
4352 | 1941 |
codeCompletionForMethodSpec:node |
4238 | 1942 |
"completion in a method's selector pattern" |
1943 |
||
4352 | 1944 |
self |
1945 |
codeCompletionForMethodSpec:node |
|
1946 |
into: |
|
1947 |
[:suggestions :action :whatIsIt | |
|
1948 |
||
1949 |
|chosen| |
|
1950 |
||
1951 |
chosen := self askUserForCompletion:whatIsIt for:codeView at:node start from:suggestions. |
|
1952 |
action value:(suggestions indexOf:chosen) |
|
4238 | 1953 |
]. |
4352 | 1954 |
|
1955 |
"/ |crsrPos |
|
1956 |
"/ selectorSoFar matchingSelectors |
|
1957 |
"/ selectors distances best rest |
|
1958 |
"/ allExistingMethods nameBag namesByCount selectors1 selectors2| |
|
1959 |
"/ |
|
1960 |
"/ crsrPos := codeView characterPositionOfCursor - 1. |
|
1961 |
"/ |
|
1962 |
"/ selectorSoFar := ''. |
|
1963 |
"/ node selectorParts doWithIndex:[:partToken :argNr| |
|
1964 |
"/ |part| |
|
1965 |
"/ |
|
1966 |
"/ part := partToken value. |
|
1967 |
"/ selectorSoFar := selectorSoFar , part. |
|
1968 |
"/ |
|
1969 |
"/ (crsrPos >= partToken start |
|
1970 |
"/ and:[crsrPos <= partToken stop]) ifTrue:[ |
|
1971 |
"/ (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
1972 |
"/ matchingSelectors := Smalltalk allClasses |
|
1973 |
"/ inject:(Set new) |
|
1974 |
"/ into:[:theSet :eachClass | |
|
1975 |
"/ |md| |
|
1976 |
"/ |
|
1977 |
"/ md := eachClass theMetaclass methodDictionary. |
|
1978 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
1979 |
"/ theSet. |
|
1980 |
"/ ]. |
|
1981 |
"/ "/ dont forget the stuff in the class-line |
|
1982 |
"/ Metaclass withAllSuperclassesDo:[:cls | |
|
1983 |
"/ matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]). |
|
1984 |
"/ ]. |
|
1985 |
"/ ] ifFalse:[ |
|
1986 |
"/ matchingSelectors := Smalltalk allClasses |
|
1987 |
"/ inject:(Set new) |
|
1988 |
"/ into:[:theSet :eachClass | |
|
1989 |
"/ |md| |
|
1990 |
"/ |
|
1991 |
"/ md := eachClass theNonMetaclass methodDictionary. |
|
1992 |
"/ theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
1993 |
"/ theSet. |
|
1994 |
"/ ]. |
|
1995 |
"/ ]. |
|
1996 |
"/ selectors := matchingSelectors asOrderedCollection. |
|
1997 |
"/ |
|
1998 |
"/ "/ if there is only one, and user has already entered it, he might want to complete the argument-name |
|
1999 |
"/ (selectors size == 1 |
|
2000 |
"/ and:[selectors first = selectorSoFar]) ifTrue:[ |
|
2001 |
"/ selectorSoFar numArgs == 0 ifTrue:[ ^ self ]. |
|
2002 |
"/ |
|
2003 |
"/ allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
2004 |
"/ collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
2005 |
"/ nameBag := Bag new. |
|
2006 |
"/ allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
2007 |
"/ namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
|
2008 |
"/ "/ take the one which occurs most often |
|
2009 |
"/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]). |
|
2010 |
"/ |
|
2011 |
"/ codeView |
|
2012 |
"/ undoableDo:[ |
|
2013 |
"/ (crsrPos+1) >= codeView contents size ifTrue:[ |
|
2014 |
"/ codeView paste:best. |
|
2015 |
"/ ] ifFalse:[ |
|
2016 |
"/ codeView insertString:best atCharacterPosition:crsrPos+1. |
|
2017 |
"/ ] |
|
2018 |
"/ ] |
|
2019 |
"/ info:'completion'. |
|
2020 |
"/ codeView cursorToCharacterPosition:(crsrPos + best size - 1). |
|
2021 |
"/ ] ifFalse:[ |
|
2022 |
"/ "the ones implemented in superclasses are shown first" |
|
2023 |
"/ classOrNil notNil ifTrue:[ |
|
2024 |
"/ selectors1 := selectors select:[:sel | classOrNil respondsTo:sel]. "/ in super |
|
2025 |
"/ selectors2 := selectors reject:[:sel | selectors1 includes:sel ]. "/ not in super |
|
2026 |
"/ ] ifFalse:[ |
|
2027 |
"/ selectors1 := selectors |
|
2028 |
"/ ]. |
|
2029 |
"/ |
|
2030 |
"/ distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2031 |
"/ distances sortWith:selectors1. |
|
2032 |
"/ selectors1 reverse. |
|
2033 |
"/ selectors := selectors1. |
|
2034 |
"/ |
|
2035 |
"/ selectors2 notEmptyOrNil ifTrue:[ |
|
2036 |
"/ distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2037 |
"/ distances sortWith:selectors2. |
|
2038 |
"/ selectors2 reverse. |
|
2039 |
"/ selectors1 := selectors1 collect:[:sel | sel allBold]. |
|
2040 |
"/ selectors := selectors1,selectors2. |
|
2041 |
"/ ]. |
|
2042 |
"/ |
|
2043 |
"/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors. |
|
2044 |
"/ best isNil ifTrue:[^ self]. |
|
2045 |
"/ |
|
2046 |
"/ rest := best copyFrom:selectorSoFar size. |
|
2047 |
"/ codeView |
|
2048 |
"/ undoableDo:[ |
|
2049 |
"/ codeView |
|
2050 |
"/ replaceFromCharacterPosition:crsrPos+1 |
|
2051 |
"/ to:crsrPos+1 |
|
2052 |
"/ with:rest |
|
2053 |
"/ ] |
|
2054 |
"/ info:'Completion'. |
|
2055 |
"/ codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
|
2056 |
"/ ]. |
|
2057 |
"/ codeView cursorRight. "/ kludge to make it visible |
|
2058 |
"/ ]. |
|
2059 |
"/ ]. |
|
4238 | 2060 |
|
2061 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
2062 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
2063 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2064 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
2065 |
! |
|
2066 |
||
4352 | 2067 |
codeCompletionForMethodSpec:node into:actionBlock |
4238 | 2068 |
"completion in a method's selector pattern" |
2069 |
||
2070 |
|crsrPos |
|
2071 |
selectorSoFar matchingSelectors |
|
2072 |
selectors distances best rest |
|
4352 | 2073 |
allExistingMethods nameBag namesByCount selectors1 selectors2 |
2074 |
editAction argNames| |
|
4238 | 2075 |
|
4302 | 2076 |
"/ Transcript showCR:'m'. |
4238 | 2077 |
crsrPos := codeView characterPositionOfCursor - 1. |
2078 |
||
2079 |
selectorSoFar := ''. |
|
2080 |
node selectorParts doWithIndex:[:partToken :argNr| |
|
2081 |
|part| |
|
2082 |
||
2083 |
part := partToken value. |
|
2084 |
selectorSoFar := selectorSoFar , part. |
|
2085 |
||
2086 |
(crsrPos >= partToken start |
|
2087 |
and:[crsrPos <= partToken stop]) ifTrue:[ |
|
2088 |
(classOrNil notNil and:[classOrNil isMeta]) ifTrue:[ |
|
2089 |
matchingSelectors := Smalltalk allClasses |
|
2090 |
inject:(Set new) |
|
2091 |
into:[:theSet :eachClass | |
|
2092 |
|md| |
|
2093 |
||
2094 |
md := eachClass theMetaclass methodDictionary. |
|
2095 |
theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2096 |
theSet. |
|
2097 |
]. |
|
2098 |
"/ dont forget the stuff in the class-line |
|
2099 |
Metaclass withAllSuperclassesDo:[:cls | |
|
2100 |
matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2101 |
]. |
|
2102 |
] ifFalse:[ |
|
2103 |
matchingSelectors := Smalltalk allClasses |
|
2104 |
inject:(Set new) |
|
2105 |
into:[:theSet :eachClass | |
|
2106 |
|md| |
|
2107 |
||
2108 |
md := eachClass theNonMetaclass methodDictionary. |
|
2109 |
theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
|
2110 |
theSet. |
|
2111 |
]. |
|
2112 |
]. |
|
4353 | 2113 |
|
4238 | 2114 |
selectors := matchingSelectors asOrderedCollection. |
4353 | 2115 |
selectors := selectors sort:[:a :b | a size < b size]. |
2116 |
selectors size > 100 ifTrue:[ |
|
2117 |
selectors := selectors copyTo:100. |
|
2118 |
]. |
|
2119 |
||
4238 | 2120 |
|
2121 |
"/ if there is only one, and user has already entered it, he might want to complete the argument-name |
|
2122 |
(selectors size == 1 |
|
2123 |
and:[selectors first = selectorSoFar]) ifTrue:[ |
|
2124 |
selectorSoFar numArgs == 0 ifTrue:[ ^ self ]. |
|
2125 |
||
2126 |
allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
|
2127 |
collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
|
2128 |
nameBag := Bag new. |
|
2129 |
allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())]. |
|
2130 |
namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
|
2131 |
"/ take the one which occurs most often |
|
2132 |
"/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]). |
|
4352 | 2133 |
argNames := (namesByCount collect:[:a | a key]). |
2134 |
editAction := |
|
2135 |
[:chosenIndex | |
|
2136 |
|chosenName| |
|
2137 |
||
2138 |
chosenName := argNames at:chosenIndex. |
|
2139 |
codeView |
|
2140 |
undoableDo:[ |
|
2141 |
(crsrPos+1) >= codeView contents size ifTrue:[ |
|
2142 |
codeView paste:best. |
|
2143 |
] ifFalse:[ |
|
2144 |
codeView insertString:chosenName atCharacterPosition:crsrPos+1. |
|
2145 |
]. |
|
2146 |
codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1). |
|
2147 |
] |
|
2148 |
info:'completion'. |
|
2149 |
]. |
|
2150 |
actionBlock |
|
2151 |
value:argNames |
|
2152 |
value:editAction |
|
2153 |
value:'argument'. |
|
2154 |
||
4238 | 2155 |
^ self. |
2156 |
||
2157 |
] ifFalse:[ |
|
2158 |
"the ones implemented in superclasses are shown first" |
|
2159 |
classOrNil notNil ifTrue:[ |
|
2160 |
selectors1 := selectors select:[:sel | classOrNil respondsTo:sel]. "/ in super |
|
2161 |
selectors2 := selectors reject:[:sel | selectors1 includes:sel ]. "/ not in super |
|
2162 |
] ifFalse:[ |
|
2163 |
selectors1 := selectors |
|
2164 |
]. |
|
2165 |
||
2166 |
distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2167 |
distances sortWith:selectors1. |
|
2168 |
selectors1 reverse. |
|
2169 |
selectors := selectors1. |
|
2170 |
||
2171 |
selectors2 notEmptyOrNil ifTrue:[ |
|
2172 |
distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar]. |
|
2173 |
distances sortWith:selectors2. |
|
2174 |
selectors2 reverse. |
|
2175 |
selectors1 := selectors1 collect:[:sel | sel allBold]. |
|
2176 |
selectors := selectors1,selectors2. |
|
2177 |
]. |
|
4350 | 2178 |
|
2179 |
editAction := |
|
4352 | 2180 |
[:selectedCompletionIndex | |
2181 |
||
2182 |
best := selectors at:selectedCompletionIndex. |
|
4350 | 2183 |
rest := best copyFrom:selectorSoFar size. |
2184 |
codeView |
|
2185 |
undoableDo:[ |
|
2186 |
codeView |
|
2187 |
replaceFromCharacterPosition:crsrPos+1 |
|
2188 |
to:crsrPos+1 |
|
2189 |
with:rest |
|
2190 |
] |
|
2191 |
info:'Completion'. |
|
2192 |
codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1). |
|
2193 |
codeView cursorRight. "/ kludge to make it visible |
|
2194 |
]. |
|
4238 | 2195 |
|
2196 |
"/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors. |
|
4352 | 2197 |
actionBlock |
2198 |
value:selectors |
|
2199 |
value:editAction |
|
2200 |
value:'selector'. |
|
4238 | 2201 |
]. |
2202 |
]. |
|
2203 |
]. |
|
2204 |
||
2205 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
2206 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
|
2207 |
"Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2208 |
"Modified: / 01-06-2012 / 20:31:36 / cg" |
|
2209 |
! |
|
2210 |
||
2211 |
codeCompletionForVariable:node into:actionBlock |
|
2212 |
|nonMetaClass crsrPos nm parent |
|
2213 |
allVariables allDistances variablesAlreadyAdded nodeVal |
|
2214 |
char oldLen newLen |
|
2215 |
getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc |
|
4366 | 2216 |
globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart |
4352 | 2217 |
editAction suggestions nameIsOK longerNames| |
4238 | 2218 |
|
4302 | 2219 |
"/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil. |
4238 | 2220 |
classOrNil notNil ifTrue:[ |
2221 |
nonMetaClass := classOrNil theNonMetaclass. |
|
2222 |
]. |
|
2223 |
||
2224 |
nm := node name. |
|
2225 |
||
2226 |
"/ if we are behind the variable and a space has already been entered, |
|
2227 |
"/ the user is probably looking for a message selector. |
|
2228 |
"/ If the variable represents a global, present its instance creation messages |
|
2229 |
crsrPos := codeView characterPositionOfCursor. |
|
2230 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
|
2231 |
char isSeparator ifTrue:[ |
|
2232 |
nm knownAsSymbol ifTrue:[ |
|
2233 |
classOrNil isNil ifTrue:[ |
|
2234 |
nodeVal := Smalltalk at:nm asSymbol. |
|
2235 |
] ifFalse:[ |
|
2236 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
2237 |
]. |
|
2238 |
nodeVal isBehavior ifTrue:[ |
|
2239 |
|methods menu exitKey idx| |
|
2240 |
||
2241 |
methods := nodeVal class methodDictionary values |
|
2242 |
select:[:m | |cat| |
|
2243 |
cat := m category asLowercase. |
|
2244 |
cat = 'instance creation' |
|
2245 |
]. |
|
2246 |
editAction := |
|
2247 |
[:answer | |
|
2248 |
codeView |
|
2249 |
undoableDo:[ |
|
2250 |
codeView insertString:answer atCharacterPosition:crsrPos. |
|
2251 |
codeView cursorToCharacterPosition:crsrPos+answer size. |
|
2252 |
] |
|
2253 |
info:'completion'. |
|
2254 |
]. |
|
2255 |
actionBlock value:(methods collect:[:each | each selector]) value:editAction. |
|
2256 |
^ self. |
|
2257 |
]. |
|
2258 |
]. |
|
2259 |
]. |
|
2260 |
||
2261 |
parent := node parent. |
|
2262 |
(parent notNil and:[parent isMessage]) ifTrue:[ |
|
2263 |
node == parent receiver ifTrue:[ |
|
2264 |
selectorOfMessageToNode := parent selector |
|
2265 |
] |
|
2266 |
]. |
|
2267 |
||
4352 | 2268 |
"/ this is pure voodoo magic (tries to make a good spelling weight, |
2269 |
"/ by weighting the number of startsWith characters into the spelling distance...) |
|
4238 | 2270 |
getDistanceComputeBlockWithWeight := |
2271 |
[:weight | |
|
2272 |
[:each | |
|
2273 |
|dist factor| |
|
2274 |
||
2275 |
dist := each spellAgainst:nm. |
|
2276 |
factor := 1. |
|
2277 |
||
2278 |
(each startsWith:nm) ifTrue:[ |
|
2279 |
factor := 6 * nm size. |
|
2280 |
] ifFalse:[ |
|
2281 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
2282 |
factor := 4 * nm size. |
|
2283 |
]. |
|
2284 |
]. |
|
2285 |
dist := dist + (weight*factor). |
|
2286 |
||
2287 |
each -> (dist * weight) |
|
2288 |
] |
|
2289 |
]. |
|
2290 |
||
2291 |
nameIsOK := false. |
|
2292 |
addWithFactorBlock := |
|
2293 |
[:names :factor | |namesToAdd| |
|
2294 |
(names includes:nm) ifTrue:[nameIsOK := true]. |
|
2295 |
namesToAdd := names reject:[:nameToAdd | (nameToAdd = nm)]. |
|
2296 |
namesToAdd := namesToAdd reject:[:each | variablesAlreadyAdded includes:each ]. |
|
2297 |
variablesAlreadyAdded addAll:namesToAdd. |
|
2298 |
allVariables addAll:namesToAdd. |
|
2299 |
allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)). |
|
2300 |
]. |
|
2301 |
||
2302 |
nm isUppercaseFirst ifTrue:[ |
|
2303 |
globalFactor := 2. "/ favour globals |
|
2304 |
localFactor := 1. |
|
2305 |
] ifFalse:[ |
|
2306 |
globalFactor := 1. "/ favour locals |
|
2307 |
localFactor := 2. |
|
2308 |
]. |
|
2309 |
||
2310 |
variablesAlreadyAdded := Set new. |
|
2311 |
allVariables := OrderedCollection new. |
|
2312 |
allDistances := OrderedCollection new. |
|
2313 |
||
2314 |
"/ are we in the method's selector spec ? |
|
2315 |
(parent notNil |
|
2316 |
and:[parent isMethod |
|
2317 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
4364 | 2318 |
"/ now thats cool: look how the name of this argument is in other implementations |
4238 | 2319 |
"/ of this method, and take that as a basis of the selection |
2320 |
||
2321 |
implementors := SystemBrowser |
|
2322 |
findImplementorsOf:(parent selector) |
|
2323 |
in:(Smalltalk allClasses) |
|
2324 |
ignoreCase:false. |
|
2325 |
"/ which argument is it |
|
2326 |
argIdx := parent arguments indexOf:node. |
|
2327 |
implementors size > 50 ifTrue:[ |
|
2328 |
implementors := implementors asOrderedCollection copyTo:50. |
|
2329 |
]. |
|
2330 |
namesUsed := implementors |
|
2331 |
collect:[:eachImplementor | |
|
2332 |
|parseTree| |
|
2333 |
parseTree := eachImplementor parseTree. |
|
2334 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
2335 |
ifFalse:nil |
|
2336 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
2337 |
thenSelect:[:a | a notNil]. |
|
2338 |
||
2339 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
2340 |
||
2341 |
classOrNil notNil ifTrue:[ |
|
2342 |
"/ also, look for the keyword before the argument, |
|
2343 |
"/ and see if there is such an instVar |
|
2344 |
"/ if so, add it with -Arg |
|
2345 |
parent selector isKeyword ifTrue:[ |
|
2346 |
kwPart := parent selector keywords at:argIdx. |
|
2347 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
|
2348 |
addWithFactorBlock |
|
2349 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
2350 |
value:(1 * localFactor). |
|
2351 |
]. |
|
2352 |
]. |
|
2353 |
] |
|
2354 |
] ifFalse:[ |
|
4364 | 2355 |
"/ locals in the block/method |
4365 | 2356 |
names := OrderedCollection withAll:node allVariablesOnScope. |
4364 | 2357 |
|
2358 |
(names isEmpty or:[rememberedScopeNodes notNil]) ifTrue:[ |
|
2359 |
rememberedScopeNodes notNil ifTrue:[ |
|
2360 |
rememberedScopeNodes do:[:each | |
|
2361 |
(each isMethod or:[each isBlock]) ifTrue:[ |
|
2362 |
each argumentNames do:[:eachName | |
|
2363 |
(names includes:eachName) ifFalse:[ names add: eachName ] |
|
2364 |
] |
|
2365 |
] ifFalse:[ |
|
2366 |
each isSequence ifTrue:[ |
|
2367 |
each temporaryNames do:[:eachName | |
|
4361 | 2368 |
(names includes:eachName) ifFalse:[ names add: eachName ] |
2369 |
] |
|
2370 |
] ifFalse:[ |
|
2371 |
] |
|
2372 |
] |
|
4238 | 2373 |
] |
2374 |
]. |
|
4364 | 2375 |
]. |
4366 | 2376 |
addWithFactorBlock value:names value:(4 * localFactor). |
4364 | 2377 |
|
2378 |
classOrNil notNil ifTrue:[ |
|
4238 | 2379 |
"/ instance variables |
2380 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
2381 |
||
2382 |
"/ inherited instance variables |
|
2383 |
classOrNil superclass notNil ifTrue:[ |
|
2384 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
2385 |
]. |
|
2386 |
]. |
|
2387 |
||
4364 | 2388 |
"/ if the node to be expanded is the receiver in a message, look for the selector sent to it |
4238 | 2389 |
selectorOfMessageToNode notNil ifTrue:[ |
2390 |
|names responders nonResponders| |
|
2391 |
||
2392 |
"/ responding to that messsage |
|
4365 | 2393 |
"/ self halt. |
4238 | 2394 |
classOrNil notNil ifTrue:[ |
2395 |
"/ private classes |
|
2396 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
2397 |
value:(1.75 * globalFactor). |
|
2398 |
||
2399 |
"/ class variables |
|
2400 |
names := nonMetaClass classVarNames. |
|
2401 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
2402 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
2403 |
||
2404 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
2405 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
2406 |
||
2407 |
"/ superclass var names |
|
2408 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
2409 |
names := superClass classVarNames. |
|
2410 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
2411 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
2412 |
||
2413 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
|
2414 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
2415 |
]. |
|
2416 |
||
2417 |
"/ namespace vars |
|
2418 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
2419 |
names := classOrNil topNameSpace keys. |
|
2420 |
names := names reject:[:nm | nm includes:$:]. |
|
2421 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
2422 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2423 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2424 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
2425 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
2426 |
]. |
|
2427 |
]. |
|
2428 |
||
2429 |
"/ globals |
|
2430 |
names := Smalltalk keys. |
|
4352 | 2431 |
names := names reject: |
2432 |
[:nm | |
|
2433 |
(nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not] |
|
2434 |
]. |
|
2435 |
||
4238 | 2436 |
names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection. |
2437 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2438 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2439 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
2440 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
2441 |
||
4314 | 2442 |
classOrNil notNil ifTrue:[ |
2443 |
"/ pool variables |
|
2444 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
2445 |
|pool names| |
|
2446 |
||
2447 |
pool := Smalltalk at:poolName. |
|
2448 |
names := pool classVarNames. |
|
2449 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
2450 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2451 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
2452 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
2453 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
2454 |
]. |
|
2455 |
] |
|
4238 | 2456 |
] ifFalse:[ |
2457 |
classOrNil notNil ifTrue:[ |
|
2458 |
"/ private classes |
|
2459 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
2460 |
value:(1.75 * globalFactor). |
|
2461 |
||
2462 |
"/ class variables |
|
2463 |
addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor). |
|
2464 |
classOrNil superclass notNil ifTrue:[ |
|
2465 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor). |
|
2466 |
]. |
|
2467 |
||
2468 |
"/ namespace vars |
|
2469 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
2470 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
2471 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
2472 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
2473 |
]. |
|
2474 |
||
2475 |
"/ pool variables |
|
2476 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
2477 |
|pool names| |
|
2478 |
||
2479 |
pool := Smalltalk at:poolName. |
|
2480 |
names := pool classVarNames. |
|
2481 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
2482 |
]. |
|
2483 |
]. |
|
2484 |
||
2485 |
"/ globals |
|
2486 |
names := Smalltalk keys. |
|
2487 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
4366 | 2488 |
"/ only consider all globals, if the first char of the completed name is uppercase; |
2489 |
"/ otherwise, only consider names with a caseInsensitve prefix match |
|
2490 |
nm first isUppercase ifTrue:[ |
|
2491 |
||
2492 |
] ifFalse:[ |
|
2493 |
names := names select:[:globalName | globalName asLowercase startsWith: nm]. |
|
2494 |
]. |
|
4238 | 2495 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
2496 |
]. |
|
2497 |
||
2498 |
"/ pseudos - assuming that thisContext is seldom used. |
|
2499 |
"/ also assuming, that nil is short so its usually typed in. |
|
2500 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
2501 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
4352 | 2502 |
addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor). |
4238 | 2503 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
2504 |
]. |
|
2505 |
||
2506 |
allDistances isEmpty ifTrue:[^ self]. |
|
2507 |
||
2508 |
bestAssoc := allDistances at:1. |
|
2509 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
2510 |
ifTrue:[el] |
|
2511 |
ifFalse:[best] |
|
2512 |
]. |
|
2513 |
||
2514 |
allDistances sort:[:a :b | |
|
2515 |
a value > b value ifTrue:[ |
|
2516 |
true |
|
2517 |
] ifFalse:[ |
|
2518 |
a value = b value ifTrue:[ |
|
2519 |
a key < b key |
|
2520 |
] ifFalse:[ |
|
2521 |
false |
|
2522 |
] |
|
2523 |
] |
|
2524 |
]. |
|
4352 | 2525 |
|
2526 |
allTheBest := allDistances. |
|
2527 |
||
4238 | 2528 |
nameIsOK ifTrue:[ |
4352 | 2529 |
"/ if the name already exists, only allow longer names, if there are |
2530 |
longerNames := allTheBest select:[:assoc | assoc key startsWith:nm]. |
|
2531 |
longerNames notEmpty ifTrue:[ |
|
2532 |
allTheBest := longerNames. |
|
2533 |
]. |
|
4238 | 2534 |
]. |
2535 |
allTheBest size > 15 ifTrue:[ |
|
4352 | 2536 |
"/ remove all those which are below some threshold |
2537 |
0.4 to:0.8 by:0.1 do:[:delta | |
|
2538 |
"/ if still too many, remove more and more |
|
2539 |
allTheBest size > 15 ifTrue:[ |
|
2540 |
allTheBest := allDistances select:[:entry | (entry key startsWith:nm) or:[ entry value >= (bestAssoc value * delta) ]]. |
|
2541 |
] |
|
2542 |
]. |
|
4238 | 2543 |
]. |
2544 |
suggestions := allTheBest collect:[:assoc | assoc key]. |
|
2545 |
||
4352 | 2546 |
"/ finally, the trick is to bring them into a reasonable order... |
2547 |
"/ sort the prefix matchers by length, the others by spelling distance |
|
2548 |
"/ and bring the prefix-matchers towards the beginning |
|
2549 |
suggestions := ((suggestions select:[:s | s startsWith:nm]) sort:[:a :b | a size < b size ]) |
|
2550 |
, |
|
2551 |
(suggestions reject:[:s | s startsWith:nm]). |
|
2552 |
||
4238 | 2553 |
editAction := |
2554 |
[:index | |
|
2555 |
|answer start stop oldVar| |
|
2556 |
||
2557 |
answer := suggestions at:index. |
|
2558 |
||
2559 |
start := node start. |
|
2560 |
stop := node stop. |
|
2561 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
2562 |
||
4352 | 2563 |
oldLen := stop - start + 1. |
2564 |
newLen := answer size. |
|
2565 |
||
4238 | 2566 |
codeView |
4352 | 2567 |
undoableDo:[ |
2568 |
codeView replaceFromCharacterPosition:start to:stop with:(answer). |
|
2569 |
||
2570 |
(answer startsWith:oldVar) ifTrue:[ |
|
2571 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
2572 |
codeView dontReplaceSelectionOnInput |
|
2573 |
] ifFalse:[ |
|
2574 |
codeView selectFromCharacterPosition:start to:start+newLen-1. |
|
2575 |
codeView dontReplaceSelectionOnInput |
|
2576 |
]. |
|
2577 |
] |
|
4238 | 2578 |
info:'Completion'. |
2579 |
||
2580 |
]. |
|
2581 |
||
4352 | 2582 |
actionBlock value:suggestions value:editAction value:nil. |
4238 | 2583 |
|
2584 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
2585 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4314 | 2586 |
"Modified: / 30-07-2013 / 08:36:11 / cg" |
4238 | 2587 |
! |
2588 |
||
2589 |
findNodeForInterval:interval in:source |
|
2590 |
|tree node| |
|
2591 |
||
2592 |
interval isEmpty ifTrue: [^ nil]. |
|
2593 |
RBParser isNil ifTrue: [^ nil]. |
|
2594 |
||
2595 |
source = LastSource ifTrue:[ |
|
2596 |
tree := LastParseTree. |
|
2597 |
] ifFalse:[ |
|
2598 |
tree := RBParser |
|
2599 |
parseMethod:source |
|
2600 |
onError: |
|
2601 |
[:str :err ":nodesSoFar" | |
|
2602 |
"Transcript showCR:'Parse-Error: ',str." |
|
2603 |
nil |
|
2604 |
]. |
|
2605 |
||
2606 |
tree isNil ifTrue:[ |
|
2607 |
"/ try to parse as an expression |
|
2608 |
tree := RBParser |
|
2609 |
parseExpression:source |
|
2610 |
onError: |
|
2611 |
[:str :err ":nodesSoFar" | |
|
2612 |
"Transcript showCR:'Parse-Error: ',str." |
|
2613 |
nil |
|
2614 |
]. |
|
2615 |
||
2616 |
tree isNil ifTrue:[ |
|
2617 |
^ nil |
|
2618 |
]. |
|
2619 |
]. |
|
2620 |
||
2621 |
LastSource := source. |
|
2622 |
LastParseTree := tree. |
|
2623 |
]. |
|
2624 |
||
2625 |
node := tree whichNodeIsContainedBy:interval. |
|
2626 |
node isNil ifTrue: [ |
|
2627 |
node := tree bestNodeFor: interval. |
|
2628 |
node isNil ifTrue: [ |
|
2629 |
node := self findNodeIn:tree forInterval:interval |
|
2630 |
]. |
|
2631 |
]. |
|
2632 |
^ node |
|
2633 |
||
2634 |
"Modified: / 06-07-2011 / 12:42:53 / cg" |
|
2635 |
! |
|
2636 |
||
2637 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
|
2638 |
^ self |
|
2639 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
|
2640 |
mustBeMethod:false |
|
2641 |
||
2642 |
"Modified: / 16-09-2011 / 14:52:28 / cg" |
|
2643 |
! |
|
2644 |
||
2645 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod |
|
2646 |
"if mustBeMethod is true, do not try a regular expression (as in a workspace)." |
|
2647 |
||
4352 | 2648 |
^ self |
2649 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
|
2650 |
mustBeMethod:mustBeMethod mustBeExpression:false |
|
2651 |
! |
|
2652 |
||
2653 |
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression |
|
2654 |
"parse it as expression or method; |
|
2655 |
if mustBeMethod is true, do not try a regular expressions (as in a workspace); |
|
4367 | 2656 |
if mustBeExpression is true, do not try method" |
2657 |
||
2658 |
|intersectingNodes smallestIntersectingNode firstIntersectingNode |
|
2659 |
lastIntersectingNode onErrorBlock |
|
2660 |
nodeGenerationHook parser currentScopeNodes bestNode| |
|
4238 | 2661 |
|
2662 |
interval isEmpty ifTrue: [^ nil]. |
|
2663 |
RBParser isNil ifTrue: [^ nil]. |
|
2664 |
||
4361 | 2665 |
rememberedScopeNodes := nil. |
2666 |
||
4238 | 2667 |
"/ LastSource := nil. |
2668 |
source = LastSource ifTrue:[ |
|
2669 |
tree := LastParseTree. |
|
2670 |
tokens := LastScanTokens. |
|
2671 |
] ifFalse:[ |
|
2672 |
intersectingNodes := OrderedCollection new. |
|
4361 | 2673 |
currentScopeNodes := IdentitySet new. |
4238 | 2674 |
|
2675 |
onErrorBlock := |
|
2676 |
[:str :err :nodesSoFar | |
|
2677 |
|nodes| |
|
2678 |
||
2679 |
allowErrors ifTrue:[ |
|
4361 | 2680 |
rememberedScopeNodes := currentScopeNodes. |
4301 | 2681 |
firstIntersectingNode notNil ifTrue:[ |
2682 |
^ firstIntersectingNode |
|
2683 |
]. |
|
4238 | 2684 |
nodesSoFar notNil ifTrue:[ |
2685 |
nodes := nodesSoFar asOrderedCollection |
|
2686 |
collect:[:nd | nd whichNodeIntersects:interval] |
|
2687 |
thenSelect:[:nd | nd notNil ]. |
|
2688 |
nodes size == 1 ifTrue:[ |
|
2689 |
^ nodes first |
|
2690 |
]. |
|
2691 |
] |
|
2692 |
]. |
|
2693 |
nil |
|
2694 |
]. |
|
2695 |
||
4367 | 2696 |
self debuggingCodeFor:#cg is:[ |
2697 |
Transcript show:'looking for: '; showCR:interval. |
|
2698 |
]. |
|
2699 |
||
4238 | 2700 |
nodeGenerationHook := |
2701 |
[:node | |
|
2702 |
"/ we would like to return here as soon as the node has been created by the parser; |
|
2703 |
"/ however, at that time, its parent(chain) is not yet created and so we might not know |
|
4352 | 2704 |
"/ what the semantic interpretation (especially: scope of variable) will be. |
4238 | 2705 |
"/ therefore, we parse all, and return the found node at the end. |
4361 | 2706 |
(node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[ |
2707 |
currentScopeNodes add:node. |
|
2708 |
] ifFalse:[ |
|
4367 | 2709 |
self debuggingCodeFor:#cg is:[ |
2710 |
Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop. |
|
2711 |
]. |
|
2712 |
||
4361 | 2713 |
(node intersectsInterval:interval) ifTrue:[ |
4367 | 2714 |
self debuggingCodeFor:#cg is:[ |
2715 |
Transcript showCR:'yes'. |
|
2716 |
]. |
|
4361 | 2717 |
intersectingNodes add:node. |
2718 |
firstIntersectingNode isNil ifTrue:[ |
|
4367 | 2719 |
firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node |
4361 | 2720 |
] ifFalse:[ |
2721 |
|lenNode lenSmallest| |
|
2722 |
||
2723 |
lenNode := (node stop - node start). |
|
2724 |
lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start). |
|
2725 |
lenNode < lenSmallest ifTrue:[ |
|
2726 |
smallestIntersectingNode := node. |
|
4367 | 2727 |
]. |
2728 |
node start > lastIntersectingNode start ifTrue:[ |
|
2729 |
lastIntersectingNode := node. |
|
2730 |
]. |
|
4361 | 2731 |
]. |
2732 |
]. |
|
4238 | 2733 |
]. |
2734 |
]. |
|
2735 |
||
4361 | 2736 |
"/ one of the big problems when using the RBParser here is |
2737 |
"/ that it behaves badly when a syntax error is encountered; |
|
4367 | 2738 |
"/ for example, a node's parent is usually set AFTER the children are |
4361 | 2739 |
"/ completely parsed (for example, a blockNode gets the parent-method only |
4367 | 2740 |
"/ after parsing). Thus, when an error is encountered, we cannot walk |
4361 | 2741 |
"/ the parent chain, and therefore will not see the outer locals/args of |
4367 | 2742 |
"/ an inner scope (allVariablesOnScope returns only a partial set). |
4361 | 2743 |
"/ A walkaround is to remember Method/Block nodes as created in the above node generation. |
2744 |
"/ The disadvantage of it is that we do not have correct scope information, until the nodes |
|
4367 | 2745 |
"/ parent gets set eventually, this we might consider locals from sibling blocks. |
2746 |
"/ See rememberedScopeNodes handling above. |
|
2747 |
"/ Those other nodes are only remembered for failed parses; |
|
2748 |
"/ if the parse is ok, rememberedScopeNodes will be nil. |
|
4352 | 2749 |
mustBeExpression ifFalse:[ |
2750 |
tree := RBParser |
|
2751 |
parseMethod: source |
|
2752 |
setup:[:p | |
|
2753 |
parser := p. |
|
2754 |
p rememberNodes:true. |
|
2755 |
p rememberTokens:true. |
|
2756 |
p nodeGenerationCallback:nodeGenerationHook |
|
2757 |
] |
|
2758 |
onError: onErrorBlock. |
|
2759 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
|
2760 |
]. |
|
4238 | 2761 |
|
2762 |
mustBeMethod ifTrue:[ |
|
2763 |
"/ only cache parsed methods |
|
2764 |
tree notNil ifTrue:[ |
|
2765 |
LastSource := source. |
|
2766 |
LastParseTree := tree. |
|
2767 |
LastScanTokens := tokens. |
|
2768 |
]. |
|
2769 |
] ifFalse:[ |
|
2770 |
(tree isNil or:[firstIntersectingNode isNil]) ifTrue:[ |
|
2771 |
"/ try as an expression |
|
2772 |
tree := RBParser |
|
2773 |
parseExpression: source |
|
2774 |
setup:[:p | |
|
2775 |
parser := p. |
|
2776 |
p rememberNodes:true. |
|
2777 |
p rememberTokens:true. |
|
2778 |
p nodeGenerationCallback:nodeGenerationHook |
|
2779 |
] |
|
2780 |
onError: onErrorBlock. |
|
4276 | 2781 |
parser notNil ifTrue:[ tokens := parser rememberedTokens ]. |
4238 | 2782 |
]. |
2783 |
]. |
|
4367 | 2784 |
lastIntersectingNode notNil ifTrue:[ |
2785 |
self debuggingCodeFor:#cg is:[ |
|
2786 |
Transcript show:'last: '; showCR:lastIntersectingNode. |
|
2787 |
]. |
|
2788 |
^ lastIntersectingNode |
|
2789 |
]. |
|
2790 |
"/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ]. |
|
4238 | 2791 |
]. |
2792 |
||
4367 | 2793 |
bestNode := self findNodeForInterval:interval inParseTree:tree. |
2794 |
self debuggingCodeFor:#cg is:[ |
|
2795 |
Transcript show:'best: '; showCR:bestNode. |
|
2796 |
]. |
|
2797 |
^ bestNode |
|
4238 | 2798 |
|
2799 |
"Created: / 16-09-2011 / 14:52:08 / cg" |
|
2800 |
! |
|
2801 |
||
2802 |
findNodeForInterval:interval inParseTree:parseTree |
|
2803 |
|node| |
|
2804 |
||
2805 |
interval isEmpty ifTrue: [^ nil]. |
|
2806 |
parseTree isNil ifTrue:[^ nil]. |
|
2807 |
||
2808 |
node := parseTree whichNodeIsContainedBy:interval. |
|
2809 |
node isNil ifTrue:[ |
|
2810 |
node := parseTree whichNodeIntersects:interval. |
|
2811 |
node isNil ifTrue: [ |
|
2812 |
node := self findNodeIn:parseTree forInterval:interval |
|
2813 |
]. |
|
2814 |
]. |
|
2815 |
^ node |
|
2816 |
||
2817 |
"Modified: / 10-11-2006 / 13:13:58 / cg" |
|
2818 |
! |
|
2819 |
||
2820 |
findNodeIn:tree forInterval:interval |
|
2821 |
|nodeFound wouldReturn| |
|
2822 |
||
2823 |
nodeFound := nil. |
|
2824 |
tree nodesDo:[:eachNode | |
|
2825 |
(eachNode intersectsInterval:interval) ifTrue:[ |
|
2826 |
(nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[ |
|
2827 |
nodeFound := eachNode |
|
2828 |
] ifFalse:[ |
|
2829 |
(nodeFound parent == eachNode parent |
|
2830 |
and:[ eachNode start >= nodeFound start |
|
2831 |
and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[ |
|
2832 |
] ifFalse:[ |
|
2833 |
(nodeFound parent notNil |
|
2834 |
and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil] |
|
2835 |
] |
|
2836 |
] |
|
2837 |
] ifFalse:[ |
|
2838 |
nodeFound notNil ifTrue:[ |
|
2839 |
"/ already found one - beyond that one; leave |
|
2840 |
wouldReturn notNil ifTrue:[wouldReturn := nodeFound]. |
|
2841 |
] |
|
2842 |
]. |
|
2843 |
]. |
|
2844 |
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt]. |
|
2845 |
^ nodeFound |
|
2846 |
||
2847 |
"Modified: / 20-11-2006 / 12:31:12 / cg" |
|
2848 |
! |
|
2849 |
||
2850 |
old_askUserForCompletion:what for:codeView from:allTheBest |
|
2851 |
|list resources choice lastChoice| |
|
2852 |
||
2853 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
|
2854 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
|
2855 |
||
2856 |
list := allTheBest. |
|
2857 |
LastChoices notNil ifTrue:[ |
|
2858 |
lastChoice := LastChoices at:what ifAbsent:nil. |
|
2859 |
lastChoice notNil ifTrue:[ |
|
4340 | 2860 |
"/ move tha last choice to the top of the list, if it is in. |
4238 | 2861 |
(list includes: lastChoice) ifTrue:[ |
4340 | 2862 |
(list indexOf: lastChoice) < 10 ifTrue:[ |
2863 |
list := {lastChoice allBold } , (list copyWithout:lastChoice). |
|
2864 |
] |
|
4238 | 2865 |
] |
2866 |
]. |
|
2867 |
]. |
|
2868 |
||
2869 |
list size < 30 ifTrue:[ |
|
2870 |
|menu idx exitKey| |
|
2871 |
||
2872 |
menu := PopUpMenu labels:list. |
|
2873 |
menu hideOnKeyFilter:[:key | |hide| |
|
2874 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
2875 |
hide ifTrue:[ |
|
2876 |
exitKey := key. |
|
2877 |
]. |
|
2878 |
hide]. |
|
4346 | 2879 |
menu memorizeLastSelection:3 "sigh, not 1 because of heading!!". |
2880 |
idx := menu startUpWithHeading:'Choose ',what. |
|
4238 | 2881 |
idx == 0 ifTrue:[ |
2882 |
exitKey notNil ifTrue:[ |
|
2883 |
codeView keyPress:exitKey x:0 y:0. |
|
2884 |
]. |
|
2885 |
^ nil |
|
2886 |
]. |
|
2887 |
choice := list at:idx. |
|
2888 |
] ifFalse:[ |
|
2889 |
resources := codeView application isNil |
|
2890 |
ifTrue:[ codeView resources] |
|
2891 |
ifFalse:[ codeView application resources ]. |
|
2892 |
||
2893 |
choice := Dialog |
|
2894 |
choose:(resources string:'Choose ',what) |
|
2895 |
fromList:list |
|
2896 |
lines:20 |
|
2897 |
initialSelection:(list firstIfEmpty:nil) |
|
2898 |
title:(resources string:'Code completion'). |
|
2899 |
choice isNil ifTrue:[^ nil]. |
|
2900 |
]. |
|
4301 | 2901 |
choice := choice string. |
4238 | 2902 |
|
2903 |
LastChoices isNil ifTrue:[ |
|
2904 |
LastChoices := Dictionary new. |
|
2905 |
]. |
|
2906 |
LastChoices at:what put:choice. |
|
2907 |
^ choice |
|
2908 |
||
2909 |
"Created: / 16-02-2010 / 09:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 2910 |
"Modified: / 28-08-2013 / 15:28:01 / cg" |
4238 | 2911 |
! |
2912 |
||
2913 |
treeForCode:source allowErrors:allowErrors |
|
2914 |
|tree| |
|
2915 |
||
2916 |
source = LastSource ifTrue:[ |
|
2917 |
tree := LastParseTree. |
|
2918 |
] ifFalse:[ |
|
2919 |
tree := RBParser |
|
2920 |
parseMethod:source |
|
2921 |
onError: [:str :err :nodesSoFar :parserOrNil| |
|
2922 |
allowErrors ifTrue:[ |
|
2923 |
"/ parserOrNil isNil if raised by the scanner |
|
2924 |
parserOrNil notNil ifTrue:[ |
|
2925 |
^ parserOrNil currentMethodNode |
|
2926 |
] |
|
2927 |
]. |
|
2928 |
^ nil |
|
2929 |
] |
|
2930 |
proceedAfterError:false |
|
2931 |
rememberNodes:true. |
|
2932 |
||
2933 |
tree notNil ifTrue:[ |
|
2934 |
LastSource := source. |
|
2935 |
LastParseTree := tree. |
|
2936 |
] |
|
2937 |
]. |
|
2938 |
^ tree |
|
2939 |
||
2940 |
"Modified: / 13-01-2012 / 11:54:30 / cg" |
|
4352 | 2941 |
! |
2942 |
||
2943 |
tryCodeCompletionWithSource:source nodeInterval:interval into:actionBlock |
|
2944 |
"this is tried twice; first with the source copied up to the cursor position, |
|
2945 |
then with the full source. |
|
2946 |
Either one may geive better results (for example, when completing |
|
2947 |
after a keyword selector, and the remaining code would lead to a syntactically |
|
2948 |
legal, but stupid message send to be parsed... |
|
2949 |
(which happens often after inserting)" |
|
2950 |
||
4368 | 2951 |
|node checkedNode characterPositionOfCursor characterBeforeCursor nodeIsInTemporaries| |
2952 |
||
2953 |
characterPositionOfCursor := codeView characterPositionOfCursor. |
|
4352 | 2954 |
|
2955 |
"/ this is too naive and stupid; if there is a syntactic error, |
|
2956 |
"/ we will not find a node for a long time (stepping back more and more, |
|
2957 |
"/ until reaching the beginning). This leads to a thousand and more times reparsing |
|
2958 |
"/ without any progress. |
|
2959 |
"/ TODO: do it vice-versa, in that the parser does a callOut for every node generated |
|
2960 |
"/ as it parses the code. Stop, when the interval is hit. |
|
2961 |
"/ that will also work for syntactic incorrect source code. |
|
4356 | 2962 |
(methodOrNil notNil or:[classOrNil notNil]) ifTrue:[ |
4352 | 2963 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true. |
2964 |
]. |
|
2965 |
node isNil ifTrue:[ |
|
2966 |
node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true. |
|
2967 |
node isNil ifTrue:[ |
|
2968 |
Transcript showCR:'No parseNode found (syntax error before?)'. |
|
2969 |
self information:'No parseNode found (syntax error before?)'. |
|
2970 |
^ self. |
|
2971 |
]. |
|
2972 |
]. |
|
2973 |
||
2974 |
(node isVariable |
|
2975 |
and:[ node parent notNil |
|
2976 |
and:[ node parent isMessage |
|
4368 | 2977 |
and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[ |
4352 | 2978 |
node := node parent. |
2979 |
]. |
|
2980 |
||
2981 |
characterBeforeCursor := codeView characterBeforeCursor. |
|
2982 |
characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self]. |
|
4358 | 2983 |
characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self]. |
4352 | 2984 |
|
2985 |
node isVariable ifTrue:[ |
|
2986 |
nodeIsInTemporaries := |
|
2987 |
node parent notNil |
|
2988 |
and:[ node parent isSequence |
|
2989 |
and:[ node parent temporaries notEmptyOrNil |
|
2990 |
and:[ node stop <= node parent temporaries last stop ]]]. |
|
2991 |
nodeIsInTemporaries ifFalse:[ |
|
2992 |
"/ cursor must be right after the variable |
|
4368 | 2993 |
characterPositionOfCursor == (node stop + 1) ifTrue:[ |
4352 | 2994 |
self codeCompletionForVariable:node into:actionBlock. |
2995 |
] |
|
2996 |
]. |
|
2997 |
^ self. |
|
2998 |
]. |
|
4367 | 2999 |
|
4352 | 3000 |
node isLiteral ifTrue:[ |
4367 | 3001 |
"/ cursor must be right after the literal |
4368 | 3002 |
characterPositionOfCursor == (node stop + 1) ifTrue:[ |
4352 | 3003 |
node value isSymbol ifTrue:[ |
4368 | 3004 |
self codeCompletionForLiteralSymbol:node considerAll:false into:actionBlock. |
4352 | 3005 |
^ self. |
3006 |
]. |
|
3007 |
]. |
|
4368 | 3008 |
"/ however, user may want to complete a symbol inside a literal array!! |
3009 |
node value isArray ifTrue:[ |
|
3010 |
node token isLiteralArray ifTrue:[ |
|
3011 |
|elementBeforeCursor| |
|
3012 |
||
3013 |
elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil. |
|
3014 |
(elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[ |
|
3015 |
self codeCompletionForLiteralSymbol:elementBeforeCursor considerAll:true into:actionBlock. |
|
3016 |
^ self. |
|
3017 |
]. |
|
3018 |
]. |
|
3019 |
]. |
|
3020 |
||
4367 | 3021 |
"/ huh - completing strings, numbers or what? |
3022 |
(node parent notNil |
|
3023 |
and:[ node parent isMessage |
|
3024 |
and:[ node parent isKeyword ]]) |
|
3025 |
ifFalse:[ |
|
3026 |
^ self |
|
3027 |
]. |
|
3028 |
"/ no, move up and try completing the outer keyword message (next arg) |
|
3029 |
node := node parent. |
|
4352 | 3030 |
]. |
3031 |
||
3032 |
checkedNode := node. |
|
3033 |
[checkedNode notNil] whileTrue:[ |
|
4368 | 3034 |
(characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[ |
4352 | 3035 |
self information:'Inside a message node'. |
3036 |
^ self. |
|
3037 |
]. |
|
3038 |
||
3039 |
checkedNode isMessage ifTrue:[ |
|
3040 |
"/ completion in a message-send |
|
3041 |
self codeCompletionForMessage:checkedNode into:actionBlock. |
|
3042 |
^ self |
|
3043 |
]. |
|
3044 |
checkedNode isMethod ifTrue:[ |
|
3045 |
"/ completion in a method's selector pattern |
|
3046 |
self codeCompletionForMethodSpec:checkedNode into:actionBlock. |
|
3047 |
^ self. |
|
3048 |
]. |
|
3049 |
checkedNode := checkedNode parent. |
|
3050 |
]. |
|
3051 |
||
3052 |
self information:'Node is neither variable nor message.'. |
|
3053 |
||
3054 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
|
3055 |
"Modified: / 16-09-2011 / 14:54:47 / cg" |
|
4238 | 3056 |
! ! |
3057 |
||
3058 |
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'! |
|
3059 |
||
3060 |
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView |
|
3061 |
|sym possibleCompletions best start stop oldLen newLen oldVar| |
|
3062 |
||
3063 |
sym := node value. |
|
3064 |
possibleCompletions := OrderedCollection new. |
|
3065 |
||
3066 |
Symbol allInstancesDo:[:existingSym | |
|
3067 |
(existingSym startsWith:sym) ifTrue:[ |
|
3068 |
(existingSym = sym) ifFalse:[ |
|
3069 |
possibleCompletions add:existingSym |
|
3070 |
]. |
|
3071 |
]. |
|
3072 |
]. |
|
3073 |
possibleCompletions sort. |
|
3074 |
||
3075 |
best := possibleCompletions longestCommonPrefix. |
|
3076 |
(best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[ |
|
3077 |
best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions. |
|
3078 |
best isNil ifTrue:[^ self]. |
|
3079 |
]. |
|
3080 |
||
3081 |
"/ self showInfo:best. |
|
3082 |
||
3083 |
start := node start. |
|
3084 |
stop := node stop. |
|
3085 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
|
3086 |
start := start + 1. |
|
3087 |
]. |
|
3088 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
|
3089 |
start := start + 1. |
|
3090 |
stop := stop - 1. |
|
3091 |
]. |
|
3092 |
||
3093 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
3094 |
||
3095 |
codeView |
|
3096 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
|
3097 |
info:'Completion'. |
|
3098 |
||
3099 |
(best startsWith:oldVar) ifTrue:[ |
|
3100 |
oldLen := stop - start + 1. |
|
3101 |
newLen := best size. |
|
3102 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3103 |
codeView dontReplaceSelectionOnInput |
|
3104 |
]. |
|
3105 |
||
3106 |
"Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3107 |
"Modified (format): / 03-07-2011 / 15:58:45 / cg" |
|
3108 |
! |
|
3109 |
||
4345 | 3110 |
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView |
3111 |
|selector srchClass implClass |
|
3112 |
bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best info numArgs |
|
3113 |
newParts nSelParts oldLen newLen selectorParts |
|
3114 |
findBest parentNode selectorInBest selector2InBest2 |
|
3115 |
parser selectorsSentInCode selectorsImplementedInClass split |
|
4346 | 3116 |
varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass| |
4345 | 3117 |
|
3118 |
RefactoryTyper notNil ifTrue:[ |
|
3119 |
"/ refactory package also provides a (very limited) typer; |
|
3120 |
"/ ask it for its oppinion as well (temporary - will vanish, once we have a better typer) |
|
3121 |
(node receiver isVariable) ifTrue:[ |
|
3122 |
varName := node receiver name. |
|
3123 |
varName isUppercaseFirst ifTrue:[ |
|
3124 |
] ifFalse:[ |
|
3125 |
tree := RBParser |
|
3126 |
parseMethod:codeView contents string |
|
3127 |
onError:[:aString :pos | nil]. |
|
3128 |
tree notNil ifTrue:[ |
|
3129 |
rbTypes := RefactoryTyper |
|
3130 |
classesFor: varName |
|
3131 |
in: tree |
|
3132 |
model: nil |
|
3133 |
ignoredSelectors:(Array with:node selector). |
|
3134 |
rbTypes size > 0 ifTrue:[ |
|
3135 |
rbTypes size > 1 ifTrue:[ |
|
3136 |
rbTypes remove:ProtoObject ifAbsent:[]. |
|
3137 |
rbTypes remove:Autoload ifAbsent:[]. |
|
3138 |
rbTypes remove:ObsoleteObject ifAbsent:[]. |
|
3139 |
]. |
|
3140 |
rbTypes size == 1 ifTrue:[ |
|
3141 |
rbType := rbTypes first. |
|
3142 |
] ifFalse:[ |
|
3143 |
rbType := Class commonSuperclassOf:rbTypes |
|
3144 |
]. |
|
3145 |
(rbType notNil "and:[rbType ~= Object]") ifTrue:[ |
|
3146 |
bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true. |
|
3147 |
]. |
|
3148 |
] |
|
3149 |
] |
|
3150 |
] |
|
3151 |
]. |
|
3152 |
]. |
|
3153 |
||
3154 |
classOrNil notNil ifTrue:[ |
|
3155 |
parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true. |
|
3156 |
selectorsSentInCode := parser messagesSent. |
|
3157 |
]. |
|
3158 |
classOrNil notNil ifTrue:[ |
|
3159 |
selectorsImplementedInClass := classOrNil selectors. |
|
3160 |
]. |
|
3161 |
||
3162 |
findBest := [:node :selector | |
|
3163 |
|srchClass bestSelectors bestPrefixes| |
|
3164 |
||
3165 |
codeView topView withCursor:(Cursor questionMark) do:[ |
|
4358 | 3166 |
srchClass := self classOfNode:node receiver. |
4345 | 3167 |
srchClass notNil ifTrue:[ |
3168 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true. |
|
3169 |
] ifFalse:[ |
|
3170 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true. |
|
3171 |
]. |
|
3172 |
]. |
|
3173 |
||
3174 |
(bestSelectors includes:selector) ifTrue:[ |
|
3175 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
|
3176 |
]. |
|
3177 |
bestSelectors |
|
3178 |
]. |
|
3179 |
||
3180 |
selector := node selector. |
|
3181 |
bestSelectors := findBest value:node value:selector. |
|
3182 |
||
3183 |
parentNode := node parent. |
|
3184 |
||
3185 |
parentIsKeywordMessage := |
|
3186 |
(parentNode notNil |
|
3187 |
and:[ parentNode isMessage |
|
3188 |
and:[ parentNode selector isKeywordSelector]]). |
|
4346 | 3189 |
parentIsBinaryMessage := |
3190 |
(parentNode notNil |
|
3191 |
and:[ parentNode isMessage |
|
3192 |
and:[ parentNode selector isBinarySelector]]). |
|
4345 | 3193 |
|
3194 |
tryParent := false. |
|
3195 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
|
3196 |
(node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[ |
|
3197 |
tryParent := true. |
|
3198 |
] ifFalse:[ |
|
3199 |
"/ if the parent is an instance creation message, take that as lookup class. |
|
3200 |
(node isMessage |
|
3201 |
and:[ node receiver isMessage |
|
3202 |
and:[ node receiver receiver isVariable |
|
3203 |
and:[ node receiver receiver name isUppercaseFirst |
|
3204 |
and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[ |
|
3205 |
rcvrClass := Smalltalk classNamed:(node receiver receiver name). |
|
3206 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
3207 |
bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true. |
|
3208 |
] ifFalse:[ |
|
3209 |
"/ also, if nothing was found |
|
3210 |
(bestSelectors isEmpty |
|
3211 |
and:[ parentNode notNil |
|
3212 |
and:[ parentNode isMessage ]]) ifTrue:[ |
|
3213 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil. |
|
3214 |
"/ selector2 := parentNode selector. |
|
3215 |
"/ selector2 := selector2,selector. |
|
3216 |
bestSelectors := findBest value:parentNode value:selector. |
|
3217 |
] |
|
3218 |
] |
|
3219 |
]. |
|
3220 |
tryParent ifTrue:[ |
|
3221 |
selector2 := parentNode selector,selector. |
|
3222 |
bestSelectors2 := findBest value:parentNode value:selector2. |
|
3223 |
]. |
|
4346 | 3224 |
bestSelectorsFromRB notEmptyOrNil ifTrue:[ |
3225 |
bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]). |
|
3226 |
]. |
|
4345 | 3227 |
|
3228 |
"/ if the parent is a keyword selector, the child cannot |
|
4346 | 3229 |
(parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[ |
4345 | 3230 |
bestSelectors := bestSelectors reject:[:sel | sel isKeywordSelector] |
3231 |
]. |
|
3232 |
||
3233 |
bestSelectors2 isEmptyOrNil ifTrue:[ |
|
3234 |
allBest := bestSelectors. |
|
3235 |
] ifFalse:[ |
|
3236 |
bestSelectors isEmptyOrNil ifTrue:[ |
|
3237 |
allBest := bestSelectors2 |
|
3238 |
] ifFalse:[ |
|
3239 |
selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]). |
|
3240 |
selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]). |
|
3241 |
||
3242 |
(selectorInBest not and:[ selector2InBest2 ]) ifTrue:[ |
|
3243 |
"/ selector2 is more likely |
|
3244 |
allBest := bestSelectors2 |
|
3245 |
] ifFalse:[ |
|
3246 |
(selectorInBest and:[ selector2InBest2 not ]) ifTrue:[ |
|
3247 |
"/ selector more likely |
|
3248 |
allBest := bestSelectors |
|
3249 |
] ifFalse:[ |
|
3250 |
"/ assume same likelyness |
|
3251 |
||
3252 |
allBest := bestSelectors isEmpty |
|
3253 |
ifTrue:[ bestSelectors2 ] |
|
3254 |
ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ]. |
|
3255 |
] |
|
3256 |
]. |
|
3257 |
]. |
|
3258 |
]. |
|
3259 |
||
3260 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
|
3261 |
||
3262 |
split := |
|
3263 |
[:list :splitHow | |
|
3264 |
|part1 part2 all| |
|
3265 |
||
3266 |
part1 := list select:splitHow. |
|
3267 |
part2 := list reject:splitHow. |
|
3268 |
part1 isEmpty ifTrue:[ |
|
3269 |
all := part2. |
|
3270 |
] ifFalse:[ |
|
3271 |
part2 isEmpty ifTrue:[ |
|
3272 |
all := part1. |
|
3273 |
] ifFalse:[ |
|
3274 |
all := part1 , part2. |
|
3275 |
] |
|
3276 |
]. |
|
3277 |
all |
|
3278 |
]. |
|
3279 |
||
3280 |
selectorsImplementedInClass notNil ifTrue:[ |
|
3281 |
"/ the ones implemented in the receiver class are moved to the top of the list. |
|
3282 |
allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel]. |
|
3283 |
]. |
|
3284 |
selectorsSentInCode notNil ifTrue:[ |
|
3285 |
"/ the ones already sent in the code are moved to the top of the list. |
|
3286 |
allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel]. |
|
3287 |
]. |
|
3288 |
||
3289 |
"/ the ones which are a prefix are moved towards the top of the list |
|
3290 |
allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]]. |
|
3291 |
||
3292 |
best := allBest first. |
|
3293 |
allBest size > 1 ifTrue:[ |
|
3294 |
"allBest size < 20 ifTrue:[ |
|
3295 |
|idx| |
|
3296 |
||
3297 |
idx := (PopUpMenu labels:allBest) startUp. |
|
3298 |
idx == 0 ifTrue:[ ^ self]. |
|
3299 |
best := allBest at:idx. |
|
3300 |
] ifFalse:[ |
|
3301 |
allBest remove:nil ifAbsent:[]. |
|
3302 |
best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest. |
|
3303 |
||
3304 |
]." |
|
3305 |
allBest remove:nil ifAbsent:[]. |
|
4346 | 3306 |
best := self askUserForCompletion:('Selector for "%1"' bindWith:selector) for:codeView at: node selectorParts first start from:allBest. |
4345 | 3307 |
best isEmptyOrNil ifTrue:[^ self]. |
3308 |
best = '-' ifTrue:[^ self]. |
|
3309 |
]. |
|
3310 |
||
3311 |
false ifTrue:[ |
|
3312 |
srchClass notNil ifTrue:[ |
|
3313 |
implClass := srchClass whichClassIncludesSelector:best. |
|
3314 |
] ifFalse:[ |
|
3315 |
implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
|
3316 |
implClass size == 1 ifTrue:[ |
|
3317 |
implClass := implClass first. |
|
3318 |
] ifFalse:[ |
|
3319 |
implClass := nil |
|
3320 |
] |
|
3321 |
]. |
|
3322 |
||
3323 |
info := best storeString. |
|
3324 |
implClass notNil ifTrue:[ |
|
3325 |
info := implClass name , ' >> ' , info. |
|
3326 |
]. |
|
3327 |
self information:info. |
|
3328 |
]. |
|
3329 |
||
3330 |
best ~= selector ifTrue:[ |
|
3331 |
numArgs := best numArgs. |
|
3332 |
||
3333 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[ |
|
3334 |
selectorParts := parentNode selectorParts , node selectorParts. |
|
3335 |
] ifFalse:[ |
|
3336 |
selectorParts := node selectorParts. |
|
3337 |
]. |
|
3338 |
nSelParts := selectorParts size. |
|
3339 |
||
3340 |
newParts := best asCollectionOfSubstringsSeparatedBy:$:. |
|
3341 |
newParts := newParts select:[:part | part size > 0]. |
|
3342 |
||
3343 |
codeView |
|
3344 |
undoableDo:[ |
|
3345 |
|newCursorPosition stop| |
|
3346 |
||
3347 |
numArgs > nSelParts ifTrue:[ |
|
3348 |
stop := selectorParts last stop. |
|
3349 |
||
3350 |
"/ append the rest ... |
|
3351 |
numArgs downTo:nSelParts+1 do:[:idx | |
|
3352 |
|newPart| |
|
3353 |
||
3354 |
newPart := newParts at:idx. |
|
3355 |
(best endsWith:$:) ifTrue:[ |
|
3356 |
newPart := newPart , ':' |
|
3357 |
]. |
|
3358 |
||
3359 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
|
3360 |
newPart := ':' , newPart. |
|
3361 |
]. |
|
3362 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
|
3363 |
||
3364 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
|
3365 |
newCursorPosition := stop + newPart size. |
|
3366 |
] |
|
3367 |
]. |
|
3368 |
||
3369 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
|
3370 |
|newPart oldPartialToken start stop| |
|
3371 |
||
3372 |
newPart := newParts at:idx. |
|
3373 |
oldPartialToken := selectorParts at:idx. |
|
3374 |
start := oldPartialToken start. |
|
3375 |
stop := oldPartialToken stop. |
|
3376 |
||
3377 |
(best isKeywordSelector) ifTrue:[ |
|
3378 |
(oldPartialToken value endsWith:$:) ifTrue:[ |
|
3379 |
newPart := newPart , ':' |
|
3380 |
] ifFalse:[ |
|
3381 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
|
3382 |
newPart := newPart , ':' |
|
3383 |
] |
|
3384 |
] |
|
3385 |
] ifFalse:[ |
|
3386 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
|
3387 |
newPart := newPart , ':' |
|
3388 |
] ifFalse:[ |
|
3389 |
(codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[ |
|
3390 |
(').' includes:(codeView characterAtCharacterPosition:stop+1)) ifFalse:[ |
|
3391 |
newPart := newPart , ' ' |
|
3392 |
]. |
|
3393 |
] |
|
3394 |
] |
|
3395 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
|
3396 |
"/ ] ifFalse:[ |
|
3397 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
3398 |
]. |
|
3399 |
||
3400 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
|
3401 |
||
3402 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3403 |
newCursorPosition isNil ifTrue:[ |
|
3404 |
oldLen := stop - start + 1. |
|
3405 |
newLen := newPart size. |
|
3406 |
||
3407 |
newCursorPosition := stop + (newLen-oldLen) |
|
3408 |
]. |
|
3409 |
]. |
|
3410 |
||
3411 |
codeView cursorToCharacterPosition:newCursorPosition. |
|
3412 |
codeView cursorRight. "/ avoid going to the next line !! |
|
3413 |
||
3414 |
((best endsWith:':') and:[numArgs == 1]) ifTrue:[ |
|
3415 |
|impls impl| |
|
3416 |
||
3417 |
"/ see if it expects a block argument (heuristic) |
|
3418 |
best := best asSymbol. |
|
3419 |
(node notNil |
|
3420 |
and:[classOrNil notNil |
|
3421 |
and:[node receiver isSelf]]) ifTrue:[ |
|
3422 |
(impl := classOrNil whichClassImplements:best) isNil ifTrue:[ |
|
3423 |
impls := #(). |
|
3424 |
Screen current beep. |
|
3425 |
] ifFalse:[ |
|
3426 |
impls := { impl } |
|
3427 |
] |
|
3428 |
] ifFalse:[ |
|
3429 |
impls := Smalltalk allImplementorsOf:best. |
|
3430 |
]. |
|
3431 |
(impls contains:[:cls | |
|
3432 |
|argName| |
|
3433 |
||
3434 |
argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase. |
|
3435 |
(argName includesString:'block') or:[ (argName includesString:'action')]] |
|
3436 |
) ifTrue:[ |
|
3437 |
codeView insertStringAtCursor:'[' |
|
3438 |
]. |
|
3439 |
]. |
|
3440 |
codeView dontReplaceSelectionOnInput. |
|
3441 |
] |
|
3442 |
info:'Completion'. |
|
3443 |
]. |
|
3444 |
||
3445 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
|
3446 |
"Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 3447 |
"Modified: / 28-08-2013 / 15:27:32 / cg" |
4345 | 3448 |
! |
3449 |
||
4238 | 3450 |
codeCompletionForVariable:node inClass:classOrNil codeView:codeView |
4277 | 3451 |
|parent nonMetaClass crsrPos nm |
4238 | 3452 |
allVariables allDistances best nodeVal |
3453 |
char start stop oldLen newLen oldVar |
|
3454 |
getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc |
|
3455 |
globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart| |
|
3456 |
||
3457 |
classOrNil notNil ifTrue:[ |
|
3458 |
nonMetaClass := classOrNil theNonMetaclass. |
|
3459 |
]. |
|
3460 |
||
3461 |
nm := node name. |
|
3462 |
||
3463 |
"/ if we are behind the variable and a space has already been entered, |
|
3464 |
"/ the user is probably looking for a message selector. |
|
3465 |
"/ If the variable represents a global, present its instance creation messages |
|
3466 |
crsrPos := codeView characterPositionOfCursor. |
|
3467 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
|
3468 |
char isSeparator ifTrue:[ |
|
3469 |
classOrNil isNil ifTrue:[ |
|
3470 |
nodeVal := Smalltalk at:nm asSymbol. |
|
3471 |
] ifFalse:[ |
|
3472 |
nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
|
3473 |
]. |
|
3474 |
nodeVal isBehavior ifTrue:[ |
|
3475 |
|methods menu exitKey idx| |
|
3476 |
||
3477 |
methods := nodeVal class methodDictionary values |
|
3478 |
select:[:m | |cat| |
|
3479 |
cat := m category asLowercase. |
|
3480 |
cat = 'instance creation' |
|
3481 |
]. |
|
3482 |
||
3483 |
menu := PopUpMenu labels:(methods collect:[:each | each selector]). |
|
3484 |
menu hideOnKeyFilter:[:key | |hide| |
|
3485 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
|
3486 |
hide ifTrue:[ |
|
3487 |
exitKey := key. |
|
3488 |
]. |
|
3489 |
hide]. |
|
3490 |
||
3491 |
idx := menu startUp. |
|
3492 |
idx == 0 ifTrue:[ |
|
3493 |
exitKey notNil ifTrue:[ |
|
3494 |
codeView keyPress:exitKey x:0 y:0. |
|
3495 |
]. |
|
3496 |
^ self |
|
3497 |
]. |
|
3498 |
best := (methods at:idx) selector. |
|
3499 |
codeView |
|
3500 |
undoableDo:[ |
|
3501 |
codeView insertString:best atCharacterPosition:crsrPos. |
|
3502 |
codeView cursorToCharacterPosition:crsrPos+best size. |
|
3503 |
] |
|
3504 |
info:'completion'. |
|
3505 |
^ self. |
|
3506 |
]. |
|
3507 |
]. |
|
3508 |
||
4277 | 3509 |
((parent := node parent) notNil and:[parent isMessage]) ifTrue:[ |
3510 |
node == parent receiver ifTrue:[ |
|
3511 |
selectorOfMessageToNode := parent selector |
|
4238 | 3512 |
] |
3513 |
]. |
|
3514 |
||
3515 |
getDistanceComputeBlockWithWeight := |
|
3516 |
[:weight | |
|
3517 |
[:each | |
|
3518 |
|dist factor| |
|
3519 |
||
3520 |
dist := each spellAgainst:nm. |
|
3521 |
factor := 1. |
|
3522 |
||
3523 |
(each startsWith:nm) ifTrue:[ |
|
3524 |
factor := 6 * nm size. |
|
3525 |
] ifFalse:[ |
|
3526 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
|
3527 |
factor := 4 * nm size. |
|
3528 |
]. |
|
3529 |
]. |
|
3530 |
dist := dist + (weight*factor). |
|
3531 |
||
3532 |
each -> (dist * weight) |
|
3533 |
] |
|
3534 |
]. |
|
3535 |
||
3536 |
addWithFactorBlock := |
|
3537 |
[:names :factor | |namesToAdd| |
|
3538 |
namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ]. |
|
3539 |
namesToAdd := namesToAdd reject:[:each | allVariables includes:each ]. |
|
3540 |
allVariables addAll:namesToAdd. |
|
3541 |
allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)). |
|
3542 |
]. |
|
3543 |
||
3544 |
nm isUppercaseFirst ifTrue:[ |
|
3545 |
globalFactor := 2. "/ favour globals |
|
3546 |
localFactor := 1. |
|
3547 |
] ifFalse:[ |
|
3548 |
globalFactor := 1. "/ favour locals |
|
3549 |
localFactor := 2. |
|
3550 |
]. |
|
3551 |
||
3552 |
allVariables := OrderedCollection new. |
|
3553 |
allDistances := OrderedCollection new. |
|
3554 |
||
4308 | 3555 |
"/ are we in the method's selector spec ? |
4277 | 3556 |
((parent := node parent) notNil |
3557 |
and:[parent isMethod |
|
3558 |
and:[parent arguments includes:node]]) ifTrue:[ |
|
4238 | 3559 |
"/ now thats cool: look how the naem of this argument is in other implementations |
3560 |
"/ of this method, and take that as a basis of the selection |
|
3561 |
||
3562 |
implementors := SystemBrowser |
|
4277 | 3563 |
findImplementorsOf:(parent selector) |
4238 | 3564 |
in:(Smalltalk allClasses) |
3565 |
ignoreCase:false. |
|
3566 |
"/ which argument is it |
|
4277 | 3567 |
argIdx := parent arguments indexOf:node. |
4238 | 3568 |
implementors size > 50 ifTrue:[ |
3569 |
implementors := implementors asOrderedCollection copyTo:50. |
|
3570 |
]. |
|
3571 |
namesUsed := implementors |
|
3572 |
collect:[:eachImplementor | |
|
3573 |
|parseTree| |
|
3574 |
parseTree := eachImplementor parseTree. |
|
3575 |
(parseTree notNil and:[parseTree arguments size > 0]) |
|
3576 |
ifFalse:nil |
|
3577 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
|
3578 |
thenSelect:[:a | a notNil] as:Set. |
|
3579 |
||
3580 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
|
3581 |
||
3582 |
classOrNil notNil ifTrue:[ |
|
3583 |
"/ also, look for the keyword before the argument, |
|
3584 |
"/ and see if there is such an instVar |
|
3585 |
"/ if so, add it with -Arg |
|
4277 | 3586 |
parent selector isKeyword ifTrue:[ |
3587 |
kwPart := parent selector keywords at:argIdx. |
|
4238 | 3588 |
(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[ |
3589 |
addWithFactorBlock |
|
3590 |
value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg']) |
|
3591 |
value:(1 * localFactor). |
|
3592 |
]. |
|
3593 |
]. |
|
3594 |
] |
|
3595 |
] ifFalse:[ |
|
3596 |
classOrNil notNil ifTrue:[ |
|
3597 |
"/ locals in the block/method |
|
3598 |
names := node allVariablesOnScope. |
|
3599 |
"/ if there were no variables (due to a parse error) |
|
3600 |
"/ do another parse and see what we have |
|
3601 |
names isEmpty ifTrue:[ |
|
3602 |
tree := self treeForCode:(codeView contentsAsString string) allowErrors:true. |
|
3603 |
"/ better if we already have a body (include locals then) |
|
3604 |
"/ otherwise, only the arguments are considered |
|
3605 |
tree notNil ifTrue:[ |
|
3606 |
names := (tree body ? tree) allVariablesOnScope. |
|
3607 |
] |
|
3608 |
]. |
|
3609 |
||
3610 |
addWithFactorBlock value:names value:(4 * localFactor). |
|
3611 |
||
3612 |
"/ instance variables |
|
3613 |
addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor). |
|
3614 |
||
3615 |
"/ inherited instance variables |
|
3616 |
classOrNil superclass notNil ifTrue:[ |
|
3617 |
addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor). |
|
3618 |
]. |
|
3619 |
]. |
|
3620 |
||
3621 |
selectorOfMessageToNode notNil ifTrue:[ |
|
3622 |
|names responders nonResponders| |
|
3623 |
||
3624 |
"/ responding to that messsage |
|
3625 |
||
3626 |
classOrNil notNil ifTrue:[ |
|
3627 |
"/ private classes |
|
3628 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3629 |
value:(1.75 * globalFactor). |
|
3630 |
||
3631 |
"/ class variables |
|
3632 |
names := nonMetaClass classVarNames. |
|
3633 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3634 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3635 |
||
3636 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
3637 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3638 |
||
3639 |
"/ superclass var names |
|
3640 |
nonMetaClass allSuperclassesDo:[:superClass | |
|
3641 |
names := superClass classVarNames. |
|
3642 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3643 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
|
3644 |
||
3645 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
|
3646 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
|
3647 |
]. |
|
3648 |
||
3649 |
"/ namespace vars |
|
3650 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
3651 |
names := classOrNil topNameSpace keys. |
|
3652 |
names := names reject:[:nm | nm includes:$:]. |
|
3653 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3654 |
responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3655 |
nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3656 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
3657 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3658 |
]. |
|
3659 |
]. |
|
3660 |
||
3661 |
"/ globals |
|
3662 |
names := Smalltalk keys. |
|
3663 |
"/ names := names reject:[:nm | nm includes:$:]. |
|
3664 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3665 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3666 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3667 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
|
3668 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
|
3669 |
||
3670 |
"/ pool variables |
|
3671 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3672 |
|pool names| |
|
3673 |
||
3674 |
pool := Smalltalk at:poolName. |
|
3675 |
names := pool classVarNames. |
|
3676 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3677 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3678 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
|
3679 |
addWithFactorBlock value:responders value:(2.5 * globalFactor). |
|
3680 |
addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor). |
|
3681 |
]. |
|
3682 |
] ifFalse:[ |
|
3683 |
classOrNil notNil ifTrue:[ |
|
3684 |
"/ private classes |
|
3685 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
|
3686 |
value:(1.75 * globalFactor). |
|
3687 |
||
3688 |
"/ class variables |
|
3689 |
addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor). |
|
3690 |
classOrNil superclass notNil ifTrue:[ |
|
3691 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor). |
|
3692 |
]. |
|
3693 |
||
3694 |
"/ namespace vars |
|
3695 |
classOrNil nameSpace ~~ Smalltalk ifTrue:[ |
|
3696 |
names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
|
3697 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3698 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
3699 |
]. |
|
3700 |
||
3701 |
"/ pool variables |
|
3702 |
classOrNil theNonMetaclass sharedPoolNames do:[:poolName | |
|
3703 |
|pool names| |
|
3704 |
||
3705 |
pool := Smalltalk at:poolName. |
|
3706 |
names := pool classVarNames. |
|
3707 |
addWithFactorBlock value:names value:(2.5 * globalFactor). |
|
3708 |
]. |
|
3709 |
]. |
|
3710 |
||
3711 |
"/ globals |
|
3712 |
names := Smalltalk keys. |
|
3713 |
names := names select:[:nm | nm isUppercaseFirst ]. |
|
3714 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
|
3715 |
]. |
|
3716 |
||
3717 |
"/ pseudos - assuming that thisContext is seldom used. |
|
3718 |
"/ also assuming, that nil is short so its usually typed in. |
|
3719 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
|
3720 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
|
3721 |
addWithFactorBlock value:#('super' 'false') value:(2 * localFactor). |
|
3722 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
|
4340 | 3723 |
addWithFactorBlock value:#('true') value:(1 * localFactor). |
3724 |
addWithFactorBlock value:#('false') value:(1 * localFactor). |
|
4238 | 3725 |
]. |
3726 |
||
3727 |
allDistances isEmpty ifTrue:[^ self]. |
|
3728 |
bestAssoc := allDistances at:1. |
|
3729 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
|
3730 |
ifTrue:[el] |
|
3731 |
ifFalse:[best] |
|
3732 |
]. |
|
3733 |
||
3734 |
allDistances sort:[:a :b | |
|
3735 |
a value > b value ifTrue:[ |
|
3736 |
true |
|
3737 |
] ifFalse:[ |
|
3738 |
a value = b value ifTrue:[ |
|
3739 |
a key < b key |
|
3740 |
] ifFalse:[ |
|
3741 |
false |
|
3742 |
] |
|
3743 |
] |
|
3744 |
]. |
|
4340 | 3745 |
((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[ |
3746 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)]. |
|
3747 |
allTheBest size > 15 ifTrue:[ |
|
3748 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)]. |
|
3749 |
]. |
|
4238 | 3750 |
]. |
3751 |
||
4346 | 3752 |
best := self askUserForCompletion:('Variable for "%1"' bindWith:node name) for:codeView at: node start from:(allTheBest collect:[:assoc | assoc key]). |
4238 | 3753 |
best isNil ifTrue:[^ self]. |
3754 |
||
3755 |
"/ self showInfo:best. |
|
3756 |
||
3757 |
start := node start. |
|
3758 |
stop := node stop. |
|
3759 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
|
3760 |
||
3761 |
codeView |
|
3762 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
|
3763 |
info:'Completion'. |
|
3764 |
||
3765 |
(best startsWith:oldVar) ifTrue:[ |
|
3766 |
oldLen := stop - start + 1. |
|
3767 |
newLen := best size. |
|
3768 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
|
3769 |
codeView dontReplaceSelectionOnInput |
|
3770 |
]. |
|
3771 |
||
3772 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
|
3773 |
"Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4346 | 3774 |
"Modified: / 28-08-2013 / 15:37:28 / cg" |
4238 | 3775 |
! ! |
3776 |
||
3854
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3777 |
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3778 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3779 |
bestName:bestNameArg matchingNames:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3780 |
^ self with:bestNameArg with:matchingNamesArg |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3781 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3782 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3783 |
self bestName:123 matchingNames:345 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3784 |
" |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3785 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3786 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3787 |
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3788 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3789 |
bestName |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3790 |
^ self at:1 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3791 |
! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3792 |
|
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3793 |
matchingNames |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3794 |
^ self at:2 |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3795 |
! ! |
d7904ce12bb6
changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents:
3853
diff
changeset
|
3796 |
|
2376 | 3797 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
3798 |
||
4281 | 3799 |
version |
4368 | 3800 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.140 2013-09-03 12:14:25 cg Exp $' |
4281 | 3801 |
! |
3802 |
||
3761
6584390d427d
dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
3803 |
version_CVS |
4368 | 3804 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.140 2013-09-03 12:14:25 cg Exp $' |
2376 | 3805 |
! ! |
4194 | 3806 |