Add highlighting to current nesting level in Carp highlighter

This commit is contained in:
2022-04-17 16:42:10 +02:00
parent f1cac9749e
commit 0469c6dbdf
2 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
Class {
#name : #CarpApplication,
#superclass : #LanguageLinkApplication,
#instVars : [
'uniqueInstance'
],
#category : #'Carp-LanguageLink'
}
{ #category : #'start-stop' }
CarpApplication class >> start [
^ self startWith: LanguageLinkSettings jsDefaultSettings.
]
{ #category : #accessing }
CarpApplication >> baseApplication [
^ CarpApplication
]
{ #category : #accessing }
CarpApplication >> initializeHandlers [
loggingHandler := LanguageLinkLoggingHandler application: self.
communicationHandler := LanguageLinkCommunicationHandler application: self.
processHandler := LanguageLinkServerHandler application: self.
"executionHandler := CarpExecutionHandler application: self"
]

View File

@@ -0,0 +1,88 @@
Class {
#name : #CarpStylerUtilities,
#superclass : #Object,
#category : #'Carp-Styler'
}
{ #category : #accessing }
CarpStylerUtilities class >> colorAndHighlightParenthesesLeft: aLeftIndex right: aRightIndex atNestingLevel: aNestingLevel inText: aText [
self
highlightParenthesesLeft: aLeftIndex
right: aRightIndex
inText: aText.
self
colorParenthesesLeft: aLeftIndex
right: aRightIndex
atNestingLevel: aNestingLevel
inText: aText
]
{ #category : #accessing }
CarpStylerUtilities class >> colorParenthesesLeft: aLeftIndex right: aRightIndex atNestingLevel: aNestingLevel inText: aText [
| color |
color := self parenthesesColorAt: aNestingLevel.
(aText
from: aLeftIndex
to: aLeftIndex)
foreground: color.
(aText
from: aRightIndex
to: aRightIndex)
foreground: color
]
{ #category : #accessing }
CarpStylerUtilities class >> highlightParenthesesLeft: aLeftIndex right: aRightIndex inText: aText [
| theParanthesesMarker cursorEnterAction cursorLeaveAction |
theParanthesesMarker := BrTextInvisibleMarkerAttribute new.
aText
attribute: theParanthesesMarker
from: aLeftIndex
to: aRightIndex.
cursorEnterAction := [ :aTextEditor |
aTextEditor text
findAttribute: theParanthesesMarker
indicesDo: [ :aParanthesesStart :aParanthesesEnd |
aTextEditor text
attribute: (GtPharoParenthesesHighlightAttribute paint: BrGlamorousColors neutralBackgroundColor)
from: aParanthesesStart
to: aParanthesesEnd ] ].
cursorLeaveAction := [ :aTextEditor |
aTextEditor text
findAttribute: theParanthesesMarker
indicesDo: [ :aParanthesesStart :aParanthesesEnd |
(aTextEditor text
from: aParanthesesStart
to: aParanthesesEnd)
clearAttributesOfClass: GtPharoParenthesesHighlightAttribute ] ].
(aText
from: aLeftIndex
to: aLeftIndex)
onCursorEnter: cursorEnterAction
leave: cursorLeaveAction.
(aText
from: aRightIndex
to: aRightIndex)
onCursorEnter: cursorEnterAction
leave: cursorLeaveAction
]
{ #category : #accessing }
CarpStylerUtilities class >> parenthesesColorAt: anIndex [
| colors |
colors := self parenthesesColors.
^ colors at: (anIndex - 1) \\ colors size + 1
]
{ #category : #accessing }
CarpStylerUtilities class >> parenthesesColors [
| colors |
colors := BrGlamorousColors distinctTenStrongColors allButFirst allButLast
collect: [ :each | each twiceDarker ].
^ colors
]