diff --git a/package.json b/package.json index 5671f7bb..deeec9d8 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "valet", "sail", "lando", + "ddev", "local" ], "enumItemLabels": [ @@ -86,6 +87,7 @@ "Valet", "Sail", "Lando", + "DDEV", "Local" ], "markdownEnumDescriptions": [ @@ -94,6 +96,7 @@ "Auto detect PHP version Valet is using for the project.", "Sail", "Lando", + "DDEV", "Use PHP installed on the local machine." ], "default": "auto", diff --git a/src/features/route.ts b/src/features/route.ts index 4766c239..87b954a2 100644 --- a/src/features/route.ts +++ b/src/features/route.ts @@ -11,6 +11,7 @@ import { contract, facade } from "@src/support/util"; import { AutocompleteParsingResult } from "@src/types"; import * as vscode from "vscode"; import { FeatureTag, HoverProvider, LinkProvider } from ".."; +import { usesRelativePaths, resolveProjectPath } from "@src/support/php"; const toFind: FeatureTag = [ { method: ["route", "signedRoute", "to_route"] }, @@ -86,9 +87,13 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => { return null; } + const filename = usesRelativePaths() + ? resolveProjectPath(route.filename) + : route.filename + return new vscode.DocumentLink( detectedRange(param), - vscode.Uri.file(route.filename).with({ + vscode.Uri.file(filename).with({ fragment: `L${route.line ?? 0}`, }), ); diff --git a/src/support/config.ts b/src/support/config.ts index 37e19781..9818022c 100644 --- a/src/support/config.ts +++ b/src/support/config.ts @@ -29,5 +29,6 @@ export type PhpEnvironment = | "herd" | "valet" | "sail" - | "local" - | "lando"; + | "lando" + | "ddev" + | "local"; diff --git a/src/support/php.ts b/src/support/php.ts index 6d1fd349..27689116 100644 --- a/src/support/php.ts +++ b/src/support/php.ts @@ -30,7 +30,7 @@ let hasVendor = projectPathExists("vendor/autoload.php"); const hasBootstrap = projectPathExists("bootstrap/app.php"); let phpEnvKey: PhpEnvironment | null = null; -const phpEnvsThatUseRelativePaths: PhpEnvironment[] = ["sail", "lando"]; +const phpEnvsThatUseRelativePaths: PhpEnvironment[] = ["sail", "lando", "ddev"]; export const initVendorWatchers = () => { // fs.readdirSync(internalVendorPath()).forEach((file) => { @@ -119,6 +119,11 @@ const getPhpCommand = (): string => { command: "lando php", }); + options.set("ddev", { + check: "ddev php -r 'echo PHP_BINARY;'", + command: "ddev php", + }); + options.set("local", { check: "php -r 'echo PHP_BINARY;'", command: `"{binaryPath}"`, @@ -354,3 +359,16 @@ export const artisan = (command: string): Promise => { ); }); }; + +export const usesRelativePaths = () => phpEnvsThatUseRelativePaths.includes(phpEnvKey!) + +export const resolveProjectPath = (path: string) => { + switch (phpEnvKey) { + case 'ddev': + const relativePath = path.replace(new RegExp('^/var/www/html/'),'') + return projectPath(relativePath) + + default: + return path; + } +} \ No newline at end of file