Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class PHPCBF {

// ${workspaceRoot} is deprecated
if (this.executablePath.startsWith("${workspaceRoot}")) {
this.addRootPath("${workspaceRoot}");
this.addRootPath("${workspaceRoot}", configUri);
}
if (this.executablePath.startsWith("${workspaceFolder}")) {
this.addRootPath("${workspaceFolder}");
this.addRootPath("${workspaceFolder}", configUri);
}
if (this.executablePath.startsWith(".")) {
this.addRootPath(".");
this.addRootPath(".", configUri);
}
if (this.executablePath.startsWith("~")) {
this.executablePath = this.executablePath.replace(
Expand Down Expand Up @@ -226,16 +226,23 @@ class PHPCBF {
return promise;
}

addRootPath(prefix) {
const resources = [];
if (workspace.workspaceFolders) {
addRootPath(prefix, configUri) {
// Determine the workspace folder for the document being formatted.
// When configUri is provided, use that folder (correct for multi-root
// workspaces where each folder may have its own per-folder executablePath).
// Fall back to iterating all workspace folders when no URI is available
// (e.g. at extension activation before any document is formatted).
let resources = [];
if (configUri) {
resources = [configUri];
} else if (workspace.workspaceFolders) {
for (let wsFolder of workspace.workspaceFolders) {
resources.push(wsFolder.uri);
}
} else {
const editor = window.activeTextEditor;
if (editor) {
resources.push(editor.document.uri);
resources = [editor.document.uri];
}
}
for (let resource of resources) {
Expand All @@ -247,11 +254,9 @@ class PHPCBF {
prefix,
rootPath
);
fs.exists(tmpExecutablePath, exists => {
if (exists) {
this.executablePath = tmpExecutablePath;
}
});
if (fs.existsSync(tmpExecutablePath)) {
this.executablePath = tmpExecutablePath;
}
}
}
}
Expand Down