Skip to content

Commit

Permalink
Cleanup Shout
Browse files Browse the repository at this point in the history
- Remove #stylingEnabled: because this is never used and if we do not want to style a text, we should not give it to the styler
- Remove #text ivar that is unused
- Remove #plugins that are unused

Fixes pharo-project#16310
  • Loading branch information
jecisc committed Oct 10, 2024
1 parent 87df29b commit f1ec7fd
Showing 1 changed file with 8 additions and 55 deletions.
63 changes: 8 additions & 55 deletions src/Shout/SHRBTextStyler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ Class {
'bracketLevel',
'classOrMetaClass',
'workspace',
'plugins',
'braceLevel',
'view',
'stylingEnabled',
'text',
'isScripting'
],
#classInstVars : [
Expand Down Expand Up @@ -723,12 +720,6 @@ SHRBTextStyler class >> vintageStyleTable [
(pragma (cyan muchDarker)))
]

{ #category : 'private' }
SHRBTextStyler >> addASTTransformationPlugin: aPlugin [

self plugins add: aPlugin
]

{ #category : 'formatting' }
SHRBTextStyler >> addAttributes: attributes forNode: aNode [

Expand Down Expand Up @@ -756,12 +747,6 @@ SHRBTextStyler >> addAttributesFrom: attributeRuns satisfying: aTestBlock to: aT
^ aText
]

{ #category : 'accessing' }
SHRBTextStyler >> addPlugin: aPlugin [

self plugins add: aPlugin
]

{ #category : 'formatting' }
SHRBTextStyler >> addStyle: styleSymbol attribute: additionalAttribute from: start to: end [
self addAttributes: (self attributesFor: styleSymbol), {additionalAttribute} from: start to: end
Expand Down Expand Up @@ -835,7 +820,6 @@ SHRBTextStyler >> hasSymbolStartingBy: aSymbol [
SHRBTextStyler >> initialize [

super initialize.
stylingEnabled := true.
isScripting := false
]

Expand Down Expand Up @@ -904,29 +888,19 @@ SHRBTextStyler >> parenthesisStyleName [
ifFalse: [ level asString ])) asSymbol
]

{ #category : 'private' }
SHRBTextStyler >> plugins [

^ plugins ifNil: [ plugins := OrderedCollection new ]
]

{ #category : 'private' }
SHRBTextStyler >> privateStyle: aText [
| compiler |

| compiler |
aText ifEmpty: [ ^ self ].

compiler := classOrMetaClass compiler
source: aText asString;
receiver: (self isScripting ifTrue: [workspace ifNotNil: [:w | w doItReceiver]]);
isScripting: self isScripting;
requestor: workspace.
source: aText asString;
receiver: (self isScripting ifTrue: [ workspace ifNotNil: [ :w | w doItReceiver ] ]);
isScripting: self isScripting;
requestor: workspace.

self plugins do: [ :each | compiler addParsePlugin: each ].

^ self
style: aText
ast: compiler parse
^ self style: aText ast: compiler parse
]

{ #category : 'testing' }
Expand Down Expand Up @@ -965,8 +939,8 @@ SHRBTextStyler >> resolveVariableAttributesFor: aVariableNode [
{ #category : 'styling' }
SHRBTextStyler >> style: aText [

| text |
aText ifEmpty: [ ^ self ].
stylingEnabled ifFalse: [ ^ self ].
text := aText copy.
self privateStyle: text.
view ifNotNil: [ :view2 | view2 stylerStyled: text ]
Expand All @@ -976,16 +950,13 @@ SHRBTextStyler >> style: aText [
SHRBTextStyler >> style: aText ast: ast [

aText ifEmpty: [ ^ self ].
text := aText.
charAttr := Array new: aText size withAll: (self attributesFor: #default).
bracketLevel := 0.
parentheseLevel := 0.
braceLevel := 0.
self visitNode: ast.
"Second pass to ensure that all syntax errors are visible"
ast allErrorNotices do: [ :notice |
notice isSyntaxError ifTrue: [
self addStyle: #invalid from: notice position to: notice position ] ].
ast allErrorNotices do: [ :notice | notice isSyntaxError ifTrue: [ self addStyle: #invalid from: notice position to: notice position ] ].
^ aText runs: (RunArray newFrom: charAttr)
]

Expand Down Expand Up @@ -1073,24 +1044,6 @@ SHRBTextStyler >> styledTextFor: aText [
^ self privateStyle: aText
]

{ #category : 'private' }
SHRBTextStyler >> stylingEnabled [

^ stylingEnabled
]

{ #category : 'private' }
SHRBTextStyler >> stylingEnabled: aBoolean [

stylingEnabled := aBoolean
]

{ #category : 'private' }
SHRBTextStyler >> text [

^ text
]

{ #category : 'styling' }
SHRBTextStyler >> unstyledTextFrom: aText [
"return a Text object without all styling attributes"
Expand Down

0 comments on commit f1ec7fd

Please sign in to comment.