@@ -52,11 +52,6 @@ function symbolAtCaretPosition(parseTree: TerminalNode, caretPosition: { line: n
52
52
const start = parseTree . symbol . column
53
53
const stop = start + ( parseTree . symbol . text ?. length ?? 0 )
54
54
55
- console . log (
56
- `Checking symbol: ${ parseTree . symbol . text } , Line: ${ parseTree . symbol . line } , Start: ${ start } , Stop: ${ stop } `
57
- )
58
- console . log ( `Caret POsition: Line: ${ caretPosition . line + 1 } , character: ${ caretPosition . character } ` )
59
-
60
55
return (
61
56
parseTree . symbol . line == caretPosition . line + 1 &&
62
57
start <= caretPosition . character &&
@@ -69,7 +64,6 @@ function computeTokenIndexOfTerminalNode(
69
64
caretPosition : { line : number ; character : number }
70
65
) : number | undefined {
71
66
if ( symbolAtCaretPosition ( parseTree , caretPosition ) ) {
72
- console . log ( `Token index found: ${ parseTree . symbol . tokenIndex } for symbol: ${ parseTree . symbol . text } ` )
73
67
return parseTree . symbol . tokenIndex
74
68
} else {
75
69
return undefined
@@ -83,10 +77,8 @@ function computeTokenIndexOfChildNode(
83
77
for ( let i = 0 ; i < parseTree . getChildCount ( ) ; i ++ ) {
84
78
const child = parseTree . getChild ( i )
85
79
if ( child != null ) {
86
- console . log ( `Visiting child node at index: ${ i } ` )
87
80
const index = computeTokenIndex ( child , caretPosition )
88
81
if ( index !== undefined ) {
89
- console . log ( `Index found in child: ${ index } ` )
90
82
return index
91
83
}
92
84
}
@@ -98,7 +90,6 @@ function computeTokenIndex(
98
90
parseTree : ParseTree ,
99
91
caretPosition : { line : number ; character : number }
100
92
) : number | undefined {
101
- console . log ( `Current parseTree node type: ${ parseTree . constructor . name } ` )
102
93
if ( parseTree instanceof TerminalNode ) {
103
94
return computeTokenIndexOfTerminalNode ( parseTree , caretPosition )
104
95
} else {
@@ -118,13 +109,27 @@ function getCandidates(parser: PartiQLParser, index: number) {
118
109
119
110
// Add rules
120
111
core . preferredRules = new Set ( [
121
- // PartiQLParser.RULE_qualifiedName,
112
+ // No rules specified for now
122
113
] )
123
114
return core . collectCandidates ( index )
124
115
}
125
116
117
+ function getPosition (
118
+ content : string ,
119
+ position : { line : number ; character : number }
120
+ ) : { line : number ; character : number } {
121
+ const lines = content . split ( '\n' )
122
+ const line = lines [ position . line ]
123
+ const substring = line . substring ( 0 , position . character )
124
+ const lastSpaceIndex = substring . lastIndexOf ( ' ' )
125
+ return {
126
+ line : position . line ,
127
+ character : lastSpaceIndex + 1 ,
128
+ }
129
+ }
130
+
126
131
export function getSuggestions ( content : string , position : { line : number ; character : number } ) : CompletionList | null {
127
- console . log ( `Getting suggestions for content: ${ content } , position: ${ position . line + 1 } : ${ position . character } ` )
132
+ position = getPosition ( content , position )
128
133
const parser = initializePartiQLParser ( content )
129
134
const tokenIndex = getTokenIndexFromParseTree ( parser , position )
130
135
const candidates = getCandidates ( parser , tokenIndex )
0 commit comments