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