Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec code completion #5671

Merged
merged 6 commits into from Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 44 additions & 19 deletions src/Rubric-Tests/RubSmalltalkEditorTest.class.st
Expand Up @@ -6,7 +6,8 @@ Class {
#superclass : #TestCase,
#instVars : [
'source',
'selection'
'selection',
'currentCompletion'
],
#category : #'Rubric-Tests'
}
Expand Down Expand Up @@ -243,6 +244,13 @@ RubSmalltalkEditorTest >> selection: anInterval [
selection := anInterval
]

{ #category : #running }
RubSmalltalkEditorTest >> setUp [

super setUp.
currentCompletion := RubSmalltalkEditor completionEngineClass
]

{ #category : #accessing }
RubSmalltalkEditorTest >> source [
^ source
Expand All @@ -253,6 +261,13 @@ RubSmalltalkEditorTest >> source: aString [
source := aString
]

{ #category : #running }
RubSmalltalkEditorTest >> tearDown [

RubSmalltalkEditor completionEngineClass: currentCompletion.
super tearDown.
]

{ #category : #'tests-bestNodeIn' }
RubSmalltalkEditorTest >> testBestNodeWithInvalidEmptySource [

Expand Down Expand Up @@ -576,29 +591,39 @@ RubSmalltalkEditorTest >> testBestNodeWithValidValueMidSource [
]

{ #category : #'tests-completion' }
RubSmalltalkEditorTest >> testInstanceVersusSharedCompletionEngine [
RubSmalltalkEditorTest >> testDefaultCompletionEngineUsesGlobalClass [

| textEditor currentCompletion |
[ currentCompletion := RubSmalltalkEditor completionEngineClass.
| textEditor |
textEditor := RubSmalltalkEditor new.
self assert: textEditor completionEngine class equals: currentCompletion
]

{ #category : #'tests-completion' }
RubSmalltalkEditorTest >> testDefaultCompletionIsNilIfNoGlobalClass [

| textEditor |
textEditor := RubSmalltalkEditor new.
self assert: textEditor completionEngine class equals: currentCompletion.

RubSmalltalkEditor noCompletion.
"here we show that an existing editor is not impacted by the shared behavior"
self assert: textEditor completionEngine class equals: currentCompletion.
self assert: textEditor completionEngine isNil
]

{ #category : #'tests-completion' }
RubSmalltalkEditorTest >> testExplicitCompletionEngineIgnoresAbsenceOfGlobalClass [

| textEditor |
textEditor := RubSmalltalkEditor new.
self assert: textEditor completionEngine isNil.

RubSmalltalkEditor completionEngineClass: CompletionEngine.
self assert: textEditor completionEngine isNil.

"but now when we create a new one it gets the correct engine"
RubSmalltalkEditor noCompletion.
textEditor completionEngine: 17.
self assert: textEditor completionEngine equals: 17
]

{ #category : #'tests-completion' }
RubSmalltalkEditorTest >> testExplicitCompletionEngineIgnoresGlobalClass [

| textEditor |
textEditor := RubSmalltalkEditor new.
self assert: textEditor completionEngine class equals: CompletionEngine.


] ensure: [ RubSmalltalkEditor completionEngineClass: currentCompletion ]

textEditor completionEngine: 17.
self assert: textEditor completionEngine equals: 17
]

{ #category : #'tests-jumpFind' }
Expand Down
6 changes: 6 additions & 0 deletions src/Rubric/RubScrolledTextMorph.class.st
Expand Up @@ -267,6 +267,12 @@ RubScrolledTextMorph >> columnRuler [
^ self rulerNamed: #column
]

{ #category : #accessing }
RubScrolledTextMorph >> completionEngine: aCompletionEngine [

self textArea editor completionEngine: aCompletionEngine
]

{ #category : #configure }
RubScrolledTextMorph >> configureGhostText: aTextArea [
aTextArea width: self scrollBounds width.
Expand Down
9 changes: 6 additions & 3 deletions src/Rubric/RubSmalltalkEditor.class.st
Expand Up @@ -357,7 +357,11 @@ RubSmalltalkEditor >> completionAround: aBlock keyStroke: anEvent [

{ #category : #'completion engine' }
RubSmalltalkEditor >> completionEngine [
^ completionEngine

^ completionEngine ifNil: [
CompletionEngineClass ifNotNil: [
self completionEngine: CompletionEngineClass new.
completionEngine ] ]
]

{ #category : #'completion engine' }
Expand Down Expand Up @@ -735,8 +739,7 @@ RubSmalltalkEditor >> implementorsOfIt: aKeyboardEvent [
{ #category : #initialization }
RubSmalltalkEditor >> initialize [
super initialize.
notificationStrategy := RubTextInsertionStrategy new editor: self.
CompletionEngineClass ifNotNil: [self completionEngine: CompletionEngineClass new]
notificationStrategy := RubTextInsertionStrategy new editor: self
]

{ #category : #keymapping }
Expand Down
3 changes: 3 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicCodeAdapter.class.st
Expand Up @@ -18,6 +18,9 @@ SpMorphicCodeAdapter >> buildWidget [
self presenter whenSyntaxHighlightChangedDo: [ :hasSyntaxHighlight |
self setEditingModeFor: newWidget ].

self presenter completionEngine ifNotNil: [ :engine | newWidget completionEngine: engine ].
self presenter whenCompletionEngineChangedDo: [ :engine | newWidget completionEngine: engine ].

^ newWidget
]

Expand Down
1 change: 0 additions & 1 deletion src/Spec2-Adapters-Morphic/SpMorphicTextAdapter.class.st
Expand Up @@ -41,7 +41,6 @@ SpMorphicTextAdapter >> buildWidget [
yourself.

self setEditingModeFor: newWidget.

self presenter whenTextChangedDo: [ :text | self setText: text to: newWidget ].
self presenter whenPlaceholderChangedDo: [ :text | self setGhostText: text to: newWidget ].

Expand Down
22 changes: 21 additions & 1 deletion src/Spec2-Core/SpCodePresenter.class.st
Expand Up @@ -9,7 +9,8 @@ Class {
'#doItContext => SpObservableSlot',
'#doItReceiver => SpObservableSlot',
'#behavior => SpObservableSlot',
'#syntaxHighlight => SpObservableSlot'
'#syntaxHighlight => SpObservableSlot',
'#completionEngine => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets-Text'
}
Expand Down Expand Up @@ -116,6 +117,18 @@ SpCodePresenter >> behavior: aClass [
behavior := aClass
]

{ #category : #accessing }
SpCodePresenter >> completionEngine [

^ completionEngine
]

{ #category : #api }
SpCodePresenter >> completionEngine: aCompletionEngine [

completionEngine := aCompletionEngine
]

{ #category : #'api-doIt' }
SpCodePresenter >> doItContext [

Expand Down Expand Up @@ -217,6 +230,13 @@ SpCodePresenter >> whenBehaviorChangedDo: aBlock [
whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpCodePresenter >> whenCompletionEngineChangedDo: aBlock [
"Set a block to perform when the syntax highlight is enabled/disabled"

self property: #completionEngine whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpCodePresenter >> whenSyntaxHighlightChangedDo: aBlock [
"Set a block to perform when the syntax highlight is enabled/disabled"
Expand Down