From cfed918d7132000c0c47f1594fcbd2c9616b07d6 Mon Sep 17 00:00:00 2001 From: Andrew Aitken-Fincham Date: Thu, 17 Dec 2020 23:35:32 +1300 Subject: [PATCH] mangle paths and such to get source code links back --- conf/doctum.php | 4 +-- src/Parser/SilverStripeNodeVisitor.php | 1 + .../SilverStripeClassReflection.php | 15 +++++++++++ src/SilverStripeProject.php | 25 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/SilverStripeProject.php diff --git a/conf/doctum.php b/conf/doctum.php index 21fdf84..1477582 100644 --- a/conf/doctum.php +++ b/conf/doctum.php @@ -2,12 +2,12 @@ use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; -use Doctum\Project; use Doctum\Doctum; use SilverStripe\ApiDocs\Data\ApiJsonStore; use SilverStripe\ApiDocs\Data\Config; use SilverStripe\ApiDocs\Inspections\RecipeFinder; use SilverStripe\ApiDocs\Inspections\RecipeVersionCollection; +use SilverStripe\ApiDocs\SilverStripeProject; use SilverStripe\ApiDocs\Twig\NavigationExtension; // Get config @@ -76,7 +76,7 @@ // Override project unset($doctum['project']); $doctum['project'] = function ($sc) { - $project = new Project($sc['store'], $sc['_versions'], array( + $project = new SilverStripeProject($sc['store'], $sc['_versions'], array( 'build_dir' => $sc['build_dir'], 'cache_dir' => $sc['cache_dir'], 'remote_repository' => $sc['remote_repository'], diff --git a/src/Parser/SilverStripeNodeVisitor.php b/src/Parser/SilverStripeNodeVisitor.php index 0dd223a..bed55bc 100644 --- a/src/Parser/SilverStripeNodeVisitor.php +++ b/src/Parser/SilverStripeNodeVisitor.php @@ -21,6 +21,7 @@ protected function addClassOrInterface(ClassLikeNode $node) $class->setAliases($this->context->getAliases()); $class->setHash($this->context->getHash()); $class->setFile($this->context->getFile()); + $class->setRelativeFilePath($this->context->getFile()); $comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $class); $class->setDocComment($node->getDocComment()); diff --git a/src/Reflection/SilverStripeClassReflection.php b/src/Reflection/SilverStripeClassReflection.php index 2a2da64..0d15f50 100644 --- a/src/Reflection/SilverStripeClassReflection.php +++ b/src/Reflection/SilverStripeClassReflection.php @@ -4,6 +4,7 @@ use Doctum\Reflection\ClassReflection; use Doctum\Reflection\PropertyReflection; +use SilverStripe\ApiDocs\Data\Config; class SilverStripeClassReflection extends ClassReflection { @@ -28,4 +29,18 @@ public function getConfigs() { return $this->configs; } + + public function getSourcePath($line = null) + { + $config = Config::getConfig(); + $realPackagePath = realpath(Config::configPath($config['paths']['packages'])); + $realRelativeFilePath = realpath($this->relativeFilePath); + $filePath = substr($realRelativeFilePath, strlen($realPackagePath) + 1); + $parts = explode('/', $filePath); + $package = "{$parts[0]}/{$parts[1]}"; + $this->project->setRemoteRepository($config['packages'][$package]['repository']); + $relativePathFromPackage = substr($filePath, strlen($package)); + + return $this->project->getViewSourceUrl($relativePathFromPackage, $line); + } } diff --git a/src/SilverStripeProject.php b/src/SilverStripeProject.php new file mode 100644 index 0000000..b8609b3 --- /dev/null +++ b/src/SilverStripeProject.php @@ -0,0 +1,25 @@ +config['remote_repository'] = new GitHubRemoteRepository( + $remoteRepositoryName, + Config::getConfig()['paths']['packages'] . "/{$remoteRepositoryName}" + ); + } +}