@@ -5,7 +5,8 @@ import systemFunctions = require('./completion/systemFunctions.json');
5
5
import systemVariables = require( './completion/systemVariables.json' ) ;
6
6
import structuredSystemVariables = require( './completion/structuredSystemVariables.json' ) ;
7
7
import { ClassDefinition } from '../utils/classDefinition.js' ;
8
- import { currentFile } from '../utils/index.js' ;
8
+ import { currentFile , onlyUnique } from '../utils/index.js' ;
9
+ import { AtelierAPI } from '../api/index.js' ;
9
10
10
11
export class ObjectScriptCompletionItemProvider implements vscode . CompletionItemProvider {
11
12
provideCompletionItems (
@@ -17,14 +18,20 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
17
18
if ( context . triggerKind === vscode . CompletionTriggerKind . TriggerCharacter ) {
18
19
if ( context . triggerCharacter === '#' )
19
20
return this . macro ( document , position , token , context ) || this . entities ( document , position , token , context ) ;
20
- if ( context . triggerCharacter === '.' ) return this . entities ( document , position , token , context ) ;
21
+ if ( context . triggerCharacter === '.' ) {
22
+ if ( document . getWordRangeAtPosition ( position , / \$ s y s t e m ( \. \b \w + \b ) ? \. / i) ) {
23
+ return this . system ( document , position , token , context ) ;
24
+ }
25
+ return this . entities ( document , position , token , context ) ;
26
+ }
21
27
}
22
28
return (
23
29
this . dollarsComplete ( document , position ) ||
24
30
this . commands ( document , position ) ||
25
31
this . entities ( document , position , token , context ) ||
26
32
this . macro ( document , position , token , context ) ||
27
- this . constants ( document , position , token , context )
33
+ this . constants ( document , position , token , context ) ||
34
+ this . system ( document , position , token , context )
28
35
) ;
29
36
}
30
37
@@ -249,4 +256,43 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
249
256
250
257
return null ;
251
258
}
259
+
260
+ system (
261
+ document : vscode . TextDocument ,
262
+ position : vscode . Position ,
263
+ token : vscode . CancellationToken ,
264
+ context : vscode . CompletionContext
265
+ ) {
266
+ let range = document . getWordRangeAtPosition ( position , / \$ s y s t e m ( \. \b \w + \b ) ? ( \. \b \w + \b ) ? \. / i) ;
267
+ let text = range ? document . getText ( range ) : '' ;
268
+ let [ , className , method ] = text . match ( / \$ s y s t e m ( \. \b \w + \b ) ? ( \. \b \w + \b ) ? \. / i) ;
269
+
270
+ const api = new AtelierAPI ( ) ;
271
+ if ( ! className ) {
272
+ return api . getDocNames ( { category : 'CLS' , filter : '%SYSTEM.' } ) . then ( data => {
273
+ return data . result . content
274
+ . map ( el => el . name )
275
+ . filter ( el => el . startsWith ( '%SYSTEM.' ) )
276
+ . map ( el => el . split ( '.' ) [ 1 ] )
277
+ . filter ( onlyUnique )
278
+ . map ( el => ( {
279
+ label : el ,
280
+ kind : vscode . CompletionItemKind . Class
281
+ } ) ) ;
282
+ } ) ;
283
+ } else {
284
+ return api . actionIndex ( [ `%SYSTEM${ className } .cls` ] ) . then ( data => {
285
+ return data . result . content . pop ( ) . content . methods
286
+ . filter ( el => ! el . private )
287
+ . filter ( el => ! el . internal )
288
+ . map ( el => ( {
289
+ label : el . name ,
290
+ kind : vscode . CompletionItemKind . Method ,
291
+ insertText : new vscode . SnippetString ( `${ el . name } ($0)` ) ,
292
+ documentation : el . desc . length ? new vscode . MarkdownString ( el . desc . join ( '' ) ) : null ,
293
+ } ) ) ;
294
+ } ) ;
295
+ }
296
+ return null ;
297
+ }
252
298
}
0 commit comments