SmallSense__CompletionContext.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 21 Jan 2014 23:33:53 +0000
changeset 157 c71d2e62ece2
parent 133 bd659b67811c
child 176 df6d3225d1e4
permissions -rw-r--r--
Refactored API of CompletionEngine - caller now must set up an context pass it. ComplectionContext now contains EditSupport instance and uses it to insert completions.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

Object subclass:#CompletionContext
	instanceVariableNames:'node position support'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core'
!


!CompletionContext class methodsFor:'instance creation'!

node: node position: position

    ^self new node: node position: position

    "Created: / 26-11-2011 / 16:22:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionContext methodsFor:'accessing'!

codeView
    ^ support codeView

    "Modified: / 21-01-2014 / 23:16:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

language
    ^ support language

    "Modified: / 21-01-2014 / 23:16:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

node
    ^ node
!

position
    ^ position
!

support
    ^ support
! !

!CompletionContext methodsFor:'initialization'!

node:nd position: pos

    node := nd.
    position := pos.

    "Created: / 26-11-2011 / 16:22:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-10-2013 / 23:31:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

support: anEditSupport
    support := anEditSupport.

    "Modified: / 21-01-2014 / 23:31:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionContext methodsFor:'private'!

wordBeforeCursor
    ^ self wordBeforeCursorConsisitingOfCharactersMatching: [:c | c isAlphaNumeric ].

    "Created: / 27-09-2013 / 15:53:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 20-10-2013 / 00:17:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

wordBeforeCursorConsisitingOfCharactersMatching: characterMatchBlock
    | textView currentLine wordStart wordEnd |
    textView := self codeView.
    textView isCodeView2 ifTrue:[textView := textView textView].
    currentLine := textView list at: textView cursorLine.
    currentLine isNil ifTrue:[ ^ '' ].
    wordEnd := textView cursorCol - 1.
    wordEnd > currentLine size ifTrue:[ ^ '' ].
    wordEnd ~~ 0 ifTrue:[
        wordStart := wordEnd.
        [ wordStart > 0 and:[characterMatchBlock value:(currentLine at: wordStart) ] ] whileTrue:[
            wordStart := wordStart - 1.
        ].
        wordStart := wordStart + 1.
        wordStart <= wordEnd ifTrue:[
            ^ currentLine copyFrom: wordStart to: wordEnd.
        ].
    ].
    ^ ''

    "Created: / 20-10-2013 / 00:17:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-01-2014 / 23:31:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionContext methodsFor:'queries'!

isAfterNode
    ^ node notNil and:[node endPosition < (position - 1)]

    "Created: / 26-11-2011 / 16:24:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-10-2013 / 23:31:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isBeforeNode
    ^node notNil and:[position < node startPosition]

    "Created: / 26-11-2011 / 16:24:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 24-09-2013 / 13:11:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isInNode
    ^ node notNil and:[(position - 1) between:node startPosition and:node endPosition]

    "Created: / 26-11-2011 / 16:24:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-10-2013 / 23:31:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionContext class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id: SmallSensePosition.st 7823 2011-11-26 16:55:59Z vranyj1 $'
! !