Skip to content

Commit bea4142

Browse files
Merge pull request #327 from laravel/file-watchers
Improve file watcher performance
2 parents b7155f4 + 2876c3a commit bea4142

27 files changed

+292
-142
lines changed

php-templates/inertia.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?php
22

3-
$config = config('inertia.testing', []);
4-
5-
$pagePaths = collect($config['page_paths'] ?? [])->map(function($path) {
6-
return LaravelVsCode::relativePath($path);
7-
});
8-
9-
$config['page_paths'] = $pagePaths->toArray();
10-
11-
echo json_encode($config);
3+
echo json_encode([
4+
...config('inertia.testing', []),
5+
'page_paths' => collect(config('inertia.testing.page_paths', []))->map(fn($path) => LaravelVsCode::relativePath($path))->toArray(),
6+
]);

php-templates/routes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@ protected function getRouteReflection(\Illuminate\Routing\Route $route)
9393
}
9494
};
9595

96-
9796
echo $routes->all()->toJson();

php-templates/translations.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
public $emptyParams = [];
1414

15+
public $directoriesToWatch = [];
16+
1517
public function all()
1618
{
1719
$final = [];
@@ -82,6 +84,10 @@ public function collectFromPath(string $path, ?string $namespace = null)
8284
return [];
8385
}
8486

87+
if (!LaravelVsCode::isVendor($realPath)) {
88+
$this->directoriesToWatch[] = LaravelVsCode::relativePath($realPath);
89+
}
90+
8591
return array_map(
8692
fn($file) => $this->fromFile($file, $path, $namespace),
8793
\Illuminate\Support\Facades\File::allFiles($realPath),
@@ -342,4 +348,5 @@ protected function fromPhpFile($file, $path, $namespace)
342348
'paths' => array_keys($translator->paths),
343349
'values' => array_keys($translator->values),
344350
'params' => array_map(fn($p) => json_decode($p, true), array_keys($translator->paramResults)),
351+
'to_watch' => $translator->directoriesToWatch,
345352
]);

src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from "vscode";
44

55
import os from "os";
66
import { LanguageClient } from "vscode-languageclient/node";
7+
import { bladeSpacer } from "./blade/bladeSpacer";
78
import { initClient } from "./blade/client";
89
import { CodeActionProvider } from "./codeAction/codeActionProvider";
910
import { openFileCommand } from "./commands";
@@ -19,13 +20,15 @@ import { hoverProviders } from "./hover/HoverProvider";
1920
import { linkProviders } from "./link/LinkProvider";
2021
import { configAffected } from "./support/config";
2122
import { collectDebugInfo } from "./support/debug";
22-
import { disposeWatchers } from "./support/fileWatcher";
23+
import {
24+
disposeWatchers,
25+
watchForComposerChanges,
26+
} from "./support/fileWatcher";
2327
import { info } from "./support/logger";
2428
import { setParserBinaryPath } from "./support/parser";
2529
import { clearDefaultPhpCommand, initVendorWatchers } from "./support/php";
2630
import { hasWorkspace, projectPathExists } from "./support/project";
2731
import { cleanUpTemp } from "./support/util";
28-
import { bladeSpacer } from "./blade/bladeSpacer";
2932

3033
let client: LanguageClient;
3134

@@ -65,6 +68,7 @@ export function activate(context: vscode.ExtensionContext) {
6568
const LANGUAGES = [{ scheme: "file", language: "php" }, ...BLADE_LANGUAGES];
6669

6770
initVendorWatchers();
71+
watchForComposerChanges();
6872
setParserBinaryPath(context);
6973

7074
const TRIGGER_CHARACTERS = ["'", '"'];

src/repositories/appBinding.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ type AppBindingItem = {
99
};
1010
};
1111

12-
export const getAppBindings = repository<AppBindingItem>(
13-
() => {
12+
export const getAppBindings = repository<AppBindingItem>({
13+
load: () => {
1414
return runInLaravel<AppBindingItem>(template("app"), "App Bindings");
1515
},
16-
"app/Providers/{,*,**/*}.php",
17-
{},
18-
);
16+
pattern: "app/Providers/{,*,**/*}.php",
17+
itemsDefault: {},
18+
});

src/repositories/asset.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ const getFilesInDirectory = (dir: string, depth: number = 0): Item[] => {
5353
.flat();
5454
};
5555

56-
export const getAssets = repository<Item[]>(
57-
() =>
56+
export const getAssets = repository<Item[]>({
57+
load: () =>
5858
new Promise((resolve, reject) => {
5959
try {
6060
resolve(getFilesInDirectory("public"));
6161
} catch (exception) {
6262
reject(exception);
6363
}
6464
}),
65-
"public/**/*",
66-
[],
67-
);
65+
pattern: "public/**/*",
66+
itemsDefault: [],
67+
reloadOnComposerChanges: false,
68+
});

src/repositories/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const load = () => {
1616
return runInLaravel<AuthItems>(template("auth"), "Auth Data");
1717
};
1818

19-
export const getPolicies = repository<AuthItems>(
19+
export const getPolicies = repository<AuthItems>({
2020
load,
21-
"app/Providers/{,*,**/*}.php",
22-
{},
23-
);
21+
pattern: "app/Providers/{,*,**/*}.php",
22+
itemsDefault: {},
23+
});

src/repositories/bladeComponents.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inAppDirs } from "@src/support/fileWatcher";
12
import { runInLaravel, template } from "@src/support/php";
23
import { repository } from ".";
34

@@ -20,12 +21,15 @@ const load = () => {
2021
return runInLaravel<BladeComponents>(template("bladeComponents"));
2122
};
2223

23-
export const getBladeComponents = repository<BladeComponents>(
24+
export const getBladeComponents = repository<BladeComponents>({
2425
load,
25-
["{,**/}{view,views}/{*,**/*}", "app/View/Components/{,*,**/*}.php"],
26-
{
26+
pattern: [
27+
inAppDirs("{,**/}{view,views}/{*,**/*}"),
28+
"app/View/Components/{,*,**/*}.php",
29+
],
30+
itemsDefault: {
2731
components: {},
2832
prefixes: [],
2933
},
30-
["create", "delete"],
31-
);
34+
fileWatcherEvents: ["create", "delete"],
35+
});

src/repositories/configs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { repository } from ".";
22
import { Config } from "..";
33
import { runInLaravel, template } from "../support/php";
44

5-
export const getConfigs = repository<Config[]>(
6-
() => {
5+
export const getConfigs = repository<Config[]>({
6+
load: () => {
77
return runInLaravel<Config[]>(template("configs"), "Configs").then(
88
(result) =>
99
result.map((item) => {
@@ -16,6 +16,6 @@ export const getConfigs = repository<Config[]>(
1616
}),
1717
);
1818
},
19-
["config/{,*,**/*}.php", ".env"],
20-
[],
21-
);
19+
pattern: ["config/{,*,**/*}.php", ".env"],
20+
itemsDefault: [],
21+
});

src/repositories/controllers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inAppDirs } from "@src/support/fileWatcher";
12
import * as fs from "fs";
23
import { repository } from ".";
34
import { projectPath } from "../support/project";
@@ -74,12 +75,12 @@ const collectControllers = (path: string): string[] => {
7475
return [...controllers];
7576
};
7677

77-
export const getControllers = repository<string[]>(
78-
() => {
78+
export const getControllers = repository<string[]>({
79+
load: () => {
7980
return new Promise((resolve) => {
8081
resolve(load());
8182
});
8283
},
83-
"{,**/}{Controllers}{.php,/*.php,/**/*.php}",
84-
[],
85-
);
84+
pattern: inAppDirs("{,**/}{Controllers}{.php,/*.php,/**/*.php}"),
85+
itemsDefault: [],
86+
});

0 commit comments

Comments
 (0)