Skip to content

Commit 2463ac8

Browse files
committed
macros suggestion
1 parent 9c45e1b commit 2463ac8

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- \$SYSTEM suggestion by Classes from %SYSTEM
99
- Import and compile folder or file by context menu in File explorer
1010
- Server Explorer, now possible to open any other namespace
11+
- Macros suggestion
1112

1213
## [0.7.10]
1314

api/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,11 @@ export class AtelierAPI {
245245
includes
246246
});
247247
}
248+
// v2+
249+
getmacrollist(docname: string, includes: string[]) {
250+
return this.request(2, 'POST', `${this.ns}/action/getmacrolist`, {
251+
docname,
252+
includes
253+
});
254+
}
248255
}

providers/ObjectScriptCompletionItemProvider.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
1717
): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
1818
if (context.triggerKind === vscode.CompletionTriggerKind.TriggerCharacter) {
1919
if (context.triggerCharacter === '#')
20-
return this.macro(document, position, token, context) || this.entities(document, position, token, context);
20+
return (
21+
this.macro(document, position, token, context) ||
22+
this.entities(document, position, token, context) ||
23+
null);
24+
if (context.triggerCharacter === '$')
25+
return this.macrolist(document, position, token, context);
2126
if (context.triggerCharacter === '.') {
2227
if (document.getWordRangeAtPosition(position, /\$system(\.\b\w+\b)?\./i)) {
2328
return this.system(document, position, token, context);
@@ -31,6 +36,7 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
3136
}
3237
let completions = (
3338
this.classes(document, position, token, context) ||
39+
this.macrolist(document, position, token, context) ||
3440
this.dollarsComplete(document, position) ||
3541
this.commands(document, position) ||
3642
this.entities(document, position, token, context) ||
@@ -65,12 +71,44 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
6571
label: '##super()',
6672
insertText: new vscode.SnippetString('##super($0)'),
6773
range
74+
},
75+
{
76+
label: '#dim',
77+
insertText: new vscode.SnippetString('#dim $1 As $2'),
78+
range
6879
}
6980
];
7081
}
7182
return null;
7283
}
7384

85+
macrolist(
86+
document: vscode.TextDocument,
87+
position: vscode.Position,
88+
token: vscode.CancellationToken,
89+
context: vscode.CompletionContext
90+
): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
91+
let range = document.getWordRangeAtPosition(position, /\${3}(\b\w[\w\d]*\b)?/);
92+
let text = range ? document.getText(range) : '';
93+
if (range) {
94+
let macro = text.toLowerCase().slice(3);
95+
let file = currentFile();
96+
let api = new AtelierAPI()
97+
return api.getmacrollist(file.name, [])
98+
.then(data => data.result.content.macros)
99+
.then(list => list.filter(el => el.toLowerCase().startsWith(macro)))
100+
.then(list => list.map(el => '$$$' + el))
101+
.then(list => list.map(el => ({
102+
label: el,
103+
// kind: vscode.CompletionItemKind.Constant,
104+
// insertText: el,
105+
range
106+
})))
107+
.then(data => { console.log(data); return data; })
108+
}
109+
return null
110+
}
111+
74112
commands(
75113
document: vscode.TextDocument,
76114
position: vscode.Position

0 commit comments

Comments
 (0)