Skip to content

Commit 64a3a97

Browse files
committed
$system completion
1 parent 58e9bf4 commit 64a3a97

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

providers/ObjectScriptCompletionItemProvider.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import systemFunctions = require('./completion/systemFunctions.json');
55
import systemVariables = require('./completion/systemVariables.json');
66
import structuredSystemVariables = require('./completion/structuredSystemVariables.json');
77
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';
910

1011
export class ObjectScriptCompletionItemProvider implements vscode.CompletionItemProvider {
1112
provideCompletionItems(
@@ -17,14 +18,20 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
1718
if (context.triggerKind === vscode.CompletionTriggerKind.TriggerCharacter) {
1819
if (context.triggerCharacter === '#')
1920
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, /\$system(\.\b\w+\b)?\./i)) {
23+
return this.system(document, position, token, context);
24+
}
25+
return this.entities(document, position, token, context);
26+
}
2127
}
2228
return (
2329
this.dollarsComplete(document, position) ||
2430
this.commands(document, position) ||
2531
this.entities(document, position, token, context) ||
2632
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)
2835
);
2936
}
3037

@@ -249,4 +256,43 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
249256

250257
return null;
251258
}
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, /\$system(\.\b\w+\b)?(\.\b\w+\b)?\./i);
267+
let text = range ? document.getText(range) : '';
268+
let [, className, method] = text.match(/\$system(\.\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+
}
252298
}

0 commit comments

Comments
 (0)