Skip to content

Commit

Permalink
TmpDir is also used for non-pro checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Ronde committed Jun 9, 2024
1 parent 84203c8 commit b51180d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ https://user-images.githubusercontent.com/5385012/188924277-c9392477-9bd6-40b1-9
- `phpstan.suppressTimeoutMessage` - whether to disable the error message when the check times out (defaults to `false`)
- `phpstan.paths` - path mapping that allows for rewriting paths. Can be useful when developing inside a docker container or over SSH. Unset by default. Example for making the extension work in a docker container: `{ "/path/to/hostFolder": "/path/in/dockerContainer" }`
- `phpstan.ignoreErrors` - An array of regular expressions to ignore in error messages. If you find the PHPStan process erroring often because of a warning that can be ignored, put the warning in here and it'll be ignored in the future.
- `phpstan.proTmpDir` - Path to the PHPStan Pro TMP directory. Defaults to PHPStan's default (which is `$TMPDIR/phpstan-fixer`)
- `phpstan.tmpDir` - Path to the PHPStan TMP directory. Defaults to PHPStan's default (which is `$TMPDIR/phpstan`)

### Customization

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@
"description": "Use PHPStan Pro under the hood (if you have a license)",
"default": false
},
"phpstan.proTmpDir": {
"phpstan.tmpDir": {
"type": "string",
"description": "Path to the PHPStan Pro TMP directory. Defaults to PHPStan's default (which is /tmp/phpstan-fixer)"
"description": "Path to the PHPStan TMP directory. Defaults to PHPStan's default (which is /tmp/phpstan)"
},
"phpstan.checkValidity": {
"type": "boolean",
Expand Down
2 changes: 2 additions & 0 deletions server/src/lib/checkConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CheckConfig {
initialArgs: string[];
args: string[];
memoryLimit: string;
tmpDir: string;
}

export class ConfigurationManager {
Expand Down Expand Up @@ -243,6 +244,7 @@ export class ConfigurationManager {
binStr: binConfig.binCmd
? binConfig.binCmd
: ConfigurationManager.escapeFilePath(binConfig.binPath!),
tmpDir: extensionConfig.tmpDir,
...binConfig,
};
}
Expand Down
5 changes: 4 additions & 1 deletion server/src/lib/editorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export async function getEditorConfiguration(
replaceVariables(value, workspaceFolders),
])
),
proTmpDir: replaceVariables(editorConfig.proTmpDir, workspaceFolders),
tmpDir: replaceVariables(
editorConfig.tmpDir || editorConfig.proTmpDir || '',
workspaceFolders
),
rootDir: replaceVariables(editorConfig.rootDir, workspaceFolders),
options: editorConfig.options.map((option) =>
replaceVariables(option, workspaceFolders)
Expand Down
26 changes: 12 additions & 14 deletions server/src/lib/phpstan/pro/pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import type { ClassConfig } from '../../types';
import { ReturnResult } from '../../result';
import { PRO_PREFIX, log } from '../../log';
import * as path from 'path';
import * as os from 'os';

function getDefaultConfigDirPath(): string {
return path.join(os.tmpdir(), 'phpstan-fixer');
}

export async function launchPro(
classConfig: ClassConfig,
Expand All @@ -24,7 +19,7 @@ export async function launchPro(
}) => void
): Promise<ReturnResult<PHPStanProProcess, string>> {
const settings = await getEditorConfiguration(classConfig);
const tmpPath = settings.proTmpDir || getDefaultConfigDirPath();
const tmpPath = settings.tmpDir;

const launchConfig =
await ConfigurationManager.collectConfiguration(classConfig);
Expand All @@ -37,14 +32,20 @@ export async function launchPro(
launchConfig,
false
);
const env = { ...process.env };
const configuration: Record<string, unknown> = {
binStr,
args: [...args, '--watch'],
};
if (tmpPath) {
env.TMPDIR = tmpPath;
configuration['tmpDir'] = tmpPath;
}
await log(
classConfig.connection,
PRO_PREFIX,
'Spawning PHPStan Pro with the following configuration: ',
JSON.stringify({
binStr,
args: [...args, '--watch'],
})
JSON.stringify(configuration)
);
const procSpawner = new ProcessSpawner(classConfig.connection);
const proc = await procSpawner.spawnWithRobustTimeout(
Expand All @@ -55,10 +56,7 @@ export async function launchPro(
...SPAWN_ARGS,
cwd: launchConfig.cwd,
encoding: 'utf-8',
env: {
...process.env,
TMPDIR: tmpPath,
},
env: env,
}
);

Expand Down
17 changes: 13 additions & 4 deletions server/src/lib/phpstan/processRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,22 @@ export class PHPStanRunner implements AsyncDisposable {
checkConfig,
withProgress
);

const env = { ...process.env };
const configuration: Record<string, unknown> = {
binStr,
args: args,
};
if (checkConfig.tmpDir) {
env.TMPDIR = checkConfig.tmpDir;
configuration['tmpDir'] = checkConfig.tmpDir;
}

await log(
this._classConfig.connection,
checkPrefix(check),
'Spawning PHPStan with the following configuration: ',
JSON.stringify({
binStr,
args: args,
})
JSON.stringify(configuration)
);
const phpstan =
await this._classConfig.procSpawner.spawnWithRobustTimeout(
Expand All @@ -195,6 +203,7 @@ export class PHPStanRunner implements AsyncDisposable {
...SPAWN_ARGS,
cwd: checkConfig.cwd,
encoding: 'utf-8',
env: env,
}
);

Expand Down
4 changes: 2 additions & 2 deletions shared/commands/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ export const config = {
default: false,
},
},
'phpstan.proTmpDir': {
'phpstan.tmpDir': {
jsonDefinition: {
type: 'string',
description:
"Path to the PHPStan Pro TMP directory. Defaults to PHPStan's default (which is /tmp/phpstan-fixer)",
"Path to the PHPStan TMP directory. Defaults to PHPStan's default (which is /tmp/phpstan)",
},
},
'phpstan.checkValidity': {
Expand Down
4 changes: 3 additions & 1 deletion shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const CONFIG_KEYS = [
'ignoreErrors',
'suppressWorkspaceMessage',
'pro',
'proTmpDir',
'tmpDir',
'checkValidity',
] as const;
// Ideally we'd use `satisifies` here but the tooling (prettier & eslint) don't seem to support it yet.
Expand All @@ -36,4 +36,6 @@ export type ConfigSettings = Omit<
'phpstan.ignoreErrors'
> & {
'phpstan.ignoreErrors': (string | RegExp)[];
// Legacy setting
'phpstan.proTmpDir'?: string;
};

0 comments on commit b51180d

Please sign in to comment.