import { Gamelib } from "./gamelib.js"; export class GamelibCompleter { getCompletions(_editor, session, pos, prefix, callback) { // Check if user has written "lib." const line = session.doc["$lines"][pos.row].slice(0, pos.column); if (!line.match(/lib\.\w*$/)) { callback(null, []); return; } if (prefix.length === 0) { callback(null, []); return; } const functions = Object.getOwnPropertyNames(Gamelib.prototype); const wordList = functions.map((func) => { const definition = Gamelib.prototype[func].toString(); const signature = definition.slice(0, definition.indexOf(")") + 1); return { "name": func, "value": func, "snippet": func + "($0)", "caption": func, "score": 300, "meta": "function", "docHTML": signature, }; }); return callback(null, wordList); } }