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