Skip to content

Commit

Permalink
Skip global functions for now, and don't create empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
Numynum committed Aug 30, 2024
1 parent 107eca9 commit 45ca03c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions annotation_branch_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 21 additions & 17 deletions src/LuaFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" : '';
Expand Down

0 comments on commit 45ca03c

Please sign in to comment.