Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an option to use existing files. #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@
"type": "boolean",
"default": true,
"description": "Automatically show the judge view when opening a file that has a problem associated with it"
},
"cph.general.useExistingFile": {
"type": "string",
"default": "",
"description": "If you enter an existing file name, the existing file will be used instead of creating a new file with the problem name."
}
}
}
Expand Down Expand Up @@ -350,18 +355,18 @@
"prettier": "3.1.0",
"ts-loader": "^9.5.1",
"typescript": "^5.3.2",
"webpack": "^5.89.0",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@vscode/extension-telemetry": "^0.9.0",
"python-shell": "^5.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-textarea-autosize": "^8.5.3",
"@vscode/extension-telemetry": "^0.9.0"
"react-textarea-autosize": "^8.5.3"
},
"repository": {
"type": "git",
"url": "https://github.com/agrawal-d/competitive-programming-helper/"
}
}
}
11 changes: 10 additions & 1 deletion src/companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useShortCodeForcesName,
getMenuChoices,
getDefaultLanguageTemplateFileLocation,
getUseExistingFilePref,
} from './preferences';
import { getProblemName } from './submit';
import { spawn } from 'child_process';
Expand Down Expand Up @@ -211,7 +212,15 @@ const handleNewProblem = async (problem: Problem) => {
const splitUrl = problem.url.split('/');
problem.name = splitUrl[splitUrl.length - 1];
}
const problemFileName = getProblemFileName(problem, extn);

let name: string;
const ExistingFile = getUseExistingFilePref();
if (ExistingFile != '') {
name = `${ExistingFile}.${extn}`;
} else {
name = getProblemFileName(problem, extn);
}
const problemFileName = name;
const srcPath = path.join(folder, problemFileName);

// Add fields absent in competitive companion.
Expand Down
3 changes: 3 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export const getGoArgsPref = (): string[] =>
export const getFirstTimePref = (): boolean =>
getPreference('general.firstTime') || 'true';

export const getUseExistingFilePref = (): string =>
getPreference('general.useExistingFile');

export const getDefaultLangPref = (): string | null => {
const pref = getPreference('general.defaultLanguage');
if (pref === 'none' || pref == ' ' || !pref) {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export type prefSection =
| 'language.haskell.Command'
| 'general.retainWebviewContext'
| 'general.autoShowJudge'
| 'general.defaultLanguageTemplateFileLocation';
| 'general.defaultLanguageTemplateFileLocation'
| 'general.useExistingFile';

export type Language = {
name: LangNames;
Expand Down