completions
This commit is contained in:
parent
407019ba88
commit
d9a20c6304
@ -9,27 +9,24 @@ export class GamelibCompleter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix.length === 0) {
|
|
||||||
callback(null, []);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const functions = Object.getOwnPropertyNames(Gamelib.prototype);
|
const functions = Object.getOwnPropertyNames(Gamelib.prototype);
|
||||||
|
|
||||||
const wordList = functions.map((func) => {
|
const wordList = functions
|
||||||
const definition = Gamelib.prototype[func].toString();
|
.filter((func) => func !== "constructor")
|
||||||
const signature = definition.slice(0, definition.indexOf(")") + 1);
|
.map((func) => {
|
||||||
|
const definition = Gamelib.prototype[func].toString();
|
||||||
|
const signature = definition.slice(0, definition.indexOf(")") + 1);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"name": func,
|
name: func,
|
||||||
"value": func,
|
value: func,
|
||||||
"snippet": func + "($0)",
|
snippet: func + "($0)",
|
||||||
"caption": func,
|
caption: func,
|
||||||
"score": 300,
|
score: 0,
|
||||||
"meta": "function",
|
meta: "function",
|
||||||
"docHTML": signature,
|
docHTML: signature,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback(null, wordList);
|
return callback(null, wordList);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import { CodeStopper } from "./code_stopper.js";
|
|||||||
import { Vermiparous } from "./vermiparous.js";
|
import { Vermiparous } from "./vermiparous.js";
|
||||||
import { promptUpload } from "./prompt_upload.js";
|
import { promptUpload } from "./prompt_upload.js";
|
||||||
import { GamelibCompleter } from "./gamelib_completer.js";
|
import { GamelibCompleter } from "./gamelib_completer.js";
|
||||||
|
import { TextCompleter } from "./text_completer.js";
|
||||||
|
|
||||||
const playgroundConsole = new PlaygroundConsole(
|
const playgroundConsole = new PlaygroundConsole(
|
||||||
document.querySelector("#console-code"),
|
document.querySelector("#console-code"),
|
||||||
@ -41,9 +42,12 @@ editor.session.setMode("ace/mode/javascript");
|
|||||||
|
|
||||||
const langTools = ace.require("ace/ext/language_tools");
|
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);
|
editor.setValue(sessionStorage.getItem("code") ?? editor.getValue(), -1);
|
||||||
|
|
||||||
|
88
src/text_completer.js
Normal file
88
src/text_completer.js
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user