From be45f5522249d25cb2ac886aa5515171338aaf86 Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 16 Jun 2025 21:32:40 -0400 Subject: [PATCH] More work on making intellisense work --- Integration.code-workspace.tpl.json | 3 ++- build.py | 10 +++++++--- luprex/Makefile | 6 +++--- luprex/add-compile-commands.py | 28 ++++++++++++++++------------ luprex/cpp/core/drivenengine.cpp | 3 ++- luprex/cpp/core/eng-malloc.hpp | 2 -- luprex/cpp/core/enginewrapper.hpp | 3 +++ luprex/cpp/core/world-core.cpp | 2 +- luprex/cpp/wrap/wrap-sstream.hpp | 3 +-- 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Integration.code-workspace.tpl.json b/Integration.code-workspace.tpl.json index 4db1795f..d8fd8a5f 100644 --- a/Integration.code-workspace.tpl.json +++ b/Integration.code-workspace.tpl.json @@ -41,10 +41,11 @@ "C_Cpp.intelliSenseEngine": "disabled", "clangd.path": "/usr/bin/clangd-15", "clangd.arguments": [ + "--query-driver=/usr/bin/g++", "--compile-commands-dir=[INTEGRATION]/.vscode", "--header-insertion=never" ], - "C_Cpp.autocomplete": "Disabled" + "C_Cpp.autocomplete": "disabled" }, "extensions": { "recommendations": [ diff --git a/build.py b/build.py index 0307095d..6c02b580 100755 --- a/build.py +++ b/build.py @@ -263,10 +263,14 @@ def build_intellisense_database_for_clangd(force): create_tarfile(f"{INTEGRATION}/Intermediate", "*.rsp", f"{INTEGRATION}/rsp_files.tgz") create_tarfile(f"{UNREALENGINE}/Engine", "*.rsp", f"{UNREALENGINE}/rsp_files.tgz") try: - shell(INTEGRATION, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex IntegrationEditor {OS} DebugGame {INTEGRATION}/Integration.uproject -mode=GenerateClangDatabase -OutputDir={UNREALENGINE}/.vscode") + Path(f"{INTEGRATION}/.vscode/compile_commands.json").unlink(missing_ok=True) + shell(INTEGRATION, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex IntegrationEditor {OS} DebugGame {INTEGRATION}/Integration.uproject -mode=GenerateClangDatabase -OutputDir={INTEGRATION}/.vscode") shell(UNREALENGINE, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex UnrealEditor {OS} DebugGame -mode=GenerateClangDatabase -OutputDir={UNREALENGINE}/.vscode") - shell(INTEGRATION, f"cat {UNREALENGINE}/.vscode/compile_commands.json >> {INTEGRATION}/.vscode/compile_commands.json") - shell(INTEGRATION, f"cat {INTEGRATION}/luprex/build/{OS}/compile_commands.json >> {INTEGRATION}/.vscode/compile_commands.json") + cc1 = json.loads(Path(f"{INTEGRATION}/.vscode/compile_commands.json").read_text()) + cc2 = json.loads(Path(f"{INTEGRATION}/luprex/build/{OS}/compile_commands.json").read_text()) + cc3 = json.loads(Path(f"{UNREALENGINE}/.vscode/compile_commands.json").read_text()) + cc = cc1 + cc2 + cc3 + Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(cc, indent=2)) except Exception as e: error = e else: diff --git a/luprex/Makefile b/luprex/Makefile index 95bb03d2..26a07a09 100644 --- a/luprex/Makefile +++ b/luprex/Makefile @@ -34,7 +34,7 @@ ifeq "$(OS)" "Linux" LINKEXE:=g++ -Wall $(OPT) -std=c++20 -export-dynamic -o MAKEDEPS:=true LIBS:=-L./ext/openssl-3.0.1/lib/linux -lssl -lcrypto -ldl - CCJSON="build/$(OS)/compile_commands.json" + CCJSON:=build/$(OS)/compile_commands.json FLAGS_ERIS:=-DLUA_USE_APICHECK -DLUA_USE_POSIX FLAGS_CORE:=-I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -I./ext @@ -60,7 +60,7 @@ ifeq "$(OS)" "Windows" LINKEXE:=CL $(OPT) /std:c++20 /EHsc /nologo /Fe: MAKEDEPS:=g++ -Wall -std=c++20 -MMD -E -o LIBS:=ext/openssl-3.1.0/lib/visual/libcrypto.lib ext/openssl-3.1.0/lib/visual/libssl.lib ws2_32.lib crypt32.lib cryptui.lib user32.lib advapi32.lib - CCJSON="build/$(OS)/compile_commands.json" + CCJSON:=build/$(OS)/compile_commands.json FLAGS_ERIS:=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL FLAGS_CORE:=-I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -I./ext @@ -132,7 +132,7 @@ build/$(OS)/drv/%.obj: cpp/drv/%.cpp build/$(OS)/DIRECTORY $(COMPILE) $@ $(FLAGS_DRV) $< $(CCJSON): Makefile add-compile-commands.py - rm -rf $(CCJSON) + echo "[]" > $(CCJSON) python3 ./add-compile-commands.py "$(CCJSON)" "$(COMPILE)" "$(FLAGS_ERIS)" "build/$(OS)/eris/FILE.obj" "ext/eris-master/src/FILE.c" $(BASE_ERIS) python3 ./add-compile-commands.py "$(CCJSON)" "$(COMPILE)" "$(FLAGS_CORE)" "build/$(OS)/cpp/FILE.obj" "cpp/core/FILE.cpp" $(BASE_CORE) python3 ./add-compile-commands.py "$(CCJSON)" "$(COMPILE)" "$(FLAGS_DRV)" "build/$(OS)/drv/FILE.obj" "cpp/drv/FILE.cpp" $(BASE_DRV) diff --git a/luprex/add-compile-commands.py b/luprex/add-compile-commands.py index 1eca4507..d52e5d5a 100644 --- a/luprex/add-compile-commands.py +++ b/luprex/add-compile-commands.py @@ -1,23 +1,27 @@ -import sys, os +import sys, os, json +from pathlib import Path LUPREXDIR=os.path.dirname(os.path.abspath(sys.argv[0])) -JSON=sys.argv[1] +JSONFILE=sys.argv[1] COMPILE=sys.argv[2] FLAGS=sys.argv[3] OBJPAT=sys.argv[4] CPAT=sys.argv[5] OBJECTS=sys.argv[6:] -with open(JSON, "a") as cc: - for base in OBJECTS: - obj = LUPREXDIR + "/" + OBJPAT.replace("FILE", base) - file = LUPREXDIR + "/" + CPAT.replace("FILE", base) - flags = FLAGS.replace("-I./", f"-I{LUPREXDIR}/") - cc.write('{\n') - cc.write(f' "file" : "{file}",\n') - cc.write(f' "command" : "{COMPILE} {obj} {flags} {file}",\n') - cc.write(f' "directory" : "{LUPREXDIR}"\n') - cc.write('}\n') + +JSON = json.loads(Path(JSONFILE).read_text()) + +for base in OBJECTS: + obj = LUPREXDIR + "/" + OBJPAT.replace("FILE", base) + file = LUPREXDIR + "/" + CPAT.replace("FILE", base) + flags = FLAGS.replace("-I./", f"-I{LUPREXDIR}/") + command = f"{COMPILE} {obj} {flags} {file}" + JSON.append({"file": file, "command": command, "directory": LUPREXDIR }) + +Path(JSONFILE).write_text(json.dumps(JSON, indent=4)) + + diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 525df564..a212a2bf 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -219,7 +219,7 @@ enum DrvAction { PLAY_RELEASE, }; -inline static const char *action_string(DrvAction act) { +[[maybe_unused]] inline static const char *action_string(DrvAction act) { switch(act) { case PLAY_INITIALIZE: return "PLAY_INITIALIZE"; case PLAY_CLEAR_NEW_OUTGOING: return "PLAY_CLEAR_NEW_OUTGOING"; @@ -233,6 +233,7 @@ inline static const char *action_string(DrvAction act) { default: return "unknown"; } } + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // diff --git a/luprex/cpp/core/eng-malloc.hpp b/luprex/cpp/core/eng-malloc.hpp index 61c0be21..7b285fea 100644 --- a/luprex/cpp/core/eng-malloc.hpp +++ b/luprex/cpp/core/eng-malloc.hpp @@ -169,7 +169,6 @@ namespace eng { void *operator new(size_t size) { assert(false && "not supposed to 'new' this class"); - return NULL; } void operator delete(void *p, size_t size) @@ -180,7 +179,6 @@ namespace eng { void *operator new[](size_t size) { assert(false && "not supposed to 'new' this class"); - return NULL; } void operator delete[](void *p, size_t size) diff --git a/luprex/cpp/core/enginewrapper.hpp b/luprex/cpp/core/enginewrapper.hpp index 09d288f9..965d919e 100644 --- a/luprex/cpp/core/enginewrapper.hpp +++ b/luprex/cpp/core/enginewrapper.hpp @@ -15,6 +15,9 @@ #ifndef ENGINEWRAPPER_H #define ENGINEWRAPPER_H +#include +#include + #define DRV_MAX_CHAN 256 #define DRV_MAX_LISTEN_PORTS 256 #define DRV_ERRMSG_SIZE 8192 diff --git a/luprex/cpp/core/world-core.cpp b/luprex/cpp/core/world-core.cpp index f322cdcd..dcc5de9d 100644 --- a/luprex/cpp/core/world-core.cpp +++ b/luprex/cpp/core/world-core.cpp @@ -687,7 +687,7 @@ HttpServerResponse World::http_serve(const HttpParser &request) { } // Get the name of the desired function. - std::string_view orig_fn = request.first_path_component("index"); + eng::string orig_fn = request.first_path_component("index"); eng::string lua_fn = HttpParser::to_lua_identifier(orig_fn); if (lua_fn.empty()) { response.fail(404, util::ss("cannot convert to lua function name: ", orig_fn)); diff --git a/luprex/cpp/wrap/wrap-sstream.hpp b/luprex/cpp/wrap/wrap-sstream.hpp index eb60b0ee..e20fd6ae 100644 --- a/luprex/cpp/wrap/wrap-sstream.hpp +++ b/luprex/cpp/wrap/wrap-sstream.hpp @@ -9,8 +9,7 @@ namespace eng { template> class basic_ostringstream : public std::basic_ostringstream>, public eng::opnew { - using underlying = std::basic_ostringstream>; - using underlying::basic_ostringstream; + using std::basic_ostringstream>::basic_ostringstream; }; //template> //using basic_stringbuf = std::basic_stringbuf>;