From 45ca03caed8362ba201895845a74db5471c8761b Mon Sep 17 00:00:00 2001 From: Mark W Date: Fri, 30 Aug 2024 17:32:24 +0200 Subject: [PATCH] Skip global functions for now, and don't create empty files --- README.md | 1 + annotation_branch_readme.md | 1 + src/LuaFileParser.php | 38 ++++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ad3892962..2db696b69 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Generated annotations are limited to - "methods" for a given mixin - inheritence through `CreateFromMixins` - Global functions + - for now disabled, using Ketho's annotations, and including the wow source as workspace libraries is probably better prerequisites to run this yourself: - PHP 8.3 diff --git a/annotation_branch_readme.md b/annotation_branch_readme.md index 52fde6bcc..331128706 100644 --- a/annotation_branch_readme.md +++ b/annotation_branch_readme.md @@ -23,3 +23,4 @@ Generated annotations are limited to - "methods" for a given mixin - inheritence through `CreateFromMixins` - Global functions + - for now disabled, using Ketho's annotations, and including the wow source as workspace libraries is probably better diff --git a/src/LuaFileParser.php b/src/LuaFileParser.php index 94af18ab3..09c2ec364 100644 --- a/src/LuaFileParser.php +++ b/src/LuaFileParser.php @@ -109,29 +109,33 @@ private function extractFunctions(string $fileContents, array $mixins, ?string $ } } - // e.g. `function SomeGlobal_Function()` - $functionDeclarations = []; - preg_match_all( - '/^function ([A-Za-z0-9_]+)\s*\([^)]*\)/m', - $fileContents, - $functionDeclarations, - PREG_SET_ORDER | PREG_OFFSET_CAPTURE, - ); - foreach ($functionDeclarations as $match) { - $data = $match[0][0] . ' end'; - if ($linkPrefix) { - $lineNr = $this->getLineNrFromOffset($fileContents, $match[0][1]); - $data = "--- [Source]($linkPrefix#L$lineNr)\n$data"; - } - - $functions[$match[1][0]] = $data; - } +// disabled for now +// // e.g. `function SomeGlobal_Function()` +// $functionDeclarations = []; +// preg_match_all( +// '/^function ([A-Za-z0-9_]+)\s*\([^)]*\)/m', +// $fileContents, +// $functionDeclarations, +// PREG_SET_ORDER | PREG_OFFSET_CAPTURE, +// ); +// foreach ($functionDeclarations as $match) { +// $data = $match[0][0] . ' end'; +// if ($linkPrefix) { +// $lineNr = $this->getLineNrFromOffset($fileContents, $match[0][1]); +// $data = "--- [Source]($linkPrefix#L$lineNr)\n$data"; +// } +// +// $functions[$match[1][0]] = $data; +// } return $functions; } public function writeAnnotationsToFile(string $filename, string $outDir, string $prefixToStrip): void { + if (empty($this->mixins[$filename]) && empty($this->functions[$filename])) { + return; + } $data = "--- @meta _\n\n"; $data .= $this->mixins[$filename] ? implode("\n\n", $this->mixins[$filename]) . "\n\n" : ''; $data .= $this->functions[$filename] ? implode("\n\n", $this->functions[$filename]) . "\n" : '';