Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 - Position should be within the bounds of the source code
 - resolve it to the method's selector
  • Loading branch information
guillep committed Nov 30, 2020
1 parent 08930dc commit 0d73af6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -71,6 +71,12 @@ CNSelectorExtractionOnPositionTest >> methodWithIfTrueIfFalse [
ifFalse: [ self yourself ]
]

{ #category : #helpers }
CNSelectorExtractionOnPositionTest >> methodWithSpacesAtTheEnd [
"Please do not remove the leading spaces"
^ 1 someMessageFollowedBySpaces
]

{ #category : #helpers }
CNSelectorExtractionOnPositionTest >> methodX:a [

Expand Down Expand Up @@ -167,6 +173,16 @@ CNSelectorExtractionOnPositionTest >> testCaretAfterReturnShouldMatchChildCascad
self assert: self selectedSelector equals: cascade messages first selector
]

{ #category : #'tests - no selection - return' }
CNSelectorExtractionOnPositionTest >> testCaretAtEndOfMethodShouldMatchMethodNode [

self sourceCodeOf: self class >> #methodWithSpacesAtTheEnd.

self caretAfter: self returnNodeToTest methodNode.

self assert: self selectedSelector equals: #methodWithSpacesAtTheEnd
]

{ #category : #'tests - no selection - blocks' }
CNSelectorExtractionOnPositionTest >> testCaretBeforeMessageInBlock [

Expand Down
2 changes: 1 addition & 1 deletion src/Tools-CodeNavigation/CNSelectorExtractor.class.st
Expand Up @@ -57,7 +57,7 @@ CNSelectorExtractor >> extractSelectorFromAST: ast atPosition: aPosition [
ifTrue: [ 0 ]
ifFalse: [ -1 ].

position := aPosition + offset.
position := (aPosition + offset) min: ast stop.
bestNodeAtPosition := ast bestNodeFor: (position to: position).
^ self extractSelectorFromNode: bestNodeAtPosition
]
Expand Down

0 comments on commit 0d73af6

Please sign in to comment.