Skip to content

Commit

Permalink
Fix #6721: Do not take the completion token from the AST
Browse files Browse the repository at this point in the history
The completion context should take the completionToken from the engine.
The engine takes it from the editor.

This avoids glitches when the AST is not entirely valid, or when typing inside comments
  • Loading branch information
guillep committed Jun 29, 2020
1 parent d53ebbf commit 1b747ef
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
Expand Up @@ -62,7 +62,6 @@ CoASTHeuristicsResultSetBuilder >> visitMessageNode: aRBMessageNode [
^ self
configureFetcherForNode: aRBMessageNode
usingHeuristicAvoidingRepetitions: self messageHeuristic
narrowingWith: aRBMessageNode selector
]

{ #category : #visiting }
Expand All @@ -71,7 +70,6 @@ CoASTHeuristicsResultSetBuilder >> visitMethodNode: aRBMethodNode [
^ self
configureFetcherForNode: aRBMethodNode
usingHeuristicAvoidingRepetitions: self methodNodeHeuristic
narrowingWith: aRBMethodNode selector
]

{ #category : #visiting }
Expand All @@ -80,5 +78,4 @@ CoASTHeuristicsResultSetBuilder >> visitVariableNode: aRBVariableNode [
^ self
configureFetcherForNode: aRBVariableNode
usingHeuristicAvoidingRepetitions: self variablesHeuristic
narrowingWith: aRBVariableNode name
]
19 changes: 3 additions & 16 deletions src/HeuristicCompletion-Model/CoASTResultSetBuilder.class.st
Expand Up @@ -37,38 +37,25 @@ CoASTResultSetBuilder >> configureEmptyFetcherForNode: aNode [
^ self
configureFetcher: CoEmptyFetcher new
forNode: aNode
narrowingWith: ''
]

{ #category : #'private-building' }
CoASTResultSetBuilder >> configureFetcher: aFetcher forNode: aNode narrowingWith: aString [
CoASTResultSetBuilder >> configureFetcher: aFetcher forNode: aNode [

| completion |
completion := CoResultSet fetcher: aFetcher.
completion filterWithString: aString.
completion filterWithString: completionContext completionToken.
^ completion
]

{ #category : #'private-building' }
CoASTResultSetBuilder >> configureFetcherForNode: aNode usingHeuristic: heuristic narrowingWith: aString [

| fetcher |
fetcher := heuristic fetcherFor: aNode inContext: completionContext.
^ self
configureFetcher: fetcher
forNode: aNode
narrowingWith: aString
]

{ #category : #'private-building' }
CoASTResultSetBuilder >> configureFetcherForNode: aNode usingHeuristicAvoidingRepetitions: heuristic narrowingWith: aString [
CoASTResultSetBuilder >> configureFetcherForNode: aNode usingHeuristicAvoidingRepetitions: heuristic [

| fetcher |
fetcher := heuristic fetcherFor: aNode inContext: completionContext.
^ self
configureFetcher: fetcher withoutRepetition
forNode: aNode
narrowingWith: aString
]

{ #category : #accessing }
Expand Down
2 changes: 1 addition & 1 deletion src/HeuristicCompletion-Model/CoCompletionContext.class.st
Expand Up @@ -89,7 +89,7 @@ CoCompletionContext >> completionEnvironment [
{ #category : #accessing }
CoCompletionContext >> completionToken [

^ self completion completionToken
^ self engine completionToken
]

{ #category : #accessing }
Expand Down
Expand Up @@ -44,5 +44,4 @@ CoGlobalSorterResultSetBuilder >> visitNode: aNode [
^ self
configureFetcher: fetcher
forNode: aNode
narrowingWith: (aNode completionToken: completionContext position)
]
13 changes: 13 additions & 0 deletions src/NECompletion-Morphic/CompletionEngine.class.st
Expand Up @@ -53,6 +53,19 @@ CompletionEngine >> closeMenu [
menuMorph := nil.
]

{ #category : #replacement }
CompletionEngine >> completionToken [

"Return the word just before the caret"
^ (self editor text copyFrom: self completionTokenStart to: self editor caret - 1) asString
]

{ #category : #replacement }
CompletionEngine >> completionTokenStart [
"This is the position in the editor where the completion token starts"
^ self editor previousWord: self editor caret - 1
]

{ #category : #accessing }
CompletionEngine >> context [
^context
Expand Down

0 comments on commit 1b747ef

Please sign in to comment.