From 77235df31fc7c73d0713e26e0f3b7f96c04e6878 Mon Sep 17 00:00:00 2001 From: Reimar Date: Wed, 15 Oct 2025 14:45:36 +0200 Subject: [PATCH] add typescript linting --- index.html | 1 + src/index.js | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index ec7c3b7..b24bd62 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,7 @@ + diff --git a/src/index.js b/src/index.js index 5a2459e..a8e4454 100644 --- a/src/index.js +++ b/src/index.js @@ -6,8 +6,6 @@ import { CodeRunner } from "./code_runner.js"; import { AssetEditor } from "./asset_editor.js"; import { AssetProvider } from "./asset_provider.js"; import { Gamelib } from "./gamelib.js"; -import { GamelibCompleter } from "./gamelib_completer.js"; -import { TextCompleter } from "./text_completer.js"; import { ConsoleInput } from "./console_input.js"; import { ProjectSaveHandler } from "./project_save_handler.js"; @@ -15,18 +13,38 @@ const editor = ace.edit("editor"); editor.setTheme("ace/theme/gruvbox"); editor.session.setMode("ace/mode/javascript"); -const langTools = ace.require("ace/ext/language_tools"); - editor.setOptions({ enableBasicAutocompletion: true, enableLiveAutocompletion: true, copyWithEmptySelection: true, }); -langTools.setCompleters([new GamelibCompleter(), new TextCompleter()]); - editor.setValue(sessionStorage.getItem("code") ?? editor.getValue(), -1); +const languageProvider = LanguageProvider.fromCdn( + "https://www.unpkg.com/ace-linters@latest/build", + undefined, + { typescript: true }, +); +languageProvider.registerEditor(editor); +languageProvider.setGlobalOptions("typescript", { + extraLibs: { + "gamelib.js": { + content: await (await fetch("/src/gamelib.js")).text(), + version: 1, + }, + "karlkoder.js": { + content: ` + import { GamelibAdapter } from "./gamelib.js"; + declare global { + const karlkoder: { lib: () => GamelibAdapter } + } + `, + version: 1, + }, + }, +}); + const playgroundConsole = new PlaygroundConsole( document.querySelector("#console-code"), editor,