Skip to content

Support ${workspaceFolder} variable / workspace-relative paths in psalm.phpExecutablePath and psalm.psalmScriptPath #294

Open

Description

@Qsppl

Problem

psalm.phpExecutablePath is passed directly to fs.access(path, X_OK) without any variable substitution or workspace-relative resolution:

https://github.com/psalm/psalm-vscode-plugin/blob/master/src/LanguageServer.ts

const phpExecutablePath = this.configurationService.get('phpExecutablePath');
// ...
await access(phpExecutablePath, constants.X_OK);

This means:

  1. ${workspaceFolder}/.vscode/dev-container-proxy.sh fails - the string is passed verbatim, so the check looks for a literal ${workspaceFolder} directory.
  2. .vscode/dev-container-proxy.sh fails - relative paths are resolved against the VS Code process cwd, not the workspace root, so access(…, X_OK) reports "is not executable".

Only an absolute path works today, which is a problem for teams that commit .vscode/settings.json to the repo - every developer has a different absolute path. My use case is a proxy script (.vscode/dev-container-proxy.sh) that forwards php into a Docker container so that the Psalm language server runs with the same PHP version and Composer lockfile as CI. Other common cases: monorepos, devcontainers, Nix/direnv setups.

Reproduction

  1. In a workspace, create .vscode/php-proxy.sh and chmod +x it.
    #!/bin/bash
    php "$@"
  2. In .vscode/settings.json:
    { "psalm.phpExecutablePath": "${workspaceFolder}/.vscode/php-proxy.sh" }
  3. Reload VSCode window >>> Psalm can not start: ${workspaceFolder}/.vscode/php-proxy.sh is not executable
  4. Change to:
    { "psalm.phpExecutablePath": ".vscode/php-proxy.sh" }
  5. Reload VSCode window >>> Psalm can not start: .vscode/php-proxy.sh is not executable

Expected behaviour

psalm.phpExecutablePath (and psalm.psalmScriptPath) should:

  1. Expand ${workspaceFolder} (and ideally other standard VS Code variables like ${workspaceFolder:name}, ${env:VAR}, ${userHome}) — consistent with how most VS Code extensions behave (e.g. php.executablePath, phpstan.binCommand in phpstan-vscode).
  2. Resolve relative paths against workspace.workspaceFolders[0].uri.fsPath, not the VS Code process cwd.

Suggested fix

A small helper applied to both settings before fs.access:

import { workspace } from 'vscode';
import * as path from 'path';

function resolveWorkspacePath(raw: string): string {
    const folder = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '';
    const expanded = raw
        .replace(/\$\{workspaceFolder\}/g, folder)
        .replace(/\$\{userHome\}/g, os.homedir())
        .replace(/\$\{env:([^}]+)\}/g, (_, v) => process.env[v] ?? '');
    return path.isAbsolute(expanded) ? expanded : path.join(folder, expanded);
}

Happy to open a PR if the direction is acceptable.

Environment

  • Extension: getpsalm.psalm-vscode-plugin (current master)
  • VS Code: 1.116.0 (Universal)
  • OS: macOS 14 (Darwin 23.6.0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions