From d9a20c6304d8da50494dd912e5c7f8abda76329e Mon Sep 17 00:00:00 2001 From: Theis Pieter Hollebeek Date: Sat, 11 Oct 2025 18:38:12 +0200 Subject: [PATCH] completions --- src/gamelib_completer.js | 33 +++++++-------- src/index.js | 8 +++- src/text_completer.js | 88 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 src/text_completer.js diff --git a/src/gamelib_completer.js b/src/gamelib_completer.js index 5f68a71..964d076 100644 --- a/src/gamelib_completer.js +++ b/src/gamelib_completer.js @@ -9,27 +9,24 @@ export class GamelibCompleter { 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); + const wordList = functions + .filter((func) => func !== "constructor") + .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 { + name: func, + value: func, + snippet: func + "($0)", + caption: func, + score: 0, + meta: "function", + docHTML: signature, + }; + }); return callback(null, wordList); } diff --git a/src/index.js b/src/index.js index 1161024..d73a5e3 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import { CodeStopper } from "./code_stopper.js"; import { Vermiparous } from "./vermiparous.js"; import { promptUpload } from "./prompt_upload.js"; import { GamelibCompleter } from "./gamelib_completer.js"; +import { TextCompleter } from "./text_completer.js"; const playgroundConsole = new PlaygroundConsole( document.querySelector("#console-code"), @@ -41,9 +42,12 @@ editor.session.setMode("ace/mode/javascript"); const langTools = ace.require("ace/ext/language_tools"); -editor.setOptions({ enableBasicAutocompletion: true, enableLiveAutocompletion: true }); +editor.setOptions({ + enableBasicAutocompletion: true, + enableLiveAutocompletion: true, +}); -langTools.addCompleter(new GamelibCompleter()); +langTools.setCompleters([new GamelibCompleter(), new TextCompleter()]); editor.setValue(sessionStorage.getItem("code") ?? editor.getValue(), -1); diff --git a/src/text_completer.js b/src/text_completer.js new file mode 100644 index 0000000..9fde3b3 --- /dev/null +++ b/src/text_completer.js @@ -0,0 +1,88 @@ +/*REMEMBER 2 add KARLKODER + LIB :-)*/ + +const KEYWORDS = [ + "Array", + "ArrayBuffer", + "BigInt", + "Blob", + "CaretPosition", + "Date", + "Error", + "FormData", + "Headers", + "Infinity", + "Int8Array", + "JSON", + "Map", + "Math", + "NaN", + "Number", + "Object", + "Promise", + "ReadableStream", + "RegExp", + "Request", + "Response", + "Set", + "String", + "Symbol", + "TextDecoder", + "TextEncoder", + "URL", + "Uint8Array", + "WebSocket", + "Worker", + "WritableStream", + "alert", + "atob", + "blur", + "btoa", + "crypto", + "decodeURI", + "decodeURIComponent", + "encodeURI", + "encodeURIComponent", + "fetch", + "isFinite", + "isNaN", + "length", + "localStorage", + "navigator", + "parseFloat", + "parseInt", + "sessionStorage", + "undefined", + "window", +]; + +export class TextCompleter { + 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; + } + + const locals = []; + for (let i = 0; i <= pos.row; ++i) { + } + + const wordList = [] + .concat(locals.map((word) => ({ + name: word, + value: word, + score: 0, + meta: "local", + docHTML: signature, + }))) + .concat(KEYWORDS.map((word) => ({ + name: word, + value: word, + score: 0, + meta: "keyword", + }))); + + return callback(null, wordList); + } +}