diff --git a/php-templates/routes.php b/php-templates/routes.php index a7790a66..834017a6 100644 --- a/php-templates/routes.php +++ b/php-templates/routes.php @@ -8,6 +8,15 @@ public function all() ->merge($this->getFolioRoutes()); } + protected function getRelativePath($path) + { + $basePath = base_path() . DIRECTORY_SEPARATOR; + if (str_starts_with($path, $basePath)) { + return substr($path, strlen($basePath)); + } + return $path; + } + protected function getFolioRoutes() { try { @@ -43,7 +52,7 @@ protected function getFolioRoute($route, $mountPaths) 'name' => $route['name'], 'action' => null, 'parameters' => [], - 'filename' => $path, + 'filename' => $this->getRelativePath($path), 'line' => 0, ]; } @@ -64,7 +73,7 @@ protected function getRoute(\Illuminate\Routing\Route $route) 'name' => $route->getName(), 'action' => $route->getActionName(), 'parameters' => $route->parameterNames(), - 'filename' => $reflection ? $reflection->getFileName() : null, + 'filename' => $reflection ? $this->getRelativePath($reflection->getFileName()) : null, 'line' => $reflection ? $reflection->getStartLine() : null, ]; } diff --git a/src/features/route.ts b/src/features/route.ts index 4766c239..2a71c13b 100644 --- a/src/features/route.ts +++ b/src/features/route.ts @@ -88,7 +88,7 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => { return new vscode.DocumentLink( detectedRange(param), - vscode.Uri.file(route.filename).with({ + vscode.Uri.file(projectPath(route.filename)).with({ fragment: `L${route.line ?? 0}`, }), ); diff --git a/src/templates/routes.ts b/src/templates/routes.ts index 284f39ed..ddee4e5e 100644 --- a/src/templates/routes.ts +++ b/src/templates/routes.ts @@ -8,6 +8,15 @@ $routes = new class { ->merge($this->getFolioRoutes()); } + protected function getRelativePath($path) + { + $basePath = base_path() . DIRECTORY_SEPARATOR; + if (str_starts_with($path, $basePath)) { + return substr($path, strlen($basePath)); + } + return $path; + } + protected function getFolioRoutes() { try { @@ -43,7 +52,7 @@ $routes = new class { 'name' => $route['name'], 'action' => null, 'parameters' => [], - 'filename' => $path, + 'filename' => $this->getRelativePath($path), 'line' => 0, ]; } @@ -64,7 +73,7 @@ $routes = new class { 'name' => $route->getName(), 'action' => $route->getActionName(), 'parameters' => $route->parameterNames(), - 'filename' => $reflection ? $reflection->getFileName() : null, + 'filename' => $reflection ? $this->getRelativePath($reflection->getFileName()) : null, 'line' => $reflection ? $reflection->getStartLine() : null, ]; }