Skip to content

Add ddev support #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"valet",
"sail",
"lando",
"ddev",
"local"
],
"enumItemLabels": [
Expand All @@ -86,6 +87,7 @@
"Valet",
"Sail",
"Lando",
"DDEV",
"Local"
],
"markdownEnumDescriptions": [
Expand All @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/features/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
Expand Down Expand Up @@ -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}`,
}),
);
Expand Down
5 changes: 3 additions & 2 deletions src/support/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export type PhpEnvironment =
| "herd"
| "valet"
| "sail"
| "local"
| "lando";
| "lando"
| "ddev"
| "local";
20 changes: 19 additions & 1 deletion src/support/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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}"`,
Expand Down Expand Up @@ -354,3 +359,16 @@ export const artisan = (command: string): Promise<string> => {
);
});
};

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;
}
}