-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
31 lines (28 loc) · 1.2 KB
/
index.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
/* LookupAPI interface for both modules and export variables
* Lookup class interface: (? denoting optional)
* class LookupAgent {
* isNeeded(prefix: string, configs?: ConfigRetrieval): boolean;
* getList(prefix: string,
* filePath: string,
* configs: ConfigRetrieval): Promise<Suggestion[]>
* lookup() //method to be reused by other agents
* }
* Suggestion: https://github.com/atom/autocomplete-plus/wiki/Provider-API#suggestions
*/
class LookupApi {
constructor(filePath, lookups, configs, filterLookupsByText) {
this.filePath = filePath;
this.lookups = lookups;
this.configs = configs;
this.filterByText = filterLookupsByText;
}
filterList(agentFilter, lookupFilter, prefix) {
const relevantLookups = this.lookups.filter((lookup) => lookup.isNeeded(agentFilter, this.configs));
return relevantLookups.reduce((all, lookup) => {
return [...all,
lookup.getList(lookupFilter, this.filePath, this.configs)
.then(suggestions => this.filterByText(suggestions, lookup.massagePrefix(prefix)))];
}, []);
}
}
module.exports = LookupApi;