Skip to content

Commit c4feb94

Browse files
committed
feat: allow relative patterns in configPath
1 parent 28074a9 commit c4feb94

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
},
116116
"phpstan.configPath": {
117117
"type": "string",
118-
"description": "PHPStan config path"
118+
"description": "PHPStan config path",
119+
"default": "{phpstan.neon,phpstan.neon.dist}"
119120
},
120121
"phpstan.analysedDelay": {
121122
"type": "integer",

src/commands/findPHPStanConfigPath.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Ext } from "../extension";
2-
import { findPHPStanConfigPath as find } from "../utils/phpstan";
3-
import { isAbsolute, join } from "path";
2+
import { RelativePattern, workspace } from "vscode";
43

54
export default async function findPHPStanConfigPath(ext: Ext) {
65
const { settings, cwd } = ext;
7-
const configPath = settings.configPath
8-
? isAbsolute(settings.configPath)
9-
? settings.configPath
10-
: join(cwd, settings.configPath)
11-
: await find(ext.cwd);
12-
13-
if (!configPath) throw new Error(`Config path not found.`);
6+
const [configUri] = await workspace.findFiles(
7+
new RelativePattern(cwd, settings.configPath),
8+
null,
9+
1
10+
);
11+
if (!configUri) throw new Error(`Config path not found.`);
12+
const configPath = configUri.fsPath;
1413
ext.log({ tag: "configPath", message: configPath });
1514
return configPath;
1615
}

src/extension.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ export class Ext<
199199

200200
if (this.settings.configFileWatcher)
201201
this.fileWatchers.register(
202-
this.settings.configPath ??
203-
new RelativePattern(
204-
getWorkspacePath(),
205-
`{phpstan.neon,phpstan.neon.dist}`
206-
),
202+
new RelativePattern(getWorkspacePath(), this.settings.configPath),
207203
(uri, eventName) => {
208204
if (!this.store.fileWatcher.enabled) return;
209205
const path = sanitizeFsPath(uri.fsPath);

src/utils/phpstan.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { checkFile } from "./fs";
21
import { parseNeonFile } from "./neon";
32
import { resolvePath } from "./path";
4-
import { join } from "path";
53

64
export type PHPStanAnalyseResult = {
75
totals: {
@@ -49,18 +47,6 @@ export async function parsePHPStanConfigFile(
4947
return normalizePHPStanConfig(config, env.currentWorkingDirectory);
5048
}
5149

52-
export async function findPHPStanConfigPath(
53-
cwd: string
54-
): Promise<string | undefined> {
55-
const baseNames = ["phpstan.neon", "phpstan.neon.dist"];
56-
for (const basename of baseNames) {
57-
const path = join(cwd, basename);
58-
if (await checkFile(path)) {
59-
return path;
60-
}
61-
}
62-
}
63-
6450
export function normalizePHPStanConfig(
6551
config: PHPStanConfig,
6652
cwd: string

0 commit comments

Comments
 (0)