Skip to content
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
28 changes: 2 additions & 26 deletions src/commands/artisan.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from "vscode";

import { Command } from "@src/artisan/types";
import { buildArtisanCommand } from "@src/artisan/builder";
import { Command } from "@src/artisan/types";
import { getPathFromOutput } from "@src/support/artisan";
import { artisan, runArtisanInTerminal } from "@src/support/php";
import { getWorkspaceFolders } from "@src/support/project";
import { getWorkspaceFolder } from "@src/support/workspace";
import { openFileCommand } from ".";

export const runArtisanCommand = async (
Expand Down Expand Up @@ -102,27 +102,3 @@ const openGeneratedFile = (

openFileCommand(vscode.Uri.file(outputPath), 1, 1);
};

const getWorkspaceFolder = (
uri: vscode.Uri | undefined,
): vscode.WorkspaceFolder | undefined => {
if (uri) {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);

if (workspaceFolder) {
return workspaceFolder;
}
}

if (vscode.window.activeTextEditor) {
const fileUri = vscode.window.activeTextEditor.document.uri;

const workspaceFolder = vscode.workspace.getWorkspaceFolder(fileUri);

if (workspaceFolder) {
return workspaceFolder;
}
}

return getWorkspaceFolders()?.[0];
};
11 changes: 3 additions & 8 deletions src/commands/pint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import {
statusBarSuccess,
statusBarWorking,
} from "@src/support/statusBar";
import { getWorkspaceFolder } from "@src/support/workspace";
import * as cp from "child_process";
import * as vscode from "vscode";
import { commandName } from ".";
import { config } from "../support/config";
import { showErrorPopup } from "../support/popup";
import {
getWorkspaceFolders,
projectPath,
projectPathExists,
} from "../support/project";
import { projectPath, projectPathExists } from "../support/project";

let debounceTimer: ReturnType<typeof setTimeout> | undefined;
let runningProcess: cp.ChildProcess | undefined;
Expand Down Expand Up @@ -123,9 +120,7 @@ export const runPintOnSave = (document: vscode.TextDocument) => {
}

if (
!document.uri.fsPath.startsWith(
getWorkspaceFolders()[0]?.uri?.fsPath || "",
)
!document.uri.fsPath.startsWith(getWorkspaceFolder()?.uri?.fsPath || "")
) {
return;
}
Expand Down
15 changes: 8 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import * as vscode from "vscode";

import os from "os";
import { LanguageClient } from "vscode-languageclient/node";
import {
registerArtisanCommands,
registerArtisanMakeCommands,
} from "./artisan/registry";
import { bladeSpacer } from "./blade/bladeSpacer";
import { initClient } from "./blade/client";
import { commandName, openFileCommand } from "./commands";
import { configureDockerEnvironment } from "./commands/configureDockerEnvironment";
import { generateNamespaceCommand } from "./commands/generateNamespace";
import { goToRouteCommand } from "./commands/goToRoute";
import {
Expand All @@ -30,6 +35,7 @@ import {
wrapSelectionCommand,
wrapWithHelperCommands,
} from "./commands/wrapWithHelper";
import { registerPestHelper } from "./features/pest";
import { configAffected } from "./support/config";
import { collectDebugInfo } from "./support/debug";
import {
Expand All @@ -44,14 +50,9 @@ import {
initPhp,
initVendorWatchers,
} from "./support/php";
import { hasWorkspace, projectPathExists } from "./support/project";
import { projectPathExists } from "./support/project";
import { cleanUpTemp } from "./support/util";
import {
registerArtisanCommands,
registerArtisanMakeCommands,
} from "./artisan/registry";
import { configureDockerEnvironment } from "./commands/configureDockerEnvironment";
import { registerPestHelper } from "./features/pest";
import { hasWorkspace } from "./support/workspace";
import { registerTestRunner } from "./test-runner";

let client: LanguageClient;
Expand Down
11 changes: 9 additions & 2 deletions src/features/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { detectedRange, detectInDoc } from "@src/support/parser";
import { wordMatchRegex } from "@src/support/patterns";
import { projectPath, relativePath } from "@src/support/project";
import { facade } from "@src/support/util";
import { getWorkspaceFolder } from "@src/support/workspace";
import { AutocompleteParsingResult } from "@src/types";
import fs from "fs";
import * as sysPath from "path";
Expand Down Expand Up @@ -156,9 +157,15 @@ export const codeActionProvider: CodeActionProviderFunction = async (
return [];
}

const workspace = getWorkspaceFolder(document.uri);

if (!workspace) {
return [];
}

const extension =
Object.values(getInertiaViews().items)[0].path.split(".").pop() ??
inertiaPageExtensions?.[0] ??
inertiaPageExtensions[workspace.name]?.[0] ??
"vue";

const mapping: Record<string, string> = {
Expand All @@ -167,7 +174,7 @@ export const codeActionProvider: CodeActionProviderFunction = async (
),
};

return (inertiaPagePaths ?? []).map((path) => {
return (inertiaPagePaths[workspace.name] ?? []).map((path) => {
const filepath = sysPath.join(path, `${missingFilename}.${extension}`);
const uri = vscode.Uri.file(projectPath(filepath));

Expand Down
36 changes: 24 additions & 12 deletions src/features/pest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import fs from "fs";
import path from "path";
import { config } from "@src/support/config";
import { loadAndWatch } from "@src/support/fileWatcher";
import { runInLaravel, template } from "@src/support/php";
import { projectPath } from "@src/support/project";
import { indent } from "@src/support/util";
import { getLaravelWorkspaceFolders } from "@src/support/workspace";
import fs from "fs";
import path from "path";
import * as vscode from "vscode";

export interface PestConfig {
uses: PestUse[];
Expand All @@ -27,18 +29,27 @@ export const registerPestHelper = () => {
return;
}

loadAndWatch(
() => {
runInLaravel<PestConfig | null>(template("pest"))
.then(writePestDocBlocks)
.catch(console.error);
},
"tests/**/*",
["create", "delete", "change"],
);
getLaravelWorkspaceFolders().forEach((workspaceFolder) => {
loadAndWatch(
(workspaceFolder: vscode.WorkspaceFolder) => {
runInLaravel<PestConfig | null>(
template("pest"),
workspaceFolder,
)
.then((pest) => writePestDocBlocks(pest, workspaceFolder))
.catch(console.error);
},
"tests/**/*",
["create", "delete", "change"],
workspaceFolder,
);
});
};

const writePestDocBlocks = (pest: PestConfig | null): void => {
const writePestDocBlocks = (
pest: PestConfig | null,
workspaceFolder: vscode.WorkspaceFolder,
): void => {
if (!pest || (!pest.uses.length && !pest.expectations.length)) {
return;
}
Expand All @@ -51,6 +62,7 @@ const writePestDocBlocks = (pest: PestConfig | null): void => {

const pestFilePath = projectPath(
config("pest.helperFilePath", "storage/framework/testing/_pest.php"),
workspaceFolder,
);

fs.mkdirSync(path.dirname(pestFilePath), { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion src/hover/HoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { hoverProvider as appBinding } from "@src/features/appBinding";
import { hoverProvider as auth } from "@src/features/auth";
import { hoverProvider as bladeComponent } from "@src/features/bladeComponent";
import { hoverProvider as livewireComponent } from "@src/features/livewireComponent";
import { hoverProvider as config } from "@src/features/config";
import { hoverProvider as env } from "@src/features/env";
import { hoverProvider as inertia } from "@src/features/inertia";
import { hoverProvider as livewireComponent } from "@src/features/livewireComponent";
import { hoverProvider as middleware } from "@src/features/middleware";
import { hoverProvider as mix } from "@src/features/mix";
import { hoverProvider as route } from "@src/features/route";
Expand Down
9 changes: 7 additions & 2 deletions src/repositories/appBinding.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as vscode from "vscode";
import { repository } from ".";
import { runInLaravel, template } from "../support/php";

Expand All @@ -10,8 +11,12 @@ type AppBindingItem = {
};

export const getAppBindings = repository<AppBindingItem>({
load: () => {
return runInLaravel<AppBindingItem>(template("app"), "App Bindings");
load: (workspaceFolder: vscode.WorkspaceFolder) => {
return runInLaravel<AppBindingItem>(
template("app"),
workspaceFolder,
"App Bindings",
);
},
pattern: "app/Providers/{,*,**/*}.php",
itemsDefault: {},
Expand Down
18 changes: 13 additions & 5 deletions src/repositories/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ interface Item {
uri: vscode.Uri;
}

const getFilesInDirectory = (dir: string, depth: number = 0): Item[] => {
let dirFullPath = projectPath(dir);
const getFilesInDirectory = (
dir: string,
workspaceFolder: vscode.WorkspaceFolder,
depth: number = 0,
): Item[] => {
let dirFullPath = projectPath(dir, workspaceFolder);

if (!fs.existsSync(dirFullPath)) {
return [];
Expand All @@ -28,7 +32,11 @@ const getFilesInDirectory = (dir: string, depth: number = 0): Item[] => {
let stat = fs.lstatSync(fullFilePath);

if (stat.isDirectory()) {
return getFilesInDirectory(shortFilePath, depth + 1);
return getFilesInDirectory(
shortFilePath,
workspaceFolder,
depth + 1,
);
}

if (
Expand All @@ -54,10 +62,10 @@ const getFilesInDirectory = (dir: string, depth: number = 0): Item[] => {
};

export const getAssets = repository<Item[]>({
load: () =>
load: (workspaceFolder: vscode.WorkspaceFolder) =>
new Promise((resolve, reject) => {
try {
resolve(getFilesInDirectory("public"));
resolve(getFilesInDirectory("public", workspaceFolder));
} catch (exception) {
reject(exception);
}
Expand Down
27 changes: 18 additions & 9 deletions src/repositories/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { internalVendorPath } from "@src/support/project";
import fs from "fs";
import * as vscode from "vscode";
import { repository } from ".";
import { runInLaravel, template } from "./../support/php";

Expand All @@ -17,7 +18,10 @@ export type AuthItem = {
model: string | null;
};

const writeAuthBlocks = (authenticatable: string | null) => {
const writeAuthBlocks = (
authenticatable: string | null,
workspaceFolder: vscode.WorkspaceFolder,
) => {
if (!authenticatable) {
return;
}
Expand Down Expand Up @@ -101,18 +105,23 @@ interface Auth
];

blocks.forEach((block) => {
fs.writeFileSync(internalVendorPath(block.file), block.content.trim());
fs.writeFileSync(
internalVendorPath(block.file, workspaceFolder),
block.content.trim(),
);
});
};

const load = () => {
return runInLaravel<AuthItems>(template("auth"), "Auth Data").then(
(result) => {
writeAuthBlocks(result.authenticatable);
const load = (workspaceFolder: vscode.WorkspaceFolder) => {
return runInLaravel<AuthItems>(
template("auth"),
workspaceFolder,
"Auth Data",
).then((result) => {
writeAuthBlocks(result.authenticatable, workspaceFolder);

return result;
},
);
return result;
});
};

export const getPolicies = repository<AuthItems>({
Expand Down
8 changes: 6 additions & 2 deletions src/repositories/bladeComponents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inAppDirs } from "@src/support/fileWatcher";
import { runInLaravel, template } from "@src/support/php";
import * as vscode from "vscode";
import { repository } from ".";

export interface BladeComponents {
Expand All @@ -19,8 +20,11 @@ export interface BladeComponents {
prefixes: string[];
}

const load = () => {
return runInLaravel<BladeComponents>(template("bladeComponents"));
const load = (workspaceFolder: vscode.WorkspaceFolder) => {
return runInLaravel<BladeComponents>(
template("bladeComponents"),
workspaceFolder,
);
};

export const getBladeComponents = repository<BladeComponents>({
Expand Down
Loading
Loading