author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 05 Feb 2012 01:49:41 +0000 | |
branch | jv |
changeset 12144 | 18c25ec50d96 |
parent 12138 | 84205b6b75b4 |
child 12170 | 6c9c4b7981ee |
permissions | -rw-r--r-- |
9980 | 1 |
" |
10077 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
10440
ad79e93dc9b7
no need to access BackgroundJob via Smalltalk - the bug
Claus Gittinger <cg@exept.de>
parents:
10439
diff
changeset
|
3 |
All Rights Reserved |
9980 | 4 |
|
10077 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9980 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
"{ NameSpace: Tools }" |
|
29 |
||
12125 | 30 |
BackgroundSourceProcessingService subclass:#CodeHighlightingService |
31 |
instanceVariableNames:'' |
|
10439
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
32 |
classVariableNames:'' |
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
33 |
poolDictionaries:'' |
6a41520db1be
variable renamed in: #initialize
Claus Gittinger <cg@exept.de>
parents:
10438
diff
changeset
|
34 |
category:'Interface-CodeView' |
9980 | 35 |
! |
36 |
||
37 |
!CodeHighlightingService class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
10077 | 41 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
10440
ad79e93dc9b7
no need to access BackgroundJob via Smalltalk - the bug
Claus Gittinger <cg@exept.de>
parents:
10439
diff
changeset
|
42 |
All Rights Reserved |
10077 | 43 |
|
44 |
Permission is hereby granted, free of charge, to any person |
|
45 |
obtaining a copy of this software and associated documentation |
|
46 |
files (the 'Software'), to deal in the Software without |
|
47 |
restriction, including without limitation the rights to use, |
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
49 |
copies of the Software, and to permit persons to whom the |
|
50 |
Software is furnished to do so, subject to the following |
|
51 |
conditions: |
|
9980 | 52 |
|
10077 | 53 |
The above copyright notice and this permission notice shall be |
54 |
included in all copies or substantial portions of the Software. |
|
55 |
||
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
63 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9980 | 64 |
" |
65 |
! ! |
|
66 |
||
67 |
!CodeHighlightingService class methodsFor:'accessing'! |
|
68 |
||
69 |
label |
|
70 |
||
71 |
"Answers short label - for UI" |
|
72 |
||
73 |
^'Syntax Highlighting' |
|
74 |
||
75 |
"Created: / 07-03-2010 / 14:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! ! |
|
77 |
||
10486 | 78 |
!CodeHighlightingService methodsFor:'accessing'! |
79 |
||
80 |
syntaxHighlighter |
|
12125 | 81 |
| app lang highlighter | |
10486 | 82 |
|
83 |
"First, ask application..." |
|
84 |
app := codeView application. |
|
85 |
app notNil ifTrue:[ |
|
12125 | 86 |
| mthd class | |
87 |
||
88 |
mthd := codeView methodHolder value. |
|
89 |
class := codeView classHolder value. |
|
10486 | 90 |
(mthd notNil and:[app respondsTo: #syntaxHighlighterForMethod:]) ifTrue:[ |
91 |
highlighter := app syntaxHighlighterForMethod:mthd. |
|
92 |
] ifFalse:[ |
|
93 |
(class notNil and:[app respondsTo: #syntaxHighlighterForClass:]) ifTrue:[ |
|
94 |
highlighter := app syntaxHighlighterForClass: class. |
|
12125 | 95 |
] ifFalse:[ |
96 |
(class notNil and:[app respondsTo: #syntaxHighlighter]) ifTrue:[ |
|
97 |
highlighter := app syntaxHighlighterClass. |
|
98 |
]. |
|
10486 | 99 |
]. |
100 |
] |
|
101 |
]. |
|
102 |
"App did not provide any highlighter..." |
|
103 |
highlighter isNil ifTrue:[ |
|
12125 | 104 |
highlighter := (lang := codeView language) |
10486 | 105 |
ifNil:[nil] |
106 |
ifNotNil:[lang syntaxHighlighterClass]. |
|
107 |
]. |
|
108 |
"HACK!!!!!!" |
|
109 |
highlighter == SyntaxHighlighter ifTrue:[ |
|
110 |
highlighter := SyntaxHighlighter2 |
|
111 |
]. |
|
112 |
^ highlighter |
|
113 |
||
114 |
"Created: / 05-08-2011 / 10:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12125 | 115 |
"Modified: / 26-09-2011 / 15:50:10 / cg" |
116 |
"Modified: / 28-09-2011 / 00:23:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10486 | 117 |
! |
118 |
||
119 |
syntaxHighlighters |
|
120 |
||
121 |
| highlighters | |
|
122 |
||
123 |
highlighters := OrderedCollection new: 4. |
|
124 |
||
125 |
codeView services do:[:service| |
|
126 |
| highlighter | |
|
127 |
highlighter := service syntaxHighlighter. |
|
128 |
highlighter notNil ifTrue:[ |
|
129 |
"HACK, since AbstractSyntaxHighlighter overwrite |
|
130 |
emphasis instead of adding it..." |
|
131 |
(highlighter isKindOf: AbstractSyntaxHighlighter class) ifTrue:[ |
|
132 |
highlighters addFirst: highlighter |
|
133 |
] ifFalse:[ |
|
134 |
highlighters add: highlighter |
|
135 |
]. |
|
136 |
] |
|
137 |
]. |
|
138 |
||
139 |
^highlighters |
|
140 |
||
141 |
"Created: / 05-08-2011 / 10:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 |
! ! |
|
143 |
||
12125 | 144 |
!CodeHighlightingService methodsFor:'acessing-defaults'! |
9980 | 145 |
|
12125 | 146 |
defaultJobName |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
147 |
|
12125 | 148 |
^'CodeView2''s syntax highlighting job' |
10710
5aa37ab3189e
Fixes for syntax highlighting and code navigation. Now it should work fine debugger.
vrany
parents:
10701
diff
changeset
|
149 |
|
12125 | 150 |
"Created: / 24-01-2012 / 12:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10420 | 151 |
! ! |
152 |
||
9980 | 153 |
!CodeHighlightingService methodsFor:'private'! |
154 |
||
12125 | 155 |
process |
156 |
"(Re)starts the processing job. Should be called whenever a source |
|
157 |
must be (re)processed." |
|
9980 | 158 |
|
12125 | 159 |
| highlighters | |
9980 | 160 |
|
12125 | 161 |
(highlighters := self syntaxHighlighters) isEmptyOrNil ifTrue:[ |
10486 | 162 |
"No higlighter, nothing to do" |
10968
5e738ee1cd2a
No highlighting by default (either method or language must be set)
vrany
parents:
10961
diff
changeset
|
163 |
^self |
10420 | 164 |
]. |
9980 | 165 |
|
12125 | 166 |
super process. |
10420 | 167 |
|
168 |
"Modified: / 07-07-2011 / 12:26:12 / Jan Vrany <jan.vrant@fit.cvut,cz>" |
|
12125 | 169 |
"Modified: / 26-09-2011 / 15:40:23 / cg" |
170 |
"Created: / 24-01-2012 / 12:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10420 | 171 |
! |
172 |
||
12125 | 173 |
process: delayed |
10420 | 174 |
|
10486 | 175 |
|oldCode oldCodeList newCode elements cls mthd highlighterClasses| |
10420 | 176 |
|
177 |
done := false. |
|
12125 | 178 |
modified := false. |
10420 | 179 |
codeView syntaxElements: nil. |
180 |
codeView syntaxElementSelection: nil. |
|
181 |
||
10486 | 182 |
highlighterClasses := self syntaxHighlighters. |
10149 | 183 |
|
10420 | 184 |
cls := codeView klass. |
185 |
(cls notNil and:[cls isObsolete]) ifTrue:[ |
|
10486 | 186 |
cls isMeta ifTrue:[ |
187 |
cls := (Smalltalk at:cls theNonMetaclass name) class |
|
188 |
] ifFalse:[ |
|
189 |
cls := Smalltalk at:cls name |
|
190 |
]. |
|
10420 | 191 |
]. |
192 |
mthd := codeView methodHolder value. |
|
10149 | 193 |
|
12125 | 194 |
"textView" modified ifFalse:[ |
10486 | 195 |
oldCodeList := textView list copy. |
12125 | 196 |
"textView" modified ifFalse:[ |
10486 | 197 |
oldCodeList isNil ifFalse:[ |
198 |
oldCode := oldCodeList asStringWithoutEmphasis. |
|
12125 | 199 |
"textView" modified ifFalse:[ |
10486 | 200 |
Screen currentScreenQuerySignal answer:codeView device |
201 |
do:[ |
|
202 |
Parser::ParseError handle:[:ex | |
|
203 |
|errMsg| |
|
9980 | 204 |
|
10486 | 205 |
errMsg := ex description asStringCollection first asString. |
9980 | 206 |
|
10486 | 207 |
"/ Transcript topView raiseDeiconified. |
208 |
"/ Transcript showCR:'ParseError: ', ex description. |
|
9980 | 209 |
"/ self halt. |
10486 | 210 |
"/ self showInfo:(errMsg colorizeAllWith:Color red). |
211 |
newCode := nil. |
|
212 |
] do:[ |
|
213 |
elements := SortedCollection new. |
|
214 |
newCode := oldCode asText. |
|
215 |
codeView codeAspect == #method ifTrue:[ |
|
216 |
highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using: nil elementsInto: elements]. |
|
217 |
] ifFalse:[ |
|
218 |
codeView codeAspect == #expression ifTrue:[ |
|
219 |
highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements]. |
|
220 |
] ifFalse:[ |
|
221 |
codeView codeAspect == #classDefinition ifTrue:[ |
|
222 |
highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode in:cls elementsInto: elements]. |
|
223 |
] |
|
224 |
]. |
|
225 |
]. |
|
226 |
] |
|
227 |
]. |
|
228 |
newCode notNil ifTrue:[ |
|
12125 | 229 |
"textView" modified ifFalse:[ |
10486 | 230 |
newCode ~= oldCodeList ifTrue:[ |
231 |
newCode := newCode asStringCollection. |
|
12125 | 232 |
"textView" modified ifFalse:[ |
10486 | 233 |
done := true. |
234 |
textView notNil ifTrue:[ |
|
235 |
"/ must add this event - and not been interrupted |
|
236 |
"/ by any arriving key-event. |
|
237 |
"/ self showInfo:nil. |
|
238 |
delayed ifTrue:[ |
|
239 |
codeView sensor |
|
240 |
pushUserEvent:#setHighlightedCode:elements: |
|
241 |
for:self |
|
242 |
withArguments:(Array with:newCode with: elements). |
|
243 |
"/self delayedUpdateBufferLabelWithCheckIfModified |
|
244 |
] ifFalse:[ |
|
245 |
textView contents: newCode. |
|
246 |
] |
|
247 |
] |
|
248 |
] |
|
249 |
]. |
|
250 |
] |
|
251 |
] |
|
252 |
] |
|
253 |
] |
|
254 |
] |
|
10420 | 255 |
] |
9980 | 256 |
|
12125 | 257 |
"Modified: / 22-08-2011 / 14:17:47 / cg" |
258 |
"Modified: / 16-09-2011 / 17:01:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
259 |
"Created: / 24-01-2012 / 12:21:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
260 |
! |
|
261 |
||
262 |
setHighlightedCode:newCode elements: elements |
|
263 |
"the background synhighlighter has generated new colored text, |
|
264 |
with highlighted syntax. |
|
265 |
If there have been no modifications in the meantime, install it." |
|
266 |
||
267 |
|firstShown lastShown cursorWasOn anyChange newLines l replaceAction list| |
|
268 |
||
269 |
"textView" modified ifTrue:[ |
|
270 |
"/ new input arrived in the meantime |
|
9980 | 271 |
|
12125 | 272 |
^ self |
273 |
]. |
|
274 |
done ifFalse:[ |
|
275 |
"/ another coloring process has already been started. |
|
276 |
"/ ignore this (leftover) code. |
|
277 |
^ self |
|
278 |
]. |
|
279 |
||
280 |
firstShown := textView firstLineShown. |
|
281 |
lastShown := textView lastLineShown. |
|
282 |
||
283 |
replaceAction := [:lNr :line | |
|
284 |
|oldLine| |
|
285 |
||
286 |
oldLine := list at:lNr ifAbsent:nil. |
|
287 |
oldLine notNil ifTrue:[ |
|
288 |
line notNil ifTrue:[ |
|
289 |
"/ this check is needed - there is a race |
|
290 |
"/ when the text is converted. This detects the |
|
291 |
"/ resulting error. |
|
292 |
"/ Certainly a kludge. |
|
10410 | 293 |
|
12125 | 294 |
oldLine string = line string ifTrue:[ |
12138
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
295 |
| i | |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
296 |
|
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
297 |
"JV@2012-02-01: Remove any emphasis on leading whitespace" |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
298 |
"(presumably created by LintHighlighter)" |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
299 |
i := line string indexOfNonSeparator. |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
300 |
i > 1 ifTrue:[ |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
301 |
| e | |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
302 |
|
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
303 |
(e := (line emphasisAt: i - 1)) notNil ifTrue:[ |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
304 |
line emphasisFrom: 1 to: i - 1 remove: e. |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
305 |
] |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
306 |
]. |
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
307 |
|
12125 | 308 |
oldLine emphasis ~= line emphasis ifTrue:[ |
309 |
textView modifiedChannel removeDependent:self. |
|
310 |
list at:lNr put:line. |
|
311 |
textView modifiedChannel addDependent:self. |
|
312 |
(lNr between:firstShown and:lastShown) ifTrue:[ |
|
313 |
anyChange ifFalse:[ |
|
314 |
anyChange := true. |
|
315 |
cursorWasOn := textView hideCursor |
|
316 |
]. |
|
317 |
textView redrawLine:lNr |
|
318 |
] |
|
319 |
] |
|
320 |
] |
|
321 |
] |
|
322 |
] |
|
323 |
]. |
|
10410 | 324 |
|
12125 | 325 |
anyChange := false. |
326 |
newLines := newCode asStringCollection. |
|
327 |
list := textView list. |
|
328 |
list isNil ifTrue:[ |
|
329 |
textView list:newLines. |
|
330 |
] ifFalse:[ |
|
331 |
"/ the cursor line first - that's where your eyes are ... |
|
332 |
(l := textView cursorLine) notNil ifTrue:[ |
|
333 |
l <= newLines size ifTrue:[ |
|
334 |
replaceAction value:l value:(newLines at:l) |
|
335 |
] |
|
336 |
]. |
|
337 |
newLines keysAndValuesDo:replaceAction. |
|
338 |
anyChange ifTrue:[ |
|
339 |
cursorWasOn ifTrue:[ |
|
340 |
textView showCursor |
|
341 |
] |
|
342 |
] |
|
343 |
]. |
|
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
344 |
codeView syntaxElements: elements. |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
345 |
gutterView invalidate. |
10410 | 346 |
|
12125 | 347 |
"Modified: / 09-10-2006 / 11:50:17 / cg" |
348 |
"Created: / 14-02-2010 / 16:10:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
349 |
"Modified (format): / 21-08-2011 / 09:38:22 / cg" |
|
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
350 |
"Modified: / 30-01-2012 / 16:49:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
12138
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
351 |
"Modified: / 01-02-2012 / 19:18:00 / jv" |
10410 | 352 |
! ! |
353 |
||
9980 | 354 |
!CodeHighlightingService class methodsFor:'documentation'! |
355 |
||
10497 | 356 |
version |
12138
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
357 |
^ '$Id: Tools__CodeHighlightingService.st 7865 2012-02-01 19:44:39Z vranyj1 $' |
10497 | 358 |
! |
359 |
||
9980 | 360 |
version_CVS |
12125 | 361 |
^ '§Header: /cvs/stx/stx/libtool/Tools__CodeHighlightingService.st,v 1.30 2012/01/24 12:56:13 vrany Exp §' |
9980 | 362 |
! |
363 |
||
364 |
version_SVN |
|
12138
84205b6b75b4
Tools::CodeHighlightingService: remove emphasis from leading whitespace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
365 |
^ '$Id: Tools__CodeHighlightingService.st 7865 2012-02-01 19:44:39Z vranyj1 $' |
12125 | 366 |
! ! |