-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
CompletionContext.class.st
82 lines (69 loc) · 1.98 KB
/
CompletionContext.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"
I am a context class that hooks the new completion functionality into the system. To do that, i reimplement some of the methods but use most of the old ones from NECompletion package, such as the functionality to call the menu, etc.
"
Class {
#name : #CompletionContext,
#superclass : #Object,
#instVars : [
'source',
'position',
'completionToken',
'model',
'ast',
'node',
'isWorkspace',
'class'
],
#category : #'NECompletion-New'
}
{ #category : #'instance creation' }
CompletionContext class >> controller: aNECController class: aClass source: aString position: anInteger [
^ self new
setController: aNECController
class: aClass
source: aString
position: anInteger
]
{ #category : #accessing }
CompletionContext >> completionToken [
"here we need to return the name of the var or selector"
node ifNil: [ ^ '' ].
^ completionToken ifNil: [ node completionToken ]
]
{ #category : #accessing }
CompletionContext >> createModel [
self parseSource.
node := ast nodeForOffset: position.
^ CompletionModel new node: node
]
{ #category : #accessing }
CompletionContext >> model [
^model ifNil: [ model := self createModel ]
]
{ #category : #action }
CompletionContext >> narrowWith: aString [
completionToken := aString.
model := self createModel.
model narrowWith: aString
]
{ #category : #parsing }
CompletionContext >> parseSource [
ast := isWorkspace
ifTrue: [RBParser parseFaultyExpression: source]
ifFalse: [RBParser parseFaultyMethod: source].
ast methodNode
compilationContext:
(Smalltalk compiler compilationContextClass new
class: class;forSyntaxHighlighting: true).
ast doSemanticAnalysisIn: class.
TypingVisitor new visitNode: ast
]
{ #category : #'initialize-release' }
CompletionContext >> setController: aECController class: aClass source: aString position: anInteger [
isWorkspace:= aECController
ifNotNil: [ aECController isScripting ]
ifNil: [ false ].
class := aClass.
source := aString.
position := anInteger
]