Skip to content

Commit

Permalink
Add auto refactor preference for moving files in workspace mode
Browse files Browse the repository at this point in the history
  • Loading branch information
d2c7727d4668 committed Jul 8, 2024
1 parent 4320739 commit a94c151
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
"default": false,
"description": "If enabled, the generated file location will be `workspaceRoot/.cph` . If disabled (default), the save location will follow `cph.general.saveLocation`"
},
"cph.general.autoRefactor": {
"type": "boolean",
"default": true,
"description": "Automatically change the file path in the .prob file to new file path when the file is renamed or moved. Works only in workspace mode."
},
"cph.general.timeOut": {
"type": "number",
"default": 3000,
Expand Down Expand Up @@ -369,4 +374,4 @@
"type": "git",
"url": "https://github.com/agrawal-d/competitive-programming-helper/"
}
}
}
3 changes: 3 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const getSaveLocationPref = (): string => {
return pref;
};

export const getAutoRefactorPref = (): boolean =>
getPreference('general.autoRefactor');

export const getWorkspaceModePref = (): boolean =>
getPreference('general.workspaceMode');

Expand Down
4 changes: 2 additions & 2 deletions src/refactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
saveProblem,
} from './parser';
import fs from 'fs';
import { getAutoRefactorPref } from './preferences';

export const editorRename = (e: vscode.FileRenameEvent) => {
const workspaceRoot = getWorkspaceRoot();
if (!workspaceRoot) return;
if (!getAutoRefactorPref() || !getWorkspaceRoot()) return;
e.files.forEach((file) => {
const oldProblemPath = getProbSaveLocation(file.oldUri.fsPath);
const problem = getProblemFromProbPath(oldProblemPath);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as vscode from 'vscode';
export type prefSection =
| 'general.saveLocation'
| 'general.workspaceMode'
| 'general.autoRefactor'
| 'general.defaultLanguage'
| 'general.timeOut'
| 'general.hideStderrorWhenCompiledOK'
Expand Down

0 comments on commit a94c151

Please sign in to comment.