Skip to content

Commit

Permalink
support some variables in config (fixes #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Ronde committed Jul 5, 2023
1 parent 923aa24 commit db2c982
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"items": {
"type": "string"
},
"description": "Extra commandline options to be passed to PHPStan"
"description": "Extra commandline options to be passed to PHPStan. Supports substituting ${workspaceFolder}"
},
"phpstan.enableStatusBar": {
"type": "boolean",
Expand Down
5 changes: 4 additions & 1 deletion server/src/lib/phpstan/configManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { replaceVariables } from '../variables';
import { showErrorOnce } from '../errorUtil';
import { getConfiguration } from '../config';
import type { ClassConfig } from './manager';
Expand Down Expand Up @@ -234,7 +235,9 @@ export class ConfigurationManager {
configFile
)
: null,
args: extensionConfig.options ?? [],
args: (extensionConfig.options ?? []).map((arg) =>
replaceVariables(arg, this._config)
),
memoryLimit: extensionConfig.memoryLimit,
...binConfig,
};
Expand Down
13 changes: 13 additions & 0 deletions server/src/lib/variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ClassConfig } from './phpstan/manager';

export function replaceVariables(str: string, config: ClassConfig): string {
return str.replace(/\${workspaceFolder}/g, () => {
const workspaceFolder = config.getWorkspaceFolder();
if (!workspaceFolder) {
throw new Error(
'workspaceFolder is not set but is used in a variable'
);
}
return workspaceFolder.fsPath;
});
}
3 changes: 2 additions & 1 deletion shared/commands/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const config = {
items: {
type: 'string',
},
description: 'Extra commandline options to be passed to PHPStan',
description:
'Extra commandline options to be passed to PHPStan. Supports substituting ${workspaceFolder}',
},
},
'phpstan.enableStatusBar': {
Expand Down

0 comments on commit db2c982

Please sign in to comment.