SmallSense__CompletionContext.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 17 Oct 2013 01:41:47 +0100
changeset 132 7c23c51d2cfd
parent 108 71471dc81e77
child 133 bd659b67811c
permissions -rw-r--r--
Completion insertion refactoring. Added language and codeView into CompletionContext. Added context slot into PO so the PO itself know the completion context and can tweak its presentation accordingly. Also, actual text insertion is now delegated to the PO so the PO can insert proper text according to the context (especially - language)

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

Object subclass:#CompletionContext
	instanceVariableNames:'node position codeView language'
	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
    ^ codeView
!

language
    ^ language
!

node
    ^ node
!

position
    ^ position
! !

!CompletionContext methodsFor:'initialization'!

codeView:something
    codeView := something.
!

language:something
    language := something.
!

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>"
! !

!CompletionContext methodsFor:'private'!

wordBeforeCursor
    | textView currentLine wordStart wordEnd |
    textView := 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:[(currentLine at: wordStart) isAlphaNumeric] ] whileTrue:[
            wordStart := wordStart - 1.
        ].
        wordStart := wordStart + 1.
        wordStart <= wordEnd ifTrue:[
            ^ currentLine copyFrom: wordStart to: wordEnd.
        ].
    ].
    ^ ''

    "Created: / 27-09-2013 / 15:53:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-10-2013 / 00:46:51 / 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 $'
! !