@@ -5,6 +5,53 @@ import type { SyntaxNode } from '@lezer/common';
5
5
import { parser } from './pg.grammar' ;
6
6
import { pgVariables , pgOperators , pgOperatorCompletions } from './pg-variables' ;
7
7
8
+ const pgOperatorCompletionOptions : Completion [ ] = [ ] ;
9
+
10
+ for ( const operator of pgOperators . values ( ) ) {
11
+ const completions = pgOperatorCompletions . get ( operator ) ;
12
+ if ( completions ) {
13
+ for ( const template of completions ) {
14
+ pgOperatorCompletionOptions . push (
15
+ snippetCompletion ( template , {
16
+ label : operator ,
17
+ info : template
18
+ . replaceAll ( / \$ { ( [ ^ } ] * ) } / g, '$1' )
19
+ . replaceAll ( / \t / g, '' )
20
+ . replaceAll ( / \n / g, ' ' ) ,
21
+ type : 'variable' ,
22
+ section : { name : 'PG Methods' , rank : 1 }
23
+ } )
24
+ ) ;
25
+ }
26
+ } else {
27
+ pgOperatorCompletionOptions . push (
28
+ snippetCompletion ( `${ operator } (\${})\${}` , {
29
+ label : operator ,
30
+ info : `${ operator } ()` ,
31
+ type : 'variable' ,
32
+ section : { name : 'PG Methods' , rank : 1 }
33
+ } )
34
+ ) ;
35
+ }
36
+ }
37
+
38
+ for ( const pkg of [ 'Scaffold' , 'Section' ] ) {
39
+ for ( const position of [ 'Begin' , 'End' ] ) {
40
+ pgOperatorCompletionOptions . push (
41
+ snippetCompletion ( `${ pkg } ::${ position } (\${});\${}` , {
42
+ label : `${ pkg } ::${ position } ` ,
43
+ info : `${ pkg } ::${ position } ();` ,
44
+ type : 'variable' ,
45
+ section : { name : 'PG Methods' , rank : 1 }
46
+ } )
47
+ ) ;
48
+ }
49
+ }
50
+
51
+ for ( const pkg of [ 'Label' , 'Circle' , 'Fun' ] ) {
52
+ pgOperatorCompletionOptions . push ( { label : pkg , type : 'variable' , section : { name : 'WWPlot Object' , rank : 2 } } ) ;
53
+ }
54
+
8
55
export const pgCompletion = ( isTop = false ) => {
9
56
return ( context : CompletionContext ) => {
10
57
const nodeAt = syntaxTree ( context . state ) . resolveInner ( context . pos , - 1 ) ;
@@ -78,48 +125,15 @@ export const pgCompletion = (isTop = false) => {
78
125
79
126
if (
80
127
inside ( [ 'CallExpression' , 'FunctionName' , 'Identifier' ] ) &&
81
- ! inside ( [ 'StringSingleQuoted' , 'StringQQuoted' , 'InterpolatedStringContent' , 'UninterpolatedHeredocBody' ] )
128
+ ! inside ( [
129
+ 'StringSingleQuoted' ,
130
+ 'StringQQuoted' ,
131
+ 'InterpolatedStringContent' ,
132
+ 'UninterpolatedHeredocBody' ,
133
+ 'MethodInvocation'
134
+ ] )
82
135
) {
83
- for ( const operator of pgOperators . values ( ) ) {
84
- const completions = pgOperatorCompletions . get ( operator ) ;
85
- if ( completions ) {
86
- for ( const template of completions ) {
87
- completionOptions . push (
88
- snippetCompletion ( template , {
89
- label : operator ,
90
- info : template
91
- . replaceAll ( / \$ { ( [ ^ } ] * ) } / g, '$1' )
92
- . replaceAll ( / \t / g, '' )
93
- . replaceAll ( / \n / g, ' ' ) ,
94
- type : 'variable' ,
95
- section : { name : 'PG Methods' }
96
- } )
97
- ) ;
98
- }
99
- } else {
100
- completionOptions . push (
101
- snippetCompletion ( `${ operator } (\${})\${}` , {
102
- label : operator ,
103
- info : `${ operator } ()` ,
104
- type : 'variable' ,
105
- section : { name : 'PG Methods' }
106
- } )
107
- ) ;
108
- }
109
- }
110
-
111
- for ( const part of [ 'Scaffold' , 'Section' ] ) {
112
- for ( const position of [ 'Begin' , 'End' ] ) {
113
- completionOptions . push (
114
- snippetCompletion ( `${ part } ::${ position } (\${});\${}` , {
115
- label : `${ part } ::${ position } ` ,
116
- info : `${ part } ::${ position } ();` ,
117
- type : 'variable' ,
118
- section : { name : 'PG Methods' }
119
- } )
120
- ) ;
121
- }
122
- }
136
+ completionOptions . push ( ...pgOperatorCompletionOptions ) ;
123
137
}
124
138
125
139
return completeFromList ( completionOptions ) ( context ) ;
0 commit comments