add parameters to locals

This commit is contained in:
Theis Pieter Hollebeek 2025-10-11 19:28:53 +02:00
parent c2a8875af3
commit ca8b713f94

View File

@ -56,7 +56,7 @@ const KEYWORDS = [
];
export class TextCompleter {
getCompletions(_editor, session, pos, prefix, callback) {
getCompletions(_editor, session, pos, _, callback) {
// Check if user has written "lib."
const line = session.doc["$lines"][pos.row].slice(0, pos.column);
if (line.match(/lib\.\w*$/)) {
@ -66,6 +66,41 @@ export class TextCompleter {
const locals = [];
for (let i = 0; i <= pos.row; ++i) {
const line = session.doc["$lines"][i].trim();
if (line.startsWith("const ") || line.startsWith("let ")) {
const [_, name] = line.match(/^\w+ (\w+)/);
locals.push(name);
continue;
}
if (line.startsWith("function ")) {
const lineNoFunction = line.slice("function ".length);
const [_, name] = lineNoFunction.match(/^\s*(\w+)/);
locals.push(name);
let local = "";
const start = lineNoFunction.indexOf(name) + name.length;
for (let i = start; i < lineNoFunction.length; ++i) {
if (lineNoFunction[i].trim() === "") {
continue;
}
const ch = lineNoFunction[i];
if (["{", "=", "}", "(", ")", "[", "]"].includes(ch)) {
continue;
}
if (ch === ",") {
locals.push(local);
local = "";
continue;
}
local += ch;
}
if (local.trim() !== "") {
locals.push(local);
}
continue;
}
}
const wordList = []
@ -74,7 +109,6 @@ export class TextCompleter {
value: word,
score: 0,
meta: "local",
docHTML: signature,
})))
.concat(KEYWORDS.map((word) => ({
name: word,