From dac13a4973ecd93dc5ad0e0c2c10aac071880ce7 Mon Sep 17 00:00:00 2001 From: Reimar Date: Tue, 14 Oct 2025 15:38:09 +0200 Subject: [PATCH] fix autocompletion for gamelib with adapter --- src/gamelib.js | 2 +- src/gamelib_completer.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gamelib.js b/src/gamelib.js index 8c107e7..8d2b138 100644 --- a/src/gamelib.js +++ b/src/gamelib.js @@ -134,7 +134,7 @@ export class Gamelib { } } -class GamelibAdapter { +export class GamelibAdapter { MouseButton = { Left: 0, Right: 1, diff --git a/src/gamelib_completer.js b/src/gamelib_completer.js index bba1307..7b9db10 100644 --- a/src/gamelib_completer.js +++ b/src/gamelib_completer.js @@ -1,4 +1,4 @@ -import { Gamelib } from "./gamelib.js"; +import { GamelibAdapter } from "./gamelib.js"; export class GamelibCompleter { getCompletions(_editor, session, pos, _prefix, callback) { @@ -9,21 +9,24 @@ export class GamelibCompleter { return; } - const functions = Object.getOwnPropertyNames(Gamelib.prototype); + const functions = Object.getOwnPropertyNames(GamelibAdapter.prototype); const wordList = functions .filter((func) => func !== "constructor") .map((func) => { - const definition = Gamelib.prototype[func].toString(); + const getter = GamelibAdapter.prototype.__lookupGetter__(func); + + const definition = getter?.name ?? GamelibAdapter.prototype[func].toString(); + const signature = definition.slice(0, definition.indexOf(")") + 1); return { name: func, value: func, - snippet: func + "($0)", + snippet: func + (getter ? "" : "($0)"), caption: func, score: 0, - meta: "function", + meta: getter ? "property" : "function", docHTML: signature, }; });