Initial support for incremental highlighting. Not ideal, but works for Java.
--- a/SmallSenseSyntaxHighlightingService.st Sat Aug 03 15:39:09 2013 +0100
+++ b/SmallSenseSyntaxHighlightingService.st Sun Aug 04 01:23:12 2013 +0100
@@ -101,6 +101,75 @@
"Created: / 03-08-2013 / 11:08:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!SmallSenseSyntaxHighlightingService methodsFor:'private'!
+
+setHighlightedLine: line at: lineNr
+ |firstShown lastShown anyChange replaceAction list|
+
+ "textView" modified ifTrue:[
+ "/ new input arrived in the meantime
+
+ ^ self
+ ].
+"/ done ifFalse:[
+"/ "/ another coloring process has already been started.
+"/ "/ ignore this (leftover) code.
+"/ ^ self
+"/ ].
+
+ firstShown := textView firstLineShown.
+ lastShown := textView lastLineShown.
+
+ replaceAction := [:lNr :line |
+ |oldLine|
+
+ oldLine := list at:lNr ifAbsent:nil.
+ oldLine notNil ifTrue:[
+ line notNil ifTrue:[
+ "/ this check is needed - there is a race
+ "/ when the text is converted. This detects the
+ "/ resulting error.
+ "/ Certainly a kludge.
+
+ oldLine string = line string ifTrue:[
+ | i |
+
+ "JV@2012-02-01: Remove any emphasis on leading whitespace"
+ "(presumably created by LintHighlighter)"
+ i := line string indexOfNonSeparator.
+ i > 1 ifTrue:[
+ | e |
+
+ (e := (line emphasisAt: i - 1)) notNil ifTrue:[
+ line emphasisFrom: 1 to: i - 1 remove: e.
+ ]
+ ].
+
+ oldLine emphasis ~= line emphasis ifTrue:[
+ textView modifiedChannel removeDependent:self.
+ list at:lNr put:line.
+ textView modifiedChannel addDependent:self.
+ (lNr between:firstShown and:lastShown) ifTrue:[
+ anyChange ifFalse:[
+ anyChange := true.
+ ].
+ textView redrawLine:lNr
+ ]
+ ]
+ ]
+ ]
+ ]
+ ].
+ list := textView list.
+ replaceAction value: lineNr value: line.
+ gutterView invalidate.
+
+"/ Transcript showCR:'--> rehighlighted ', self identityHash printString.
+
+ "Created: / 03-08-2013 / 23:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-08-2013 / 00:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!SmallSenseSyntaxHighlightingService methodsFor:'processing'!
process
@@ -123,7 +192,8 @@
textView modifiedChannel setValue:false.
].
- (lastLineFromChanged isNil and:[lastLineToChanged isNil]) ifTrue:[
+ ((lastLineFromChanged isNil and:[lastLineToChanged isNil])
+ or:[lastLineFromChanged == 1 and:[lastLineToChanged == textView size]]) ifTrue:[
job stopAndRemoveAll.
job add: nil.
] ifFalse:[
@@ -131,7 +201,8 @@
]
"Created: / 03-08-2013 / 11:07:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 03-08-2013 / 13:04:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-08-2013 / 21:09:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 03-08-2013 / 22:09:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
process: delayed
@@ -144,14 +215,14 @@
process: delayed changed: interval
- |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
+ |oldCode oldCodeList newCode elements cls mthd highlighters|
done := false.
modified := false.
codeView syntaxElements: nil.
codeView syntaxElementSelection: nil.
- highlighterClasses := self syntaxHighlighters.
+ highlighters := self syntaxHighlighters.
cls := codeView klass.
(cls notNil and:[cls isObsolete]) ifTrue:[
@@ -169,8 +240,7 @@
oldCodeList isNil ifFalse:[
oldCode := oldCodeList asStringWithoutEmphasis.
"textView" modified ifFalse:[
- Screen currentScreenQuerySignal answer:codeView device
- do:[
+ Screen currentScreenQuerySignal answer:codeView device do:[
Parser parseErrorSignal handle:[:ex |
|errMsg|
@@ -187,17 +257,76 @@
elements := ParseTreeIndex new.
newCode := oldCode asText.
codeAspect := codeView codeAspect.
- codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[
- highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements].
- ] ifFalse:[
- codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[
- highlighterClasses do:[:e|newCode := e formatExpression:newCode in:cls elementsInto: elements].
+
+ "/ switch codeAspect
+ "/ case method
+ codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[
+ highlighters do:[:h|
+ (interval notNil and:[h respondsTo:#formatMethod:source:line:number:in:using:]) ifTrue:[
+ interval do:[:lnr |
+ | ln |
+
+ ln := oldCodeList at: lnr ifAbsent:[nil].
+ ln notEmptyOrNil ifTrue:[
+ | nln |
+
+ nln := h formatMethod:mthd source:newCode line: ln string number: lnr in:cls using:syntaxPreferences.
+ nln ~~ ln ifTrue:[
+ delayed ifTrue:[
+ codeView sensor
+ pushUserEvent:#setHighlightedLine:at:
+ for:self
+ withArguments:(Array with:nln with: lnr).
+ ] ifFalse:[
+ self setHighlightedLine: nln at: lnr.
+ ]
+ ]
+ ]
+ ].
+ done := true.
+ ^ self.
+ ] ifFalse:[
+ newCode := h formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements
+ ].
+ ].
] ifFalse:[
- codeView codeAspect == #classDefinition ifTrue:[
- highlighterClasses do:[:e|newCode := e formatClassDefinition:newCode in:cls elementsInto: elements].
- ]
- ].
- ].
+ "/ case expession
+ codeAspect == (SyntaxHighlighter codeAspectExpression) ifTrue:[
+ highlighters do:[:h|
+ newCode := h formatExpression:newCode in:cls elementsInto: elements
+ ].
+ ] ifFalse:[
+ "/case class definition
+ codeView codeAspect == #classDefinition ifTrue:[
+ highlighters do:[:h|
+ (interval notNil and:[h respondsTo:#formatClassDefinition:line:number:in:]) ifTrue:[
+ interval do:[:lnr |
+ | ln |
+
+ ln := oldCodeList at: lnr ifAbsent:[nil].
+ ln notEmptyOrNil ifTrue:[
+ | nln |
+
+ nln := h formatClassDefinition:newCode line: ln string number: lnr in:cls.
+ nln ~~ ln ifTrue:[
+ delayed ifTrue:[
+ codeView sensor
+ pushUserEvent:#setHighlightedLine:at:
+ for:self
+ withArguments:(Array with:nln with: lnr).
+ ] ifFalse:[
+ self setHighlightedLine: nln at: lnr.
+ ]
+ ]
+ ]
+ ].
+ done := true.
+ ^ self
+ ] ifFalse:[
+ newCode := h formatClassDefinition:newCode in:cls elementsInto: elements
+ ]
+ ].
+ ]]].
]
].
newCode notNil ifTrue:[
@@ -226,13 +355,13 @@
].
]
]
- ]
+ ] "/ ---
]
]
]
"Created: / 03-08-2013 / 11:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 03-08-2013 / 13:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-08-2013 / 00:49:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!SmallSenseSyntaxHighlightingService class methodsFor:'documentation'!
--- a/abbrev.stc Sat Aug 03 15:39:09 2013 +0100
+++ b/abbrev.stc Sun Aug 04 01:23:12 2013 +0100
@@ -14,11 +14,11 @@
SmallSenseParseNodeInspector SmallSenseParseNodeInspector jv:smallsense 'SmallSense-Interface' 1
SmallSenseParseNodeVisitor SmallSenseParseNodeVisitor jv:smallsense 'SmallSense-Core' 0
SmallSenseParser SmallSenseParser jv:smallsense 'SmallSense-Core' 3
-SmallSenseParserTests SmallSenseParserTests jv:smallsense 'SmallSense-Tests' 1
+SmallSenseParserTests SmallSenseParserTests jv:smallsense 'SmallSense-Tests' 0
SmallSensePosition SmallSensePosition jv:smallsense 'SmallSense-Core' 0
SmallSenseQuickFixer SmallSenseQuickFixer jv:smallsense 'SmallSense-Lint' 0
SmallSenseRecognizer SmallSenseRecognizer jv:smallsense 'SmallSense-Core' 0
-SmallSenseRecognizerTests SmallSenseRecognizerTests jv:smallsense 'SmallSense-Tests' 1
+SmallSenseRecognizerTests SmallSenseRecognizerTests jv:smallsense 'SmallSense-Tests' 0
SmallSenseResultSet SmallSenseResultSet jv:smallsense 'SmallSense-Core' 0
SmallSenseSelectorNode SmallSenseSelectorNode jv:smallsense 'SmallSense-Core' 0
SmallSenseService SmallSenseService jv:smallsense 'SmallSense-Services' 0
--- a/smallsense.rc Sat Aug 03 15:39:09 2013 +0100
+++ b/smallsense.rc Sun Aug 04 01:23:12 2013 +0100
@@ -3,7 +3,7 @@
// automagically generated from the projectDefinition: jv_smallsense.
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 6,2,32767,32767
+ FILEVERSION 6,2,1589,1589
PRODUCTVERSION 6,2,3,0
#if (__BORLANDC__)
FILEFLAGSMASK VS_FF_DEBUG | VS_FF_PRERELEASE
@@ -20,12 +20,12 @@
BEGIN
VALUE "CompanyName", "eXept Software AG\0"
VALUE "FileDescription", "Smalltalk/X Class library (LIB)\0"
- VALUE "FileVersion", "6.2.32767.32767\0"
+ VALUE "FileVersion", "6.2.1589.1589\0"
VALUE "InternalName", "jv:smallsense\0"
VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\0"
VALUE "ProductName", "Smalltalk/X\0"
VALUE "ProductVersion", "6.2.3.0\0"
- VALUE "ProductDate", "Sun, 28 Jul 2013 09:17:52 GMT\0"
+ VALUE "ProductDate", "Sun, 04 Aug 2013 00:21:50 GMT\0"
END
END