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
18 changes: 18 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,32 @@ const TmpDir = os.tmpdir();

class PHPCBF {
constructor() {
// Tracks the last workspace-folder key for which settings were loaded.
// Cleared whenever configuration changes so the next format reloads.
this._lastSettingsKey = null;
this.loadSettings();
}

/** Invalidate the per-folder settings cache (call on config changes). */
clearSettingsCache() {
this._lastSettingsKey = null;
}

loadSettings(uri) {
// Use the provided URI (e.g. the document being formatted), fall back to
// the active editor, or null (global settings) if neither is available.
const configUri = uri ||
(window.activeTextEditor ? window.activeTextEditor.document.uri : null);

// Derive a stable key from the workspace folder so that repeated saves
// within the same folder (the common case) skip redundant config reads.
const folder = configUri ? workspace.getWorkspaceFolder(configUri) : null;
const settingsKey = folder ? folder.uri.toString() : '';
if (settingsKey !== '' && settingsKey === this._lastSettingsKey) {
return;
}
this._lastSettingsKey = settingsKey;

let config = workspace.getConfiguration("phpcbf", configUri);
if (!config.get("enable") === true) {
return;
Expand Down Expand Up @@ -287,6 +304,7 @@ exports.activate = context => {

context.subscriptions.push(
workspace.onDidChangeConfiguration(() => {
phpcbf.clearSettingsCache();
phpcbf.loadSettings();
})
);
Expand Down