-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletionProvider.js
66 lines (51 loc) · 1.71 KB
/
completionProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const vscode = require('vscode');
console.log("FindMe");
function getConverterNames(text) {
const regex = /Converter=([^,]+),/g;
const converterNames = [];
let match;
while ((match = regex.exec(text)) !== null) {
const converterName = match[1].trim();
if (!converterNames.includes(converterName)) {
converterNames.push(converterName);
}
}
return converterNames;
}
function provideCompletionItems(document, position) {
const range = document.getWordRangeAtPosition(position);
const start = range ? range.start : position;
const textBeforeCursor = document.getText(new vscode.Range(start.with(undefined, 0), position));
if (textBeforeCursor.includes("Converter=")) {
const suggestions = getSuggestions(converterDescriptions);
return suggestions.map(suggestion => new vscode.CompletionItem(suggestion));
}
return [];
}
function getSuggestions(descriptions) {
const converterNames = [];
descriptions.forEach(description => {
const converterName = getConverterNames(description);
converterNames.push(converterName);
});
return converterNames;
}
const converterDescriptions = [
"Converter=EnumEquals, Converts enum values",
"Converter=NumberToText, Converts numbers to text"
];
function activate(context) {
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
{ language: 'json' },
{
provideCompletionItems
},
'.'
)
);
}
module.exports = {
provideCompletionItems: provideCompletionItems
};
exports.activate = activate;